summaryrefslogtreecommitdiffstats
path: root/tests/unit/network_services
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2017-09-28 00:10:43 -0700
committerEdward MacGillivray <edward.s.macgillivray@intel.com>2017-10-02 16:26:26 -0700
commit0eccf0cb46496b4a0fc1865f2c2c40d226697853 (patch)
treeead6c52b041bce0caa15b36d49f5f92c18d4bf20 /tests/unit/network_services
parent77c7d358bc6a61e2a5c24c6056cc3e40561f27c7 (diff)
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 <ross.b.brattain@intel.com>
Diffstat (limited to 'tests/unit/network_services')
-rw-r--r--tests/unit/network_services/collector/test_subscriber.py88
-rw-r--r--tests/unit/network_services/nfvi/test_resource.py2
2 files changed, 59 insertions, 31 deletions
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"]