From 67bd29933789e7f31c52290fdd43835e54f89eaf Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Thu, 23 Nov 2017 09:08:14 +0000 Subject: Make GenericVNF an abstract class GenericVNF class is now an abstract class. Only optional methods are implemented. Mandatory methods: - instantiate - wait_for_instantiate - terminate - scale - collect_kpi. JIRA: YARDSTICK-866 Change-Id: Ia8766f9f98816e11894d1e72b0f3bd573d091d99 Signed-off-by: Rodolfo Alonso Hernandez --- .../vnf_generic/vnf/test_sample_vnf.py | 47 +++++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py') diff --git a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py index 85b10c5a9..b4306ce61 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py @@ -15,10 +15,6 @@ # limitations under the License. # -# Unittest for yardstick.network_services.vnf_generic.vnf.sample_vnf - -from __future__ import absolute_import - import unittest import mock from copy import deepcopy @@ -26,8 +22,8 @@ from copy import deepcopy from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from tests.unit import STL_MOCKS from yardstick.benchmark.contexts.base import Context +from yardstick.common import exceptions as y_exceptions from yardstick.network_services.nfvi.resource import ResourceProfile -from yardstick.network_services.traffic_profile.base import TrafficProfile from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper @@ -571,7 +567,7 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.open') @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.find_relative_file') @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig') - def test_build_config(self, mock_multi_port_config_class, mock_find, _): + def test_build_config(self, mock_multi_port_config_class, mock_find, *args): mock_multi_port_config = mock_multi_port_config_class() vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() @@ -610,8 +606,8 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch('yardstick.ssh.SSH') - def test_setup_vnf_environment(self, _, mock_time): - def execute(cmd, *args, **kwargs): + def test_setup_vnf_environment(self, *args): + def execute(cmd): if cmd.startswith('which '): return exec_failure return exec_success @@ -643,7 +639,7 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): @mock.patch('yardstick.ssh.SSH') def test__setup_dpdk_short(self, _): - def execute_side(cmd, *args, **kwargs): + def execute_side(cmd): if 'joined_path' in cmd: return 0, 'output', '' return 1, 'bad output', 'error output' @@ -691,7 +687,7 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): self.assertEqual(dpdk_setup_helper.socket, 1) @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') - def test__detect_and_bind_drivers(self, mock_time): + def test__detect_and_bind_drivers(self, *args): vnfd_helper = VnfdHelper(deepcopy(self.VNFD_0)) ssh_helper = mock.Mock() # ssh_helper.execute = mock.Mock(return_value = (0, 'text', '')) @@ -1002,7 +998,7 @@ class TestClientResourceHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG') @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.STLError', new_callable=lambda: MockError) - def test_get_stats_not_connected(self, mock_state_error, mock_logger): + def test_get_stats_not_connected(self, mock_state_error, *args): vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() @@ -1221,7 +1217,7 @@ class TestClientResourceHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG') @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.STLError', new_callable=lambda: MockError) - def test__connect_with_failures(self, mock_error, mock_logger, mock_time): + def test__connect_with_failures(self, mock_error, *args): vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() @@ -1393,7 +1389,7 @@ class TestSampleVNFDeployHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch('subprocess.check_output') - def test_deploy_vnfs_disabled(self, mock_check_output, mock_time): + def test_deploy_vnfs_disabled(self, *args): vnfd_helper = mock.Mock() ssh_helper = mock.Mock() ssh_helper.join_bin_path.return_value = 'joined_path' @@ -1408,7 +1404,7 @@ class TestSampleVNFDeployHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch('subprocess.check_output') - def test_deploy_vnfs(self, mock_check_output, mock_time): + def test_deploy_vnfs(self, *args): vnfd_helper = mock.Mock() ssh_helper = mock.Mock() ssh_helper.join_bin_path.return_value = 'joined_path' @@ -1422,7 +1418,7 @@ class TestSampleVNFDeployHelper(unittest.TestCase): self.assertEqual(ssh_helper.put.call_count, 1) @mock.patch('subprocess.check_output') - def test_deploy_vnfs_early_success(self, mock_check_output): + def test_deploy_vnfs_early_success(self, *args): vnfd_helper = mock.Mock() ssh_helper = mock.Mock() ssh_helper.join_bin_path.return_value = 'joined_path' @@ -1700,7 +1696,7 @@ class TestSampleVnf(unittest.TestCase): self.assertEqual(result, expected) @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.Process') - def test__start_vnf(self, mock_process_type): + def test__start_vnf(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf._run = mock.Mock() @@ -1754,7 +1750,7 @@ class TestSampleVnf(unittest.TestCase): @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") @mock.patch("yardstick.ssh.SSH") - def test_wait_for_instantiate_empty_queue(self, ssh, mock_time): + def test_wait_for_instantiate_empty_queue(self, ssh, *args): mock_ssh(ssh, exec_result=(1, "", "")) queue_size_list = [ @@ -1798,7 +1794,7 @@ class TestSampleVnf(unittest.TestCase): self.assertIsNotNone(sample_vnf.my_ports) @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") - def test_vnf_execute_with_queue_data(self, mock_time): + def test_vnf_execute_with_queue_data(self, *args): queue_size_list = [ 1, 1, @@ -1843,7 +1839,7 @@ class TestSampleVnf(unittest.TestCase): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.APP_NAME = 'sample1' - sample_vnf.COLLECT_KPI = '\s(\d+)\D*(\d+)\D*(\d+)' + sample_vnf.COLLECT_KPI = r'\s(\d+)\D*(\d+)\D*(\d+)' sample_vnf.COLLECT_MAP = { 'k1': 3, 'k2': 1, @@ -1866,7 +1862,7 @@ class TestSampleVnf(unittest.TestCase): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] sample_vnf = SampleVNF('vnf1', vnfd) sample_vnf.APP_NAME = 'sample1' - sample_vnf.COLLECT_KPI = '\s(\d+)\D*(\d+)\D*(\d+)' + sample_vnf.COLLECT_KPI = r'\s(\d+)\D*(\d+)\D*(\d+)' sample_vnf.get_stats = mock.Mock(return_value='') expected = { @@ -1877,6 +1873,12 @@ class TestSampleVnf(unittest.TestCase): result = sample_vnf.collect_kpi() self.assertDictEqual(result, expected) + def test_scale(self): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sample_vnf = SampleVNF('vnf1', vnfd) + self.assertRaises(y_exceptions.FunctionNotImplemented, + sample_vnf.scale) + class TestSampleVNFTrafficGen(unittest.TestCase): @@ -2051,3 +2053,8 @@ class TestSampleVNFTrafficGen(unittest.TestCase): self.assertEqual(sample_vnf_tg._wait_for_process(), 234) mock_proc.is_alive.assert_has_calls([mock.call(), mock.call()]) mock_status.assert_has_calls([mock.call(), mock.call()]) + + def test_scale(self): + sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) + self.assertRaises(y_exceptions.FunctionNotImplemented, + sample_vnf_tg.scale) -- cgit 1.2.3-korg