#10 Test for open issues, and abort if present.
Merged 4 years ago by pingou. Opened 4 years ago by asaleh.
fedora-ci/ asaleh/monitor-gating check_for_open_issues  into  master

file added
+3
@@ -0,0 +1,3 @@ 

+ [flake8]

+ ignore = E128, W503

+ max-line-length = 120

@@ -0,0 +1,18 @@ 

+ # See https://pre-commit.com for more information

+ # See https://pre-commit.com/hooks.html for more hooks

+ repos:

+ -   repo: https://github.com/pre-commit/pre-commit-hooks

+     rev: v2.4.0

+     hooks:

+     -   id: trailing-whitespace

+     -   id: end-of-file-fixer

+     -   id: check-yaml

+     -   id: check-added-large-files

+     -   id: check-ast

+     -   id: check-merge-conflict

+     -   id: check-toml

+     -   id: debug-statements

+ -   repo: https://gitlab.com/PyCQA/flake8

+     rev: master

+     hooks:

+     -   id: flake8

file modified
+6
@@ -1,6 +1,12 @@ 

  # Time between two runs in second

  delay = 3600

  

+ # Time between two blocked runs in second

+ delay_when_failing = 43200

+ 

+ # blocker issue tags, issue has to have all of them

+ blocker_tags = ['packager_workflow_blocker', 'staging']

+ 

  # CLI arguments to give to the script testing the single build gating workflow

  workflow_single_gating_args = "--conf monitor_gating_stg.cfg --auto-update --no-pr"

  

file modified
+15 -7
@@ -42,7 +42,7 @@ 

              body=message

          )

          fedora_messaging.api.publish(msg)

-     except fedora_messaging.exceptions.PublishReturned as e:

+     except fedora_messaging.exceptions.PublishReturned as err:

          print(f"Fedora Messaging broker rejected message {msg.id}: {err}")

      except fedora_messaging.exceptions.ConnectionException as err:

          print(f"Error sending message {msg.id}: {err}")
@@ -53,6 +53,8 @@ 

  def schedule(conf):

      """ Run the test and schedules the next one. """

      delay = conf["delay"]

+     delay_when_failing = conf["delay_when_failing"]

+     blocker_tags = conf["blocker_tags"]

      print("Tests started:", datetime.datetime.utcnow())

      try:

          # Single Build Gating
@@ -64,8 +66,8 @@ 

              }

          )

          output = monitor_gating_single_build.main(single_args)

-         output_text="\n".join(output)

-         success="[FAILED]" not in output_text

+         output_text = "\n".join(output)

+         success = "[FAILED]" not in output_text

          notify(

              topic=f"single-build.end.{success}",

              message={
@@ -84,8 +86,8 @@ 

              }

          )

          output = monitor_gating_multi_builds.main(multi_args)

-         output_text="\n".join(output)

-         success="[FAILED]" not in output_text

+         output_text = "\n".join(output)

