Пример #1
0
 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()
Пример #2
0
 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()
Пример #3
0
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

    def __init__(self):
        super(GitRepoAction, self).__init__()
        self.name = "git-repo-action"
        self.description = "apply git repository of tests to the test image"
        self.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):
        if repo_type == 'git':
            return True
        return False

    def run(self, connection, 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, 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.data['test'][self.uuid]['overlay_path'][self.parameters['test_name']]
        if os.path.exists(runner_path) and os.listdir(runner_path) == []:
            raise RuntimeError("Directory already exists and is not empty - duplicate Action?")
        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
        self.logger.debug(os.path.join(runner_path, self.parameters['path']))
        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:
            testdef = yaml.safe_load(test_file)

        # set testdef metadata in base class
        self.store_testdef(testdef, 'git', commit_id)

        return connection
Пример #4
0
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

    def __init__(self):
        super(GitRepoAction, self).__init__()
        self.name = "git-repo-action"
        self.description = "apply git repository of tests to the test image"
        self.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):
        if repo_type == 'git':
            return True
        return False

    def run(self, connection, 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, 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.data['test'][self.uuid]['overlay_path'][self.parameters['test_name']]
        if os.path.exists(runner_path) and os.listdir(runner_path) == []:
            raise RuntimeError("Directory already exists and is not empty - duplicate Action?")
        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
        self.logger.debug(os.path.join(runner_path, self.parameters['path']))
        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:
            testdef = yaml.safe_load(test_file)

        # set testdef metadata in base class
        self.store_testdef(testdef, 'git', commit_id)

        return connection