diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-08-19 15:05:05 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-08-19 16:34:16 +0000 |
commit | 35f3a8779a316ed6a44ce5bb62bea9e2d7c67a16 (patch) | |
tree | ee675867f2d131b874cfc3cda612ee49a2717e31 /morphlib/exts | |
parent | 7e2553e2101310e9ddfce2ca93c1c923b062ad1e (diff) | |
download | morph-35f3a8779a316ed6a44ce5bb62bea9e2d7c67a16.tar.gz |
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.
Diffstat (limited to 'morphlib/exts')
-rwxr-xr-x | morphlib/exts/rawdisk.check | 21 |
1 files changed, 21 insertions, 0 deletions
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() |