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):
41 NODES = {'context1': [{'name': 'node1',
44 'plugins': {'abc': 12, 'def': 34},
52 vnf.start_collect = mock.Mock()
53 vnf.stop_collect = mock.Mock()
54 self.ssh_patch = mock.patch.object(ssh, 'AutoConnectSSH')
55 mock_ssh = self.ssh_patch.start()
56 mock_instance = mock.Mock()
57 mock_instance.execute.return_value = 0, '', ''
58 mock_ssh.from_node.return_value = mock_instance
59 self.collector = subscriber.Collector([vnf], self.NODES)
64 def test___init__(self, *_):
66 collector = subscriber.Collector([vnf], self.NODES)
67 self.assertEqual(len(collector.vnfs), 1)
68 self.assertEqual(len(collector.nodes), 1)
70 def test_start(self, *_):
71 resource_profile = mock.MagicMock()
72 self.collector.resource_profiles = {'key': resource_profile}
73 self.collector.bin_path = 'path'
75 self.assertIsNone(self.collector.start())
76 for vnf in self.collector.vnfs:
77 vnf.start_collect.assert_called_once()
79 for resource_profile in self.collector.resource_profiles.values():
80 resource_profile.initiate_systemagent.assert_called_once_with('path')
81 resource_profile.start.assert_called_once()
82 resource_profile.amqp_process_for_nfvi_kpi.assert_called_once()
84 def test_stop(self, *_):
85 resource_profile = mock.MagicMock()
86 self.collector.resource_profiles = {'key': resource_profile}
88 self.assertIsNone(self.collector.stop())
89 for vnf in self.collector.vnfs:
90 vnf.stop_collect.assert_called_once()
92 for resource in self.collector.resource_profiles.values():
93 resource.stop.assert_called_once()
95 def test_get_kpi(self, *_):
96 result = self.collector.get_kpi()
98 self.assertEqual(2, len(result))
99 self.assertEqual(4, len(result["vnf__1"]))
100 self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100)
101 self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5)
102 self.assertEqual(result["vnf__1"]["pkt_in_down_stream"], 50)
103 self.assertEqual(result["vnf__1"]["pkt_drop_down_stream"], 40)