diff options
Diffstat (limited to 'tests')
11 files changed, 131 insertions, 46 deletions
diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc025.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc025.yaml index a37f83b83..3e630caf2 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc025.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc025.yaml @@ -19,7 +19,7 @@ description: > {% set file = file or '/etc/yardstick/pod.yaml' %} {% set jump_host = jump_host or 'node0' %} {% set attack_host = attack_host or 'node1' %} -{% set monitor_time = monitor_time or 180 %} +{% set monitor_time = monitor_time or 30 %} scenarios: - diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc055.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc055.yaml index 7e33741b1..10a7a7108 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc055.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc055.yaml @@ -24,7 +24,6 @@ description: > scenarios: - type: ComputeCapacity - options: nodes: host: {{host}} diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py index d1b5855f9..2e546805d 100644 --- a/tests/unit/benchmark/contexts/test_heat.py +++ b/tests/unit/benchmark/contexts/test_heat.py @@ -227,19 +227,20 @@ class HeatContextTestCase(unittest.TestCase): mock_os.path.exists.return_value = True self.assertIsNone(self.test_context.undeploy()) - def test__get_server_found_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to get a server that matches based on a dictionary input. """ foo2_server = mock.Mock() - foo2_server.key_filename = 'key_file' + foo2_server.key_filename = None foo2_server.private_ip = '10.0.0.2' foo2_server.public_ip = '127.0.0.2' foo2_server.context.user = 'oof' baz3_server = mock.Mock() - baz3_server.key_filename = 'key_filename' + baz3_server.key_filename = None baz3_server.private_ip = '10.0.0.3' baz3_server.public_ip = '127.0.0.3' baz3_server.context.user = 'zab' @@ -264,11 +265,11 @@ class HeatContextTestCase(unittest.TestCase): } result = self.test_context._get_server(attr_name) self.assertEqual(result['user'], 'bot') - self.assertIsNotNone(result['key_filename']) self.assertEqual(result['ip'], '127.0.0.1') self.assertEqual(result['private_ip'], '10.0.0.1') - def test__get_server_found_dict_no_attrs(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_dict_no_attrs(self, mock_pkg_resources): """ Use HeatContext._get_server to get a server that matches based on a dictionary input. @@ -301,13 +302,13 @@ class HeatContextTestCase(unittest.TestCase): } result = self.test_context._get_server(attr_name) self.assertEqual(result['user'], 'bot') - self.assertIsNotNone(result['key_filename']) # no private ip attr mapping in the map results in None value in the result self.assertIsNone(result['private_ip']) # no public ip attr mapping in the map results in no value in the result self.assertNotIn('ip', result) - def test__get_server_found_not_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_not_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to get a server that matches based on a non-dictionary input @@ -339,12 +340,12 @@ class HeatContextTestCase(unittest.TestCase): attr_name = 'baz3' result = self.test_context._get_server(attr_name) self.assertEqual(result['user'], 'zab') - self.assertIsNotNone(result['key_filename']) self.assertEqual(result['private_ip'], '10.0.0.3') # no public_ip on the server results in no value in the result self.assertNotIn('public_ip', result) - def test__get_server_none_found_not_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_none_found_not_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to not get a server due to None value associated with the match to a non-dictionary @@ -377,7 +378,8 @@ class HeatContextTestCase(unittest.TestCase): result = self.test_context._get_server(attr_name) self.assertIsNone(result) - def test__get_server_not_found_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_not_found_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to not get a server for lack of a match to a dictionary input @@ -412,7 +414,8 @@ class HeatContextTestCase(unittest.TestCase): result = self.test_context._get_server(attr_name) self.assertIsNone(result) - def test__get_server_not_found_not_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_not_found_not_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to not get a server for lack of a match to a non-dictionary input diff --git a/tests/unit/benchmark/contexts/test_kubernetes.py b/tests/unit/benchmark/contexts/test_kubernetes.py index 4976a9fe0..3a926f85c 100644 --- a/tests/unit/benchmark/contexts/test_kubernetes.py +++ b/tests/unit/benchmark/contexts/test_kubernetes.py @@ -47,13 +47,15 @@ class KubernetesTestCase(unittest.TestCase): # clear kubernetes contexts from global list so we don't break other tests Context.list = [] + @mock.patch('{}.KubernetesContext._delete_services'.format(prefix)) @mock.patch('{}.KubernetesContext._delete_ssh_key'.format(prefix)) @mock.patch('{}.KubernetesContext._delete_rcs'.format(prefix)) @mock.patch('{}.KubernetesContext._delete_pods'.format(prefix)) def test_undeploy(self, mock_delete_pods, mock_delete_rcs, - mock_delete_ssh): + mock_delete_ssh, + mock_delete_services): k8s_context = KubernetesContext() k8s_context.init(context_cfg) @@ -61,7 +63,9 @@ class KubernetesTestCase(unittest.TestCase): self.assertTrue(mock_delete_ssh.called) self.assertTrue(mock_delete_rcs.called) self.assertTrue(mock_delete_pods.called) + self.assertTrue(mock_delete_services.called) + @mock.patch('{}.KubernetesContext._create_services'.format(prefix)) @mock.patch('{}.KubernetesContext._wait_until_running'.format(prefix)) @mock.patch('{}.KubernetesTemplate.get_rc_pods'.format(prefix)) @mock.patch('{}.KubernetesContext._create_rcs'.format(prefix)) @@ -70,7 +74,8 @@ class KubernetesTestCase(unittest.TestCase): mock_set_ssh_key, mock_create_rcs, mock_get_rc_pods, - mock_wait_until_running): + mock_wait_until_running, + mock_create_services): k8s_context = KubernetesContext() k8s_context.init(context_cfg) @@ -78,6 +83,7 @@ class KubernetesTestCase(unittest.TestCase): k8s_context.deploy() self.assertTrue(mock_set_ssh_key.called) self.assertTrue(mock_create_rcs.called) + self.assertTrue(mock_create_services.called) self.assertTrue(mock_get_rc_pods.called) self.assertTrue(mock_wait_until_running.called) @@ -106,14 +112,39 @@ class KubernetesTestCase(unittest.TestCase): mock_read_pod_status.return_value = 'Running' k8s_context._wait_until_running() - @mock.patch('{}.k8s_utils.get_pod_list'.format(prefix)) - def test_get_server(self, mock_get_pod_list): + @mock.patch('{}.k8s_utils.get_pod_by_name'.format(prefix)) + @mock.patch('{}.KubernetesContext._get_node_ip'.format(prefix)) + @mock.patch('{}.k8s_utils.get_service_by_name'.format(prefix)) + def test_get_server(self, + mock_get_service_by_name, + mock_get_node_ip, + mock_get_pod_by_name): + class Service(object): + def __init__(self): + self.name = 'yardstick' + self.node_port = 30000 + + class Services(object): + def __init__(self): + self.ports = [Service()] + + class Status(object): + def __init__(self): + self.pod_ip = '172.16.10.131' + + class Pod(object): + def __init__(self): + self.status = Status() + k8s_context = KubernetesContext() k8s_context.init(context_cfg) - mock_get_pod_list.return_value.items = [] + mock_get_service_by_name.return_value = Services() + mock_get_pod_by_name.return_value = Pod() + mock_get_node_ip.return_value = '172.16.10.131' + server = k8s_context._get_server('server') - self.assertIsNone(server) + self.assertIsNotNone(server) @mock.patch('{}.KubernetesContext._create_rc'.format(prefix)) def test_create_rcs(self, mock_create_rc): @@ -143,6 +174,28 @@ class KubernetesTestCase(unittest.TestCase): k8s_context._delete_rc({}) self.assertTrue(mock_delete_replication_controller.called) + @mock.patch('{}.k8s_utils.get_node_list'.format(prefix)) + def test_get_node_ip(self, mock_get_node_list): + + k8s_context = KubernetesContext() + k8s_context.init(context_cfg) + k8s_context._get_node_ip() + self.assertTrue(mock_get_node_list.called) + + @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.create') + def test_create_services(self, mock_create): + k8s_context = KubernetesContext() + k8s_context.init(context_cfg) + k8s_context._create_services() + self.assertTrue(mock_create.called) + + @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.delete') + def test_delete_services(self, mock_delete): + k8s_context = KubernetesContext() + k8s_context.init(context_cfg) + k8s_context._delete_services() + self.assertTrue(mock_delete.called) + def main(): unittest.main() diff --git a/tests/unit/network_services/traffic_profile/test_prox_acl.py b/tests/unit/network_services/traffic_profile/test_prox_acl.py index be172f26b..a0c60186c 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_acl.py +++ b/tests/unit/network_services/traffic_profile/test_prox_acl.py @@ -29,19 +29,38 @@ if stl_patch: from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple -class TestProxRampProfile(unittest.TestCase): +class TestProxACLProfile(unittest.TestCase): def test_run_test_with_pkt_size(self): + def target(*args, **kwargs): + runs.append(args[2]) + if args[2] < 0 or args[2] > 100: + raise RuntimeError(' '.join([str(args), str(runs)])) + if args[2] > 75.0: + return fail_tuple, {} + return success_tuple, {} + + def get_mock_samples(*args, **kwargs): + if args[2] < 0: + raise RuntimeError(' '.join([str(args), str(runs)])) + return success_tuple + tp_config = { - 'traffic_profile': { + 'traffic_profile': { 'upper_bound': 100.0, + 'lower_bound': 0.0, + 'tolerated_loss': 50.0, + 'attempts': 20 }, } + runs = [] success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4) fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4) traffic_gen = mock.MagicMock() + traffic_gen.run_test = target + traffic_gen.resource_helper.run_test.side_effect = [ success_tuple, success_tuple, @@ -53,14 +72,15 @@ class TestProxRampProfile(unittest.TestCase): fail_tuple, ] - fill_values = [1, 2, 3, 4, RuntimeError] - profile = ProxACLProfile(tp_config) - profile.fill_samples = fill_samples = mock.MagicMock(side_effect=fill_values) - profile.queue = mock.MagicMock() + profile.init(mock.MagicMock()) - with self.assertRaises(RuntimeError): - profile.run_test_with_pkt_size(traffic_gen, 128, 30) + profile.prox_config["attempts"] = 20 + profile.queue = mock.MagicMock() + profile.tolerated_loss = 50.0 + profile.pkt_size = 128 + profile.duration = 30 + profile.test_value = 100.0 + profile.tolerated_loss = 100.0 - self.assertEqual(traffic_gen.resource_helper.run_test.call_count, 5) - self.assertEqual(fill_samples.call_count, 5) + profile.run_test_with_pkt_size(traffic_gen, profile.pkt_size, profile.duration) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py index 76f2d5b5d..0a4c12446 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py @@ -311,8 +311,9 @@ class TestCgnaptApproxVnf(unittest.TestCase): cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd) self.assertIsNone(cgnapt_approx_vnf._vnf_process) + @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch(SSH_HELPER) - def test_collect_kpi(self, ssh, mock_process): + def test_collect_kpi(self, ssh, mock_time, mock_process): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -324,8 +325,9 @@ class TestCgnaptApproxVnf(unittest.TestCase): result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0} self.assertEqual(result, cgnapt_approx_vnf.collect_kpi()) + @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch(SSH_HELPER) - def test_vnf_execute_command(self, ssh, mock_process): + def test_vnf_execute_command(self, ssh, mock_time, mock_process): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] diff --git a/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py index 2202c11a5..995b4a2cc 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py @@ -934,7 +934,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): ], } - mock_find_path.side_effect = ['1', '2'] + mock_find_path.side_effect = ['1', '2'] + [str(i) for i in range(len(vnf1['prox_files']))] vnfd_helper = mock.MagicMock() ssh_helper = mock.MagicMock() scenario_helper = ScenarioHelper('vnf1') diff --git a/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py index f8b592d8c..c88b1528c 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py @@ -342,7 +342,7 @@ class TestProxApproxVnf(unittest.TestCase): resource_helper = mock.MagicMock() resource_helper.execute.return_value = list(range(12)) - resource_helper.collect_kpi.return_value = {'core': {'result': 234}} + resource_helper.collect_collectd_kpi.return_value = {'core': {'result': 234}} prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.resource_helper = resource_helper diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py index 4e82c0d5e..eb569cfe6 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py @@ -20,7 +20,6 @@ import mock from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from tests.unit import STL_MOCKS -from yardstick.network_services.nfvi.resource import ResourceProfile SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' NAME = 'vnf__1' @@ -334,7 +333,7 @@ class TestProxTrafficGen(unittest.TestCase): prox_traffic_gen._vnf_wrapper.resource_helper.resource = mock.MagicMock( **{"check_if_sa_running.return_value": [False]}) prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="") - self.assertEqual({"core": {}}, prox_traffic_gen.collect_kpi()) + self.assertEqual({}, prox_traffic_gen.collect_kpi()) @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.CpuSysCores') @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file') @@ -372,12 +371,12 @@ class TestProxTrafficGen(unittest.TestCase): 'task_path': '', 'options': {'tg__1': {'prox_args': {'-e': '', '-t': ''}, - 'prox_config': 'configs/l3-gen-2.cfg', - 'prox_path': '/root/dppd-PROX-v035/build/prox'}, - 'vnf__1': {'prox_args': {'-t': ''}, - 'prox_config': 'configs/l3-swap-2.cfg', - 'prox_path': '/root/dppd-PROX-v035/build/prox'} - } + 'prox_config': 'configs/l3-gen-2.cfg', + 'prox_path': '/root/dppd-PROX-v035/build/prox'}, + 'vnf__1': {'prox_args': {'-t': ''}, + 'prox_config': 'configs/l3-swap-2.cfg', + 'prox_path': '/root/dppd-PROX-v035/build/prox'} + } } prox_traffic_gen.instantiate(scenario_cfg, {}) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py index 0e303dc3b..f62a0fb3b 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py @@ -252,6 +252,7 @@ class TestIXIATrafficGen(unittest.TestCase): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE + # traffic_profile.ports is standardized on port_num mock_traffic_profile.ports = [0, 1] mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH) @@ -346,8 +347,12 @@ class TestIXIATrafficGen(unittest.TestCase): 'task_path': '/path/to/task' } - with mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', - create=True) as mock_open: - mock_open.return_value = mock.MagicMock() + @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True) + @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open', + mock.mock_open(), create=True) + @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception') + def _traffic_runner(*args): result = sut._traffic_runner(mock_traffic_profile) self.assertIsNone(result) + + _traffic_runner() diff --git a/tests/unit/orchestrator/test_kubernetes.py b/tests/unit/orchestrator/test_kubernetes.py index 51718ab86..1a3291c89 100644 --- a/tests/unit/orchestrator/test_kubernetes.py +++ b/tests/unit/orchestrator/test_kubernetes.py @@ -62,7 +62,10 @@ service ssh restart;while true ; do sleep 10000; done" }, "name": "k8s-86096c30-key" } - ] + ], + "nodeSelector": { + "kubernetes.io/hostname": "node-01" + } } } } @@ -71,7 +74,8 @@ service ssh restart;while true ; do sleep 10000; done" 'command': '/bin/bash', 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \ service ssh restart;while true ; do sleep 10000; done'], - 'ssh_key': 'k8s-86096c30-key' + 'ssh_key': 'k8s-86096c30-key', + 'nodeSelector': { 'kubernetes.io/hostname': 'node-01'} } name = 'host-k8s-86096c30' output_r = KubernetesObject(name, **input_s).get_template() |