summaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/benchmark/core/test_task.py36
-rw-r--r--tests/unit/benchmark/core/test_testcase.py4
-rw-r--r--tests/unit/cmd/commands/test_testcase.py21
-rw-r--r--tests/unit/network_services/nfvi/test_collectd.py5
-rw-r--r--tests/unit/network_services/nfvi/test_resource.py33
5 files changed, 54 insertions, 45 deletions
diff --git a/tests/unit/benchmark/core/test_task.py b/tests/unit/benchmark/core/test_task.py
index 5dd32ea17..c56e21047 100644
--- a/tests/unit/benchmark/core/test_task.py
+++ b/tests/unit/benchmark/core/test_task.py
@@ -24,6 +24,7 @@ except ImportError:
from yardstick.benchmark.core import task
+from yardstick.common import constants as consts
class TaskTestCase(unittest.TestCase):
@@ -92,10 +93,10 @@ class TaskTestCase(unittest.TestCase):
task_files, task_args, task_args_fnames = t.parse_suite()
print("files=%s, args=%s, fnames=%s" % (task_files, task_args,
task_args_fnames))
- self.assertEqual(task_files[0],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
- self.assertEqual(task_files[1],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
+ self.assertEqual(task_files[0], self.change_to_abspath(
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml'))
+ self.assertEqual(task_files[1], self.change_to_abspath(
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml'))
self.assertEqual(task_args[0], None)
self.assertEqual(task_args[1], None)
self.assertEqual(task_args_fnames[0], None)
@@ -109,10 +110,10 @@ class TaskTestCase(unittest.TestCase):
task_files, task_args, task_args_fnames = t.parse_suite()
print("files=%s, args=%s, fnames=%s" % (task_files, task_args,
task_args_fnames))
- self.assertEqual(task_files[0],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
- self.assertEqual(task_files[1],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
+ self.assertEqual(task_files[0], self.change_to_abspath(
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml'))
+ self.assertEqual(task_files[1], self.change_to_abspath(
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml'))
self.assertEqual(task_args[0], None)
self.assertEqual(task_args[1],
'{"host": "node1.LF","target": "node2.LF"}')
@@ -127,10 +128,10 @@ class TaskTestCase(unittest.TestCase):
task_files, task_args, task_args_fnames = t.parse_suite()
print("files=%s, args=%s, fnames=%s" % (task_files, task_args,
task_args_fnames))
- self.assertEqual(task_files[0],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
- self.assertEqual(task_files[1],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
+ self.assertEqual(task_files[0], self.change_to_abspath(
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml'))
+ self.assertEqual(task_files[1], self.change_to_abspath(
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml'))
self.assertEqual(task_args[0], None)
self.assertEqual(task_args[1], None)
self.assertEqual(task_args_fnames[0], None)
@@ -144,10 +145,10 @@ class TaskTestCase(unittest.TestCase):
task_files, task_args, task_args_fnames = t.parse_suite()
print("files=%s, args=%s, fnames=%s" % (task_files, task_args,
task_args_fnames))
- self.assertEqual(task_files[0],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
- self.assertEqual(task_files[1],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
+ self.assertEqual(task_files[0], self.change_to_abspath(
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml'))
+ self.assertEqual(task_files[1], self.change_to_abspath(
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml'))
self.assertEqual(task_args[0], None)
self.assertEqual(task_args[1],
'{"host": "node1.LF","target": "node2.LF"}')
@@ -159,6 +160,9 @@ class TaskTestCase(unittest.TestCase):
file_path = os.path.join(curr_path, filename)
return file_path
+ def change_to_abspath(self, filepath):
+ return os.path.join(consts.YARDSTICK_ROOT_PATH, filepath)
+
def main():
unittest.main()
diff --git a/tests/unit/benchmark/core/test_testcase.py b/tests/unit/benchmark/core/test_testcase.py
index c7da2de7c..1f5aad75e 100644
--- a/tests/unit/benchmark/core/test_testcase.py
+++ b/tests/unit/benchmark/core/test_testcase.py
@@ -28,13 +28,13 @@ class TestcaseUT(unittest.TestCase):
def test_list_all(self):
t = testcase.Testcase()
result = t.list_all("")
- self.assertEqual(result, True)
+ self.assertIsInstance(result, list)
def test_show(self):
t = testcase.Testcase()
casename = Arg()
result = t.show(casename)
- self.assertEqual(result, True)
+ self.assertTrue(result)
def main():
diff --git a/tests/unit/cmd/commands/test_testcase.py b/tests/unit/cmd/commands/test_testcase.py
new file mode 100644
index 000000000..515784352
--- /dev/null
+++ b/tests/unit/cmd/commands/test_testcase.py
@@ -0,0 +1,21 @@
+import unittest
+from mock import patch
+
+from yardstick.cmd.commands.testcase import TestcaseCommands
+
+
+class TestcaseCommandsUT(unittest.TestCase):
+ @patch('yardstick.cmd.commands.testcase.TestcaseCommands._format_print')
+ @patch('yardstick.cmd.commands.client')
+ def test_do_list(self, mock_client, mock_print):
+ mock_client.get.return_value = {'result': []}
+ TestcaseCommands().do_list({})
+ self.assertTrue(mock_print.called)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/network_services/nfvi/test_collectd.py b/tests/unit/network_services/nfvi/test_collectd.py
index 5bd7196df..866c31d32 100644
--- a/tests/unit/network_services/nfvi/test_collectd.py
+++ b/tests/unit/network_services/nfvi/test_collectd.py
@@ -23,15 +23,12 @@ from yardstick.network_services.nfvi.collectd import AmqpConsumer
class TestAmqpConsumer(unittest.TestCase):
def setUp(self):
self.queue = multiprocessing.Queue()
- self.url = 'amqp://admin:admin@1.1.1.1:5672/%2F'
+ self.url = 'amqp://admin:admin@127.0.0.1:5672/%2F'
self.amqp_consumer = AmqpConsumer(self.url, self.queue)
def test___init__(self):
self.assertEqual(self.url, self.amqp_consumer._url)
- def test_connect(self):
- self.assertRaises(RuntimeError, self.amqp_consumer.connect)
-
def test_on_connection_open(self):
self.amqp_consumer._connection = mock.Mock(autospec=AmqpConsumer)
self.amqp_consumer._connection.add_on_close_callback = \
diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py
index 90910d89b..26d18838b 100644
--- a/tests/unit/network_services/nfvi/test_resource.py
+++ b/tests/unit/network_services/nfvi/test_resource.py
@@ -27,13 +27,13 @@ class TestResourceProfile(unittest.TestCase):
[{'short-name': 'VpeVnf',
'vdu':
[{'routing_table':
- [{'network': '152.16.100.20',
+ [{'network': '172.16.100.20',
'netmask': '255.255.255.0',
- 'gateway': '152.16.100.20',
+ 'gateway': '172.16.100.20',
'if': 'xe0'},
- {'network': '152.16.40.20',
+ {'network': '172.16.40.20',
'netmask': '255.255.255.0',
- 'gateway': '152.16.40.20',
+ 'gateway': '172.16.40.20',
'if': 'xe1'}],
'description': 'VPE approximation using DPDK',
'name': 'vpevnf-baremetal',
@@ -51,34 +51,34 @@ class TestResourceProfile(unittest.TestCase):
[{'virtual-interface':
{'dst_mac': '3c:fd:fe:9e:64:38',
'vpci': '0000:05:00.0',
- 'local_ip': '152.16.100.19',
+ 'local_ip': '172.16.100.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
'dpdk_port_num': '0',
'bandwidth': '10 Gbps',
- 'dst_ip': '152.16.100.20',
+ 'dst_ip': '172.16.100.20',
'local_mac': '3c:fd:fe:a1:2b:80'},
'vnfd-connection-point-ref': 'xe0',
'name': 'xe0'},
{'virtual-interface':
{'dst_mac': '00:1e:67:d0:60:5c',
'vpci': '0000:05:00.1',
- 'local_ip': '152.16.40.19',
+ 'local_ip': '172.16.40.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
'dpdk_port_num': '1',
'bandwidth': '10 Gbps',
- 'dst_ip': '152.16.40.20',
+ 'dst_ip': '172.16.40.20',
'local_mac': '3c:fd:fe:a1:2b:81'},
'vnfd-connection-point-ref': 'xe1',
'name': 'xe1'}]}],
'description': 'Vpe approximation using DPDK',
'mgmt-interface':
{'vdu-id': 'vpevnf-baremetal',
- 'host': '1.1.1.1',
+ 'host': '127.0.0.1',
'password': 'r00t',
'user': 'root',
- 'ip': '1.1.1.1'},
+ 'ip': '127.0.0.1'},
'benchmark':
{'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
@@ -103,19 +103,6 @@ class TestResourceProfile(unittest.TestCase):
self.assertEqual(self.resource_profile.check_if_sa_running("collectd"),
[True, {}])
- def test_amqp_collect_nfvi_kpi(self):
- _queue = multiprocessing.Queue()
- _queue.put({"cpu/cpu-0/ipc": "ipc:10"})
- amqp = self.resource_profile.amqp_collect_nfvi_kpi(_queue)
- _queue.put({"/memory/bandwidth": "local:10"})
- amqp = self.resource_profile.amqp_collect_nfvi_kpi(_queue)
- expected = {'timestamp': '', 'cpu': {}, 'memory': {'bandwidth': '10'}}
- self.assertDictEqual(expected, amqp)
-
- def test_amqp_collect_nfvi_kpi_exception(self):
- amqp = self.resource_profile.amqp_collect_nfvi_kpi({})
- self.assertDictEqual({}, amqp)
-
def test_get_cpu_data(self):
reskey = ["", "cpufreq", "cpufreq-0"]
value = "metric:10"