Adding 2 node ixia generic scale-out test case generation
[yardstick.git] / tests / unit / network_services / collector / test_subscriber.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016-2017 Intel Corporation
4 #
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
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 #
17
18 # Unittest for yardstick.network_services.collector.subscriber
19
20 from __future__ import absolute_import
21 import unittest
22 import mock
23
24 from yardstick.network_services.collector import subscriber
25
26
27 class MockVnfAprrox(object):
28
29     def __init__(self):
30         self.result = {}
31         self.name = "vnf__1"
32
33     def collect_kpi(self):
34         self.result = {
35             'pkt_in_up_stream': 100,
36             'pkt_drop_up_stream': 5,
37             'pkt_in_down_stream': 50,
38             'pkt_drop_down_stream': 40
39         }
40         return self.result
41
42
43 class CollectorTestCase(unittest.TestCase):
44
45     NODES = {
46         'node1': {},
47         'node2': {
48             'collectd': {
49                 'plugins': {'abc': 12, 'def': 34},
50                 'interval': 987,
51             },
52         },
53     }
54     TRAFFIC_PROFILE = {
55         'key1': 'value1',
56     }
57
58     def setUp(self):
59         vnf = MockVnfAprrox()
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)
66
67     def tearDown(self):
68         self.ssh_patch.stop()
69
70     def test___init__(self, *_):
71         vnf = MockVnfAprrox()
72         collector = subscriber.Collector([vnf], {}, {})
73         self.assertEqual(len(collector.vnfs), 1)
74         self.assertEqual(collector.traffic_profile, {})
75
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)
80
81     def test___init___negative(self, *_):
82         pass
83
84     def test_start(self, *_):
85         self.assertIsNone(self.collector.start())
86
87     def test_stop(self, *_):
88         self.assertIsNone(self.collector.stop())
89
90     def test_get_kpi(self, *_):
91         result = self.collector.get_kpi()
92
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)