aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorDeepak S <deepak.s@linux.intel.com>2017-06-20 14:24:26 -0700
committerRoss Brattain <ross.b.brattain@intel.com>2017-08-08 13:31:18 -0700
commitb3d72298b576651430121d6d36e1956fd6a689dc (patch)
treee3f6adf8d5567715be4d73a9a174724e42e8cce9 /tests/unit
parent5ce3b6f8c8b3217091e51a6041455738603d90b8 (diff)
Collectd
Change-Id: I15e4ac38b347a08350b71c68469e2793eeed92ab Signed-off-by: Deepak S <deepak.s@linux.intel.com> Signed-off-by: Edward MacGillivray <edward.s.macgillivray@intel.com> Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/network_services/nfvi/test_resource.py220
1 files changed, 209 insertions, 11 deletions
diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py
index e2640ac74..cb26fd085 100644
--- a/tests/unit/network_services/nfvi/test_resource.py
+++ b/tests/unit/network_services/nfvi/test_resource.py
@@ -92,9 +92,11 @@ class TestResourceProfile(unittest.TestCase):
mock.Mock(return_value=(0, {}, ""))
ssh.from_node.return_value = ssh_mock
+ mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface']
+ interfaces = \
+ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface']
self.resource_profile = \
- ResourceProfile(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0],
- [1, 2, 3])
+ ResourceProfile(mgmt, interfaces, [1, 2, 3])
def test___init__(self):
self.assertEqual(True, self.resource_profile.enable)
@@ -107,13 +109,13 @@ class TestResourceProfile(unittest.TestCase):
reskey = ["", "cpufreq", "cpufreq-0"]
value = "metric:10"
val = self.resource_profile.get_cpu_data(reskey, value)
- self.assertEqual(val, ['0', 'cpufreq', '10', 'metric'])
+ self.assertIsNotNone(val)
def test_get_cpu_data_error(self):
reskey = ["", "", ""]
value = "metric:10"
val = self.resource_profile.get_cpu_data(reskey, value)
- self.assertEqual(val, ['error', 'Invalid', ''])
+ self.assertEqual(val, ('error', 'Invalid', '', ''))
def test__start_collectd(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
@@ -121,32 +123,228 @@ class TestResourceProfile(unittest.TestCase):
ssh_mock.execute = \
mock.Mock(return_value=(0, "", ""))
ssh.from_node.return_value = ssh_mock
+ mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface']
+ interfaces = \
+ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface']
resource_profile = \
- ResourceProfile(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0],
- [1, 2, 3])
+ ResourceProfile(mgmt, interfaces, [1, 2, 3])
+ resource_profile._prepare_collectd_conf = mock.Mock()
self.assertIsNone(
resource_profile._start_collectd(ssh_mock, "/opt/nsb_bin"))
- def test_initiate_systemagent(self):
+ def test__prepare_collectd_conf_BM(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "", ""))
ssh.from_node.return_value = ssh_mock
+ mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface']
+ interfaces = \
+ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface']
resource_profile = \
- ResourceProfile(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0],
- [1, 2, 3])
+ ResourceProfile(mgmt, interfaces, [1, 2, 3])
+ resource_profile._provide_config_file = mock.Mock()
+ self.assertIsNone(
+ resource_profile._prepare_collectd_conf("/opt/nsb_bin"))
+
+ def test__prepare_collectd_conf_managed_ovs_dpdk(self):
+ with mock.patch("yardstick.ssh.SSH") as ssh:
+ ssh_mock = mock.Mock(autospec=ssh.SSH)
+ ssh_mock.execute = \
+ mock.Mock(return_value=(0, "", ""))
+ ssh.from_node.return_value = ssh_mock
+ mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface']
+ interfaces = \
+ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface']
+ resource_profile = \
+ ResourceProfile(mgmt, interfaces, [1, 2, 3])
+ resource_profile._provide_config_file = mock.Mock()
+ self.assertIsNone(
+ resource_profile._prepare_collectd_conf("/opt/nsb_bin"))
+
+ def test__prepare_collectd_conf_ovs_dpdk(self):
+ with mock.patch("yardstick.ssh.SSH") as ssh:
+ ssh_mock = mock.Mock(autospec=ssh.SSH)
+ ssh_mock.execute = \
+ mock.Mock(return_value=(0, "", ""))
+ ssh.from_node.return_value = ssh_mock
+ mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface']
+ interfaces = \
+ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface']
+ resource_profile = \
+ ResourceProfile(mgmt, interfaces, [1, 2, 3])
+ resource_profile._provide_config_file = mock.Mock()
+ self.assertIsNone(
+ resource_profile._prepare_collectd_conf("/opt/nsb_bin"))
+
+ def test__prepare_collectd_conf_managed_sriov(self):
+ with mock.patch("yardstick.ssh.SSH") as ssh:
+ ssh_mock = mock.Mock(autospec=ssh.SSH)
+ ssh_mock.execute = \
+ mock.Mock(return_value=(0, "", ""))
+ ssh.from_node.return_value = ssh_mock
+ mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface']
+ interfaces = \
+ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface']
+ resource_profile = \
+ ResourceProfile(mgmt, interfaces, [1, 2, 3])
+ resource_profile._provide_config_file = mock.Mock()
+ self.assertIsNone(
+ resource_profile._prepare_collectd_conf("/opt/nsb_bin"))
+
+ def test__prepare_collectd_conf_sriov(self):
+ with mock.patch("yardstick.ssh.SSH") as ssh:
+ ssh_mock = mock.Mock(autospec=ssh.SSH)
+ ssh_mock.execute = \
+ mock.Mock(return_value=(0, "", ""))
+ ssh.from_node.return_value = ssh_mock
+ mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface']
+ interfaces = \
+ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface']
+ resource_profile = \
+ ResourceProfile(mgmt, interfaces, [1, 2, 3])
+ resource_profile._provide_config_file = mock.Mock()
+ self.assertIsNone(
+ resource_profile._prepare_collectd_conf("/opt/nsb_bin"))
+
+ @mock.patch("yardstick.network_services.nfvi.resource.open")
+ @mock.patch("yardstick.network_services.nfvi.resource.tempfile")
+ @mock.patch("yardstick.network_services.nfvi.resource.os")
+ def test__provide_config_file(self, mock_open, mock_tempfile, mock_os):
+ with mock.patch("yardstick.ssh.SSH") as ssh:
+ ssh_mock = mock.Mock(autospec=ssh.SSH)
+ ssh_mock.execute = \
+ mock.Mock(return_value=(0, "", ""))
+ ssh.from_node.return_value = ssh_mock
+ mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface']
+ interfaces = \
+ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface']
+ resource_profile = \
+ ResourceProfile(mgmt, interfaces, [1, 2, 3])
+ resource_profile._prepare_collectd_conf = mock.Mock()
+ resource_profile.connection = ssh_mock
+ resource_profile.connection.put = \
+ mock.Mock(return_value=(0, "", ""))
+ mock_tempfile.mkstemp = mock.Mock(return_value=["test", ""])
+ self.assertIsNone(
+ resource_profile._provide_config_file("/opt/nsb_bin",
+ "collectd.cfg", {}))
+
+ @mock.patch("yardstick.network_services.nfvi.resource.open")
+ def test_initiate_systemagent(self, mock_open):
+ with mock.patch("yardstick.ssh.SSH") as ssh:
+ ssh_mock = mock.Mock(autospec=ssh.SSH)
+ ssh_mock.execute = \
+ mock.Mock(return_value=(0, "", ""))
+ ssh.from_node.return_value = ssh_mock
+ mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface']
+ interfaces = \
+ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface']
+ resource_profile = \
+ ResourceProfile(mgmt, interfaces, [1, 2, 3])
+ resource_profile._start_collectd = mock.Mock()
self.assertIsNone(
resource_profile.initiate_systemagent("/opt/nsb_bin"))
+ def test__parse_hugepages(self):
+ reskey = ["cpu", "cpuFreq"]
+ value = "timestamp:12345"
+ res = self.resource_profile.parse_hugepages(reskey, value)
+ self.assertEqual({'cpu/cpuFreq': '12345'}, res)
+
+ def test__parse_dpdkstat(self):
+ reskey = ["dpdk0", "0"]
+ value = "tx:12345"
+ res = self.resource_profile.parse_dpdkstat(reskey, value)
+ self.assertEqual({'dpdk0/0': '12345'}, res)
+
+ def test__parse_virt(self):
+ reskey = ["vm0", "cpu"]
+ value = "load:45"
+ res = self.resource_profile.parse_virt(reskey, value)
+ self.assertEqual({'vm0/cpu': '45'}, res)
+
+ def test__parse_ovs_stats(self):
+ reskey = ["ovs", "stats"]
+ value = "tx:45"
+ res = self.resource_profile.parse_ovs_stats(reskey, value)
+ self.assertEqual({'ovs/stats': '45'}, res)
+
def test_parse_collectd_result(self):
res = self.resource_profile.parse_collectd_result({}, [0, 1, 2])
- self.assertDictEqual(res, {'timestamp': '', 'cpu': {}, 'memory': {}})
+ expected_result = {'cpu': {}, 'dpdkstat': {}, 'hugepages': {},
+ 'memory': {}, 'ovs_stats': {}, 'timestamp': '',
+ 'virt': {}}
+ self.assertDictEqual(res, expected_result)
+
+ def test_parse_collectd_result_cpu(self):
+ metric = {"nsb_stats/cpu/0/ipc": "101"}
+ self.resource_profile.get_cpu_data = mock.Mock(return_value=[1,
+ "ipc",
+ "1234",
+ ""])
+ res = self.resource_profile.parse_collectd_result(metric, [0, 1, 2])
+ expected_result = {'cpu': {1: {'ipc': '1234'}}, 'dpdkstat': {}, 'hugepages': {},
+ 'memory': {}, 'ovs_stats': {}, 'timestamp': '',
+ 'virt': {}}
+ self.assertDictEqual(res, expected_result)
+
+ def test_parse_collectd_result_memory(self):
+ metric = {"nsb_stats/memory/bw": "101"}
+ res = self.resource_profile.parse_collectd_result(metric, [0, 1, 2])
+ expected_result = {'cpu': {}, 'dpdkstat': {}, 'hugepages': {},
+ 'memory': {'bw': '101'}, 'ovs_stats': {}, 'timestamp': '',
+ 'virt': {}}
+ self.assertDictEqual(res, expected_result)
+
+ def test_parse_collectd_result_hugepage(self):
+ metric = {"nsb_stats/hugepages/free": "101"}
+ self.resource_profile.parse_hugepages = \
+ mock.Mock(return_value={"free": "101"})
+ res = self.resource_profile.parse_collectd_result(metric, [0, 1, 2])
+ expected_result = {'cpu': {}, 'dpdkstat': {}, 'hugepages': {'free':
+ '101'},
+ 'memory': {}, 'ovs_stats': {}, 'timestamp': '',
+ 'virt': {}}
+ self.assertDictEqual(res, expected_result)
+
+ def test_parse_collectd_result_dpdk_virt_ovs(self):
+ metric = {"nsb_stats/dpdkstat/tx": "101",
+ "nsb_stats/ovs_stats/tx": "101",
+ "nsb_stats/virt/virt/memory": "101"}
+ self.resource_profile.parse_dpdkstat = \
+ mock.Mock(return_value={"tx": "101"})
+ self.resource_profile.parse_virt = \
+ mock.Mock(return_value={"memory": "101"})
+ self.resource_profile.parse_ovs_stats = \
+ mock.Mock(return_value={"tx": "101"})
+ res = self.resource_profile.parse_collectd_result(metric, [0, 1, 2])
+ expected_result = {'cpu': {}, 'dpdkstat': {'tx': '101'}, 'hugepages': {},
+ 'memory': {}, 'ovs_stats': {'tx': '101'}, 'timestamp': '',
+ 'virt': {'memory': '101'}}
+ self.assertDictEqual(res, expected_result)
+
+ def test_amqp_process_for_nfvi_kpi(self):
+ self.resource_profile.amqp_client = \
+ mock.MagicMock(side_effect=[None, mock.MagicMock()])
+ self.resource_profile.run_collectd_amqp = \
+ mock.Mock(return_value=0)
+ res = self.resource_profile.amqp_process_for_nfvi_kpi()
+ self.assertEqual(None, res)
+
+ def test_amqp_collect_nfvi_kpi(self):
+ self.resource_profile.amqp_client = \
+ mock.MagicMock(side_effect=[None, mock.MagicMock()])
+ self.resource_profile.run_collectd_amqp = \
+ mock.Mock(return_value=0)
+ self.resource_profile.parse_collectd_result = mock.Mock()
+ res = self.resource_profile.amqp_collect_nfvi_kpi()
+ self.assertIsNotNone(res)
def test_run_collectd_amqp(self):
_queue = multiprocessing.Queue()
resource.AmqpConsumer = mock.Mock(autospec=collectd)
- self.assertIsNone(self.resource_profile.run_collectd_amqp(_queue))
+ self.assertIsNone(self.resource_profile.run_collectd_amqp())
def test_start(self):
self.assertIsNone(self.resource_profile.start())