From 0cc8ae0fae8be4a729300dee5c4e128985212004 Mon Sep 17 00:00:00 2001 From: Roman Dobosz Date: Mon, 9 May 2022 13:32:51 +0200 Subject: [PATCH] Change naming (again) for networks and subnets. There is a need for changing names again, since namespace id is no longer stored in description and name for net/subnet is a compound of name and uid. Depends-On: https://review.opendev.org/c/openstack/kuryr-tempest-plugin/+/845745 Change-Id: Ib97a597f8afb47316e77154a9bf3ced41ce48468 --- .../tests/scenario/test_namespace.py | 28 ++++++++++++---- .../tests/scenario/test_port_pool.py | 33 ++++++++++--------- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/kuryr_tempest_plugin/tests/scenario/test_namespace.py b/kuryr_tempest_plugin/tests/scenario/test_namespace.py index 23a14f8e..4b78af14 100644 --- a/kuryr_tempest_plugin/tests/scenario/test_namespace.py +++ b/kuryr_tempest_plugin/tests/scenario/test_namespace.py @@ -49,6 +49,7 @@ class TestNamespaceScenario(base.BaseKuryrScenarioTest): # Check resources are created namespace_name, namespace = self.create_namespace() self.namespaces.append(namespace) + ns_uid = namespace.metadata.uid existing_namespaces = [ns.metadata.name for ns in self.list_namespaces().items] @@ -63,9 +64,11 @@ class TestNamespaceScenario(base.BaseKuryrScenarioTest): seen_subnets = self.os_admin.subnets_client.list_subnets() seen_subnet_names = [n['name'] for n in seen_subnets['subnets']] - subnet_name = namespace_name + subnet_name = (f"{ns_uid}/{namespace_name}") if subnet_name not in seen_subnet_names: subnet_name = 'ns/' + namespace_name + '-subnet' + if subnet_name not in seen_subnet_names: + subnet_name = namespace_name self.assertIn(subnet_name, seen_subnet_names) @@ -112,9 +115,9 @@ class TestNamespaceScenario(base.BaseKuryrScenarioTest): seen_sg_ids = [sg['id'] for sg in seen_sgs] subnet_ns1_name, net_crd_ns1 = self._get_and_check_ns_resources( - ns1_name, existing_namespaces, seen_sg_ids) + ns1, existing_namespaces, seen_sg_ids) subnet_ns2_name, net_crd_ns2 = self._get_and_check_ns_resources( - ns2_name, existing_namespaces, seen_sg_ids) + ns2, existing_namespaces, seen_sg_ids) self.assertIn('default', existing_namespaces) # Create pods in different namespaces @@ -153,17 +156,24 @@ class TestNamespaceScenario(base.BaseKuryrScenarioTest): seen_subnets = self.os_admin.subnets_client.list_subnets() if subnet_ns1_name not in seen_subnets: subnet_ns1_name = f'ns/{ns1_name}-subnet' + if subnet_ns1_name not in seen_subnets: + subnet_ns1_name = ns1_name if subnet_ns2_name not in seen_subnets: subnet_ns2_name = f'ns/{ns2_name}-subnet' + if subnet_ns2_name not in seen_subnets: + subnet_ns2_name = ns2_name self._delete_namespace_resources(ns1_name, net_crd_ns1, subnet_ns1_name) self._delete_namespace_resources(ns2_name, net_crd_ns2, subnet_ns2_name) - def _get_and_check_ns_resources(self, ns_name, existing_namespaces, + def _get_and_check_ns_resources(self, ns, existing_namespaces, existing_sgs): - subnet_ns_name = ns_name + ns_name = ns.metadata.name + ns_uid = ns.metadata.name + subnet_ns_name = f'{ns_uid}/{ns_name}' + net_crd_ns_name = 'ns-' + ns_name self.assertIn(ns_name, existing_namespaces) @@ -209,9 +219,9 @@ class TestNamespaceScenario(base.BaseKuryrScenarioTest): seen_sg_ids = [sg['id'] for sg in seen_sgs] subnet_ns1_name, net_crd_ns1 = self._get_and_check_ns_resources( - ns1_name, existing_namespaces, seen_sg_ids) + ns1, existing_namespaces, seen_sg_ids) subnet_ns2_name, net_crd_ns2 = self._get_and_check_ns_resources( - ns2_name, existing_namespaces, seen_sg_ids) + ns2, existing_namespaces, seen_sg_ids) self.assertIn('default', existing_namespaces) pod_nsdefault_name, pod_nsdefault = self.create_pod( @@ -255,8 +265,12 @@ class TestNamespaceScenario(base.BaseKuryrScenarioTest): seen_subnets = self.os_admin.subnets_client.list_subnets() if subnet_ns1_name not in seen_subnets: subnet_ns1_name = f'ns/{ns1_name}-subnet' + if subnet_ns1_name not in seen_subnets: + subnet_ns1_name = ns1_name if subnet_ns2_name not in seen_subnets: subnet_ns2_name = f'ns/{ns2_name}-subnet' + if subnet_ns2_name not in seen_subnets: + subnet_ns2_name = ns2_name self._delete_namespace_resources(ns1_name, net_crd_ns1, subnet_ns1_name) diff --git a/kuryr_tempest_plugin/tests/scenario/test_port_pool.py b/kuryr_tempest_plugin/tests/scenario/test_port_pool.py index b0c34926..57e9bd58 100644 --- a/kuryr_tempest_plugin/tests/scenario/test_port_pool.py +++ b/kuryr_tempest_plugin/tests/scenario/test_port_pool.py @@ -53,19 +53,20 @@ class TestPortPoolScenario(base.BaseKuryrScenarioTest): 'ports_pool_batch', 'ports_pool_min', 'ports_pool_max', 'ports_pool_update_frequency']) - def get_subnet_id_for_ns(self, namespace_name): - subnet_name = namespace_name + def get_subnet_id_for_ns(self, namespace): subnets_list = self.os_admin.subnets_client.list_subnets() - subnet_id = [n['id'] for n in subnets_list['subnets'] - if n['name'] == subnet_name] - if subnet_id: - subnet_id = subnet_id[0] - else: - subnet_name = f'ns/{namespace_name}-subnet' - subnet_id = [n['id'] for n in subnets_list['subnets'] - if n['name'] == subnet_name][0] + ns_name = namespace.metadata.name + ns_uid = namespace.metadata.uid - return subnet_id + for subnet_name in (f'{ns_name}/{ns_uid}', + f'ns/{ns_name}-subnet', + ns_name): + subnet_id = [n['id'] for n in subnets_list['subnets'] + if n['name'] == subnet_name] + if subnet_id: + return subnet_id[0] + + return None def check_initial_ports_num(self, subnet_id, namespace_name, pool_batch): # check the original length of list of ports for new ns @@ -105,9 +106,9 @@ class TestPortPoolScenario(base.BaseKuryrScenarioTest): # create a pod to test the port pool increase pod_name1, _ = self.create_pod(namespace=namespace_name, labels={'type': 'demo'}) - subnet_id = self.get_subnet_id_for_ns(namespace_name) + subnet_id = self.get_subnet_id_for_ns(namespace) else: - subnet_id = self.get_subnet_id_for_ns(namespace_name) + subnet_id = self.get_subnet_id_for_ns(namespace) port_list_num = self.check_initial_ports_num(subnet_id, namespace_name, pool_batch) @@ -190,7 +191,7 @@ class TestPortPoolScenario(base.BaseKuryrScenarioTest): # Check resources are created namespace_name, namespace = self.create_namespace() self.addCleanup(self.delete_namespace, namespace_name) - subnet_id = self.get_subnet_id_for_ns(namespace_name) + subnet_id = self.get_subnet_id_for_ns(namespace) self.update_config_map_ini_section_and_restart( name=self.CONFIG_MAP_NAME, conf_to_update=self.CONF_TO_UPDATE, @@ -253,7 +254,7 @@ class TestPortPoolScenario(base.BaseKuryrScenarioTest): # Check resources are created namespace_name, namespace = self.create_namespace() self.addCleanup(self.delete_namespace, namespace_name) - subnet_id = self.get_subnet_id_for_ns(namespace_name) + subnet_id = self.get_subnet_id_for_ns(namespace) # Read the value of the drivers update_pools_vif_drivers = self.get_config_map_ini_value( @@ -348,7 +349,7 @@ class TestPortPoolScenario(base.BaseKuryrScenarioTest): # Check resources are created namespace_name, namespace = self.create_namespace() self.addCleanup(self.delete_namespace, namespace_name) - subnet_id = self.get_subnet_id_for_ns(namespace_name) + subnet_id = self.get_subnet_id_for_ns(namespace) self.update_config_map_ini_section_and_restart( name=self.CONFIG_MAP_NAME,