#21 Rename the utils variable to not conflict with the utils module
Merged 4 years ago by pingou. Opened 4 years ago by pingou.
fedora-ci/ pingou/monitor-gating staging  into  master

file modified
+12 -13
@@ -14,12 +14,12 @@ 

  def get_cli_args(args):

  

      parser = argparse.ArgumentParser(

-         prog="clean up side-tags", formatter_class=argparse.ArgumentDefaultsHelpFormatter

+         prog="clean up side-tags",

+         formatter_class=argparse.ArgumentDefaultsHelpFormatter,

      )

  

      parser.add_argument(

-         "conf",

-         help="Configuration file used by the runner",

+         "conf", help="Configuration file used by the runner",

      )

  

      return parser.parse_args(args)
@@ -33,7 +33,9 @@ 

      try:

          output = subprocess.check_output(command, stderr=subprocess.PIPE)

      except subprocess.CalledProcessError as e:

-         _log.error("Command `{}` return code: `{}`".format(" ".join(command), e.returncode))

+         _log.error(

+             "Command `{}` return code: `{}`".format(" ".join(command), e.returncode)

+         )

          _log.error("stdout:\n-------\n{}".format(e.stdout))

          _log.error("stderr:\n-------\n{}".format(e.stderr))

          pass
@@ -45,14 +47,14 @@ 

  

      conf = toml.load(args.conf)

      if conf.get("kb_principal") and conf.get("kb_keytab_file"):

-         print(f"Logging as {conf['kb_principal']} into kerberos using: {conf['kb_keytab_file']}")

+         print(

+             f"Logging as {conf['kb_principal']} into kerberos using: {conf['kb_keytab_file']}"

+         )

          cmd = ["kinit", conf["kb_principal"], "-kt", conf["kb_keytab_file"]]

          run_command(cmd)

  

      # list side-tags:

-     cmd = [

-         conf["fedpkg"], "list-side-tags", "--user", conf["kb_principal"]

-     ]

+     cmd = [conf["fedpkg"], "list-side-tags", "--user", conf["kb_principal"]]

      output = run_command(cmd)

  

      if not output:
@@ -63,15 +65,12 @@ 

      # Remove all the side-tags but the last one (which is the latest one), which

      # we keep in case there is a run ongoing

      for line in output[:-1]:

-         side_tag = line.split('\t')[0]

+         side_tag = line.split("\t")[0]

          print("Removing side-tag: %s" % side_tag)

-         cmd = [

-             conf["fedpkg"], "remove-side-tag", side_tag

-         ]

+         cmd = [conf["fedpkg"], "remove-side-tag", side_tag]

          output = run_command(cmd)

  

  

- 

  if __name__ == "__main__":

      """ Main method. """

  

file modified
+17 -21
@@ -9,16 +9,18 @@ 

  import sched

  import sys

  import time

- import utils

  import uuid

  

  import fedora_messaging.api

  import fedora_messaging.exceptions

- import toml

  

- import monitor_gating_single_build

  import monitor_gating_multi_builds

- from utils import MonitoringUtils, run_command

+ 

+ import monitor_gating_single_build

+ 

+ import toml

+ 

+ from utils import MonitoringUtils, blocking_issues, run_command

  

  s = sched.scheduler(time.time, time.sleep)

  conf = toml.load
@@ -51,10 +53,8 @@ 

  def _clean_up_side_tags(utils):

      try:

          print("  Removing side-tag: %s" % utils.side_tag_name)

-         cmd = [

-             conf["fedpkg"], "remove-side-tag", utils.side_tag_name

-         ]

-         output = run_command(cmd)

+         cmd = [conf["fedpkg"], "remove-side-tag", utils.side_tag_name]

+         run_command(cmd)

      except Exception:

          pass

  
@@ -77,7 +77,7 @@ 

          single_args = conf["workflow_single_gating_args"].split()

          notify(

              topic=f"single-build.start",

-             message={"arguments": single_args, "runid": runid,},

+             message={"arguments": single_args, "runid": runid},

          )

          output = monitor_gating_single_build.main(single_args)

          output_text = "\n".join(output)
@@ -97,15 +97,15 @@ 

  

          # Multi Build Gating

          multi_args = conf["workflow_multi_gating_args"].split()

-         utils = MonitoringUtils()

+         monit_utils = MonitoringUtils()

          notify(

              topic=f"multi-build.start",

-             message={"arguments": multi_args, "runid": runid,},

+             message={"arguments": multi_args, "runid": runid},

          )

          try:

-             output = monitor_gating_multi_builds.main(multi_args, utils=utils)

+             output = monitor_gating_multi_builds.main(multi_args, utils=monit_utils)

          finally:

-             _clean_up_side_tags(utils)

+             _clean_up_side_tags(monit_utils)

  

          output_text = "\n".join(output)

          if "[FAILED]" not in output_text:
@@ -128,19 +128,15 @@ 

          print(sys.exc_info()[0])

  

          notify(

-             topic=f"multi-build.end.error",

-             message={

-                 "runid": runid,

-                 "exception": err,

-             },

+             topic=f"multi-build.end.error", message={"runid": runid, "exception": err},

          )

  

-     blocking_issues = utils.blocking_issues(blocker_tags)

+     blocking_issues_list = blocking_issues(blocker_tags)

      now = datetime.datetime.utcnow().strftime("%H:%M:%S")

-     if blocking_issues:

+     if blocking_issues_list:

          print(

              f"{now} Next run in: {delay_when_failing} seconds because of "

-             f"{len(blocking_issues)} open issues",

+             f"{len(blocking_issues_list)} open issues",

              flush=True,

          )

          s.enter(delay_when_failing, 1, schedule, argument=(conf,))

file modified
+2 -4
@@ -172,7 +172,7 @@ 

          info_log = f"Creating PR from forks/{username}/{namespace}/{name}"

          self.print_user(info_log)

          url = "/".join(

-             [base_url.rstrip("/"), "api/0", namespace, name, "pull-request/new",]

+             [base_url.rstrip("/"), "api/0", namespace, name, "pull-request/new"]

          )

          data = {

              "branch_to": branch,
@@ -258,9 +258,7 @@ 

              "koji",

          ]

          if koji_url:

-             command.extend(

-                 ["-s", koji_url,]

-             )

+             command.extend(["-s", koji_url])

          command.extend(["call", "listTags", nevr])

  

          success = False

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

1 new commit added

  • Refactor the code to make explicit what is imported from utils
4 years ago

2 new commits added

  • flake8 and black fixes for the entire project
  • Run black on the entire project
4 years ago

Looks good to merge :)

So we're not entirely there yet, but this definitely improve things, so I'm going to merge it and see if I can fix the remaining pieces.

Pull-Request has been merged by pingou

4 years ago