From 6801867b535eacb87197acee026b6c243c86e94e Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Thu, 28 Sep 2017 00:10:43 -0700 Subject: add collectd resource node capability allow manually adding collectd nodes using Node context. if a node is present with a collectd config dict then we can create a ResourceProfile object for it and connect to collectd. example nodes: - name: compute_0 role: Compute ip: 1.1.1.1 user: root password: r00t collectd: interval: 5 plugins: ovs_stats: {} Change-Id: Ie0c00fdb58373206071daa1fb13faf175c4313e0 Signed-off-by: Ross Brattain --- .../network_services/collector/test_subscriber.py | 88 ++++++++++++++-------- tests/unit/network_services/nfvi/test_resource.py | 2 +- 2 files changed, 59 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/tests/unit/network_services/collector/test_subscriber.py b/tests/unit/network_services/collector/test_subscriber.py index 373f5dccf..260f0bb27 100644 --- a/tests/unit/network_services/collector/test_subscriber.py +++ b/tests/unit/network_services/collector/test_subscriber.py @@ -19,51 +19,79 @@ from __future__ import absolute_import import unittest +import mock from yardstick.network_services.collector import subscriber -class CollectorTestCase(unittest.TestCase): - - TRAFFIC_PROFILE = {} - VNFS = {} - - def setUp(self): - self.test_subscriber = subscriber.Collector(self.TRAFFIC_PROFILE, - self.VNFS) +class MockVnfAprrox(object): - def test_successful_init(self): + def __init__(self): + self.result = {} + self.name = "vnf__1" - self.assertEqual(self.test_subscriber.traffic_profile, {}) - self.assertEqual(self.test_subscriber.service, {}) + def collect_kpi(self): + self.result = { + 'pkt_in_up_stream': 100, + 'pkt_drop_up_stream': 5, + 'pkt_in_down_stream': 50, + 'pkt_drop_down_stream': 40 + } + return self.result - def test_unsuccessful_init(self): - pass - def test_start(self): - self.assertIsNone(self.test_subscriber.start()) +class CollectorTestCase(unittest.TestCase): - def test_stop(self): - self.assertIsNone(self.test_subscriber.stop()) + NODES = { + 'node1': {}, + 'node2': { + 'collectd': { + 'plugins': {'abc': 12, 'def': 34}, + 'interval': 987, + }, + }, + } + TRAFFIC_PROFILE = { + 'key1': 'value1', + } - def test_get_kpi(self): + def setUp(self): + vnf = MockVnfAprrox() + self.ssh_patch = mock.patch('yardstick.network_services.nfvi.resource.ssh', autospec=True) + mock_ssh = self.ssh_patch.start() + mock_instance = mock.Mock() + mock_instance.execute.return_value = 0, '', '' + mock_ssh.AutoConnectSSH.from_node.return_value = mock_instance + self.collector = subscriber.Collector([vnf], self.NODES, self.TRAFFIC_PROFILE, 1800) + + def tearDown(self): + self.ssh_patch.stop() + + def test___init__(self, *_): + vnf = MockVnfAprrox() + collector = subscriber.Collector([vnf], {}, {}) + self.assertEqual(len(collector.vnfs), 1) + self.assertEqual(collector.traffic_profile, {}) + + def test___init___with_data(self, *_): + self.assertEqual(len(self.collector.vnfs), 1) + self.assertDictEqual(self.collector.traffic_profile, self.TRAFFIC_PROFILE) + self.assertEqual(len(self.collector.resource_profiles), 1) + + def test___init___negative(self, *_): + pass - class VnfAprrox(object): - def __init__(self): - self.result = {} - self.name = "vnf__1" + def test_start(self, *_): + self.assertIsNone(self.collector.start()) - def collect_kpi(self): - self.result = {'pkt_in_up_stream': 100, - 'pkt_drop_up_stream': 5, - 'pkt_in_down_stream': 50, - 'pkt_drop_down_stream': 40} - return self.result + def test_stop(self, *_): + self.assertIsNone(self.collector.stop()) - vnf = VnfAprrox() - result = self.test_subscriber.get_kpi(vnf) + def test_get_kpi(self, *_): + result = self.collector.get_kpi() self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100) self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5) self.assertEqual(result["vnf__1"]["pkt_in_down_stream"], 50) self.assertEqual(result["vnf__1"]["pkt_drop_down_stream"], 40) + self.assertIn('node2', result) diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py index eba38c688..4fc6d7773 100644 --- a/tests/unit/network_services/nfvi/test_resource.py +++ b/tests/unit/network_services/nfvi/test_resource.py @@ -105,7 +105,7 @@ class TestResourceProfile(unittest.TestCase): def test_check_if_sa_running(self): self.assertEqual(self.resource_profile.check_if_sa_running("collectd"), - [True, {}]) + (True, {})) def test_get_cpu_data(self): reskey = ["", "cpufreq", "cpufreq-0"] -- cgit 1.2.3-korg