From 7d849ca1db73c1544073acb6b7c88a33ec88be8d Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Tue, 20 May 2014 09:37:49 +0000 Subject: deploy: Do sanity checks earlier in ssh-rsync (upgrade) extension --- morphlib/exts/ssh-rsync.check | 24 ++++++++++++++++++++++++ morphlib/exts/ssh-rsync.write | 26 -------------------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/morphlib/exts/ssh-rsync.check b/morphlib/exts/ssh-rsync.check index 90029cb4..6a776ce9 100755 --- a/morphlib/exts/ssh-rsync.check +++ b/morphlib/exts/ssh-rsync.check @@ -33,4 +33,28 @@ class SshRsyncCheckExtension(morphlib.writeexts.WriteExtension): 'Baserock machines. It cannot be used for an initial ' 'deployment.') + location = args[0] + self.check_ssh_connectivity(location) + self.check_is_baserock_system(location) + + # The new system that being deployed as an upgrade must contain + # baserock-system-config-sync and system-version-manager. However, the + # old system simply needs to have SSH and rsync. + self.check_command_exists(location, 'rsync') + + def check_is_baserock_system(self, location): + output = cliapp.ssh_runcmd(location, ['sh', '-c', + 'test -d /baserock || echo -n dirnotfound']) + if output == 'dirnotfound': + raise cliapp.AppException('%s is not a baserock system' + % location) + + def check_command_exists(self, location, command): + test = 'type %s > /dev/null 2>&1 || echo -n cmdnotfound' % command + output = cliapp.ssh_runcmd(location, ['sh', '-c', test]) + if output == 'cmdnotfound': + raise cliapp.AppException( + "%s does not have %s" % (location, command)) + + SshRsyncCheckExtension().run() diff --git a/morphlib/exts/ssh-rsync.write b/morphlib/exts/ssh-rsync.write index 509520ae..c139b6c0 100755 --- a/morphlib/exts/ssh-rsync.write +++ b/morphlib/exts/ssh-rsync.write @@ -51,7 +51,6 @@ class SshRsyncWriteExtension(morphlib.writeexts.WriteExtension): temp_root, location = args - self.check_valid_target(location) self.upgrade_remote_system(location, temp_root) def upgrade_remote_system(self, location, temp_root): @@ -145,30 +144,5 @@ class SshRsyncWriteExtension(morphlib.writeexts.WriteExtension): if (line_words[1] == '/' and line_words[0] != 'rootfs'): return line_words[0] - def check_valid_target(self, location): - try: - cliapp.ssh_runcmd(location, ['true']) - except Exception as e: - raise cliapp.AppException('%s does not respond to ssh:\n%s' - % (location, e)) - - output = cliapp.ssh_runcmd(location, ['sh', '-c', - 'test -d /baserock || echo -n dirnotfound']) - if output == 'dirnotfound': - raise cliapp.AppException('%s is not a baserock system' - % location) - - def check_command_exists(command): - test = 'type %s > /dev/null 2>&1 || echo -n cmdnotfound' % command - output = cliapp.ssh_runcmd(location, ['sh', '-c', test]) - if output == 'cmdnotfound': - raise cliapp.AppException( - "%s does not have %s" % (location, command)) - - # The deploy requires baserock-system-config-sync and - # system-version-manager in the new system only. The old system doesn't - # need to have them at all. - check_command_exists('rsync') - SshRsyncWriteExtension().run() -- cgit v1.2.1