Exemplo n.º 1
0
    def run(self, args):
        sandbox = SandBox(root_dir=args.sandbox)

        sandbox.create_dirs()

        if args.spec_git_url:
            g = GitRepository(sandbox.specs_dir)
            if e3.log.default_output_stream is not None:
                g.log_stream = e3.log.default_output_stream
            g.init()
            g.update(args.spec_git_url, args.spec_git_branch, force=True)

        sandbox.dump_configuration()
        sandbox.write_scripts()
Exemplo n.º 2
0
    def run(self, args):
        sandbox = SandBox()
        sandbox.root_dir = args.sandbox

        sandbox.create_dirs()

        if args.spec_git_url:
            mkdir(sandbox.spec_dir)
            g = GitRepository(sandbox.spec_dir)
            if e3.log.default_output_stream is not None:
                g.log_stream = e3.log.default_output_stream
            g.init()
            g.update(args.spec_git_url, args.spec_git_branch, force=True)

        sandbox.dump_configuration()
        sandbox.write_scripts()
Exemplo n.º 3
0
 def do_checkout(self):
     """Get sources from vcs to sandbox vcs_dir."""
     repo_name = self.data.repo_name
     repo_url = self.data.repo_data['url']
     repo_revision = self.data.repo_data['revision']
     repo_vcs = self.data.repo_data['vcs']
     if repo_vcs != 'git':
         logger.error('%s vcs type not supported', repo_vcs)
         self.status = STATUS.failure
         return
     repo_dir = os.path.join(self.sandbox.vcs_dir, repo_name)
     g = GitRepository(repo_dir)
     if e3.log.default_output_stream is not None:
         g.log_stream = e3.log.default_output_stream
     g.init()
     g.update(repo_url, repo_revision, force=True)
     self.status = STATUS.success
Exemplo n.º 4
0
 def do_checkout(self) -> None:
     """Get sources from vcs to sandbox vcs_dir."""
     repo_name = self.data.repo_name
     repo_url = self.data.repo_data["url"]
     repo_revision = self.data.repo_data["revision"]
     repo_vcs = self.data.repo_data["vcs"]
     if repo_vcs != "git":
         logger.error("%s vcs type not supported", repo_vcs)
         self.__status = STATUS.failure
         return
     assert self.sandbox.vcs_dir is not None
     repo_dir = os.path.join(self.sandbox.vcs_dir, repo_name)
     g = GitRepository(repo_dir)
     if e3.log.default_output_stream is not None:
         g.log_stream = e3.log.default_output_stream
     g.init()
     g.update(repo_url, repo_revision, force=True)
     self.__status = STATUS.success
Exemplo n.º 5
0
    def run(self, args):
        sandbox = SandBox()
        sandbox.root_dir = args.sandbox

        if args.specs_dir:
            sandbox.specs_dir = args.specs_dir

        if args.create_sandbox:
            sandbox.create_dirs()

        if args.create_sandbox and args.spec_git_url:
            mkdir(sandbox.specs_dir)
            g = GitRepository(sandbox.specs_dir)
            if e3.log.default_output_stream is not None:
                g.log_stream = e3.log.default_output_stream
            g.init()
            g.update(args.spec_git_url, args.spec_git_branch, force=True)

        sandbox.dump_configuration()
        sandbox.write_scripts()

        asr = AnodSpecRepository(sandbox.specs_dir)
        check_api_version(asr.api_version)

        # Load plan content if needed
        if args.plan:
            if not os.path.isfile(args.plan):
                raise SandBoxError("plan file %s does not exist" % args.plan,
                                   origin="SandBoxExec.run")
            with open(args.plan, "r") as plan_fd:
                plan_content = ["def main_entry_point():"]
                plan_content += [
                    "    %s" % line for line in plan_fd.read().splitlines()
                ]
                plan_content = "\n".join(plan_content)

            env = BaseEnv()
            cm = PlanContext(server=env)
            store = None
            resolver = getattr(
                AnodContext,
                str(args.resolver),
                AnodContext.always_create_source_resolver,
            )
            logger.debug("Using resolver %s", resolver.__name__)

            # Declare available actions and their signature
            def anod_action(module,
                            build=None,
                            host=None,
                            target=None,
                            qualifier=None):
                pass  # all: no cover

            for a in ("anod_install", "anod_build", "anod_test"):
                cm.register_action(a, anod_action)

            # Load the plan and execute
            plan = Plan(data={})
            plan.load_chunk(plan_content)
            actions = cm.execute(plan, "main_entry_point")

            ac = AnodContext(asr, default_env=env)
            for action in actions:
                ac.add_anod_action(
                    action.module,
                    action,
                    action.action.replace("anod_", "", 1),
                    action.qualifier,
                )

            # Check if machine plan is locally schedulable
            action_list = ac.schedule(resolver)
            e = ElectrolytJobFactory(sandbox, asr, store, dry_run=args.dry_run)
            e.run(action_list)
Exemplo n.º 6
0
    def update_git(self, url, revision):
        """Update working dir using a Git repository.

        :param url: git repository url
        :type url: str
        :param revision: git revision
        :type revision: str
        """
        # For git repositories revision cannot be None
        if revision is None:
            return ReturnValue.failure, None, None

        g = GitRepository(working_tree=self.working_dir)
        g.log_stream = e3.log.default_output_stream
        old_commit, new_commit = None, None

        # Create a remote for which name is bind to a an url
        # This ensure that when the url does not change, git will not
        # redownload all the objects on each objects (and thus avoid
        # disk space leaks).
        if isinstance(url, str):
            remote_name = hashlib.sha256(url.encode("utf-8")).hexdigest()
        else:
            remote_name = hashlib.sha256(url).hexdigest()
        g.init()

        # Do the remote addition manually as in that context we can ignore
        # safely any error returned by this command.
        try:
            remote_list = g.git_cmd(["remote"], output=PIPE).out.splitlines()
            if remote_name not in remote_list:
                g.git_cmd(["remote", "add", remote_name, url])
        except Exception:
            # Ignore exception as it probably means that remote already exist
            # In case of real error the failure will be detected later.
            pass

        try:
            old_commit = g.rev_parse()

            # Using fetch + checkout ensure caching is effective
            g.git_cmd(
                ["fetch", "-f", remote_name,
                 "%s:refs/e3-checkout" % revision])
            g.checkout("refs/e3-checkout", force=True)
            new_commit = g.rev_parse()

            # Verify that there is no local change
            p = g.git_cmd(["status", "--porcelain"], output=PIPE)
            if p.out:
                logger.error(
                    "Repository %s is locally modified, saving "
                    "diff in stash\n%s",
                    self.name,
                    p.out,
                )
                g.git_cmd(["stash", "save", "-u"])

            if old_commit == new_commit:
                result = ReturnValue.unchanged
            elif self.compute_changelog:
                # Fetch the change log and dump it into the changelog file
                with closing(
                        tempfile.NamedTemporaryFile(mode="w",
                                                    delete=False)) as fd:
                    g.write_log(fd,
                                rev_range="%s..%s" % (old_commit, new_commit))
                    tmp_filename = fd.name
                try:
                    with open(tmp_filename) as fd:
                        commits = [
                            commit
                            for commit in g.parse_log(fd, max_diff_size=1024)
                        ]
                finally:
                    rm(tmp_filename)

                with open(self.changelog_file, "w") as fd:
                    json.dump(commits, fd)
                # We have removed local changes or updated the git repository
                result = ReturnValue.success
            else:
                result = ReturnValue.success

        except GitError:
            logger.exception("Error during git update %s" % self.name)
            result = ReturnValue.failure
        return result, old_commit, new_commit