From af394dd5f82ddc6a02ea944ce297593af3c69dbb Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Thu, 12 Nov 2020 14:26:13 +0000 Subject: [PATCH] Implement "get_hostname" in SSH client class This method will retrieve the remote machine host name first executing "hostname" command. If that command fails, it will try to read "/etc/hostname" file. Change-Id: I2e4de049d77858e5bf11b7d0758c9494099802f7 Closes-Bug: #1903982 --- neutron_tempest_plugin/common/ssh.py | 7 +++++++ neutron_tempest_plugin/scenario/base.py | 2 +- neutron_tempest_plugin/scenario/test_internal_dns.py | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/neutron_tempest_plugin/common/ssh.py b/neutron_tempest_plugin/common/ssh.py index c6204a43..83345217 100644 --- a/neutron_tempest_plugin/common/ssh.py +++ b/neutron_tempest_plugin/common/ssh.py @@ -286,6 +286,13 @@ class Client(ssh.Client): command=shell, host=self.host, script=script, stderr=stderr, stdout=stdout, exit_status=exit_status) + def get_hostname(self): + """Retrieve the remote machine hostname""" + try: + return self.exec_command('hostname') + except exceptions.SSHExecCommandFailed: + return self.exec_command('cat /etc/hostname') + def _buffer_to_string(data_buffer, encoding): return data_buffer.decode(encoding).replace("\r\n", "\n").replace( diff --git a/neutron_tempest_plugin/scenario/base.py b/neutron_tempest_plugin/scenario/base.py index c7c54596..6dcc1697 100644 --- a/neutron_tempest_plugin/scenario/base.py +++ b/neutron_tempest_plugin/scenario/base.py @@ -513,7 +513,7 @@ class BaseTempestTestCase(base_api.BaseNetworkTest): pkey=self.keypair['private_key'], **kwargs) self.assertIn(server['name'], - ssh_client.exec_command('hostname')) + ssh_client.get_hostname()) except (lib_exc.SSHTimeout, ssh_exc.AuthenticationException) as ssh_e: LOG.debug(ssh_e) if log_errors: diff --git a/neutron_tempest_plugin/scenario/test_internal_dns.py b/neutron_tempest_plugin/scenario/test_internal_dns.py index c6202330..406af3d6 100644 --- a/neutron_tempest_plugin/scenario/test_internal_dns.py +++ b/neutron_tempest_plugin/scenario/test_internal_dns.py @@ -59,7 +59,7 @@ class InternalDNSTest(base.BaseTempestTestCase): CONF.validation.image_ssh_user, pkey=self.keypair['private_key']) - self.assertIn('luke', ssh_client.exec_command('hostname')) + self.assertIn('luke', ssh_client.get_hostname()) leia_port = self.client.list_ports( network_id=self.network['id'],