From 4fe91e20fafd897e966e3dd65feecf48c4fb9a81 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 6 Nov 2024 08:08:35 -0800 Subject: [PATCH] Update requirements-check job to run on arbitrary targets Update the requirements-check job to run on repos other than the zuul.project, but keep that as the default. Add the job as a check and gate job to this repo, but targeting nova. This allows us to run the job on changes to its definition. Change-Id: I67b818cdff01d29c62497826d4b4e3387c74e9e9 Depends-On: https://review.opendev.org/c/openstack/requirements/+/934249 --- .zuul.d/project-template.yaml | 27 +++++++++++++++++++++ .zuul.d/project.yaml | 2 ++ playbooks/requirements-check.yaml | 18 +++----------- roles/check-requirements/README.rst | 13 ++++++++++ roles/check-requirements/defaults/main.yaml | 2 ++ roles/check-requirements/tasks/main.yaml | 9 +++++++ 6 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 roles/check-requirements/README.rst create mode 100644 roles/check-requirements/defaults/main.yaml create mode 100644 roles/check-requirements/tasks/main.yaml diff --git a/.zuul.d/project-template.yaml b/.zuul.d/project-template.yaml index 018afc9357..6aa6b60068 100644 --- a/.zuul.d/project-template.yaml +++ b/.zuul.d/project-template.yaml @@ -10,6 +10,21 @@ - job: name: requirements-check parent: unittests + description: | + Check that requirements in the target repo match OpenStack + global requirements. + + **Job Variables** + + .. zuul:jobvar:: zuul_work_dir + :default: {{ zuul.project.src_dir }} + + Directory holding the project to check. + + .. zuul:jobvar:: zuul_branch + :default: {{ zuul.branch }} + + Branch to check. # NOTE(gmann): Update the nodeset if we move testing to the new version # of ubuntu. We are explicitly setting the nodeset here because the base # job (unittests) moving to the ubuntu latest version can break this @@ -28,3 +43,15 @@ - ^doc/requirements.txt$ - playbooks/requirements-check.yaml - ^lower-constraints.txt$ + +- job: + name: requirements-check-self + description: | + Run the requirements-check job on another repo in order to + self-test changes to its job configuration. + parent: requirements-check + # This could be any project, nova is chosen arbitrarily. + required-projects: openstack/nova + vars: + zuul_work_dir: "{{ zuul.projects['opendev.org/openstack/nova'].src_dir }}" + zuul_branch: "master" diff --git a/.zuul.d/project.yaml b/.zuul.d/project.yaml index b566fa8a0d..e5d63fe636 100644 --- a/.zuul.d/project.yaml +++ b/.zuul.d/project.yaml @@ -13,6 +13,7 @@ files: - bindep.txt - openstack-tox-validate + - requirements-check-self - requirements-tox-babel - requirements-tox-bindep: voting: false @@ -79,6 +80,7 @@ files: - bindep.txt - openstack-tox-validate + - requirements-check-self - requirements-tox-babel - requirements-tox-py39-check-uc - requirements-tox-py310-check-uc diff --git a/playbooks/requirements-check.yaml b/playbooks/requirements-check.yaml index e12491b816..d4fd2b06a9 100644 --- a/playbooks/requirements-check.yaml +++ b/playbooks/requirements-check.yaml @@ -1,16 +1,4 @@ - hosts: all - pre_tasks: - - name: Ensure pip - include_role: - name: ensure-pip - - tasks: - - name: Install openstack_requirements - command: "pip3 install --user {{ zuul.projects['opendev.org/openstack/requirements'].src_dir }}" - - - name: Run requirements check script - # Use command module here instead of script since Zuul gets output - # with command into job-output.txt file. - # Command expects the file to be at the remote system - the system - # running the tests. Ask zuul variables for the path. - command: "{{ zuul.projects['opendev.org/openstack/requirements'].src_dir }}/playbooks/files/project-requirements-change.py {{ zuul.project.src_dir }} {{ zuul.branch }}" + roles: + - ensure-pip + - check-requirements diff --git a/roles/check-requirements/README.rst b/roles/check-requirements/README.rst new file mode 100644 index 0000000000..985532a692 --- /dev/null +++ b/roles/check-requirements/README.rst @@ -0,0 +1,13 @@ +Check that a project's requirements match the global requirements repo. + +**Role Variables** + +.. zuul:rolevar:: zuul_work_dir + :default: {{ zuul.project.src_dir }} + + Directory holding the project to check. + +.. zuul:rolevar:: zuul_branch + :default: {{ zuul.branch }} + + Branch to check. diff --git a/roles/check-requirements/defaults/main.yaml b/roles/check-requirements/defaults/main.yaml new file mode 100644 index 0000000000..3657c3e3e4 --- /dev/null +++ b/roles/check-requirements/defaults/main.yaml @@ -0,0 +1,2 @@ +zuul_work_dir: "{{ zuul.project.src_dir }}" +zuul_branch: "{{ zuul.branch }}" diff --git a/roles/check-requirements/tasks/main.yaml b/roles/check-requirements/tasks/main.yaml new file mode 100644 index 0000000000..b973902c60 --- /dev/null +++ b/roles/check-requirements/tasks/main.yaml @@ -0,0 +1,9 @@ +- name: Install openstack_requirements + command: "pip3 install --user {{ zuul.projects['opendev.org/openstack/requirements'].src_dir }}" + +- name: Run requirements check script + # Use command module here instead of script since Zuul gets output + # with command into job-output.txt file. + # Command expects the file to be at the remote system - the system + # running the tests. Ask zuul variables for the path. + command: "{{ zuul.projects['opendev.org/openstack/requirements'].src_dir }}/playbooks/files/project-requirements-change.py {{ zuul_work_dir }} {{ zuul_branch }}"