summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-08-19 15:05:05 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-08-19 16:34:16 +0000
commit59d03b0ae4d1643bba0f0b2b83e85b7068092819 (patch)
tree373e3f852673cd1108c9948f55608728f0af7f26
parent0da35ea65a40526cd395b3f47b51743366efccbc (diff)
downloaddefinitions-59d03b0ae4d1643bba0f0b2b83e85b7068092819.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.
-rwxr-xr-xrawdisk.check21
1 files changed, 21 insertions, 0 deletions
diff --git a/rawdisk.check b/rawdisk.check
index 6a656ee7..5e75abe2 100755
--- a/rawdisk.check
+++ b/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()