Add more console output log for scenario tests

- Generalize _log_console_output
- Added console log ouput for ssh or ping check

Change-Id: I2900a64de4ea2ce447cb41c3b0290aa3186098e2
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 409fcc2..46f0d02 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -527,6 +527,13 @@
             private_key = self.keypair.private_key
         return RemoteClient(ip, username, pkey=private_key)
 
+    def _log_console_output(self, servers=None):
+        if not servers:
+            servers = self.compute_client.servers.list()
+        for server in servers:
+            LOG.debug('Console output for %s', server.id)
+            LOG.debug(server.get_console_output())
+
 
 class NetworkScenarioTest(OfficialClientTest):
     """
diff --git a/tempest/scenario/test_cross_tenant_connectivity.py b/tempest/scenario/test_cross_tenant_connectivity.py
index faba987..a269017 100644
--- a/tempest/scenario/test_cross_tenant_connectivity.py
+++ b/tempest/scenario/test_cross_tenant_connectivity.py
@@ -371,6 +371,7 @@
                             msg)
         except Exception:
             debug.log_ip_ns()
+            self._log_console_output(servers=self.servers)
             raise
 
     def _test_in_tenant_block(self, tenant):
diff --git a/tempest/scenario/test_minimum_basic.py b/tempest/scenario/test_minimum_basic.py
index 8a51cd1..890d00f 100644
--- a/tempest/scenario/test_minimum_basic.py
+++ b/tempest/scenario/test_minimum_basic.py
@@ -131,7 +131,12 @@
         self.server.add_floating_ip(self.floating_ip)
 
     def ssh_to_server(self):
-        self.linux_client = self.get_remote_client(self.floating_ip.ip)
+        try:
+            self.linux_client = self.get_remote_client(self.floating_ip.ip)
+        except Exception:
+            LOG.exception('ssh to server failed')
+            self._log_console_output()
+            raise
 
     def check_partitions(self):
         partitions = self.linux_client.get_partitions()
diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py
index 52a36e6..94e0f81 100644
--- a/tempest/scenario/test_network_basic_ops.py
+++ b/tempest/scenario/test_network_basic_ops.py
@@ -213,11 +213,6 @@
             name = data_utils.rand_name('server-smoke-%d-' % i)
             self._create_server(name, network)
 
-    def _log_console_output(self):
-        for server, key in self.servers.items():
-            LOG.debug('Console output for %s', server.id)
-            LOG.debug(server.get_console_output())
-
     def _check_tenant_network_connectivity(self):
         if not CONF.network.tenant_networks_reachable:
             msg = 'Tenant networks not configured to be reachable.'
@@ -234,7 +229,8 @@
                                                     key.private_key)
         except Exception:
             LOG.exception('Tenant connectivity check failed')
-            self._log_console_output()
+            self._log_console_output(
+                servers=[server for server, _key in self.servers])
             debug.log_ip_ns()
             raise
 
@@ -272,7 +268,8 @@
                                             should_connect=should_connect)
         except Exception:
             LOG.exception('Public network connectivity check failed')
-            self._log_console_output()
+            self._log_console_output(
+                servers=[server for server, _key in self.servers])
             debug.log_ip_ns()
             raise
 
diff --git a/tempest/scenario/test_server_basic_ops.py b/tempest/scenario/test_server_basic_ops.py
index ca3035d..279b80e 100644
--- a/tempest/scenario/test_server_basic_ops.py
+++ b/tempest/scenario/test_server_basic_ops.py
@@ -151,10 +151,15 @@
             instance = self.get_resource('instance')
             instance.add_floating_ip(floating_ip)
             # Check ssh
-            self.get_remote_client(
-                server_or_ip=floating_ip.ip,
-                username=self.image_utils.ssh_user(self.image_ref),
-                private_key=self.keypair.private)
+            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)
+            except Exception:
+                LOG.exception('ssh to server failed')
+                self._log_console_output()
+                raise
 
     @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 00139f0..874bc60 100644
--- a/tempest/scenario/test_snapshot_pattern.py
+++ b/tempest/scenario/test_snapshot_pattern.py
@@ -15,10 +15,14 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from tempest.openstack.common import log
 from tempest.scenario import manager
 from tempest.test import services
 
 
+LOG = log.getLogger(__name__)
+
+
 class TestSnapshotPattern(manager.OfficialClientTest):
     """
     This test is for snapshotting an instance and booting with it.
@@ -40,7 +44,11 @@
         self.keypair = self.create_keypair()
 
     def _ssh_to_server(self, server_or_ip):
-        linux_client = self.get_remote_client(server_or_ip)
+        try:
+            linux_client = 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):
diff --git a/tempest/scenario/test_volume_boot_pattern.py b/tempest/scenario/test_volume_boot_pattern.py
index fa9a228..2a2b527 100644
--- a/tempest/scenario/test_volume_boot_pattern.py
+++ b/tempest/scenario/test_volume_boot_pattern.py
@@ -13,10 +13,14 @@
 #    under the License.
 
 from tempest.common.utils import data_utils
+from tempest.openstack.common import log
 from tempest.scenario import manager
 from tempest.test import services
 
 
+LOG = log.getLogger(__name__)
+
+
 class TestVolumeBootPattern(manager.OfficialClientTest):
 
     """
@@ -96,8 +100,14 @@
             network_name_for_ssh = self.config.compute.network_for_ssh
             ip = server.networks[network_name_for_ssh][0]
 
-        client = self.get_remote_client(ip,
-                                        private_key=keypair.private_key)
+        try:
+            client = 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):