class BzrRepoAction(RepoAction): # pylint: disable=too-many-public-methods """ Each repo action is for a single repository, tests using multiple repositories get multiple actions. """ priority = 1 def __init__(self): super(BzrRepoAction, self).__init__() self.name = "bzr-repo-action" self.description = "apply bazaar repository of tests to the test image" self.summary = "branch a bzr test repo" self.testdef = None def validate(self): if 'repository' not in self.parameters: self.errors = "Bzr repository not specified in job definition" if 'path' not in self.parameters: self.errors = "Path to YAML file not specified in the job definition" if not self.valid: return self.vcs = BzrHelper(self.parameters['repository']) super(BzrRepoAction, self).validate() @classmethod def accepts(cls, repo_type): if repo_type == 'bzr': return True return False def run(self, connection, args=None): """ Clone the bazar repository into a directory """ connection = super(BzrRepoAction, self).run(connection, self.parameters) # NOTE: the runner_path dir must remain empty until after the VCS clone, so let the VCS clone create the final dir runner_path = os.path.join(self.data['test-definition']['overlay_dir'], 'tests', self.parameters['test_name']) commit_id = self.vcs.clone(runner_path, self.parameters.get('revision', None)) if commit_id is None: raise RuntimeError("Unable to get test definition from %s (%s)" % (self.vcs.binary, self.parameters)) self.results = {'success': commit_id} # now read the YAML to create a testdef dict to retrieve metadata yaml_file = os.path.join(runner_path, self.parameters['path']) if not os.path.exists(yaml_file): raise JobError("Unable to find test definition YAML: %s" % yaml_file) with open(yaml_file, 'r') as test_file: self.testdef = yaml.safe_load(test_file) # set testdef metadata in base class self.store_testdef(self.testdef, 'bzr', commit_id) return connection