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):
50 'plugins': {'abc': 12, 'def': 34},
61 self.ssh_patch = mock.patch('yardstick.network_services.nfvi.resource.ssh', autospec=True)
62 mock_ssh = self.ssh_patch.start()
63 mock_instance = mock.Mock()
64 mock_instance.execute.return_value = 0, '', ''
65 mock_ssh.AutoConnectSSH.from_node.return_value = mock_instance
66 self.collector = subscriber.Collector([vnf], self.NODES, self.TRAFFIC_PROFILE, 1800)
71 def test___init__(self, *_):
73 collector = subscriber.Collector([vnf], {}, {})
74 self.assertEqual(len(collector.vnfs), 1)
75 self.assertEqual(collector.traffic_profile, {})
77 def test___init___with_data(self, *_):
78 self.assertEqual(len(self.collector.vnfs), 1)
79 self.assertDictEqual(self.collector.traffic_profile, self.TRAFFIC_PROFILE)
80 self.assertEqual(len(self.collector.resource_profiles), 1)
82 def test___init___negative(self, *_):
85 def test_start(self, *_):
86 self.assertIsNone(self.collector.start())
88 def test_stop(self, *_):
89 self.assertIsNone(self.collector.stop())
91 def test_get_kpi(self, *_):
92 result = self.collector.get_kpi()
94 self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100)
95 self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5)
96 self.assertEqual(result["vnf__1"]["pkt_in_down_stream"], 50)
97 self.assertEqual(result["vnf__1"]["pkt_drop_down_stream"], 40)
98 self.assertIn('node2', result)