diff options
Diffstat (limited to 'yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py')
-rw-r--r-- | yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py | 131 |
1 files changed, 56 insertions, 75 deletions
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py index a1802aa55..5dae5cdb1 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py @@ -16,6 +16,7 @@ from copy import deepcopy import unittest import mock +import time import paramiko @@ -1062,58 +1063,6 @@ class TestClientResourceHelper(unittest.TestCase): self.assertIs(client_resource_helper._connect(client), client) - @mock.patch.object(ClientResourceHelper, '_build_ports') - @mock.patch.object(ClientResourceHelper, '_run_traffic_once', - return_value=(True, mock.ANY)) - def test_run_traffic(self, mock_run_traffic_once, mock_build_ports): - client_resource_helper = ClientResourceHelper(mock.Mock()) - client = mock.Mock() - traffic_profile = mock.Mock() - mq_producer = mock.Mock() - with mock.patch.object(client_resource_helper, '_connect') \ - as mock_connect, \ - mock.patch.object(client_resource_helper, '_terminated') \ - as mock_terminated: - mock_connect.return_value = client - type(mock_terminated).value = mock.PropertyMock( - side_effect=[0, 1, 1, lambda x: x]) - client_resource_helper.run_traffic(traffic_profile, mq_producer) - - mock_build_ports.assert_called_once() - traffic_profile.register_generator.assert_called_once() - mq_producer.tg_method_started.assert_called_once() - mq_producer.tg_method_finished.assert_called_once() - mq_producer.tg_method_iteration.assert_called_once_with(1) - mock_run_traffic_once.assert_called_once_with(traffic_profile) - - @mock.patch.object(ClientResourceHelper, '_build_ports') - @mock.patch.object(ClientResourceHelper, '_run_traffic_once', - side_effect=Exception) - def test_run_traffic_exception(self, mock_run_traffic_once, - mock_build_ports): - client_resource_helper = ClientResourceHelper(mock.Mock()) - client = mock.Mock() - traffic_profile = mock.Mock() - mq_producer = mock.Mock() - with mock.patch.object(client_resource_helper, '_connect') \ - as mock_connect, \ - mock.patch.object(client_resource_helper, '_terminated') \ - as mock_terminated: - mock_connect.return_value = client - type(mock_terminated).value = mock.PropertyMock(return_value=0) - mq_producer.reset_mock() - # NOTE(ralonsoh): "trex_stl_exceptions.STLError" is mocked - with self.assertRaises(Exception): - client_resource_helper.run_traffic(traffic_profile, - mq_producer) - - mock_build_ports.assert_called_once() - traffic_profile.register_generator.assert_called_once() - mock_run_traffic_once.assert_called_once_with(traffic_profile) - mq_producer.tg_method_started.assert_called_once() - mq_producer.tg_method_finished.assert_not_called() - mq_producer.tg_method_iteration.assert_not_called() - class TestRfc2544ResourceHelper(unittest.TestCase): @@ -1518,7 +1467,7 @@ class TestSampleVnf(unittest.TestCase): } def test___init__(self): - sample_vnf = SampleVNF('vnf1', self.VNFD_0, 'task_id') + sample_vnf = SampleVNF('vnf1', self.VNFD_0) self.assertEqual(sample_vnf.name, 'vnf1') self.assertDictEqual(sample_vnf.vnfd_helper, self.VNFD_0) @@ -1536,8 +1485,7 @@ class TestSampleVnf(unittest.TestCase): class MyResourceHelper(ResourceHelper): pass - sample_vnf = SampleVNF('vnf1', self.VNFD_0, 'task_id', - MySetupEnvHelper, MyResourceHelper) + sample_vnf = SampleVNF('vnf1', self.VNFD_0, MySetupEnvHelper, MyResourceHelper) self.assertEqual(sample_vnf.name, 'vnf1') self.assertDictEqual(sample_vnf.vnfd_helper, self.VNFD_0) @@ -1551,7 +1499,7 @@ class TestSampleVnf(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.Process') def test__start_vnf(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf._run = mock.Mock() self.assertIsNone(sample_vnf.queue_wrapper) @@ -1570,7 +1518,7 @@ class TestSampleVnf(unittest.TestCase): } vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.scenario_helper.scenario_cfg = { 'nodes': {sample_vnf.name: 'mock'} } @@ -1614,7 +1562,7 @@ class TestSampleVnf(unittest.TestCase): 'plugin1': {'param': 1}}} vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf__0', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf__0', vnfd) sample_vnf._update_collectd_options(scenario_cfg, context_cfg) self.assertEqual(sample_vnf.setup_helper.collectd_options, expected) @@ -1641,7 +1589,7 @@ class TestSampleVnf(unittest.TestCase): 'plugin1': {'param': 1}}} vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf._update_options(options2, options1) self.assertEqual(options2, expected) @@ -1663,7 +1611,7 @@ class TestSampleVnf(unittest.TestCase): ] vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.APP_NAME = 'sample1' sample_vnf.WAIT_TIME_FOR_SCRIPT = 0 sample_vnf._start_server = mock.Mock(return_value=0) @@ -1680,6 +1628,39 @@ class TestSampleVnf(unittest.TestCase): self.assertEqual(sample_vnf.wait_for_instantiate(), 0) + @mock.patch.object(time, 'sleep') + @mock.patch.object(ssh, 'SSH') + def test_wait_for_initialize(self, ssh, *args): + test_base.mock_ssh(ssh, exec_result=(1, "", "")) + queue_get_list = [ + 'some output', + 'pipeline> ', + 'run non_existent_script_name', + 'Cannot open file "non_existent_script_name"' + ] + queue_size_list = [ + 0, + len(queue_get_list[0]), + 0, + len(queue_get_list[1]), + len(queue_get_list[2]), + 0, + len(queue_get_list[3]) + ] + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf.APP_NAME = 'sample1' + sample_vnf.WAIT_TIME_FOR_SCRIPT = 0 + sample_vnf._vnf_process = mock.Mock() + sample_vnf._vnf_process.exitcode = 0 + sample_vnf._vnf_process._is_alive.return_value = 1 + sample_vnf.queue_wrapper = mock.Mock() + sample_vnf.q_in = mock.Mock() + sample_vnf.q_out = mock.Mock() + sample_vnf.q_out.qsize.side_effect = iter(queue_size_list) + sample_vnf.q_out.get.side_effect = iter(queue_get_list) + sample_vnf.wait_for_initialize() + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") def test_vnf_execute_with_queue_data(self, *args): queue_size_list = [ @@ -1694,7 +1675,7 @@ class TestSampleVnf(unittest.TestCase): ] vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.APP_NAME = 'sample1' sample_vnf.q_out = mock.Mock() sample_vnf.q_out.qsize.side_effect = iter(queue_size_list) @@ -1704,7 +1685,7 @@ class TestSampleVnf(unittest.TestCase): def test_terminate_without_vnf_process(self): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.APP_NAME = 'sample1' sample_vnf.vnf_execute = mock.Mock() sample_vnf.ssh_helper = mock.Mock() @@ -1715,7 +1696,7 @@ class TestSampleVnf(unittest.TestCase): def test_get_stats(self): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.APP_NAME = 'sample1' sample_vnf.APP_WORD = 'sample1' sample_vnf.vnf_execute = mock.Mock(return_value='the stats') @@ -1725,7 +1706,7 @@ class TestSampleVnf(unittest.TestCase): @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') def test_collect_kpi(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.scenario_helper.scenario_cfg = { 'nodes': {sample_vnf.name: "mock"} } @@ -1753,7 +1734,7 @@ class TestSampleVnf(unittest.TestCase): @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') def test_collect_kpi_default(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.scenario_helper.scenario_cfg = { 'nodes': {sample_vnf.name: "mock"} } @@ -1772,7 +1753,7 @@ class TestSampleVnf(unittest.TestCase): def test_scale(self): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) self.assertRaises(y_exceptions.FunctionNotImplemented, sample_vnf.scale) @@ -1780,7 +1761,7 @@ class TestSampleVnf(unittest.TestCase): test_cmd = 'test cmd' run_kwargs = {'arg1': 'val1', 'arg2': 'val2'} vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') + sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.ssh_helper = mock.Mock() sample_vnf.setup_helper = mock.Mock() with mock.patch.object(sample_vnf, '_build_config', @@ -1916,30 +1897,30 @@ class TestSampleVNFTrafficGen(unittest.TestCase): } def test__check_status(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) with self.assertRaises(NotImplementedError): sample_vnf_tg._check_status() def test_listen_traffic(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) sample_vnf_tg.listen_traffic(mock.Mock()) def test_verify_traffic(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) sample_vnf_tg.verify_traffic(mock.Mock()) def test_terminate(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) sample_vnf_tg._traffic_process = mock.Mock() sample_vnf_tg._tg_process = mock.Mock() sample_vnf_tg.terminate() def test__wait_for_process(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) with mock.patch.object(sample_vnf_tg, '_check_status', return_value=0) as mock_status, \ mock.patch.object(sample_vnf_tg, '_tg_process') as mock_proc: @@ -1950,14 +1931,14 @@ class TestSampleVNFTrafficGen(unittest.TestCase): mock_status.assert_called_once() def test__wait_for_process_not_alive(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) with mock.patch.object(sample_vnf_tg, '_tg_process') as mock_proc: mock_proc.is_alive.return_value = False self.assertRaises(RuntimeError, sample_vnf_tg._wait_for_process) mock_proc.is_alive.assert_called_once() def test__wait_for_process_delayed(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) with mock.patch.object(sample_vnf_tg, '_check_status', side_effect=[1, 0]) as mock_status, \ mock.patch.object(sample_vnf_tg, @@ -1969,6 +1950,6 @@ class TestSampleVNFTrafficGen(unittest.TestCase): mock_status.assert_has_calls([mock.call(), mock.call()]) def test_scale(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) self.assertRaises(y_exceptions.FunctionNotImplemented, sample_vnf_tg.scale) |