summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-02-17 16:12:44 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-03-04 14:47:24 +0000
commit9c20ef29b11f6e1d52a29bcab8d3ea8fcdbcacc4 (patch)
tree276f63e2c215c1e0004b1ef188f4cb7fbf94d20c
parent9b9a6151aa262f748a286f72819242c2a118a7f9 (diff)
downloadmorph-9c20ef29b11f6e1d52a29bcab8d3ea8fcdbcacc4.tar.gz
deploy: Add optional 'check' extensions
A write extension will have various kinds of sanity checks to do before actually performing the write. The current architecture of 'morph deploy' means that several minutes pass between the user starting the command and the write extension actually executing. It would be rage-inducing watching `morph deploy` spend 3 minutes unpacking a system only to then abort due to a silly error such as forgetting the --upgrade switch. Therefore it's better for now to split the sanity checks out into separate extensions that can be run as soon as possible and abort if the write extension is not going to be able to operate. For now this will just be used to validate usage of the --upgrade flag but in future checking connectivity to remote servers and the like should be done here too.
-rw-r--r--morphlib/plugins/deploy_plugin.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py
index 66058973..c8538a8d 100644
--- a/morphlib/plugins/deploy_plugin.py
+++ b/morphlib/plugins/deploy_plugin.py
@@ -33,6 +33,10 @@ import morphlib
import morphlib.plugins.branch_and_merge_plugin
+class ExtensionNotFoundError(morphlib.Error):
+ pass
+
+
class DeployPlugin(cliapp.Plugin):
def enable(self):
@@ -355,6 +359,9 @@ class DeployPlugin(cliapp.Plugin):
deploy_params.items() +
user_env.items())
+ is_upgrade = 'yes' if self.app.settings['upgrade'] else 'no'
+ final_env['UPGRADE'] = is_upgrade
+
deployment_type = final_env.pop('type', None)
if not deployment_type:
raise morphlib.Error('"type" is undefined '
@@ -371,6 +378,15 @@ class DeployPlugin(cliapp.Plugin):
def do_deploy(self, build_command, root_repo_dir, ref, artifact,
deployment_type, location, env):
+ # Run optional write check extension. These are separate from the write
+ # extension because it may be several minutes before the write
+ # extension itself has the chance to raise an error.
+ try:
+ self._run_extension(
+ root_repo_dir, ref, deployment_type, '.check',
+ [location], env)
+ except ExtensionNotFoundError:
+ pass
# Create a tempdir for this deployment to work in
deploy_tempdir = tempfile.mkdtemp(
@@ -452,7 +468,7 @@ class DeployPlugin(cliapp.Plugin):
code_dir = os.path.dirname(morphlib.__file__)
ext_filename = os.path.join(code_dir, 'exts', name + kind)
if not os.path.exists(ext_filename):
- raise morphlib.Error(
+ raise ExtensionNotFoundError(
'Could not find extension %s%s' % (name, kind))
if not self._is_executable(ext_filename):
raise morphlib.Error(