From 51b71cc42eb9f1d6c35823a490fd73b6bee63eac Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Fri, 22 May 2015 10:37:22 +0100 Subject: Make ssh-rsync.check check VERSION_LABEL As well as checking whether it's defined, we make sure there isn't already a system named $VERSION_LABEL Note, this depends on the new json-list feature of system-version-manager. Change-Id: I0dee5253ba95a002b493f4179c2acda734afc37a --- extensions/ssh-rsync.check | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'extensions') diff --git a/extensions/ssh-rsync.check b/extensions/ssh-rsync.check index 436aaae0..fc9bf62d 100755 --- a/extensions/ssh-rsync.check +++ b/extensions/ssh-rsync.check @@ -17,6 +17,8 @@ import os +import json +import logging import writeexts @@ -40,6 +42,8 @@ class SshRsyncCheckExtension(writeexts.WriteExtension): location = args[0] self.check_ssh_connectivity(location) + + self.check_version_label(location, os.environ['VERSION_LABEL']) self.check_is_baserock_system(location) # The new system that being deployed as an upgrade must contain @@ -62,5 +66,19 @@ class SshRsyncCheckExtension(writeexts.WriteExtension): raise writeexts.ExtensionError( "%s does not have %s" % (location, command)) + def check_version_label(self, location, version_label): + args = ['system-version-manager', 'list', '--json'] + + try: + output = writeexts.ssh_runcmd(location, args) + except writeexts.ExtensionError: + msg = ("Couldn't get system list from system-version-manager, " + "skipping version label check") + logging.exception(msg) + return + + if version_label in json.loads(output): + raise writeexts.ExtensionError( + "There is already a system called `%s'" % version_label) SshRsyncCheckExtension().run() -- cgit v1.2.1