From e0eb010bbe8fdb2ee4b5607d9a5288a078fcb1b0 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 14 Apr 2014 12:35:26 +0000 Subject: deploy: Share SSH connectivity check in the common writeexts.py code Also, change it to log the real error message in morph.log before raising a more general exception to the user. --- morphlib/exts/kvm.check | 5 +---- morphlib/exts/nfsboot.check | 7 +------ morphlib/writeexts.py | 9 +++++++++ 3 files changed, 11 insertions(+), 10 deletions(-) (limited to 'morphlib') diff --git a/morphlib/exts/kvm.check b/morphlib/exts/kvm.check index 04c25069..6ce52e7e 100755 --- a/morphlib/exts/kvm.check +++ b/morphlib/exts/kvm.check @@ -40,10 +40,7 @@ class KvmPlusSshCheckExtension(morphlib.writeexts.WriteExtension): location = args[0] ssh_host, vm_name, vm_path = self.check_and_parse_location(location) - try: - cliapp.ssh_runcmd(ssh_host, ['true']) - except cliapp.AppException: - raise cliapp.AppException('Unable to SSH to %s' % ssh_host) + self.check_ssh_connectivity(ssh_host) def check_and_parse_location(self, location): '''Check and parse the location argument to get relevant data.''' diff --git a/morphlib/exts/nfsboot.check b/morphlib/exts/nfsboot.check index f84f187f..806e560a 100755 --- a/morphlib/exts/nfsboot.check +++ b/morphlib/exts/nfsboot.check @@ -56,12 +56,7 @@ class NFSBootCheckExtension(morphlib.writeexts.WriteExtension): version_label, location)) def test_good_server(self, server): - # Can be ssh'ed into - try: - cliapp.ssh_runcmd('root@%s' % server, ['true']) - except cliapp.AppException: - raise cliapp.AppException('You are unable to ssh into server %s' - % server) + self.check_ssh_connectivity(server) # Is an NFS server try: diff --git a/morphlib/writeexts.py b/morphlib/writeexts.py index bff21e8d..3f9c33d5 100644 --- a/morphlib/writeexts.py +++ b/morphlib/writeexts.py @@ -15,6 +15,7 @@ import cliapp +import logging import os import re import shutil @@ -417,3 +418,11 @@ class WriteExtension(cliapp.Application): else: raise cliapp.AppException('Unexpected value for %s: %s' % (variable, value)) + + def check_ssh_connectivity(self, ssh_host): + try: + cliapp.ssh_runcmd(ssh_host, ['true']) + except cliapp.AppException as e: + logging.error("Error checking SSH connectivity: %s", str(e)) + raise cliapp.AppException( + 'Unable to SSH to %s: %s' % (ssh_host, e)) -- cgit v1.2.1