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
diff --git a/neutron_tempest_plugin/common/ssh.py b/neutron_tempest_plugin/common/ssh.py
index c6204a4..8334521 100644
--- a/neutron_tempest_plugin/common/ssh.py
+++ b/neutron_tempest_plugin/common/ssh.py
@@ -286,6 +286,13 @@
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(