From d26690f2125514899801b225eee7657087255a81 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 20 2020 14:27:34 +0000 Subject: [PATCH 1/4] Fixup the time it took to get results from datagrepper Signed-off-by: Pierre-Yves Chibon --- diff --git a/utils.py b/utils.py index a621d23..793f212 100644 --- a/utils.py +++ b/utils.py @@ -367,8 +367,9 @@ class MonitoringUtils: """ Check the CI results in datagrepper for results about our specified build. """ + start_lookup = datetime.datetime.utcnow() if start is None: - start = datetime.datetime.utcnow() + start = start_lookup info_log = f"Checking datagrepper for {name} messages" self.print_user(info_log) # Start pulling messages 10 minutes before now @@ -503,7 +504,7 @@ class MonitoringUtils: info_log = f"{name} results in datagrepper returned {returned_status}" end = datetime.datetime.utcnow() - info_log += f" - ran for: {(end - start).seconds}s" + info_log += f" - ran for: {(end - start_lookup).seconds}s" self.print_user(info_log, success=success) def lookup_ci_resultsdb(self, nevr, name, url): From cd9063a334c83e89f0c06328d1980631b2ce4ec6 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 20 2020 14:28:07 +0000 Subject: [PATCH 2/4] Specify the user who is doing the clone Signed-off-by: Pierre-Yves Chibon --- diff --git a/monitor_gating_single_build.py b/monitor_gating_single_build.py index a7c1d64..880dd26 100644 --- a/monitor_gating_single_build.py +++ b/monitor_gating_single_build.py @@ -100,7 +100,13 @@ def main(args): with tempfile.TemporaryDirectory(prefix="ci-test-") as folder: print(f"Working in {folder}\n") if not args.nevr: - utils.clone_repo(conf["fedpkg"], namespace, name, folder=folder) + utils.clone_repo( + conf["fedpkg"], + conf["fas_username"], + namespace, + name, + folder=folder, + ) gitfolder = os.path.join(folder, name) utils.switch_branch(conf["fedpkg"], branch, folder=gitfolder) utils.bump_release(name, folder=gitfolder) diff --git a/utils.py b/utils.py index 793f212..e7d0563 100644 --- a/utils.py +++ b/utils.py @@ -67,13 +67,13 @@ class MonitoringUtils: self.logs.append(f"{time} - {content}") print(f"{time} - {content}", end=end, flush=True) - def clone_repo(self, command, namespace, name, folder): + def clone_repo(self, command, username, namespace, name, folder): """ Clone the specified git repo into the specified folder. """ - info_log = f"Cloning the git repo: {namespace}/{name}" + info_log = f"Cloning as {username} the git repo: {namespace}/{name}" self.print_user(info_log) try: - run_command([command, "clone", f"{namespace}/{name}"], cwd=folder) + run_command([command, "--user", username, "clone", f"{namespace}/{name}"], cwd=folder) clone_folder = os.path.join(folder, name) run_command( ["git", "config", "user.name", "packagerbot"], @@ -681,7 +681,13 @@ class MonitoringUtils: namespace = conf["namespace"] branch = conf["branch"] - self.clone_repo(conf["fedpkg"], namespace, name, folder=folder) + self.clone_repo( + conf["fedpkg"], + conf["fas_username"], + namespace, + name, + folder=folder, + ) gitfolder = os.path.join(folder, name) self.switch_branch(conf["fedpkg"], branch, folder=gitfolder) side_tag_name = None From 16b15426f6c631278a98180a4156337769c7b662 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 20 2020 14:29:35 +0000 Subject: [PATCH 3/4] Adjust the project for openshift deployment - Add a Dockerfile to build the project - Add an entrypoint.sh file called when starting the project in openshift - Hide password from the logs if the command failed - Do regular prints in openshift so the lines show in the logs (triggered via an environment variable) Signed-off-by: Pierre-Yves Chibon --- diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..34f29c4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# This Dockerfile is used to build and run monitor-gating on Openshift +FROM fedora:31 + +LABEL maintainer "Pierre-Yves Chibon " + +RUN dnf -y install python3-requests bodhi-client fedpkg fedpkg-stage \ + python3-toml git python3-koji python3-fedora-messaging cracklib-dicts \ + && dnf clean all && mkdir /.ssh && mkdir /.fedora + +COPY . /opt/code + +RUN echo "packagerbot" > /.fedora.upn \ + && chgrp -R 0 /opt/code \ + && chmod -R g=u /opt/code \ + && chgrp -R 0 /.ssh \ + && chmod -R g=u /.ssh \ + && chgrp -R 0 /.fedora \ + && chmod -R g=u /.fedora \ + && chmod g=u /etc/passwd \ + && id + + +USER 1000 +WORKDIR / +ENTRYPOINT ["sh", "/opt/code/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..ff57bbb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if ! whoami &> /dev/null; then + if [ -w /etc/passwd ]; then + echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd + fi +fi + +ln -s /opt/ssh/id_rsa /.ssh/id_rsa || true +kinit monitor-gating/os-master01.stg.phx2.fedoraproject.org@STG.FEDORAPROJECT.ORG -kt /etc/keytabs/koji-keytab +ssh-keyscan pkgs.stg.fedoraproject.org >> /.ssh/known_hosts +python3 /opt/code/runner.py /opt/config/runner.cfg diff --git a/runner.py b/runner.py index 0c3be7b..7ef762e 100644 --- a/runner.py +++ b/runner.py @@ -55,7 +55,7 @@ def schedule(conf): delay = conf["delay"] delay_when_failing = conf["delay_when_failing"] blocker_tags = conf["blocker_tags"] - print("Tests started:", datetime.datetime.utcnow()) + print("Tests started:", datetime.datetime.utcnow(), flush=True) try: # Single Build Gating single_args = conf["workflow_single_gating_args"].split() @@ -97,17 +97,19 @@ def schedule(conf): } ) - print("Tests finished:", datetime.datetime.utcnow()) + print("Tests finished:", datetime.datetime.utcnow(), flush=True) except Exception as err: - print(f"Tests failed with: {err}") + print(f"Tests failed with: {err}", flush=True) print(sys.exc_info()[0]) blocking_issues = utils.blocking_issues(blocker_tags) + now = datetime.datetime.utcnow().strftime("%H:%M:%S") if blocking_issues: - print(f"Next run in: {delay_when_failing} seconds because of {len(blocking_issues)} open issues") + print(f"{now} Next run in: {delay_when_failing} seconds because of " + f"{len(blocking_issues)} open issues", flush=True) s.enter(delay_when_failing, 1, schedule, argument=(conf,)) else: - print(f"Next run in: {delay} seconds") + print(f"{now} Next run in: {delay} seconds", flush=True) s.enter(delay, 1, schedule, argument=(conf,)) diff --git a/utils.py b/utils.py index e7d0563..67ebf53 100644 --- a/utils.py +++ b/utils.py @@ -60,7 +60,10 @@ class MonitoringUtils: else: content = "{} {}".format(content.ljust(spaces), "[FAILED]") else: - end = "\r" + if os.environ.get("OPENSHIFT"): + end = None + else: + end = "\r" now = datetime.datetime.utcnow() time = now.strftime("%H:%M:%S") @@ -715,6 +718,9 @@ def run_command(command, cwd=None): command, cwd=cwd, stderr=subprocess.PIPE ) except subprocess.CalledProcessError as e: + if "--password" in command: + idx = command.index("--password") + command[idx + 1] = "" _log.error( "Command `{}` return code: `{}`".format( " ".join(command), e.returncode From 472d6b70366738e24a7451204be2847fad0448ae Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 20 2020 16:46:07 +0000 Subject: [PATCH 4/4] Adjust the topic used when a run finished It used to be True/False which isn't quite explicit, now it'll use: succeeded/failed which is likely more user-friendly. Rename the variable while at it, success = "failed" looked a little odd to @asaleh. Signed-off-by: Pierre-Yves Chibon --- diff --git a/runner.py b/runner.py index 7ef762e..3774f9a 100644 --- a/runner.py +++ b/runner.py @@ -67,13 +67,17 @@ def schedule(conf): ) output = monitor_gating_single_build.main(single_args) output_text = "\n".join(output) - success = "[FAILED]" not in output_text + output_text="\n".join(output) + if "[FAILED]" not in output_text: + result = "succeeded" + else: + result = "failed" notify( - topic=f"single-build.end.{success}", + topic=f"single-build.end.{result}", message={ "output": output, "output_text": output_text, - "success": success, + "result": result, } ) @@ -87,13 +91,16 @@ def schedule(conf): ) output = monitor_gating_multi_builds.main(multi_args) output_text = "\n".join(output) - success = "[FAILED]" not in output_text + if "[FAILED]" not in output_text: + result = "succeeded" + else: + result = "failed" notify( - topic=f"multi-build.end.{success}", + topic=f"multi-build.end.{result}", message={ "output": output, "output_text": output_text, - "success": success, + "result": result, } )