3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # Unittest for yardstick.network_services.collector.subscriber
20 from __future__ import absolute_import
24 from yardstick.network_services.collector import subscriber
27 class MockVnfAprrox(object):
33 def collect_kpi(self):
35 'pkt_in_up_stream': 100,
36 'pkt_drop_up_stream': 5,
37 'pkt_in_down_stream': 50,
38 'pkt_drop_down_stream': 40
43 class CollectorTestCase(unittest.TestCase):
49 'plugins': {'abc': 12, 'def': 34},
60 self.ssh_patch = mock.patch('yardstick.network_services.nfvi.resource.ssh', autospec=True)
61 mock_ssh = self.ssh_patch.start()
62 mock_instance = mock.Mock()
63 mock_instance.execute.return_value = 0, '', ''
64 mock_ssh.AutoConnectSSH.from_node.return_value = mock_instance
65 self.collector = subscriber.Collector([vnf], self.NODES, self.TRAFFIC_PROFILE, 1800)
70 def test___init__(self, *_):
72 collector = subscriber.Collector([vnf], {}, {})
73 self.assertEqual(len(collector.vnfs), 1)
74 self.assertEqual(collector.traffic_profile, {})
76 def test___init___with_data(self, *_):
77 self.assertEqual(len(self.collector.vnfs), 1)
78 self.assertDictEqual(self.collector.traffic_profile, self.TRAFFIC_PROFILE)
79 self.assertEqual(len(self.collector.resource_profiles), 1)
81 def test___init___negative(self, *_):
84 def test_start(self, *_):
85 self.assertIsNone(self.collector.start())
87 def test_stop(self, *_):
88 self.assertIsNone(self.collector.stop())
90 def test_get_kpi(self, *_):
91 result = self.collector.get_kpi()
93 self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100)
94 self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5)
95 self.assertEqual(result["vnf__1"]["pkt_in_down_stream"], 50)
96 self.assertEqual(result["vnf__1"]["pkt_drop_down_stream"], 40)
97 self.assertIn('node2', result)