From 6feb524aa398b40f394d6023e073315a86c5016c Mon Sep 17 00:00:00 2001 From: Roman Safronov Date: Tue, 16 Apr 2024 21:42:04 +0300 Subject: [PATCH] Specify openstack namespace in oc commands Recent version of podified deployment does not have contexts configured in .kube/config and 'oc' commands do not work as expected. This patch adds openstack namespace parameter when running 'oc' commands. Additionally, on the recent version of podified deployment compute nodes have names with domain name specified. This caused tests that capture traffic on nodes behave not correctly. This patch fixes this. Change-Id: I888effbdc894a9e65bd0e92164456db096bb4875 --- .../tests/scenario/base.py | 39 ++++++++++++------- .../tests/scenario/test_dvr_ovn.py | 2 +- .../scenario/test_sriov_provider_network.py | 10 ++--- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/base.py b/whitebox_neutron_tempest_plugin/tests/scenario/base.py index f73a0a7..66825c1 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/base.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/base.py @@ -73,6 +73,7 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): cls.master_cont_cmd_executor = cls.run_on_master_controller cls.neutron_api_prefix = '' elif WB_CONF.openstack_type == 'podified': + cls.OC = "oc -n openstack " cls.proxy_host_client = cls.get_node_client( host=WB_CONF.proxy_host_address, username=WB_CONF.proxy_host_user, @@ -83,8 +84,8 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): WB_CONF.kubeconfig_path, WB_CONF.proxy_host_user)) cls.master_node_client = cls.proxy_host_client cls.master_cont_cmd_executor = cls.proxy_host_client.exec_command - cls.neutron_api_prefix = 'oc rsh {} '.format( - cls.get_pod_of_service()) + cls.neutron_api_prefix = '{} rsh {} '.format( + cls.OC, cls.get_pod_of_service()) else: LOG.warning(("Unrecognized deployer tool '{}', plugin supports " "openstack_type as devstack/podified.".format( @@ -165,6 +166,16 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): "Not able to find a different compute than: {}".format( exclude_hosts)) + @classmethod + def get_full_name(cls, hostname): + compute_hosts = [ + host['hypervisor_hostname'] for host + in cls.os_admin.hv_client.list_hypervisors()['hypervisors']] + for host_name in compute_hosts: + if hostname in host_name: + return host_name + return hostname + @staticmethod def _get_local_ip_from_network(network): host_ip_addresses = [ifaddresses(iface)[AF_INET][0]['addr'] @@ -268,7 +279,8 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): cls.nodes.append( {'ip': host, 'client': cls.get_node_client(host)}) for host in cls.nodes: - host['name'] = host['client'].exec_command('hostname').strip() + host['name'] = cls.get_full_name( + host['client'].exec_command('hostname').strip()) # Here we are checking if there are controller-specific # processes running on the node output = host['client'].exec_command( @@ -292,7 +304,7 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): @classmethod def get_pod_of_service(cls, service='neutron'): - pods_list = "oc get pods" + pods_list = "{} get pods".format(cls.OC) if service == 'neutron': filters = "grep neutron | grep -v meta | cut -d' ' -f1" else: @@ -307,8 +319,8 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): if service == 'neutron': pod = cls.get_pod_of_service(service) return cls.proxy_host_client.exec_command( - 'oc rsh -n openstack {} find {} -type f'.format( - pod, os.path.split( + '{} rsh {} find {} -type f'.format( + cls.OC, pod, os.path.split( WB_CONF.neutron_config)[0])).strip().split('\n') # TODO(mblue): next gen computes configuration set should be done too, @@ -341,8 +353,8 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): [{}] {} = {}'''.format( service, section, param, value) - cmd = "oc patch $(oc get oscp -o name) --type=merge --patch '" + \ - patch_buffer + "'" + cmd = ("{0} patch $({0} get oscp -o name) --type=merge " + "--patch '".format(cls.OC) + patch_buffer + "'") LOG.debug("Set configuration command:\n%s", cmd) output = cls.proxy_host_client.exec_command(cmd) LOG.debug("Output:\n%s", output) @@ -375,8 +387,8 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): """ if WB_CONF.openstack_type == 'podified': - service_prefix = "oc rsh -n openstack {}".format( - cls.get_pod_of_service(service)) + service_prefix = "{} rsh {}".format( + cls.OC, cls.get_pod_of_service(service)) else: service_prefix = "" cmd_prefix = "crudini --get" @@ -640,7 +652,7 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): def get_osp_cmd_prefix(cls, admin=True): # TODO(mblue): figure how admin used in podified setup when needed if WB_CONF.openstack_type == 'podified': - prefix = 'oc rsh -n openstack openstackclient ' + prefix = '{} rsh openstackclient '.format(cls.OC) elif WB_CONF.openstack_type == 'devstack': prefix = '. /opt/stack/devstack/openrc{} && '.format( ' admin' if admin else '') @@ -1139,8 +1151,9 @@ class BaseTempestTestCaseOvn(BaseTempestWhiteboxTestCase): def _get_ovn_dbs(cls): if WB_CONF.openstack_type == 'podified': sb_pod = cls.proxy_host_client.exec_command( - "oc get pods | grep ovsdbserver-sb | cut -f1 -d' '").strip() - sb_prefix = 'oc rsh -n openstack {}'.format(sb_pod) + "{} get pods | grep ovsdbserver-sb | " + "cut -f1 -d' '".format(cls.OC)).strip() + sb_prefix = '{} rsh {}'.format(cls.OC, sb_pod) nb_prefix = sb_prefix.replace('sb', 'nb') cmd = "{} ovn-{}ctl" return [cmd.format(nb_prefix, 'nb'), cmd.format(sb_prefix, 'sb')] diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/test_dvr_ovn.py b/whitebox_neutron_tempest_plugin/tests/scenario/test_dvr_ovn.py index 12240e7..8523641 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/test_dvr_ovn.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/test_dvr_ovn.py @@ -279,7 +279,7 @@ class OvnDvrTest(OvnDvrBase): self._setup() server2 = self._create_server(exclude_hosts=self.exclude_hosts) compute2 = self.get_host_for_server( - server2['server']['id']).split('.')[0] + server2['server']['id']) LOG.debug("compute = {}, compute2 = {}".format(self.compute, compute2)) if self.compute == compute2: self.skipTest( diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/test_sriov_provider_network.py b/whitebox_neutron_tempest_plugin/tests/scenario/test_sriov_provider_network.py index 4d88419..193b382 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/test_sriov_provider_network.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/test_sriov_provider_network.py @@ -107,20 +107,20 @@ class ProviderNetworkSriovBaseTest(base.ProviderBaseTest): # or more than one cell will be supported in the future nova_scheduler_pod = cls.get_pod_of_service("nova-scheduler") cells = cls.proxy_host_client.exec_command( - "oc rsh {} nova-manage cell_v2 list_hosts | grep compute | " - "tr -d '|' | tr -s ' ' ".format(nova_scheduler_pod) + "| " + "{} rsh {} nova-manage cell_v2 list_hosts | grep compute | " + "tr -d '|' | tr -s ' ' ".format(cls.OC, nova_scheduler_pod) + "| " "awk '{print $1}' | uniq").strip().split() if len(cells) != 1: cls.fail("Currently only environments with a single cell " "are supported") galera_pod = cls.get_pod_of_service( 'openstack-{}-galera-0'.format(cells[0])) - galera_db_exec = "oc rsh {}".format(galera_pod) + galera_db_exec = "{} rsh {}".format(cls.OC, galera_pod) data_filter = ".data.Nova{}DatabasePassword|base64decode".format( cells[0].capitalize()) db_password = cls.proxy_host_client.exec_command( - "oc get secret osp-secret -o go-template --template=" - "\"{{" + data_filter + "}}\"").strip() + "{} get secret osp-secret -o go-template --template=".format( + cls.OC) + "\"{{" + data_filter + "}}\"").strip() db_credentials = "-u root -p{}".format(db_password) mysql_cmd = ('mysql --skip-column-names {} nova_{} -e ' '"select pci_stats from compute_nodes;"'.format(