def validate(self): if "repository" not in self.parameters: self.errors = "Git 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 = GitHelper(self.parameters["repository"]) super().validate()
def validate(self): if 'repository' not in self.parameters: self.errors = "Git 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 = GitHelper(self.parameters['repository']) super(GitRepoAction, self).validate()
def install_git_repos(self, testdef, runner_path): repos = testdef["install"].get("git-repos", []) for repo in repos: commit_id = None if isinstance(repo, str): # tests should expect git clone https://path/dir/repo.git to create ./repo/ subdir = repo.replace( ".git", "", len(repo) - 1 ) # drop .git from the end, if present dest_path = os.path.join(runner_path, os.path.basename(subdir)) commit_id = GitHelper(repo).clone(dest_path) elif isinstance(repo, dict): # TODO: We use 'skip_by_default' to check if this # specific repository should be skipped. The value # for 'skip_by_default' comes from job parameters. url = repo.get("url", "") url = self._lookup_params("url", url, testdef) branch = repo.get("branch") branch = self._lookup_params("branch", branch, testdef) if not url: raise TestError( "Invalid git-repos dictionary in install definition." ) subdir = url.replace( ".git", "", len(url) - 1 ) # drop .git from the end, if present destination = repo.get("destination", os.path.basename(subdir)) destination = self._lookup_params("destination", destination, testdef) if destination: dest_path = os.path.join(runner_path, destination) if os.path.abspath(runner_path) != os.path.dirname(dest_path): raise JobError( "Destination path is unacceptable %s" % destination ) if os.path.exists(dest_path): raise TestError( "Cannot mix string and url forms for the same repository." ) commit_id = GitHelper(url).clone(dest_path, branch=branch) else: raise TestError("Unrecognised git-repos block.") if commit_id is None: raise JobError("Unable to clone %s" % str((repo)))
class GitRepoAction(RepoAction): """ Each repo action is for a single repository, tests using multiple repositories get multiple actions. """ priority = 1 name = "git-repo-action" description = "apply git repository of tests to the test image" summary = "clone git test repo" def validate(self): if "repository" not in self.parameters: self.errors = "Git 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 = GitHelper(self.parameters["repository"]) super().validate() @classmethod def accepts(cls, repo_type): return repo_type == "git" def run(self, connection, max_end_time): """ Clones the git repo into a directory name constructed from the mount_path, lava-$hostname prefix, tests, $index_$test_name elements. e.g. /tmp/tmp.234Ga213/lava-kvm01/tests/3_smoke-tests-basic Also updates some basic metadata about the test definition. """ # use the base class to populate the runner_path and overlay_path data into the context connection = super().run(connection, max_end_time) # NOTE: the runner_path dir must remain empty until after the VCS clone, so let the VCS clone create the final dir runner_path = self.get_namespace_data( action="uuid", label="overlay_path", key=self.parameters["test_name"] ) if os.path.exists(runner_path) and os.listdir(runner_path) == []: raise LAVABug( "Directory already exists and is not empty - duplicate Action?" ) # Clear the data if os.path.exists(runner_path): shutil.rmtree(runner_path) self.logger.info("Fetching tests from %s", self.parameters["repository"]) # Get the branch if specified. branch = self.parameters.get("branch") # Set shallow to False if revision is specified. # Otherwise default to True if not specified as a parameter. revision = self.parameters.get("revision") shallow = False if not revision: shallow = self.parameters.get("shallow", True) commit_id = self.vcs.clone( runner_path, shallow=shallow, revision=revision, branch=branch, history=self.parameters.get("history", True), ) if commit_id is None: raise InfrastructureError( "Unable to get test definition from %s (%s)" % (self.vcs.binary, self.parameters) ) self.results = { "commit": commit_id, "repository": self.parameters["repository"], "path": self.parameters["path"], } # now read the YAML to create a testdef dict to retrieve metadata yaml_file = os.path.join(runner_path, self.parameters["path"]) self.logger.debug("Tests stored (tmp) in %s", yaml_file) try: with open(yaml_file, "r") as test_file: testdef = yaml_safe_load(test_file) except OSError as exc: raise JobError( "Unable to open test definition '%s': %s" % (self.parameters["path"], str(exc)) ) # set testdef metadata in base class self.store_testdef(testdef, "git", commit_id) return connection
class GitRepoAction(RepoAction): # pylint: disable=too-many-public-methods """ Each repo action is for a single repository, tests using multiple repositories get multiple actions. """ priority = 1 name = "git-repo-action" description = "apply git repository of tests to the test image" summary = "clone git test repo" def validate(self): if 'repository' not in self.parameters: self.errors = "Git 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 = GitHelper(self.parameters['repository']) super(GitRepoAction, self).validate() @classmethod def accepts(cls, repo_type): return repo_type == 'git' def run(self, connection, max_end_time, args=None): """ Clones the git repo into a directory name constructed from the mount_path, lava-$hostname prefix, tests, $index_$test_name elements. e.g. /tmp/tmp.234Ga213/lava-kvm01/tests/3_smoke-tests-basic Also updates some basic metadata about the test definition. """ # use the base class to populate the runner_path and overlay_path data into the context connection = super(GitRepoAction, self).run(connection, max_end_time, 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 = self.get_namespace_data(action='uuid', label='overlay_path', key=self.parameters['test_name']) if os.path.exists(runner_path) and os.listdir(runner_path) == []: raise LAVABug("Directory already exists and is not empty - duplicate Action?") # Clear the data if os.path.exists(runner_path): shutil.rmtree(runner_path) self.logger.info("Fetching tests from %s", self.parameters['repository']) # Get the branch if specified. branch = self.parameters.get('branch', None) # Set shallow to False if revision is specified. # Otherwise default to True if not specified as a parameter. revision = self.parameters.get('revision', None) shallow = False if not revision: shallow = self.parameters.get('shallow', True) commit_id = self.vcs.clone( runner_path, shallow=shallow, revision=revision, branch=branch, history=self.parameters.get('history', True)) if commit_id is None: raise InfrastructureError("Unable to get test definition from %s (%s)" % (self.vcs.binary, self.parameters)) self.results = { 'commit': commit_id, 'repository': self.parameters['repository'], 'path': self.parameters['path']} # now read the YAML to create a testdef dict to retrieve metadata yaml_file = os.path.join(runner_path, self.parameters['path']) self.logger.debug("Tests stored (tmp) in %s", yaml_file) try: with open(yaml_file, 'r') as test_file: testdef = yaml.safe_load(test_file) except IOError as exc: raise JobError("Unable to open test definition '%s': %s" % (self.parameters['path'], str(exc))) # set testdef metadata in base class self.store_testdef(testdef, 'git', commit_id) return connection