#155 Fix to match requirements of STI spec (tests/tests*.yml)
Merged 2 years ago by zuul. Opened 2 years ago by fbo.
fbo/fedora-zuul-jobs-config sti-spec-fix  into  master

@@ -1,18 +1,20 @@ 

  ---

  - hosts: localhost

    tasks:

-     - name: Check for tests/tests.yml exists

-       stat:

-         path: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/tests.yml"

+     - name: Check for tests/tests*.yml exists

+       shell: "ls tests/tests*.yml"

+       failed_when: false

        register: tests_stat

+       args:

+         chdir: "{{ zuul.project.src_dir }}"

      - zuul_return:

          data:

            zuul:

              child_jobs:

                - rpm-sti-test

-       when: tests_stat.stat.exists

+       when: tests_stat.rc == 0

      - zuul_return:

          data:

            zuul:

              child_jobs: []

-       when: not tests_stat.stat.exists

+       when: not tests_stat.rc == 0

@@ -1,18 +1,20 @@ 

  ---

  - hosts: localhost

    tasks:

-     - name: Check for tests/tests.yml exists

-       stat:

-         path: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/tests.yml"

+     - name: Check for tests/tests*.yml exists

+       shell: "ls tests/tests*.yml"

+       failed_when: false

        register: tests_stat

+       args:

+         chdir: "{{ zuul.project.src_dir }}"

      - zuul_return:

          data:

            zuul:

              child_jobs:

                - rpm-test

-       when: tests_stat.stat.exists

+       when: tests_stat.rc == 0

      - zuul_return:

          data:

            zuul:

              child_jobs: []

-       when: not tests_stat.stat.exists

+       when: not tests_stat.rc == 0

This patch fixes an issue where only tests/tests.yml was checked
for embeded STI tests.

This also removes the useless usage of ansible_user_dir.

Build succeeded.

The * is expanded by shell, so using find gives no added benefit. The same result is returned with ls or stat.

Should this check the exit code rather than output?

Either way, the code looks like it'll work, but I don't know how to verify.

We are in a Zuul config repository so unfortunately this cannot be tested speculatively with "Depends-on". I did a test locally by running the play with ansible-playbook and an inventory file to set zuul.project.src_dir var and replacing the zuul_return module with debug module. This shows that it seems to behave as expected.

So IMO, let's merge and see if we get any trouble. Is that fine for you ?

Just saw you inline comment. Ok, wait I'll see to address them.

1 new commit added

  • Remove useless use of find and rely on return code
2 years ago

Build succeeded.

Looks correct. Not sure what failed_when does.

https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html#ignoring-failed-commands

Here we do not want the Task to be considered a failure as the normal behavior of Ansible will be to stop the play execution.

I'm merging this. I keep the related issue open until we are confident that the fix behave as expected.

Metadata Update from @fbo:
- Pull-request tagged with: gateit

2 years ago

Build succeeded (gate pipeline).

Pull-Request has been merged by zuul

2 years ago