X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Ftests%2Funit%2Fnetwork_services%2Fvnf_generic%2Fvnf%2Ftest_sample_vnf.py;h=c9d42fb3e2756d998732b841090c4c431faffbae;hb=0ff5b131fa3f93f8d47b46c2f13661c5b88d37a1;hp=331e80d003b6a3786ecc7f44d49092b465465a1e;hpb=2e5bdb770ca4f5f5e06c79b4e97f3a22bac8e960;p=yardstick.git 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 331e80d00..c9d42fb3e 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 @@ -1090,6 +1090,58 @@ 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): @@ -1154,6 +1206,7 @@ class TestRfc2544ResourceHelper(unittest.TestCase): self.assertIsNone(rfc2544_resource_helper._tolerance_high) self.assertEqual(rfc2544_resource_helper.tolerance_high, 0.15) self.assertEqual(rfc2544_resource_helper._tolerance_high, 0.15) + self.assertEqual(rfc2544_resource_helper._tolerance_precision, 2) scenario_helper.scenario_cfg = {} # ensure that resource_helper caches self.assertEqual(rfc2544_resource_helper.tolerance_high, 0.15) @@ -1188,6 +1241,7 @@ class TestRfc2544ResourceHelper(unittest.TestCase): rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) self.assertEqual(rfc2544_resource_helper.tolerance_high, 0.2) + self.assertEqual(rfc2544_resource_helper._tolerance_precision, 1) def test_property_tolerance_low_not_range(self): scenario_helper = ScenarioHelper('name1') @@ -1492,7 +1546,7 @@ class TestSampleVnf(unittest.TestCase): } def test___init__(self): - sample_vnf = SampleVNF('vnf1', self.VNFD_0) + sample_vnf = SampleVNF('vnf1', self.VNFD_0, 'task_id') self.assertEqual(sample_vnf.name, 'vnf1') self.assertDictEqual(sample_vnf.vnfd_helper, self.VNFD_0) @@ -1510,7 +1564,8 @@ class TestSampleVnf(unittest.TestCase): class MyResourceHelper(ResourceHelper): pass - sample_vnf = SampleVNF('vnf1', self.VNFD_0, MySetupEnvHelper, MyResourceHelper) + sample_vnf = SampleVNF('vnf1', self.VNFD_0, 'task_id', + MySetupEnvHelper, MyResourceHelper) self.assertEqual(sample_vnf.name, 'vnf1') self.assertDictEqual(sample_vnf.vnfd_helper, self.VNFD_0) @@ -1524,7 +1579,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) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf._run = mock.Mock() self.assertIsNone(sample_vnf.queue_wrapper) @@ -1543,7 +1598,7 @@ class TestSampleVnf(unittest.TestCase): } vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf.scenario_helper.scenario_cfg = { 'nodes': {sample_vnf.name: 'mock'} } @@ -1587,7 +1642,7 @@ class TestSampleVnf(unittest.TestCase): 'plugin1': {'param': 1}}} vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf__0', vnfd) + sample_vnf = SampleVNF('vnf__0', vnfd, 'task_id') sample_vnf._update_collectd_options(scenario_cfg, context_cfg) self.assertEqual(sample_vnf.setup_helper.collectd_options, expected) @@ -1614,7 +1669,7 @@ class TestSampleVnf(unittest.TestCase): 'plugin1': {'param': 1}}} vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf._update_options(options2, options1) self.assertEqual(options2, expected) @@ -1636,7 +1691,7 @@ class TestSampleVnf(unittest.TestCase): ] vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf.APP_NAME = 'sample1' sample_vnf.WAIT_TIME_FOR_SCRIPT = 0 sample_vnf._start_server = mock.Mock(return_value=0) @@ -1667,7 +1722,7 @@ class TestSampleVnf(unittest.TestCase): ] vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf.APP_NAME = 'sample1' sample_vnf.q_out = mock.Mock() sample_vnf.q_out.qsize.side_effect = iter(queue_size_list) @@ -1677,7 +1732,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) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf.APP_NAME = 'sample1' sample_vnf.vnf_execute = mock.Mock() sample_vnf.ssh_helper = mock.Mock() @@ -1688,7 +1743,7 @@ class TestSampleVnf(unittest.TestCase): def test_get_stats(self): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf.APP_NAME = 'sample1' sample_vnf.APP_WORD = 'sample1' sample_vnf.vnf_execute = mock.Mock(return_value='the stats') @@ -1698,7 +1753,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) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf.scenario_helper.scenario_cfg = { 'nodes': {sample_vnf.name: "mock"} } @@ -1726,7 +1781,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) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf.scenario_helper.scenario_cfg = { 'nodes': {sample_vnf.name: "mock"} } @@ -1745,7 +1800,7 @@ class TestSampleVnf(unittest.TestCase): def test_scale(self): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') self.assertRaises(y_exceptions.FunctionNotImplemented, sample_vnf.scale) @@ -1753,7 +1808,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) + sample_vnf = SampleVNF('vnf1', vnfd, 'task_id') sample_vnf.ssh_helper = mock.Mock() sample_vnf.setup_helper = mock.Mock() with mock.patch.object(sample_vnf, '_build_config', @@ -1889,30 +1944,30 @@ class TestSampleVNFTrafficGen(unittest.TestCase): } def test__check_status(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') with self.assertRaises(NotImplementedError): sample_vnf_tg._check_status() def test_listen_traffic(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') sample_vnf_tg.listen_traffic(mock.Mock()) def test_verify_traffic(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') sample_vnf_tg.verify_traffic(mock.Mock()) def test_terminate(self): - sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') 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) + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') 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: @@ -1923,14 +1978,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) + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') 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) + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') with mock.patch.object(sample_vnf_tg, '_check_status', side_effect=[1, 0]) as mock_status, \ mock.patch.object(sample_vnf_tg, @@ -1942,6 +1997,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) + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0, 'task_id') self.assertRaises(y_exceptions.FunctionNotImplemented, sample_vnf_tg.scale)