Make test-prepare-workspace-git role

This is a copy of prepare-workspace-git except that it imports
test-mirror-workspace-git-repos.  This is for base job testing.

Change-Id: I4ef3e4376c9e958761c165836c4fb546157e237a
This commit is contained in:
James E. Blair 2022-05-19 11:11:02 -07:00
parent 423a7d6044
commit 0c980bbcb7
4 changed files with 83 additions and 0 deletions

View File

@ -4,3 +4,4 @@ Deprecated and Test Roles
.. zuul:autorole:: fetch-zuul-cloner .. zuul:autorole:: fetch-zuul-cloner
.. zuul:autorole:: test-mirror-workspace-git-repos .. zuul:autorole:: test-mirror-workspace-git-repos
.. zuul:autorole:: test-upload-logs-swift .. zuul:autorole:: test-upload-logs-swift
.. zuul:autorole:: test-prepare-workspace-git

View File

@ -0,0 +1,17 @@
Mirror the local git repos to remote nodes
This role uses git operations (unlike :zuul:role:`prepare-workspace`
which uses rsync) to mirror the locally prepared git repos to the remote
nodes while taking advantage of cached repos on the node if they exist.
This role works generically regardless of the existence of a cached
repo on the node.
The cached repos need to be placed using the canonical name under the
`cached_repos_root` directory.
**Role Variables**
.. zuul:rolevar:: cached_repos_root
:default: /opt/git
The root of the cached repos.

View File

@ -0,0 +1 @@
cached_repos_root: /opt/git

View File

@ -0,0 +1,64 @@
- name: Find locally cached git repos
stat:
path: "{{ cached_repos_root }}/{{ zj_project.canonical_name }}"
with_items: "{{ zuul.projects.values() | list }}"
loop_control:
loop_var: zj_project
register: cached_repos
# We do a bare clone here first so that we skip creating a working copy that
# will be overwritten later anyway.
- name: Clone cached repo to workspace
shell: |
set -e
git clone --bare {{ cached_repos_root }}/{{ zj_project.0.canonical_name }} {{ ansible_user_dir }}/{{ zj_project.0.src_dir }}/.git
cd {{ ansible_user_dir }}/{{ zj_project.0.src_dir }}
git config --local --bool core.bare false
args:
creates: "{{ ansible_user_dir }}/{{ zj_project.0.src_dir }}"
when: zj_project.1.stat.exists
with_together:
- "{{ zuul.projects.values() | list }}"
- "{{ cached_repos.results }}"
loop_control:
loop_var: zj_project
# ANSIBLE0006: If we use the git module, we get warning
# ANSIBLE0004 since we do not give an explicit version
tags:
- skip_ansible_lint
- name: Initialize non-cached repos
command: "git init {{ ansible_user_dir }}/{{ zj_project.0.src_dir }}"
args:
creates: "{{ ansible_user_dir }}/{{ zj_project.0.src_dir }}"
when: not zj_project.1.stat.exists
with_together:
- "{{ zuul.projects.values() | list }}"
- "{{ cached_repos.results }}"
loop_control:
loop_var: zj_project
# ANSIBLE0006: If we use the git module, we get warning
# ANSIBLE0004 since we do not give an explicit version
tags:
- skip_ansible_lint
- name: Remove origin from local git repos and replace it by the zuul fake origin
# To be idempotent, remove origin only if it's found in the local list.
shell: |
set -e
git remote -v | grep origin && git remote rm origin || true
git remote add origin file:///dev/null
args:
chdir: "{{ ansible_user_dir }}/{{ zj_project.src_dir }}"
with_items: "{{ zuul.projects.values() | list }}"
loop_control:
loop_var: zj_project
# ANSIBLE0006: git remote is not supported by ansible module
tags:
- skip_ansible_lint
# TODO(tobiash): we might want to deprecate the role mirror-workspace-git-repos
# and move it here.
- name: Synchronize repos
import_role:
name: test-mirror-workspace-git-repos