From 47eddb946b1c0c1b058527267034bca373c5ae77 Mon Sep 17 00:00:00 2001 From: Logan V Date: Thu, 12 Jul 2018 10:08:35 -0500 Subject: [PATCH] Use ZUUL_SRC_PATH to pass the path to Zuul git sources To make get-ansible-role-requirements usable for 3rd party Zuul based CI, which may have test nodes that do not conform to the previously hard-coded /home/zuul home path for Zuul workers, we need to make this Zuul sources path dynamic based on the home directory of the Zuul worker user. However, we cannot rely on {{ ansible_user_dir }} inside get-ansible-role-requirements.yml, since it uses become: yes. This means ansible_user_dir will be /root, rather than the Zuul user's home directory. The solution is to pass the ZUUL_SRC_PATH that Zuul is operating with into the OSA test job environment, and use this environment var inside our role cloning playbook to locate the Zuul sources. Change-Id: Id71c6502741285e7b83d40be8006e82c9960b7ff --- scripts/get-ansible-role-requirements.yml | 12 +++++++++--- zuul.d/playbooks/run.yml | 10 +++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/get-ansible-role-requirements.yml b/scripts/get-ansible-role-requirements.yml index 3c11c767c6..220af12bbc 100644 --- a/scripts/get-ansible-role-requirements.yml +++ b/scripts/get-ansible-role-requirements.yml @@ -36,16 +36,22 @@ - name: Use Zuul provided sources in Zuul environment block: + - name: Set Zuul sources path + set_fact: + zuul_src_path: "{{ lookup('env', 'ZUUL_SRC_PATH') }}" - name: Check the Zuul src dir for cloned roles stat: - path: "/home/zuul/src/{{ item.src.split('/')[-3:] | join('/') }}" + path: "{{ zuul_src_path }}/{{ item.src.split('/')[-3:] | join('/') }}" + get_attributes: no + get_checksum: no + get_mime: no register: zuul_roles when: - item.scm == "git" or item.scm is undefined with_items: "{{ required_roles }}" - name: Link the Zuul provided roles file: - src: "/home/zuul/src/{{ item.item.src.split('/')[-3:] | join('/') }}" + src: "{{ zuul_src_path }}/{{ item.item.src.split('/')[-3:] | join('/') }}" dest: "{{ item.item.path | default(role_path_default) }}/{{ item.item.name | default(item.item.src | basename) }}" state: link owner: root @@ -54,7 +60,7 @@ | selectattr('stat.exists') | list }}" when: - - "lookup('env', 'ZUUL_PROJECT') != ''" + - "lookup('env', 'ZUUL_SRC_PATH') != ''" - name: Clone git repos (with git) git: diff --git a/zuul.d/playbooks/run.yml b/zuul.d/playbooks/run.yml index 169f83f8f4..2a69cdc6db 100644 --- a/zuul.d/playbooks/run.yml +++ b/zuul.d/playbooks/run.yml @@ -1,5 +1,9 @@ - hosts: all tasks: + - name: Set the Zuul sources path + set_fact: + zuul_src_path: "{{ ansible_user_dir }}/src" + - name: Set current test repo (cross-repo) set_fact: current_test_repo: "git.openstack.org/{{ osa_test_repo }}" @@ -19,7 +23,7 @@ args: chdir: "src/{{ current_test_repo }}" environment: - # ZUUL_PROJECT is used by tests/get-ansible-role-requirements to - # determine when CI provided repos should be used. - ZUUL_PROJECT: "{{ zuul.project.short_name }}" + # ZUUL_SRC_PATH is used by tests/get-ansible-role-requirements to + # where the CI provided git sources were cloned. + ZUUL_SRC_PATH: "{{ zuul_src_path }}" ANSIBLE_PACKAGE: "{{ ansible_package | default('') }}"