From a0c24350042082fe3e1195f8f6160da363c94843 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 27 Oct 2014 17:15:55 +0000 Subject: Fix distbuild to allow passing a commit instead of a named ref to be built The recent changes to the BuildCommand.build() function caused distbuild to break, because I didn't make the same change to the InitiatorBuildCommand.build() function but did change how it was called. This commit adds the ability to have optional fields in distbuild messages. This is used to add an optional 'original_ref' field, which will get passed to `morph serialise-artifact` by new distbuild controllers, and will be ignored by older ones. --- distbuild/build_controller.py | 2 ++ distbuild/initiator.py | 6 ++++-- distbuild/protocol.py | 19 +++++++++++++++---- morphlib/buildcommand.py | 7 ++----- morphlib/plugins/distbuild_plugin.py | 21 +++++++++++++++------ 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/distbuild/build_controller.py b/distbuild/build_controller.py index 93f97fac..387b410f 100644 --- a/distbuild/build_controller.py +++ b/distbuild/build_controller.py @@ -258,6 +258,8 @@ class BuildController(distbuild.StateMachine): self._request['ref'], self._request['morphology'], ] + if 'original_ref' in self._request: + argv.append(self._request['original_ref']) msg = distbuild.message('exec-request', id=self._idgen.next(), argv=argv, diff --git a/distbuild/initiator.py b/distbuild/initiator.py index b0993aa3..70b26c1e 100644 --- a/distbuild/initiator.py +++ b/distbuild/initiator.py @@ -39,7 +39,7 @@ class _Failed(object): class Initiator(distbuild.StateMachine): - def __init__(self, cm, conn, app, repo_name, ref, morphology): + def __init__(self, cm, conn, app, repo_name, ref, morphology, original_ref): distbuild.StateMachine.__init__(self, 'waiting') self._cm = cm self._conn = conn @@ -47,6 +47,7 @@ class Initiator(distbuild.StateMachine): self._repo_name = repo_name self._ref = ref self._morphology = morphology + self._original_ref = original_ref self._steps = None self._step_outputs = {} self._step_output_dir = app.settings['initiator-step-output-dir'] @@ -80,7 +81,8 @@ class Initiator(distbuild.StateMachine): id=random_id, repo=self._repo_name, ref=self._ref, - morphology=self._morphology + morphology=self._morphology, + original_ref=self._original_ref ) self._jm.send(msg) logging.debug('Initiator: sent to controller: %s', repr(msg)) diff --git a/distbuild/protocol.py b/distbuild/protocol.py index d5dfe2b7..ffce1fe7 100644 --- a/distbuild/protocol.py +++ b/distbuild/protocol.py @@ -19,7 +19,7 @@ '''Construct protocol message objects (dicts).''' -_types = { +_required_fields = { 'build-request': [ 'id', 'repo', @@ -84,15 +84,26 @@ _types = { } +_optional_fields = { + 'build-request': [ + 'original_ref' + ] +} + + def message(message_type, **kwargs): - assert message_type in _types - required_fields = _types[message_type] + known_types = _required_fields.keys() + assert message_type in known_types + + required_fields = _required_fields[message_type] + optional_fields = _optional_fields.get(message_type, []) for name in required_fields: assert name in kwargs, 'field %s is required' % name for name in kwargs: - assert name in required_fields, 'field %s is not allowed' % name + assert (name in required_fields or name in optional_fields), \ + 'field %s is not allowed' % name msg = dict(kwargs) msg['type'] = message_type diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index 544d88d8..438badb3 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -542,21 +542,18 @@ class InitiatorBuildCommand(BuildCommand): self.app.settings['push-build-branches'] = True super(InitiatorBuildCommand, self).__init__(app) - def build(self, args): + def build(self, repo_name, ref, filename, original_ref=None): '''Initiate a distributed build on a controller''' distbuild.add_crash_conditions(self.app.settings['crash-condition']) - if len(args) != 3: - raise morphlib.Error( - 'Need repo, ref, morphology triplet to build') - if self.addr == '': raise morphlib.Error( 'Need address of controller to run a distbuild') self.app.status(msg='Starting distributed build') loop = distbuild.MainLoop() + args = [repo_name, ref, filename, original_ref or ref] cm = distbuild.InitiatorConnectionMachine(self.app, self.addr, self.port, diff --git a/morphlib/plugins/distbuild_plugin.py b/morphlib/plugins/distbuild_plugin.py index 653eeae8..e18af492 100644 --- a/morphlib/plugins/distbuild_plugin.py +++ b/morphlib/plugins/distbuild_plugin.py @@ -45,7 +45,7 @@ class SerialiseArtifactPlugin(cliapp.Plugin): def enable(self): self.app.add_subcommand('serialise-artifact', self.serialise_artifact, - arg_synopsis='REPO REF MORPHOLOGY') + arg_synopsis='REPO REF MORPHOLOGY [ORIGINAL_REF]') def disable(self): pass @@ -55,13 +55,22 @@ class SerialiseArtifactPlugin(cliapp.Plugin): distbuild.add_crash_conditions(self.app.settings['crash-condition']) - if len(args) != 3: - raise cliapp.AppException('Must get triplet') - - repo_name, ref, morph_name = args + if len(args) != 3 and len(args) != 4: + raise cliapp.AppException( + 'This command takes a repo/ref/morph triplet, and optionally ' + 'a ref name.') + + repo_name, ref, morph_name = args[0:3] + + if len(args) == 4: + original_ref = args[3] + else: + original_ref = ref + filename = morphlib.util.sanitise_morphology_path(morph_name) build_command = morphlib.buildcommand.BuildCommand(self.app) - srcpool = build_command.create_source_pool(repo_name, ref, filename) + srcpool = build_command.create_source_pool( + repo_name, ref, filename, original_ref=original_ref) artifact = build_command.resolve_artifacts(srcpool) self.app.output.write(distbuild.serialise_artifact(artifact)) self.app.output.write('\n') -- cgit v1.2.1