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
22 class MockVnfAprrox(object):
28 def collect_kpi(self):
30 'pkt_in_up_stream': 100,
31 'pkt_drop_up_stream': 5,
32 'pkt_in_down_stream': 50,
33 'pkt_drop_down_stream': 40
38 class CollectorTestCase(unittest.TestCase):
45 'plugins': {'abc': 12, 'def': 34},
56 self.ssh_patch = mock.patch('yardstick.network_services.nfvi.resource.ssh', autospec=True)
57 mock_ssh = self.ssh_patch.start()
58 mock_instance = mock.Mock()
59 mock_instance.execute.return_value = 0, '', ''
60 mock_ssh.AutoConnectSSH.from_node.return_value = mock_instance
61 self.collector = subscriber.Collector([vnf], self.NODES, self.TRAFFIC_PROFILE, 1800)
66 def test___init__(self, *_):
68 collector = subscriber.Collector([vnf], {}, {})
69 self.assertEqual(len(collector.vnfs), 1)
70 self.assertEqual(collector.traffic_profile, {})
72 def test___init___with_data(self, *_):
73 self.assertEqual(len(self.collector.vnfs), 1)
74 self.assertDictEqual(self.collector.traffic_profile, self.TRAFFIC_PROFILE)
75 self.assertEqual(len(self.collector.resource_profiles), 1)
77 def test___init___negative(self, *_):
80 def test_start(self, *_):
81 with self.assertRaises(Exception):
82 self.collector.start()
84 def test_stop(self, *_):
85 self.assertIsNone(self.collector.stop())
87 def test_get_kpi(self, *_):
88 result = self.collector.get_kpi()
90 self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100)
91 self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5)
92 self.assertEqual(result["vnf__1"]["pkt_in_down_stream"], 50)
93 self.assertEqual(result["vnf__1"]["pkt_drop_down_stream"], 40)
94 self.assertIn('node2', result)