From 35f3a8779a316ed6a44ce5bb62bea9e2d7c67a16 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Tue, 19 Aug 2014 15:05:05 +0000 Subject: deploy: Check correct usage of --upgrade for rawdisk deployments This avoids confusion when the user expected to be doing an initial deployment and wasn't aware that a file with the same name as the target already existed. Previously rawdisk.write would try to mount the file and upgrade it. Now we require the user to pass '--upgrade' when they intend to upgrade, as with other deployment extensions. --- morphlib/exts/rawdisk.check | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/morphlib/exts/rawdisk.check b/morphlib/exts/rawdisk.check index 6a656ee7..5e75abe2 100755 --- a/morphlib/exts/rawdisk.check +++ b/morphlib/exts/rawdisk.check @@ -20,6 +20,8 @@ import cliapp import morphlib.writeexts +import os + class RawdiskCheckExtension(morphlib.writeexts.WriteExtension): def process_args(self, args): @@ -28,4 +30,23 @@ class RawdiskCheckExtension(morphlib.writeexts.WriteExtension): self.require_btrfs_in_deployment_host_kernel() + location = args[0] + upgrade = self.get_environment_boolean('UPGRADE') + if upgrade: + if not os.path.isfile(location): + raise cliapp.AppException( + 'Cannot upgrade %s: it is not an existing disk image' % + location) + + version_label = os.environ.get('VERSION_LABEL') + if version_label is None: + raise cliapp.AppException( + 'VERSION_LABEL was not given. It is required when ' + 'upgrading an existing system.') + else: + if os.path.exists(location): + raise cliapp.AppException( + 'Target %s already exists. Pass --upgrade if you want to ' + 'update an existing image.' % location) + RawdiskCheckExtension().run() -- cgit v1.2.1