diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py index 522aa43336..551a27dceb 100644 --- a/tempest/scenario/manager.py +++ b/tempest/scenario/manager.py @@ -297,7 +297,19 @@ class ScenarioTest(tempest.test.BaseTestCase): return secgroup - def get_remote_client(self, server_or_ip, username=None, private_key=None): + def get_remote_client(self, server_or_ip, username=None, private_key=None, + log_console_of_servers=None): + """Get a SSH client to a remote server + + @param server_or_ip a server object as returned by Tempest compute + client or an IP address to connect to + @param username name of the Linux account on the remote server + @param private_key the SSH private key to use + @param log_console_of_servers a list of server objects. Each server + in the list will have its console printed in the logs in case the + SSH connection failed to be established + @return a RemoteClient object + """ if isinstance(server_or_ip, six.string_types): ip = server_or_ip else: @@ -312,9 +324,13 @@ class ScenarioTest(tempest.test.BaseTestCase): pkey=private_key) try: linux_client.validate_authentication() - except exceptions.SSHTimeout: - LOG.exception('ssh connection to %s failed' % ip) + except Exception: + LOG.exception('Initializing SSH connection to %s failed' % ip) debug.log_net_debug() + # If we don't explicitely set for which servers we want to + # log the console output then all the servers will be logged. + # See the definition of _log_console_output() + self._log_console_output(log_console_of_servers) raise return linux_client diff --git a/tempest/scenario/orchestration/test_server_cfn_init.py b/tempest/scenario/orchestration/test_server_cfn_init.py index ddfabe47fe..f09f00c05a 100644 --- a/tempest/scenario/orchestration/test_server_cfn_init.py +++ b/tempest/scenario/orchestration/test_server_cfn_init.py @@ -119,14 +119,8 @@ class CfnInitScenarioTest(manager.OrchestrationScenarioTest): if self.keypair: # Check that the user can authenticate with the generated # keypair - try: - linux_client = self.get_remote_client( - server_ip, username='ec2-user') - linux_client.validate_authentication() - except (exceptions.ServerUnreachable, - exceptions.SSHTimeout) as e: - self._log_console_output(servers=[server]) - raise e + self.get_remote_client(server_ip, username='ec2-user', + log_console_of_servers=[server]) @test.attr(type='slow') @test.skip_because(bug='1374175') diff --git a/tempest/scenario/test_minimum_basic.py b/tempest/scenario/test_minimum_basic.py index 59af6b3410..16a65c92a5 100644 --- a/tempest/scenario/test_minimum_basic.py +++ b/tempest/scenario/test_minimum_basic.py @@ -14,7 +14,6 @@ # under the License. from tempest.common import custom_matchers -from tempest.common import debug from tempest import config from tempest import exceptions from tempest.openstack.common import log as logging @@ -89,17 +88,6 @@ class TestMinimumBasicScenario(manager.ScenarioTest): self.servers_client.reboot(self.server['id'], 'SOFT') self._wait_for_server_status('ACTIVE') - def ssh_to_server(self): - try: - self.linux_client = self.get_remote_client(self.floating_ip['ip']) - except Exception as e: - LOG.exception('ssh to server failed') - self._log_console_output() - # network debug is called as part of ssh init - if not isinstance(e, test.exceptions.SSHTimeout): - debug.log_net_debug() - raise - def check_partitions(self): # NOTE(andreaf) The device name may be different on different guest OS partitions = self.linux_client.get_partitions() @@ -147,7 +135,9 @@ class TestMinimumBasicScenario(manager.ScenarioTest): self.floating_ip = self.create_floating_ip(self.server) self.create_and_add_security_group() - self.ssh_to_server() + + self.linux_client = self.get_remote_client(self.floating_ip['ip']) self.nova_reboot() - self.ssh_to_server() + + self.linux_client = self.get_remote_client(self.floating_ip['ip']) self.check_partitions() diff --git a/tempest/scenario/test_server_basic_ops.py b/tempest/scenario/test_server_basic_ops.py index eb636f79c1..affed64ce2 100644 --- a/tempest/scenario/test_server_basic_ops.py +++ b/tempest/scenario/test_server_basic_ops.py @@ -88,15 +88,10 @@ class TestServerBasicOps(manager.ScenarioTest): self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], self.instance['id']) # Check ssh - try: - self.get_remote_client( - server_or_ip=floating_ip['ip'], - username=self.image_utils.ssh_user(self.image_ref), - private_key=self.keypair['private_key']) - except Exception: - LOG.exception('ssh to server failed') - self._log_console_output() - raise + self.get_remote_client( + server_or_ip=floating_ip['ip'], + username=self.image_utils.ssh_user(self.image_ref), + private_key=self.keypair['private_key']) @test.services('compute', 'network') def test_server_basicops(self): diff --git a/tempest/scenario/test_snapshot_pattern.py b/tempest/scenario/test_snapshot_pattern.py index 9a99da4007..c5c00163e9 100644 --- a/tempest/scenario/test_snapshot_pattern.py +++ b/tempest/scenario/test_snapshot_pattern.py @@ -47,21 +47,13 @@ class TestSnapshotPattern(manager.ScenarioTest): def _add_keypair(self): self.keypair = self.create_keypair() - def _ssh_to_server(self, server_or_ip): - try: - return self.get_remote_client(server_or_ip) - except Exception: - LOG.exception('Initializing SSH connection failed') - self._log_console_output() - raise - def _write_timestamp(self, server_or_ip): - ssh_client = self._ssh_to_server(server_or_ip) + ssh_client = self.get_remote_client(server_or_ip) ssh_client.exec_command('date > /tmp/timestamp; sync') self.timestamp = ssh_client.exec_command('cat /tmp/timestamp') def _check_timestamp(self, server_or_ip): - ssh_client = self._ssh_to_server(server_or_ip) + ssh_client = self.get_remote_client(server_or_ip) got_timestamp = ssh_client.exec_command('cat /tmp/timestamp') self.assertEqual(self.timestamp, got_timestamp) diff --git a/tempest/scenario/test_volume_boot_pattern.py b/tempest/scenario/test_volume_boot_pattern.py index dd115e7893..c584a6e746 100644 --- a/tempest/scenario/test_volume_boot_pattern.py +++ b/tempest/scenario/test_volume_boot_pattern.py @@ -110,14 +110,8 @@ class TestVolumeBootPattern(manager.ScenarioTest): network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] - try: - return self.get_remote_client( - ip, - private_key=keypair['private_key']) - except Exception: - LOG.exception('ssh to server failed') - self._log_console_output(servers=[server]) - raise + return self.get_remote_client(ip, private_key=keypair['private_key'], + log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text')