From 2cbbc898b2772d839c197352781a05e89e255b09 Mon Sep 17 00:00:00 2001 From: Ronelle Landy Date: Mon, 1 May 2017 10:07:47 -0400 Subject: [PATCH] Add a variable for the dir where the repo is built Previously, the repo was built in the ansible_user_dir. If multiple jobs are run with this role concurrently, there can be a clash. This review adds a variable (and defaults to the original value) so that users can move the build dir to a job-specific workspace. Change-Id: Idb08b559f2d98c8084a05fcdfe0edb0e5feca441 --- roles/build-test-packages/README.md | 2 + roles/build-test-packages/defaults/main.yml | 2 + .../build-test-packages/tasks/dlrn-build.yml | 18 ++++----- roles/build-test-packages/tasks/main.yml | 38 +++++++++---------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/roles/build-test-packages/README.md b/roles/build-test-packages/README.md index 256723266..f1af58b99 100644 --- a/roles/build-test-packages/README.md +++ b/roles/build-test-packages/README.md @@ -15,6 +15,8 @@ Role Variables -------------- * `local_working_dir` -- the directory where tripleo-quickstart is located +* `build_repo_dir` -- the directory where the DLRN repo is built. + The variable defaults to the home directory of the user. * `artg_dlrn_repo_url` -- the URL of the DLRN repository * `artg_rdoinfo_repo_url` -- the URL of the rdoinfo repository that contains the project definitions for DLRN diff --git a/roles/build-test-packages/defaults/main.yml b/roles/build-test-packages/defaults/main.yml index bd1d7e539..adcaa6722 100644 --- a/roles/build-test-packages/defaults/main.yml +++ b/roles/build-test-packages/defaults/main.yml @@ -1,5 +1,7 @@ --- +build_repo_dir: "{{ ansible_user_dir }}" + artg_dlrn_repo_url: "https://github.com/openstack-packages/DLRN.git" artg_rdoinfo_repo_url: "https://github.com/redhat-openstack/rdoinfo" artg_compressed_gating_repo: "/home/stack/gating_repo.tar.gz" diff --git a/roles/build-test-packages/tasks/dlrn-build.yml b/roles/build-test-packages/tasks/dlrn-build.yml index 7067c43df..12ea51ef0 100644 --- a/roles/build-test-packages/tasks/dlrn-build.yml +++ b/roles/build-test-packages/tasks/dlrn-build.yml @@ -14,7 +14,7 @@ - name: Override projects.ini settings lineinfile: - dest: '{{ ansible_user_dir }}/DLRN/projects.ini' + dest: '{{ build_repo_dir }}/DLRN/projects.ini' regexp: '{{ project_item.regexp }}' line: '{{ project_item.line }}' with_items: @@ -27,26 +27,26 @@ - name: Fetch local rdoinfo copy git: repo: '{{ artg_rdoinfo_repo_url }}' - dest: '{{ ansible_user_dir }}/DLRN/rdoinfo' + dest: '{{ build_repo_dir }}/DLRN/rdoinfo' version: 'master' - name: Map project name to DLRN project name register: project_name_mapped shell: > - source {{ ansible_user_dir }}/dlrn-venv/bin/activate; + source {{ build_repo_dir }}/dlrn-venv/bin/activate; export PROJECT_NAME=$(echo {{ artg_change.project }} | sed "s|openstack/||"); rdopkg findpkg $PROJECT_NAME -l rdoinfo | grep ^name | awk '{print $2}' args: - chdir: '{{ ansible_user_dir }}/DLRN' + chdir: '{{ build_repo_dir }}/DLRN' failed_when: project_name_mapped.stdout == '' - name: Create data directory if doesn't exist yet - file: path="{{ ansible_user_dir }}/DLRN/data/" state=directory + file: path="{{ build_repo_dir }}/DLRN/data/" state=directory - name: Copy from ready directories if configured command: > cp -raf {{ artg_repos_dir }}/{{ artg_change.project|regex_replace('openstack[^/]*/', '') }} - {{ ansible_user_dir }}/DLRN/data/{{ project_name_mapped.stdout }} + {{ build_repo_dir }}/DLRN/data/{{ project_name_mapped.stdout }} ignore_errors: true register: copy_dir when: artg_repos_dir is defined @@ -54,7 +54,7 @@ - name: Clone the gated change git: repo: '{{ artg_change.host }}/{{ artg_change.project }}' - dest: '{{ ansible_user_dir }}/DLRN/data/{{ project_name_mapped.stdout }}' + dest: '{{ build_repo_dir }}/DLRN/data/{{ project_name_mapped.stdout }}' refspec: '{{ artg_change.refspec }}' version: 'FETCH_HEAD' when: artg_repos_dir is not defined or copy_dir|failed @@ -62,7 +62,7 @@ - name: Run DLRN shell: > set +e; - source {{ ansible_user_dir }}/dlrn-venv/bin/activate; + source {{ build_repo_dir }}/dlrn-venv/bin/activate; while true; do dlrn --config-file projects.ini --head-only --package-name {{ project_name_mapped.stdout }} --local --info-repo rdoinfo --dev; if [ $? -eq 0 ]; then @@ -79,5 +79,5 @@ exit $?; done; args: - chdir: '{{ ansible_user_dir }}/DLRN' + chdir: '{{ build_repo_dir }}/DLRN' register: repo_built diff --git a/roles/build-test-packages/tasks/main.yml b/roles/build-test-packages/tasks/main.yml index 634b531bc..ee0e8e868 100644 --- a/roles/build-test-packages/tasks/main.yml +++ b/roles/build-test-packages/tasks/main.yml @@ -25,24 +25,24 @@ groups: mock - name: Create virtualenv for DLRN - command: virtualenv {{ ansible_user_dir }}/dlrn-venv + command: virtualenv {{ build_repo_dir }}/dlrn-venv args: - creates: '{{ ansible_user_dir }}/dlrn-venv' + creates: '{{ build_repo_dir }}/dlrn-venv' - name: Check if DLRN was already cloned by other means - stat: path='{{ ansible_user_dir }}/DLRN' + stat: path='{{ build_repo_dir }}/DLRN' register: dlrn_cloned - name: Remove data files from previous runs file: - path: '{{ ansible_user_dir }}/DLRN/data' + path: '{{ build_repo_dir }}/DLRN/data' state: absent when: dlrn_cloned.stat.exists - name: Clone DLRN git: repo: '{{ artg_dlrn_repo_url }}' - dest: '{{ ansible_user_dir }}/DLRN' + dest: '{{ build_repo_dir }}/DLRN' version: master when: not dlrn_cloned.stat.exists @@ -51,22 +51,22 @@ - name: Remove DLRN RPM install test shell: > sed -i -e 's%--postinstall%%' - {{ ansible_user_dir }}/DLRN/scripts/build_rpm.sh + {{ build_repo_dir }}/DLRN/scripts/build_rpm.sh - name: Update pip before requirements install - shell: source {{ ansible_user_dir }}/dlrn-venv/bin/activate && pip install -U pip + shell: source {{ build_repo_dir }}/dlrn-venv/bin/activate && pip install -U pip - name: Install DLRN requirements pip: - requirements: '{{ ansible_user_dir }}/DLRN/requirements.txt' - virtualenv: '{{ ansible_user_dir }}/dlrn-venv' + requirements: '{{ build_repo_dir }}/DLRN/requirements.txt' + virtualenv: '{{ build_repo_dir }}/dlrn-venv' - name: Install DLRN shell: > - source {{ ansible_user_dir }}/dlrn-venv/bin/activate; + source {{ build_repo_dir }}/dlrn-venv/bin/activate; python setup.py install; args: - chdir: '{{ ansible_user_dir }}/DLRN' + chdir: '{{ build_repo_dir }}/DLRN' - name: get env variables for changes and default change list set_fact: @@ -105,23 +105,23 @@ - block: - name: Create a directory to hold the rpms file: - path: '{{ ansible_user_dir }}/gating_repo' + path: '{{ build_repo_dir }}/gating_repo' state: directory - name: Copy the generated rpms shell: > - rm -rf {{ ansible_user_dir }}/gating_repo/*; - find {{ ansible_user_dir }}/DLRN/data/repos -type f -name '*.rpm' -print0 | xargs -0 cp -t {{ ansible_user_dir }}/gating_repo; + rm -rf {{ build_repo_dir }}/gating_repo/*; + find {{ build_repo_dir }}/DLRN/data/repos -type f -name '*.rpm' -print0 | xargs -0 cp -t {{ build_repo_dir }}/gating_repo; - name: Run createrepo on generated rpms shell: 'createrepo gating_repo' args: - chdir: '{{ ansible_user_dir }}' + chdir: '{{ build_repo_dir }}' - name: Compress the repo shell: 'tar czf {{ artg_compressed_gating_repo }} gating_repo' args: - chdir: '{{ ansible_user_dir }}' + chdir: '{{ build_repo_dir }}' when: repo_built is defined - name: Clean up @@ -129,13 +129,13 @@ path: '{{ item }}' state: absent with_items: - - '{{ ansible_user_dir }}/dlrn-venv' - - '{{ ansible_user_dir }}/gating_repo' + - '{{ build_repo_dir }}/dlrn-venv' + - '{{ build_repo_dir }}/gating_repo' when: dlrn_cleanup|bool - name: Clean up DLRN if it was cloned by the playbook file: - path: '{{ ansible_user_dir }}/DLRN' + path: '{{ build_repo_dir }}/DLRN' state: absent when: - not dlrn_cloned.stat.exists