diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/base.py b/whitebox_neutron_tempest_plugin/tests/scenario/base.py index dc064b5..71267e8 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/base.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/base.py @@ -1351,30 +1351,44 @@ class BaseDisruptiveTempestTestCase(BaseTempestWhiteboxTestCase): try: cls.proxy_host_client.exec_command( "timeout 10 ssh {} virsh list".format(WB_CONF.hypervisor_host)) + cls.hypervisor_host = WB_CONF.hypervisor_host + return + except lib_exceptions.SSHExecCommandFailed: + 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)) + host = cls.proxy_host_client.exec_command( + r"grep 'Host.*\ hypervisor$' ~/.ssh/config " + "| cut -d' ' -f 2").strip() + + try: + cls.proxy_host_client.exec_command( + "timeout 10 ssh {} virsh list".format(host)) except lib_exceptions.SSHExecCommandFailed: raise cls.skipException( "No access to virsh tool on hypervisor node. Please make sure " "that hypervisor_host is configured properly and/or virsh " "is deployed there.") + cls.hypervisor_host = host @classmethod def find_host_virsh_name(cls, host): cmd = ("timeout 10 ssh {} sudo virsh list --all --name " "| grep -w {}").format( - WB_CONF.hypervisor_host, host) + cls.hypervisor_host, host) return cls.proxy_host_client.exec_command(cmd).strip() @classmethod def is_host_state_is_shut_off(cls, host): cmd = ("timeout 10 ssh {} virsh list --state-shutoff | grep -w {} " - "|| true".format(WB_CONF.hypervisor_host, host)) + "|| true".format(cls.hypervisor_host, host)) output = cls.proxy_host_client.exec_command(cmd) return True if host in output else False @classmethod def is_host_loginable(cls, host): cmd = "timeout 10 ssh {} ssh {} hostname || true".format( - WB_CONF.hypervisor_host, host) + cls.hypervisor_host, host) output = cls.proxy_host_client.exec_command(cmd) return True if host in output else False @@ -1383,7 +1397,7 @@ class BaseDisruptiveTempestTestCase(BaseTempestWhiteboxTestCase): if not WB_CONF.run_power_operations_tests: raise cls.skipException("Power operations are not allowed") cmd = "timeout 10 ssh {} sudo virsh destroy {}".format( - WB_CONF.hypervisor_host, cls.find_host_virsh_name(host)) + cls.hypervisor_host, cls.find_host_virsh_name(host)) cls.proxy_host_client.exec_command(cmd) common_utils.wait_until_true( lambda: cls.is_host_state_is_shut_off(host), @@ -1394,7 +1408,7 @@ class BaseDisruptiveTempestTestCase(BaseTempestWhiteboxTestCase): if not WB_CONF.run_power_operations_tests: raise cls.skipException("Power operations are not allowed") cmd = "timeout 10 ssh {} sudo virsh start {}".format( - WB_CONF.hypervisor_host, cls.find_host_virsh_name(host)) + cls.hypervisor_host, cls.find_host_virsh_name(host)) cls.proxy_host_client.exec_command(cmd) # TODO(rsafrono): implement and apply additional health checks common_utils.wait_until_true( @@ -1406,7 +1420,7 @@ class BaseDisruptiveTempestTestCase(BaseTempestWhiteboxTestCase): if not WB_CONF.run_power_operations_tests: raise cls.skipException("Power operations are not allowed") cmd = "timeout 10 ssh {} sudo virsh reboot {}".format( - WB_CONF.hypervisor_host, cls.find_host_virsh_name(host)) + cls.hypervisor_host, cls.find_host_virsh_name(host)) cls.proxy_host_client.exec_command(cmd) common_utils.wait_until_true( lambda: cls.is_host_loginable(host), @@ -1417,7 +1431,7 @@ class BaseDisruptiveTempestTestCase(BaseTempestWhiteboxTestCase): """ hosts = self.proxy_host_client.exec_command( "timeout 10 ssh {} sudo virsh list --all --name".format( - WB_CONF.hypervisor_host)).strip().split() + self.hypervisor_host)).strip().split() for host in hosts: if self.is_host_state_is_shut_off(host): self.power_on_host(host)