+         success = "[FAILED]" not in output_text

          notify(

              topic=f"multi-build.end.{success}",

              message={
@@ -99,8 +101,14 @@ 

      except Exception as err:

          print(f"Tests failed with: {err}")

          print(sys.exc_info()[0])

-     print(f"Next run in: {delay} seconds")

-     s.enter(delay, 1, schedule, argument=(conf,))

+ 

+     blocking_issues = utils.blocking_issues(blocker_tags)

+     if blocking_issues:

+         print(f"Next run in: {delay_when_failing} seconds because of {len(blocking_issues)} open issues")

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

+     else:

+         print(f"Next run in: {delay} seconds")

+         s.enter(delay, 1, schedule, argument=(conf,))

  

  

  def main(args):

file modified
+28 -29
@@ -17,6 +17,28 @@ 

  _log = logging.getLogger(__name__)

  

  

+ def blocking_issues(tags):

+     """Lists blocking issues we track in the fedora-infrastructure project.

+     """

+     if not tags:

+         print(f"No tags to filter blocking issues by, returning empty.")

+         return []

+     api = f"https://pagure.io/api/0/fedora-infrastructure/issues"

+     q = f"?status=Open&tags={tags[0]}"

+     issues = []

+     try:

+         r = requests.get(api + q)

+         issues = r.json()['issues']

+         if tags:

+             t = set(tags[1:])

+             issues = [i for i in issues if t & set(i['tags'])]

+         for i in issues:

+             print(f"Found blocking issue https://pagure.io/fedora-infrastructure/issue/{i['id']}")

+     except Exception as e:

+         print(f"Error when querying pagure for blocking issues: {e}")

+     return issues

+ 

+ 

  class MonitoringException(Exception):

      """The base class for all exceptions raised by this script."""

  
@@ -45,7 +67,6 @@ 

          self.logs.append(f"{time} - {content}")

          print(f"{time} - {content}", end=end, flush=True)

  

- 

      def clone_repo(self, command, namespace, name, folder):

          """ Clone the specified git repo into the specified folder.

          """
@@ -66,7 +87,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def add_remote(self, name, url, folder):

          """ Add the specified remote to the git repo in the folder with the

          specified url.
@@ -79,7 +99,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def switch_branch(self, command, name, folder):

          """ Switch to the specified git branch in the specified git repo.

          """
@@ -91,7 +110,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def bump_release(self, name, folder):

          """ Bump the release of the spec file the specified git repo.

          """
@@ -103,7 +121,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def commit_changes(self, commit_log, folder):

          """ Commit all the changes made to *tracked* files in the git repo

          with the specified commit log.
@@ -116,7 +133,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def push_changes(self, folder, target, branch, force=False):

          """ Push all changes using git.

          """
@@ -131,7 +147,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def pull_changes(self, folder, target, branch):

          """ Pull all changes using git.

          """
@@ -144,7 +159,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def open_pullrequest(self, base_url, username, namespace, name, branch, token):

          """ Open a pull-request from the user's fork to the main project for

          the specified branch.
@@ -182,7 +196,6 @@ 

          self.print_user(info_log, success=success)

          return (success, pr_id, pr_uid)

  

- 

      def get_nevr(self, command, folder):

          """ Get the name-epoch-version-release presently in git

          """
@@ -195,7 +208,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def build_package(self, command, folder, target=None):

          """ Build the package in the current branch

          """
@@ -210,7 +222,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def chain_build_packages(self, command, packages, folder, target=None):

          """ Chain-build the packages in the current branch

          """
@@ -228,7 +239,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def get_build_tags(self, koji_url, nevr, expected_ends):

          """ List the tags associated with the specified build.

          """
@@ -292,7 +302,6 @@ 

          info_log = f"Retrieving koji tags: {tags}"

          self.print_user(info_log, success=success)

  

- 

      def create_update(self, command, item, prod=True, username=None, password=None, from_tag=False):

          """ Create the update for the package built.

          """
@@ -324,7 +333,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def get_update_id(self, nevr, url):

          """ Retrieve the update identifier from bodhi for the given nevr. """

          start = datetime.datetime.utcnow()
@@ -352,7 +360,6 @@ 

          self.print_user(info_log, success=success)

          return updateid

  

- 

      def lookup_results_datagrepper(

          self, base_url, name, topic, nevr=None, nevrs=None, rev=None,

          bodhi_id=None, start=None, duration=15
@@ -405,8 +412,8 @@ 

  

                      # New message format from the CI pipeline for koji builds

                      if (

-                         "ci.koji-build" in message["topic"] and

-                         message["msg"]["artifact"]["nvr"] == nevr

+                         "ci.koji-build" in message["topic"]

+                         and message["msg"]["artifact"]["nvr"] == nevr

                      ):

                          if message["topic"].endswith("test.complete"):

                              success = True
@@ -451,9 +458,8 @@ 

                      if (

                          "greenwave" in message["topic"]

                          and (

-                         message["msg"]["subject_identifier"] == nevr

-                         or

-                         message["msg"]["subject_identifier"] in nevrs

+                             message["msg"]["subject_identifier"] == nevr

+                             or message["msg"]["subject_identifier"] in nevrs

                          )

                      ):

                          success = True
@@ -464,9 +470,8 @@ 

                      if (

                          "waiverdb" in message["topic"]

                          and (

-                         message["msg"]["subject_identifier"] == nevr

-                         or

-                         message["msg"]["subject_identifier"] in nevrs

+                             message["msg"]["subject_identifier"] == nevr

+                             or message["msg"]["subject_identifier"] in nevrs

                          )

                      ):

                          success = True
@@ -501,7 +506,6 @@ 

          info_log += f" - ran for: {(end - start).seconds}s"

          self.print_user(info_log, success=success)

  

- 

      def lookup_ci_resultsdb(self, nevr, name, url):

          """ Check the CI results in the specified resultsdb for results about

          our specified build.
@@ -549,7 +553,6 @@ 

          info_log += f" - ran for: {(end - start).seconds}s"

          self.print_user(info_log, success=success)

  

- 

      def waive_update(self, command, updateid, prod=True, username=None, password=None):

          """ Waive all the tests results for the specified update using bodhi's

          CLI.
@@ -576,7 +579,6 @@ 

          except MonitoringException:

              self.print_user(info_log, success=False)

  

- 

      def get_pr_flag(

          self,

          base_url,
@@ -630,7 +632,6 @@ 

  

          self.print_user(info_log, success=success)

  

- 

      def merge_pr(self, base_url, username, namespace, name, pr_id, token):

          """ Merge the specified PR

          """
@@ -650,7 +651,6 @@ 

  

          self.print_user(info_log, success=success)

  

- 

      def finalize(self, start):

          """ End data returned. """

          end = datetime.datetime.utcnow()
@@ -675,7 +675,6 @@ 

              self.print_user(info_log, success=False)

          return side_tag_name

  

- 

      def clone_and_bump(self, folder, nevrs, conf, name, target=None, new_side_tag=False):

          """Clone the repo, bump the release, commit and push."""

          namespace = conf["namespace"]

Currently just Pagure issues, because that is the one issue that is blocking us :)

Hm, this ties the code to a very particular issue, once that issue is fixed there could be a different one.
It also only affects single build while the issue with waiverdb will affect the entire pipeline (ie: both)

rebased onto 4c5a748

4 years ago

Not black/pep8 compliant :)

Not black/pep8 compliant :)

Left over debugging?

I guess we should pull the environment from the configuration file as well?

Do we want to handle exceptions here?
Do we want doc strings?

1 new commit added

  • Flake fixes, added pre-commit and flake config.
4 years ago

I added a simple doc-string to the utility function.

I decided to just log on exception, and assume there are no blockers.

So far we only run runner in staging, so hard-coding it for now should be fine.

The function will print all of the issues it found, so I want to run the query at the start of the runner, even though we don't use the result.

1 new commit added

  • Tags to search blokcing issues no longer hardcoded.
4 years ago

Nice, I like this.

One note, should we add a blob in the README for the precommit?

I'll merge this as is, we can improve the README in another PR :)

Pull-Request has been merged by pingou

4 years ago