openstack-ansible-tests/get-ansible-role-requirements.yml
Jesse Pretorius 0fa83f7d3d Do not clone role being tested as a dep outside openstack-ci
When executing the clones outside of openstack-ci, we should
verify that we're not cloning the role repository for the role
we are testing because we already have it.

Change-Id: Ibc64fc5c97f0b711934eb3e297159b0d38587647
2018-04-30 17:47:13 +01:00

140 lines
5.6 KiB
YAML

---
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Note(odyssey4me):
# This uses a local connection for the lint test which
# never sets up host keys and therefore cannot connect
# to localhost as a remote host.
#
- name: Clone the role ansible-role-requirements
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Set name for role under testing
set_fact:
role_name: "{{ lookup('env', 'ROLE_NAME') | default('') }}"
- name: Remove target role directories if they are not git repositories
shell: |
EXIT_CODE=0
{% for role in osa_roles %}
{% if role['scm'] == "git" or role['scm'] is undefined %}
ROLE_REPO_PATH="{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}/{{ role['name'] | default(role['src'] | basename) }}"
if [[ -e ${ROLE_REPO_PATH} ]] && [[ ! -d "${ROLE_REPO_PATH}/.git" ]]; then
echo "${ROLE_REPO_PATH} is not a git repo, deleting..."
rm -rf "${ROLE_REPO_PATH}"
EXIT_CODE=2
fi
{% endif %}
{% endfor %}
exit ${EXIT_CODE}
args:
executable: /bin/bash
register: existing_dir_cleanup
changed_when: existing_dir_cleanup.rc == 2
failed_when: existing_dir_cleanup.rc not in [0,2]
- name: Create the ansible role directory
file:
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}"
state: directory
- name: Check whether we are in openstack-ci
stat:
path: /etc/ci/mirror_info.sh
register: _openstack_ci
- name: Clone git repos (outside openstack-ci)
when: not _openstack_ci.stat.exists
block:
- name: Clone git repos
git:
repo: "{{ item['src'] }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}/{{ item['name'] | default(item['src'] | basename) }}"
version: "{{ item['version'] | default('master') }}"
depth: "{{ item['depth'] | default('10') }}"
update: true
force: true
with_items: "{{ osa_roles }}"
retries: "{{ git_clone_retries | default(3) }}"
delay: "{{ git_clone_retry_delay | default(5) }}"
when:
- item['scm'] == "git" or item['scm'] is undefined
- role_name == '' or item['name'] != role_name
- name: Clone git repos (inside openstack-ci)
when: _openstack_ci.stat.exists
block:
- name: Find repositories already cloned by zuul
command: "find {{ zuul_git_src_dir }} -type d -maxdepth 2"
register: zuul_src_folder
- name: Simplify the given src repository list
set_fact:
zuul_src_repo_list: >
{%- set filtered_repo_list = [] %}
{%- for folder_path in zuul_src_folder['stdout_lines'] %}
{%- if folder_path | match("^" ~ zuul_git_src_dir ~ "/openstack/(openstack-ansible-|ansible-role-){1}(?!tests).*") %}
{%- set repo_cleaned = folder_path | regex_replace('^' ~ zuul_git_src_dir ~ '/', '') %}
{%- set _ = filtered_repo_list.append(repo_cleaned) %}
{%- endif %}
{%- endfor %}
{{- filtered_repo_list -}}
- name: Prepare git clone list
set_fact:
git_roles: >
{%- set filtered_role_list = [] %}
{%- for role in osa_roles %}
{%- if (role['name'] | match('os_previous_.*')) or
(role['name'] | match('previous_.*')) or
(role['src'] | regex_replace('https://git.openstack.org/', '') not in zuul_src_repo_list) %}
{%- set _ = filtered_role_list.append(role) %}
{%- endif %}
{%- endfor %}
{{- filtered_role_list -}}
- name: Link the zuul provided roles
file:
src: "{{ zuul_git_src_dir }}/{{ item }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}/{{ item | regex_replace('openstack/(openstack-ansible-|ansible-role-)', '') }}"
state: link
force: yes
with_items: "{{ zuul_src_repo_list }}"
# Do not link the role we are testing
when: role_name == '' or not item | search(role_name)
- name: Clone the remaining git repos
git:
repo: "{{ item['src'] }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}/{{ item['name'] | default(item['src'] | basename) }}"
version: "{{ item['version'] | default('master') }}"
depth: "{{ item['depth'] | default('10') }}"
update: true
force: true
with_items: "{{ git_roles }}"
retries: "{{ git_clone_retries | default(3) }}"
delay: "{{ git_clone_retry_delay | default(5) }}"
when:
- item['scm'] == "git" or item['scm'] is undefined
vars:
homedir: "{{ lookup('env', 'TESTING_HOME') }}"
role_file: "{{ lookup('env', 'ANSIBLE_ROLE_REQUIREMENTS_PATH') }}"
osa_roles: "{{ lookup('file', role_file) | from_yaml }}"
zuul_git_src_dir: "/home/zuul/src/git.openstack.org"