def start(self, basedir): LOG.info("Starting CDSW runner...") repo_type_env = OsUtils.get_env_value( BranchComparatorEnvVar.REPO_TYPE.value, RepoType.DOWNSTREAM.value) repo_type: RepoType = RepoType[repo_type_env.upper()] if repo_type == RepoType.DOWNSTREAM: self.run_clone_downstream_repos_script(basedir) elif repo_type == RepoType.UPSTREAM: # If we are in upstream mode, make sure downstream dir exist # Currently, yarndevtools requires both repos to be present when initializing. # BranchComparator is happy with one single repository, upstream or downstream, exclusively. # Git init the other repository so everything will be alright FileUtils.create_new_dir(HADOOP_CLOUDERA_BASEDIR) FileUtils.change_cwd(HADOOP_CLOUDERA_BASEDIR) os.system("git init") self.run_clone_upstream_repos_script(basedir) # TODO investigate why legacy script fails! self.run_comparator_and_send_mail(repo_type, algorithm="simple", run_legacy_script=False) self.run_comparator_and_send_mail(repo_type, algorithm="grouped", run_legacy_script=False)
def run(cls, command, working_dir=None, log_stdout=False, log_stderr=False, log_command_result=False, fail_on_error=False, fail_message="", wait_after=0, wait_message=""): if working_dir: FileUtils.change_cwd(working_dir) args = shlex.split(command) proc = subprocess.run(args, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) args2 = str(proc.args) if working_dir: FileUtils.reset_cwd() command_result = RegularCommandResult(command, args2, proc.stdout, proc.stderr, proc.returncode) if log_command_result: LOG.info("Command result: %s", command_result) if log_stdout: LOG.info("Stdout:\n %s", command_result.stdout) if log_stderr: LOG.info("Stderr:\n %s", command_result.stderr) if fail_on_error and command_result.exit_code != 0: if fail_message: LOG.error(fail_message) raise ValueError( "Execution failed! Command was: {}".format(command)) if wait_after > 0: LOG.info("Waiting for %d seconds %s", wait_message) time.sleep(wait_after)