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