summaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_monitor_command.py8
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_monitor_multi.py2
-rw-r--r--tests/unit/benchmark/scenarios/storage/test_storperf.py4
-rw-r--r--tests/unit/common/test_utils.py13
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py44
5 files changed, 47 insertions, 24 deletions
diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
index 2ed4be731..6a9b3b157 100644
--- a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
+++ b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
@@ -30,12 +30,14 @@ class ExecuteShellTestCase(unittest.TestCase):
exitcode, output = monitor_command._execute_shell_command(cmd)
self.assertEqual(exitcode, 0)
- def test__fun_execute_shell_command_fail_cmd_exception(self,
+ @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG')
+ def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log,
mock_subprocess):
cmd = "env"
mock_subprocess.check_output.side_effect = RuntimeError
exitcode, output = monitor_command._execute_shell_command(cmd)
self.assertEqual(exitcode, -1)
+ mock_log.error.assert_called_once()
@mock.patch(
@@ -67,13 +69,15 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase):
instance._result = {"outage_time": 0}
instance.verify_SLA()
- def test__monitor_command_monitor_func_failure(self, mock_subprocess):
+ @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG')
+ def test__monitor_command_monitor_func_failure(self, mock_log, mock_subprocess):
mock_subprocess.check_output.return_value = (1, 'unittest')
instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10})
instance.setup()
mock_subprocess.check_output.side_effect = RuntimeError
ret = instance.monitor_func()
self.assertEqual(ret, False)
+ mock_log.error.assert_called_once()
instance._result = {"outage_time": 10}
instance.verify_SLA()
diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py b/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py
index f8d12bd29..b59ec6cf1 100644
--- a/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py
+++ b/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py
@@ -36,7 +36,7 @@ class MultiMonitorServiceTestCase(unittest.TestCase):
'key': 'service-status',
'monitor_key': 'service-status',
'host': 'node1',
- 'monitor_time': 3,
+ 'monitor_time': 0.1,
'parameter': {'serviceName': 'haproxy'},
'sla': {'max_outage_time': 1}
}
diff --git a/tests/unit/benchmark/scenarios/storage/test_storperf.py b/tests/unit/benchmark/scenarios/storage/test_storperf.py
index 00054d531..7b16bb37d 100644
--- a/tests/unit/benchmark/scenarios/storage/test_storperf.py
+++ b/tests/unit/benchmark/scenarios/storage/test_storperf.py
@@ -130,7 +130,7 @@ class StorPerfTestCase(unittest.TestCase):
"queue_depths": 4,
"workload": "rs",
"StorPerf_ip": "192.168.23.2",
- "query_interval": 10,
+ "query_interval": 0,
"timeout": 60
}
@@ -160,7 +160,7 @@ class StorPerfTestCase(unittest.TestCase):
"queue_depths": 4,
"workload": "rs",
"StorPerf_ip": "192.168.23.2",
- "query_interval": 10,
+ "query_interval": 0,
"timeout": 60
}
diff --git a/tests/unit/common/test_utils.py b/tests/unit/common/test_utils.py
index 7f260cfe6..664b38b13 100644
--- a/tests/unit/common/test_utils.py
+++ b/tests/unit/common/test_utils.py
@@ -163,6 +163,19 @@ class TranslateToStrTestCase(unittest.TestCase):
self.assertEqual(result, output_str)
+class ChangeObjToDictTestCase(unittest.TestCase):
+
+ def test_change_obj_to_dict(self):
+ class A(object):
+ def __init__(self):
+ self.name = 'yardstick'
+
+ obj = A()
+ obj_r = utils.change_obj_to_dict(obj)
+ obj_s = {'name': 'yardstick'}
+ self.assertEqual(obj_r, obj_s)
+
+
def main():
unittest.main()
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
index b69e537aa..54934c2fe 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
@@ -16,17 +16,20 @@
#
from __future__ import absolute_import
+
+import os
import unittest
+
import mock
-import os
-from yardstick.network_services.vnf_generic.vnf.vpe_vnf import VpeApproxVnf
-from yardstick.network_services.vnf_generic.vnf import vpe_vnf
from yardstick.network_services.nfvi.resource import ResourceProfile
+from yardstick.network_services.vnf_generic.vnf import vpe_vnf
from yardstick.network_services.vnf_generic.vnf.base import \
QueueFileWrapper
+from yardstick.network_services.vnf_generic.vnf.vpe_vnf import VpeApproxVnf
+@mock.patch('yardstick.network_services.vnf_generic.vnf.vpe_vnf.time')
class TestVpeApproxVnf(unittest.TestCase):
VNFD = {'vnfd:vnfd-catalog':
{'vnfd':
@@ -218,12 +221,12 @@ class TestVpeApproxVnf(unittest.TestCase):
'password': 'r00t',
'VNF model': 'vpe_vnf.yaml'}}}
- def test___init__(self):
+ def test___init__(self, mock_time):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
vpe_approx_vnf = VpeApproxVnf(vnfd)
self.assertIsNone(vpe_approx_vnf._vnf_process)
- def test_collect_kpi(self):
+ def test_collect_kpi(self, mock_time):
with mock.patch("yardstick.ssh.SSH") as ssh:
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ssh_mock = mock.Mock(autospec=ssh.SSH)
@@ -235,15 +238,17 @@ class TestVpeApproxVnf(unittest.TestCase):
vpe_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
vpe_approx_vnf.resource.check_if_sa_running = \
mock.Mock(return_value=[0, 1])
- vpe_approx_vnf.resource.amqp_collect_nfvi_kpi= \
+ vpe_approx_vnf.resource.amqp_collect_nfvi_kpi = \
mock.Mock(return_value={})
result = {'pkt_in_down_stream': 0,
'pkt_in_up_stream': 0,
'collect_stats': {'core': {}},
'pkt_drop_down_stream': 0, 'pkt_drop_up_stream': 0}
- self.assertEqual(result, vpe_approx_vnf.collect_kpi())
+ # mock execute_command because it sleeps for 3 seconds.
+ with mock.patch.object(vpe_approx_vnf, "execute_command", return_value=""):
+ self.assertEqual(result, vpe_approx_vnf.collect_kpi())
- def test_execute_command(self):
+ def test_execute_command(self, mock_time):
with mock.patch("yardstick.ssh.SSH") as ssh:
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ssh_mock = mock.Mock(autospec=ssh.SSH)
@@ -255,7 +260,7 @@ class TestVpeApproxVnf(unittest.TestCase):
cmd = "quit"
self.assertEqual("", vpe_approx_vnf.execute_command(cmd))
- def test_get_stats_vpe(self):
+ def test_get_stats_vpe(self, mock_time):
with mock.patch("yardstick.ssh.SSH") as ssh:
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ssh_mock = mock.Mock(autospec=ssh.SSH)
@@ -270,7 +275,7 @@ class TestVpeApproxVnf(unittest.TestCase):
'pkt_drop_down_stream': 400, 'pkt_drop_up_stream': 600}
self.assertEqual(result, vpe_approx_vnf.get_stats_vpe())
- def test_run_vpe(self):
+ def test_run_vpe(self, mock_time):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
@@ -288,7 +293,7 @@ class TestVpeApproxVnf(unittest.TestCase):
self.assertEqual(None,
vpe_approx_vnf._run_vpe(queue_wrapper, vpe_vnf))
- def test_instantiate(self):
+ def test_instantiate(self, mock_time):
with mock.patch("yardstick.ssh.SSH") as ssh:
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ssh_mock = mock.Mock(autospec=ssh.SSH)
@@ -301,11 +306,12 @@ class TestVpeApproxVnf(unittest.TestCase):
vpe_approx_vnf._run_vpe = mock.Mock(return_value=0)
vpe_approx_vnf._resource_collect_start = mock.Mock(return_value=0)
vpe_approx_vnf.q_out.put("pipeline>")
- vpe_vnf.WAIT_TIME = 3
- self.assertEqual(0, vpe_approx_vnf.instantiate(self.scenario_cfg,
- self.context_cfg))
+ vpe_vnf.WAIT_TIME = 0.1
+ # if process it still running exitcode will be None
+ self.assertIn(vpe_approx_vnf.instantiate(self.scenario_cfg, self.context_cfg),
+ {0, None})
- def test_instantiate_panic(self):
+ def test_instantiate_panic(self, mock_time):
with mock.patch("yardstick.ssh.SSH") as ssh:
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ssh_mock = mock.Mock(autospec=ssh.SSH)
@@ -316,17 +322,17 @@ class TestVpeApproxVnf(unittest.TestCase):
vpe_approx_vnf = VpeApproxVnf(vnfd)
self.scenario_cfg['vnf_options'] = {'vpe': {'cfg': ""}}
vpe_approx_vnf._run_vpe = mock.Mock(return_value=0)
- vpe_vnf.WAIT_TIME = 1
+ vpe_vnf.WAIT_TIME = 0.1
self.assertRaises(RuntimeError, vpe_approx_vnf.instantiate,
self.scenario_cfg, self.context_cfg)
- def test_scale(self):
+ def test_scale(self, mock_time):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
vpe_approx_vnf = VpeApproxVnf(vnfd)
flavor = ""
self.assertRaises(NotImplementedError, vpe_approx_vnf.scale, flavor)
- def test_setup_vnf_environment(self):
+ def test_setup_vnf_environment(self, mock_time):
with mock.patch("yardstick.ssh.SSH") as ssh:
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ssh_mock = mock.Mock(autospec=ssh.SSH)
@@ -338,7 +344,7 @@ class TestVpeApproxVnf(unittest.TestCase):
self.assertEqual(None,
vpe_approx_vnf.setup_vnf_environment(ssh_mock))
- def test_terminate(self):
+ def test_terminate(self, mock_time):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
vpe_approx_vnf = VpeApproxVnf(vnfd)
self.assertEqual(None, vpe_approx_vnf.terminate())