diff options
Diffstat (limited to 'tests/unit/benchmark')
6 files changed, 136 insertions, 60 deletions
diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py index 582d9ab99..2e546805d 100644 --- a/tests/unit/benchmark/contexts/test_heat.py +++ b/tests/unit/benchmark/contexts/test_heat.py @@ -182,11 +182,17 @@ class HeatContextTestCase(unittest.TestCase): u'd-mac_address': u'00:10', u'd-device_id': u'dev43', u'd-network_id': u'net987', + u'e': u'40.30.20.15', + u'e-subnet_id': 2, + u'e-mac_address': u'00:10', + u'e-device_id': u'dev43', + u'e-network_id': u'net987', } server = mock.MagicMock() server.ports = OrderedDict([ - ('a', {'stack_name': 'b', 'port': 'port_a'}), - ('c', {'stack_name': 'd', 'port': 'port_c'}), + ('a', [{'stack_name': 'b', 'port': 'port_a'}]), + ('c', [{'stack_name': 'd', 'port': 'port_c'}, + {'stack_name': 'e', 'port': 'port_f'}]), ]) expected = { @@ -205,7 +211,7 @@ class HeatContextTestCase(unittest.TestCase): } self.test_context.add_server_port(server) self.assertEqual(server.private_ip, '10.20.30.45') - self.assertEqual(len(server.interfaces), 2) + self.assertEqual(len(server.interfaces), 3) self.assertDictEqual(server.interfaces['port_a'], expected) @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') @@ -221,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' @@ -258,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. @@ -295,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 @@ -333,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 @@ -371,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 @@ -406,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/benchmark/core/test_task.py b/tests/unit/benchmark/core/test_task.py index e3917b5b2..737e7058b 100644 --- a/tests/unit/benchmark/core/test_task.py +++ b/tests/unit/benchmark/core/test_task.py @@ -70,10 +70,10 @@ class TaskTestCase(unittest.TestCase): 'network_name': 'mgmt', }, 'xe0': { - 'network_name': 'private_0', + 'network_name': 'uplink_0', }, 'xe1': { - 'network_name': 'public_0', + 'network_name': 'downlink_0', }, }, }, @@ -82,11 +82,11 @@ class TaskTestCase(unittest.TestCase): 'mgmt': { 'network_name': 'mgmt', }, - 'private_0': { - 'network_name': 'private_0', + 'uplink_0': { + 'network_name': 'uplink_0', }, - 'public_0': { - 'network_name': 'public_0', + 'downlink_0': { + 'network_name': 'downlink_0', }, }, }, @@ -100,15 +100,15 @@ class TaskTestCase(unittest.TestCase): }, {}, { - 'name': 'private_0', + 'name': 'uplink_0', 'subnet_cidr': '10.20.0.0/16', }, { - 'name': 'public_0', + 'name': 'downlink_0', 'segmentation_id': '1001', }, { - 'name': 'private_1', + 'name': 'uplink_1', }, ]) @@ -116,9 +116,9 @@ class TaskTestCase(unittest.TestCase): expected_get_network_calls = 6 expected = { 'mgmt': {'name': 'mgmt', 'network_type': 'flat'}, - 'private_0': {'name': 'private_0', 'subnet_cidr': '10.20.0.0/16'}, - 'private_1': {'name': 'private_1'}, - 'public_0': {'name': 'public_0', 'segmentation_id': '1001'}, + 'uplink_0': {'name': 'uplink_0', 'subnet_cidr': '10.20.0.0/16'}, + 'uplink_1': {'name': 'uplink_1'}, + 'downlink_0': {'name': 'downlink_0', 'segmentation_id': '1001'}, } networks = task.get_networks_from_nodes(nodes) diff --git a/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml b/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml index cfa166a74..2123e4705 100644 --- a/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml +++ b/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml @@ -49,13 +49,13 @@ private: ipv4: outer_l2: framesize: - 64B: "{{ get(imix, 'imix.private.imix_small', '0') }}" - 128B: "{{ get(imix, 'imix.private.imix_128B', '0') }}" - 256B: "{{ get(imix, 'imix.private.imix_256B', '0') }}" - 373b: "{{ get(imix, 'imix.private.imix_373B', '0') }}" - 570B: "{{get(imix, 'imix.private.imix_570B', '0') }}" - 1400B: "{{get(imix, 'imix.private.imix_1400B', '0') }}" - 1518B: "{{get(imix, 'imix.private.imix_1500B', '0') }}" + 64B: "{{ get(imix, 'imix.uplink.imix_small', '0') }}" + 128B: "{{ get(imix, 'imix.uplink.imix_128B', '0') }}" + 256B: "{{ get(imix, 'imix.uplink.imix_256B', '0') }}" + 373b: "{{ get(imix, 'imix.uplink.imix_373B', '0') }}" + 570B: "{{get(imix, 'imix.uplink.imix_570B', '0') }}" + 1400B: "{{get(imix, 'imix.uplink.imix_1400B', '0') }}" + 1518B: "{{get(imix, 'imix.uplink.imix_1500B', '0') }}" QinQ: S-VLAN: @@ -81,13 +81,13 @@ public: ipv4: outer_l2: framesize: - 64B: "{{ get(imix, 'imix.private.imix_small', '0') }}" - 128B: "{{ get(imix, 'imix.private.imix_128B', '0') }}" - 256B: "{{ get(imix, 'imix.private.imix_256B', '0') }}" - 373b: "{{ get(imix, 'imix.private.imix_373B', '0') }}" - 570B: "{{get(imix, 'imix.private.imix_570B', '0') }}" - 1400B: "{{get(imix, 'imix.private.imix_1400B', '0') }}" - 1518B: "{{get(imix, 'imix.private.imix_1500B', '0') }}" + 64B: "{{ get(imix, 'imix.uplink.imix_small', '0') }}" + 128B: "{{ get(imix, 'imix.uplink.imix_128B', '0') }}" + 256B: "{{ get(imix, 'imix.uplink.imix_256B', '0') }}" + 373b: "{{ get(imix, 'imix.uplink.imix_373B', '0') }}" + 570B: "{{get(imix, 'imix.uplink.imix_570B', '0') }}" + 1400B: "{{get(imix, 'imix.uplink.imix_1400B', '0') }}" + 1518B: "{{get(imix, 'imix.uplink.imix_1500B', '0') }}" outer_l3v4: proto: "tcp" diff --git a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py index 58244b8f5..fa9b8549d 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py +++ b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -24,6 +24,8 @@ import errno import unittest import mock +from copy import deepcopy + from tests.unit import STL_MOCKS from yardstick.benchmark.scenarios.networking.vnf_generic import \ SshManager, NetworkServiceTestCase, IncorrectConfig, \ @@ -240,11 +242,11 @@ class TestNetworkServiceTestCase(unittest.TestCase): 'vnf__1': self.vnf__1, }, 'networks': { - 'private': { - 'vld_id': 'private', + GenericVNF.UPLINK: { + 'vld_id': GenericVNF.UPLINK, }, - 'public': { - 'vld_id': 'public', + GenericVNF.DOWNLINK: { + 'vld_id': GenericVNF.DOWNLINK, }, }, } @@ -263,7 +265,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): } ], 'type': 'ELAN', - 'id': 'private', + 'id': GenericVNF.UPLINK, 'name': 'tg__1 to vnf__1 link 1' } @@ -281,7 +283,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): } ], 'type': 'ELAN', - 'id': 'public', + 'id': GenericVNF.DOWNLINK, 'name': 'vnf__1 to tg__1 link 2' } @@ -365,6 +367,24 @@ class TestNetworkServiceTestCase(unittest.TestCase): result = '152.16.100.2-152.16.100.254' self.assertEqual(result, self.s._get_ip_flow_range({"tg__1": 'xe0'})) + @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.ipaddress') + def test__get_ip_flow_range_no_node_data(self, mock_ipaddress): + scenario_cfg = deepcopy(self.scenario_cfg) + scenario_cfg["traffic_options"]["flow"] = \ + self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml") + + mock_ipaddress.ip_network.return_value = ipaddr = mock.Mock() + ipaddr.hosts.return_value = [] + + expected = '0.0.0.0' + result = self.s._get_ip_flow_range({"tg__2": 'xe0'}) + self.assertEqual(result, expected) + + def test__get_ip_flow_range_no_nodes(self): + expected = '0.0.0.0' + result = self.s._get_ip_flow_range({}) + self.assertEqual(result, expected) + def test___get_traffic_flow(self): self.scenario_cfg["traffic_options"]["flow"] = \ self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml") @@ -653,12 +673,6 @@ class TestNetworkServiceTestCase(unittest.TestCase): res = NetworkServiceTestCase.parse_netdev_info(output) assert res == self.SAMPLE_VM_NETDEVS - def test_sort_dpdk_port_num(self): - netdevs = self.SAMPLE_NETDEVS.copy() - NetworkServiceTestCase._sort_dpdk_port_num(netdevs) - assert netdevs['lan']['dpdk_port_num'] == 0 - assert netdevs['enp11s0']['dpdk_port_num'] == 1 - def test_probe_missing_values(self): netdevs = self.SAMPLE_NETDEVS.copy() network = {'local_mac': '0a:de:ad:be:ef:f5'} diff --git a/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml b/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml index 0de4b6e79..1ac6c1f89 100644 --- a/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml +++ b/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml @@ -27,7 +27,7 @@ nsd:nsd-catalog: VNF model: ../../vnf_descriptors/vpe_vnf.yaml #tg_l3fwd.yaml #tg_trex_tpl.yaml #TREX vld: - - id: private + - id: uplink name: tg__1 to vnf__1 link 1 type: ELAN vnfd-connection-point-ref: @@ -38,7 +38,7 @@ nsd:nsd-catalog: vnfd-connection-point-ref: xe0 vnfd-id-ref: vnf__1 #VNF - - id: public + - id: downlink name: vnf__1 to tg__1 link 2 type: ELAN vnfd-connection-point-ref: |