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.
16 # Unittest for yardstick.network_services.collector.subscriber
18 from __future__ import absolute_import
22 from yardstick.network_services.collector import subscriber
25 class MockVnfAprrox(object):
31 def collect_kpi(self):
33 'pkt_in_up_stream': 100,
34 'pkt_drop_up_stream': 5,
35 'pkt_in_down_stream': 50,
36 'pkt_drop_down_stream': 40
41 class CollectorTestCase(unittest.TestCase):
48 'plugins': {'abc': 12, 'def': 34},
59 self.ssh_patch = mock.patch('yardstick.network_services.nfvi.resource.ssh', autospec=True)
60 mock_ssh = self.ssh_patch.start()
61 mock_instance = mock.Mock()
62 mock_instance.execute.return_value = 0, '', ''
63 mock_ssh.AutoConnectSSH.from_node.return_value = mock_instance
64 self.collector = subscriber.Collector([vnf], self.NODES, self.TRAFFIC_PROFILE, 1800)
69 def test___init__(self, *_):
71 collector = subscriber.Collector([vnf], {}, {})
72 self.assertEqual(len(collector.vnfs), 1)
73 self.assertEqual(collector.traffic_profile, {})
75 def test___init___with_data(self, *_):
76 self.assertEqual(len(self.collector.vnfs), 1)
77 self.assertDictEqual(self.collector.traffic_profile, self.TRAFFIC_PROFILE)
78 self.assertEqual(len(self.collector.resource_profiles), 1)
80 def test___init___negative(self, *_):
83 def test_start(self, *_):
84 self.assertIsNone(self.collector.start())
86 def test_stop(self, *_):
87 self.assertIsNone(self.collector.stop())
89 def test_get_kpi(self, *_):
90 result = self.collector.get_kpi()
92 self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100)
93 self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5)
94 self.assertEqual(result["vnf__1"]["pkt_in_down_stream"], 50)
95 self.assertEqual(result["vnf__1"]["pkt_drop_down_stream"], 40)
96 self.assertIn('node2', result)