From 15692a9fa80220af787c74daaf78e21335eff051 Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Mon, 14 Oct 2024 17:48:09 +0200 Subject: [PATCH] Add short_name to the nodes information Some functions included in BaseDisruptiveTempestTestCase class execute commands on the hypervisor server. They did not work properly with latest ci-fmw changes. This patch adapts those commands and now they work well, by using the short hostname from the nodes instead of the FQDNs. Related-bug: OSPRH-8595 Change-Id: I02c5cd4f9bcaf69011f3b59d853931a2ce5a714b --- .../tests/scenario/base.py | 33 +++++++++---------- .../tests/scenario/test_dvr_ovn.py | 30 +++++++++-------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/base.py b/whitebox_neutron_tempest_plugin/tests/scenario/base.py index efaae90..df76f40 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/base.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/base.py @@ -123,6 +123,9 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): server_details = self.os_admin.servers_client.show_server(server_id) return server_details['server']['OS-EXT-SRV-ATTR:host'] + def get_shortname_for_server(self, server_id): + return self.get_host_for_server(server_id).split('.')[0] + @classmethod def get_external_gateway(cls): if CONF.network.public_network_id: @@ -166,7 +169,7 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): for node in self.nodes: # we want to make sure we are comparing short names # in this case either short or long node_name will work - if node['name'].split('.')[0] == node_name.split('.')[0]: + if node['short_name'] == node_name.split('.')[0]: return node['client'] def find_different_compute_host(self, exclude_hosts): @@ -179,13 +182,6 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): "Not able to find a different compute than: {}".format( exclude_hosts)) - def get_node_full_name(self, node_name): - for node in self.nodes: - # we want to make sure we are comparing short names - # in this case either short or long node_name will work - if node['name'].split('.')[0] == node_name.split('.')[0]: - return node['client'].exec_command('hostname -f').strip() - def get_network_type(self, network_id): network_details = self.os_admin.network_client.show_network( network_id) @@ -344,6 +340,7 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): if not local_utils.host_responds_to_ping(host['ip']): continue host['name'] = host['client'].exec_command('hostname -f').strip() + host['short_name'] = host['name'].split('.')[0] host['is_compute'] = (host['name'] in compute_hosts) host['is_networker'] = (host['name'] in l3_agent_hosts) if WB_CONF.openstack_type == 'devstack': @@ -368,7 +365,7 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): def get_node_setting(self, node_name, setting): for node in self.nodes: - if node_name == node['name']: + if node_name == node['name'] or node_name == node['short_name']: return node[setting] @classmethod @@ -1082,7 +1079,7 @@ class TrafficFlowTest(BaseTempestWhiteboxTestCase): # split('.')[0] ensures that we always compare short names. # This will work even if for some reason one value is short # (can happen in get pods output) and another is long(fqdn). - if line.split()[0].split('.')[0] == node['name'].split('.')[0]: + if line.split()[0].split('.')[0] == node['short_name']: node['ovs_pod'] = line.split()[1] def _start_captures(self, filters, scenario='north_south', interface=None): @@ -1164,7 +1161,7 @@ class TrafficFlowTest(BaseTempestWhiteboxTestCase): self._stop_captures() LOG.debug('Expected routing nodes: {}'.format( ','.join(expected_routing_nodes))) - actual_routing_nodes = [node['name'] + actual_routing_nodes = [node['short_name'] for node in self.nodes if (node.get('capture') and not node['capture'].is_empty())] @@ -1209,7 +1206,7 @@ class TrafficFlowTest(BaseTempestWhiteboxTestCase): ssh_client, dst_ip, mtu=size, ping_count=2) self._stop_captures() LOG.debug('Expected routing nodes: {}'.format(expected_routing_nodes)) - actual_routing_nodes = [node['name'] + actual_routing_nodes = [node['short_name'] for node in self.nodes if (node.get('capture') and not node['capture'].is_empty())] @@ -1325,7 +1322,7 @@ class BaseTempestTestCaseOvn(BaseTempestWhiteboxTestCase): cmd = "{} get chassis {} hostname".format(self.sbctl, self.chassis_id) LOG.debug("Running '{}' on the master node".format(cmd)) res = self.run_on_master_controller(cmd) - return self.get_node_full_name(res.replace('"', '')) + return res.replace('"', '').split('.')[0] def get_router_gateway_chassis_list(self, router_port_id): cmd = (self.nbctl + " lrp-get-gateway-chassis lrp-" + router_port_id) @@ -1335,7 +1332,7 @@ class BaseTempestTestCaseOvn(BaseTempestWhiteboxTestCase): def get_router_gateway_chassis_by_id(self, chassis_id): res = self.run_on_master_controller( self.sbctl + " get chassis " + chassis_id + " hostname").rstrip() - return self.get_node_full_name(res.replace('"', '')) + return res.replace('"', '').split('.')[0] def get_router_port_gateway_mtu(self, router_port_id): cmd = (self.nbctl + " get logical_router_port lrp-" + router_port_id + @@ -1415,8 +1412,10 @@ class BaseDisruptiveTempestTestCase(BaseTempestWhiteboxTestCase): LOG.debug("Attempt to execute virsh command on hypervisor_host: " "'{}' failed. Trying to discover hypervisor host from " ".ssh/config file.".format(WB_CONF.hypervisor_host)) + # Depending on ci-fmw version and/or setup, .ssh/config file could + # include an entry for either hypervisor or hypervisor-1 host = cls.proxy_host_client.exec_command( - r"grep 'Host.*\ hypervisor$' ~/.ssh/config " + r"grep 'Host.*\ \(hypervisor\|hypervisor-1\)$' ~/.ssh/config " "| cut -d' ' -f 2").strip() try: @@ -1441,14 +1440,14 @@ class BaseDisruptiveTempestTestCase(BaseTempestWhiteboxTestCase): cmd = ("timeout 10 ssh {} virsh list --state-shutoff | grep -w {} " "|| true".format(cls.hypervisor_host, host)) output = cls.proxy_host_client.exec_command(cmd) - return True if host in output else False + return host in output @classmethod def is_host_loginable(cls, host): cmd = "timeout 10 ssh {} ssh {} hostname || true".format( cls.hypervisor_host, host) output = cls.proxy_host_client.exec_command(cmd) - return True if host in output else False + return host in output @classmethod def power_off_host(cls, host): 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 24c007a..acc9d3a 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/test_dvr_ovn.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/test_dvr_ovn.py @@ -142,7 +142,8 @@ class OvnDvrBase(base.TrafficFlowTest, base.BaseTempestTestCaseOvn): self.server = self._create_server( exclude_hosts=self.exclude_hosts) - self.compute = self.get_host_for_server(self.server['server']['id']) + self.compute = self.get_shortname_for_server( + self.server['server']['id']) self.exclude_hosts.append(self.compute) self.server_ssh_client = ssh.Client( @@ -251,7 +252,8 @@ class OvnDvrTest(OvnDvrBase): ext_vm['port']['fixed_ips'][0]['ip_address'], self.username, pkey=self.keypair['private_key']) ssh_client = self.ext_vm_ssh_client - ext_vm_host = self.get_host_for_server(ext_vm['server']['id']) + ext_vm_host = self.get_shortname_for_server( + ext_vm['server']['id']) # expected_routing_nodes should not have duplicates expected_routing_nodes = list(set([self.compute, ext_vm_host])) return ssh_client, expected_routing_nodes @@ -322,7 +324,7 @@ class OvnDvrTest(OvnDvrBase): """ self._setup() server2 = self._create_server(exclude_hosts=self.exclude_hosts) - compute2 = self.get_host_for_server( + compute2 = self.get_shortname_for_server( server2['server']['id']) LOG.debug("compute = {}, compute2 = {}".format(self.compute, compute2)) if self.compute == compute2: @@ -397,7 +399,7 @@ class OvnDvrTest(OvnDvrBase): CONF.validation.image_ssh_user, pkey=self.keypair['private_key'], proxy_client=self.server_ssh_client) - server2_host = self.get_host_for_server( + server2_host = self.get_shortname_for_server( server2['server']['id']) # verify N/S connection with self.server @@ -435,7 +437,7 @@ class OvnDvrTest(OvnDvrBase): block_migration=block_migration) self.wait_for_server_active( self.server['server'], client=self.os_admin.servers_client) - new_host = self.get_host_for_server( + new_host = self.get_shortname_for_server( self.server['server']['id']) self.assertNotEqual(self.compute, new_host, 'Server1 did not migrate') # migrate server2 @@ -450,7 +452,7 @@ class OvnDvrTest(OvnDvrBase): self.wait_for_server_active( server2['server'], client=self.os_admin.servers_client) - new_server2_host = self.get_host_for_server( + new_server2_host = self.get_shortname_for_server( server2['server']['id']) self.assertNotEqual(server2_host, new_server2_host, 'Server2 did not migrate') @@ -522,7 +524,7 @@ class OvnDvrTest(OvnDvrBase): else {}) servers.append(self._create_server( network=networks[i], scheduler_hints=scheduler_hints)) - servers_host.append(self.get_host_for_server( + servers_host.append(self.get_shortname_for_server( servers[i]['server']['id'])) servers_fip_mac.append(self.get_fip_port_details( servers[i]['fip'])['mac_address']) @@ -546,7 +548,7 @@ class OvnDvrTest(OvnDvrBase): def get_mac_mapping_for_vm(vm): return self.get_mac_mappings( self.find_node_client( - self.get_host_for_server(vm['server']['id'])), + self.get_shortname_for_server(vm['server']['id'])), 'datacentre') def get_expected_macs_for_vlan_tenant(): @@ -596,7 +598,7 @@ class OvnDvrTest(OvnDvrBase): server['server']['id'], host=host, block_migration=block_migration) self.wait_for_server_active(server['server']) - new_servers_host.append(self.get_host_for_server( + new_servers_host.append(self.get_shortname_for_server( server['server']['id'])) self.assertNotEqual(servers_host[i], new_servers_host[i], 'Server%d did not migrate' % i) @@ -696,7 +698,7 @@ class OvnDvrTest(OvnDvrBase): port_id=test_server['port']['id'], floating_network_id=CONF.network.public_network_id)['floatingip'] fip_port_mac = self.get_fip_port_details(fip)['mac_address'] - test_server_compute = self.get_host_for_server( + test_server_compute = self.get_shortname_for_server( test_server['server']['id']) self.check_north_south_icmp_flow( dst_ip=self.gateway_external_ip, @@ -850,7 +852,7 @@ class OvnDvrAdvancedTest(base.BaseTempestTestCaseAdvanced, LOG.debug('Expected routing nodes: {}'.format( ','.join(self.expected_routing_nodes))) - actual_routing_nodes = [node['name'] + actual_routing_nodes = [node['short_name'] for node in self.nodes if (node.get('capture') and not node['capture'].is_empty())] @@ -878,7 +880,7 @@ class OvnDvrAdvancedTest(base.BaseTempestTestCaseAdvanced, ip, self.username, pkey=self.keypair['private_key'], proxy_client=ext_vm_ssh_client) - ext_vm_host = self.get_host_for_server( + ext_vm_host = self.get_shortname_for_server( ext_vm['server']['id']) if ext_vm_host not in self.expected_routing_nodes: self.expected_routing_nodes.append(ext_vm_host) @@ -933,7 +935,7 @@ class OvnDvrAdvancedTest(base.BaseTempestTestCaseAdvanced, for vm in [vm1, vm2]: nic = local_utils.get_default_interface(vm['ssh_client']) self.expected_routing_nodes.append( - self.get_host_for_server(vm['id'])) + self.get_shortname_for_server(vm['id'])) vip_ssh_client = ssh.Client( vip_fip['floating_ip_address'], self.username, @@ -1033,7 +1035,7 @@ class OvnDvrAdvancedTest(base.BaseTempestTestCaseAdvanced, for vm in [vm1, vm2]: nic = local_utils.get_default_interface(vm['ssh_client']) self.expected_routing_nodes.append( - self.get_host_for_server(vm['id'])) + self.get_shortname_for_server(vm['id'])) # checking whether an external IPv6 subnet exists or not ip_versions = [