tempest: Log server console output of failed SSH

Tempest has a code in its base class. As we inherit from API base class
in tempest tests, we lost this capability. This patch adds a copy from
tempest code.

Change-Id: I24fc7e4c5f2726a16af15288987e65b77532e709
diff --git a/neutron/tests/tempest/scenario/base.py b/neutron/tests/tempest/scenario/base.py
index 351e587..6cf73c9 100644
--- a/neutron/tests/tempest/scenario/base.py
+++ b/neutron/tests/tempest/scenario/base.py
@@ -18,6 +18,7 @@
 from tempest.common import waiters
 from tempest.lib.common import ssh
 from tempest.lib.common.utils import data_utils
+from tempest.lib import exceptions as lib_exc
 
 from neutron.tests.tempest.api import base as base_api
 from neutron.tests.tempest import config
@@ -149,11 +150,6 @@
         return fip
 
     @classmethod
-    def check_connectivity(cls, host, ssh_user, ssh_key=None):
-        ssh_client = ssh.Client(host, ssh_user, pkey=ssh_key)
-        ssh_client.test_connection_auth()
-
-    @classmethod
     def setup_network_and_server(cls, router=None, **kwargs):
         """Create network resources and a server.
 
@@ -189,3 +185,30 @@
                                      device_id=cls.server[
                                           'server']['id'])['ports'][0]
         cls.fip = cls.create_and_associate_floatingip(port['id'])
+
+    def check_connectivity(self, host, ssh_user, ssh_key, servers=None):
+        ssh_client = ssh.Client(host, ssh_user, pkey=ssh_key)
+        try:
+            ssh_client.test_connection_auth()
+        except lib_exc.SSHTimeout as ssh_e:
+            LOG.debug(ssh_e)
+            self._log_console_output(servers)
+            raise
+
+    def _log_console_output(self, servers=None):
+        if not CONF.compute_feature_enabled.console_output:
+            LOG.debug('Console output not supported, cannot log')
+            return
+        if not servers:
+            servers = self.manager.servers_client.list_servers()
+            servers = servers['servers']
+        for server in servers:
+            try:
+                console_output = (
+                    self.manager.servers_client.get_console_output(
+                        server['id'])['output'])
+                LOG.debug('Console output for %s\nbody=\n%s',
+                          server['id'], console_output)
+            except lib_exc.NotFound:
+                LOG.debug("Server %s disappeared(deleted) while looking "
+                          "for the console log", server['id'])