From 91db24e002cf89811a58283272547b17866556b5 Mon Sep 17 00:00:00 2001 From: Elena Ezhova Date: Fri, 28 Feb 2014 20:47:10 +0400 Subject: [PATCH] Fix RemoteClient usage in scenario tests Some scenario tests use the following patter to work with RemoteClient: client = self.get_remote_client(ip, private_key=keypair.private_key) return client.ssh_client ssh_client is directly accessed because exec_command method is not directly available in RemoteClient In order to preserve encapsulation, RemoteClient should be improved to expose that method. Change-Id: I054762d769d002b5fb45c871d85a8ca8ff294695 Closes-Bug: #1285539 --- tempest/common/utils/linux/remote_client.py | 27 +++++++++++--------- tempest/scenario/test_snapshot_pattern.py | 3 +-- tempest/scenario/test_stamp_pattern.py | 3 +-- tempest/scenario/test_volume_boot_pattern.py | 3 +-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py index 8420ad0dbf..00e5e0d28d 100644 --- a/tempest/common/utils/linux/remote_client.py +++ b/tempest/common/utils/linux/remote_client.py @@ -43,6 +43,9 @@ class RemoteClient(): ssh_timeout, pkey=pkey, channel_timeout=ssh_channel_timeout) + def exec_command(self, cmd): + return self.ssh_client.exec_command(cmd) + def validate_authentication(self): """Validate ssh connection and authentication This method raises an Exception when the validation fails. @@ -51,33 +54,33 @@ class RemoteClient(): def hostname_equals_servername(self, expected_hostname): # Get host name using command "hostname" - actual_hostname = self.ssh_client.exec_command("hostname").rstrip() + actual_hostname = self.exec_command("hostname").rstrip() return expected_hostname == actual_hostname def get_files(self, path): # Return a list of comma separated files command = "ls -m " + path - return self.ssh_client.exec_command(command).rstrip('\n').split(', ') + return self.exec_command(command).rstrip('\n').split(', ') def get_ram_size_in_mb(self): - output = self.ssh_client.exec_command('free -m | grep Mem') + output = self.exec_command('free -m | grep Mem') if output: return output.split()[1] def get_number_of_vcpus(self): command = 'cat /proc/cpuinfo | grep processor | wc -l' - output = self.ssh_client.exec_command(command) + output = self.exec_command(command) return int(output) def get_partitions(self): # Return the contents of /proc/partitions command = 'cat /proc/partitions' - output = self.ssh_client.exec_command(command) + output = self.exec_command(command) return output def get_boot_time(self): cmd = 'cut -f1 -d. /proc/uptime' - boot_secs = self.ssh_client.exec_command(cmd) + boot_secs = self.exec_command(cmd) boot_time = time.time() - int(boot_secs) return time.localtime(boot_time) @@ -85,27 +88,27 @@ class RemoteClient(): message = re.sub("([$\\`])", "\\\\\\\\\\1", message) # usually to /dev/ttyS0 cmd = 'sudo sh -c "echo \\"%s\\" >/dev/console"' % message - return self.ssh_client.exec_command(cmd) + return self.exec_command(cmd) def ping_host(self, host): cmd = 'ping -c1 -w1 %s' % host - return self.ssh_client.exec_command(cmd) + return self.exec_command(cmd) def get_mac_address(self): cmd = "/sbin/ifconfig | awk '/HWaddr/ {print $5}'" - return self.ssh_client.exec_command(cmd) + return self.exec_command(cmd) def get_ip_list(self): cmd = "/bin/ip address" - return self.ssh_client.exec_command(cmd) + return self.exec_command(cmd) def assign_static_ip(self, nic, addr): cmd = "sudo /bin/ip addr add {ip}/{mask} dev {nic}".format( ip=addr, mask=CONF.network.tenant_network_mask_bits, nic=nic ) - return self.ssh_client.exec_command(cmd) + return self.exec_command(cmd) def turn_nic_on(self, nic): cmd = "sudo /bin/ip link set {nic} up".format(nic=nic) - return self.ssh_client.exec_command(cmd) + return self.exec_command(cmd) diff --git a/tempest/scenario/test_snapshot_pattern.py b/tempest/scenario/test_snapshot_pattern.py index 37beb070c2..562020a4ab 100644 --- a/tempest/scenario/test_snapshot_pattern.py +++ b/tempest/scenario/test_snapshot_pattern.py @@ -45,11 +45,10 @@ class TestSnapshotPattern(manager.OfficialClientTest): def _ssh_to_server(self, server_or_ip): try: - linux_client = self.get_remote_client(server_or_ip) + return self.get_remote_client(server_or_ip) except Exception: LOG.exception() self._log_console_output() - return linux_client.ssh_client def _write_timestamp(self, server_or_ip): ssh_client = self._ssh_to_server(server_or_ip) diff --git a/tempest/scenario/test_stamp_pattern.py b/tempest/scenario/test_stamp_pattern.py index 841f9e1dfe..128ec17c3a 100644 --- a/tempest/scenario/test_stamp_pattern.py +++ b/tempest/scenario/test_stamp_pattern.py @@ -72,8 +72,7 @@ class TestStampPattern(manager.OfficialClientTest): server.add_floating_ip(floating_ip) def _ssh_to_server(self, server_or_ip): - linux_client = self.get_remote_client(server_or_ip) - return linux_client.ssh_client + return self.get_remote_client(server_or_ip) def _create_volume_snapshot(self, volume): snapshot_name = data_utils.rand_name('scenario-snapshot-') diff --git a/tempest/scenario/test_volume_boot_pattern.py b/tempest/scenario/test_volume_boot_pattern.py index 9a250d708f..9803664cac 100644 --- a/tempest/scenario/test_volume_boot_pattern.py +++ b/tempest/scenario/test_volume_boot_pattern.py @@ -101,14 +101,13 @@ class TestVolumeBootPattern(manager.OfficialClientTest): ip = server.networks[network_name_for_ssh][0] try: - client = self.get_remote_client( + return self.get_remote_client( ip, private_key=keypair.private_key) except Exception: LOG.exception('ssh to server failed') self._log_console_output() raise - return client.ssh_client def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text')