1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 from yardstick.network_services.collector import subscriber
20 from yardstick import ssh
23 class MockVnfAprrox(object):
29 def collect_kpi(self):
31 'pkt_in_up_stream': 100,
32 'pkt_drop_up_stream': 5,
33 'pkt_in_down_stream': 50,
34 'pkt_drop_down_stream': 40
39 class CollectorTestCase(unittest.TestCase):
43 vnf.start_collect = mock.Mock()
44 vnf.stop_collect = mock.Mock()
45 self.ssh_patch = mock.patch.object(ssh, 'AutoConnectSSH')
46 mock_ssh = self.ssh_patch.start()
47 mock_instance = mock.Mock()
48 mock_instance.execute.return_value = 0, '', ''
49 mock_ssh.from_node.return_value = mock_instance
50 self.collector = subscriber.Collector([vnf])
55 def test___init__(self, *_):
57 collector = subscriber.Collector([vnf])
58 self.assertEqual(len(collector.vnfs), 1)
60 def test_start(self, *_):
61 self.assertIsNone(self.collector.start())
62 for vnf in self.collector.vnfs:
63 vnf.start_collect.assert_called_once()
65 def test_stop(self, *_):
66 self.assertIsNone(self.collector.stop())
67 for vnf in self.collector.vnfs:
68 vnf.stop_collect.assert_called_once()
70 def test_get_kpi(self, *_):
71 result = self.collector.get_kpi()
73 self.assertEqual(1, len(result))
74 self.assertEqual(4, len(result["vnf__1"]))
75 self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100)
76 self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5)
77 self.assertEqual(result["vnf__1"]["pkt_in_down_stream"], 50)
78 self.assertEqual(result["vnf__1"]["pkt_drop_down_stream"], 40)