Skip ansible-lint test against roles

In order to decouple changes in the roles repositories from changes
needed in other repositories due to the ansible-lint test, the roles
repositories will skip all dependent roles when executing the lint test.
The roles can be updated in time as patches are submitted to those
repositories. In order to do that, we need to stop symlinking the
role into the same directory where its dependent roles are and place
it to its own directory so we can ignore the dependent roles in
ansible-lint.

Change-Id: I49c01fb63054e45bae5ae45a89cce986579959de
Closes-Bug: #1737310
(cherry picked from commit 4bb840d2de)
This commit is contained in:
Markos Chandras 2017-12-18 10:17:18 +00:00 committed by Jesse Pretorius (odyssey4me)
parent 1b8116b86c
commit 3ed70ba249
4 changed files with 23 additions and 13 deletions

View File

@ -24,12 +24,16 @@
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_DIR') }}/{{ role['name'] | default(role['src'] | basename) }}"
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}"
@ -46,7 +50,7 @@
- name: Create the ansible role directory
file:
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DIR') }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}"
state: directory
- name: Check whether zuul-cloner is installed and provide the path to it
@ -84,7 +88,7 @@
- name: Clone git repos
git:
repo: "{{ item['src'] }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DIR') }}/{{ item['name'] | default(item['src'] | basename) }}"
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
@ -134,7 +138,7 @@
- name: Clone git repos (non openstack)
git:
repo: "{{ item['src'] }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DIR') }}/{{ item['name'] | default(item['src'] | basename) }}"
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
@ -152,7 +156,7 @@
- name: 'openstack/openstack-ansible-tests'
dest: '{{ lookup("env", "WORKING_DIR") }}/tests/common'
- name: 'openstack/openstack-ansible-(?!tests)(.*)'
dest: '{{ lookup("env", "ANSIBLE_ROLE_DIR") }}/\1'
dest: '{{ lookup("env", "ANSIBLE_ROLE_DEP_DIR") }}/\1'
- name: 'openstack/(?!openstack-ansible)(.*)'
dest: '{{ homedir }}/git/openstack/\1'
dest: "{{ homedir }}/.ansible/clonemap.yml"
@ -203,15 +207,17 @@
- name: Link the zuul provided roles
file:
src: "{{ zuul_git_src_dir }}/{{ item }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DIR') }}/{{ item | regex_replace('openstack/openstack-ansible-', '') }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}/{{ item | regex_replace('openstack/openstack-ansible-', '') }}"
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_DIR') }}/{{ item['name'] | default(item['src'] | basename) }}"
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

View File

@ -40,7 +40,8 @@ export ANSIBLE_CFG_PATH="${TESTING_HOME}/.ansible.cfg"
export ANSIBLE_LOG_DIR="${TESTING_HOME}/.ansible/logs"
export ANSIBLE_NOCOLOR=1
export ANSIBLE_PLUGIN_DIR="${TESTING_HOME}/.ansible/plugins"
export ANSIBLE_ROLE_DIR="${TESTING_HOME}/.ansible/roles"
export ANSIBLE_ROLE_DEP_DIR="${TESTING_HOME}/.ansible/roles"
export ANSIBLE_ROLE_DIR="${TESTING_HOME}/.ansible/testing-role"
export COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
export OSA_OPS_DIR="${WORKING_DIR}/openstack-ansible-ops"
@ -153,7 +154,7 @@ fi
# Download the Ansible role repositories if they are not present on the host.
# This is ignored if there is no ansible-role-requirements file.
if [ ! -d "${ANSIBLE_ROLE_DIR}" ] && [ -f "${ANSIBLE_ROLE_REQUIREMENTS_PATH}" ]; then
if [ ! -d "${ANSIBLE_ROLE_DEP_DIR}" ] && [ -f "${ANSIBLE_ROLE_REQUIREMENTS_PATH}" ]; then
ansible-playbook -i ${ANSIBLE_INVENTORY} \
${COMMON_TESTS_PATH}/get-ansible-role-requirements.yml \
-v
@ -188,6 +189,6 @@ fi
# role paths if any are provided and they're not already set.
if [ ! -z "${ANSIBLE_EXTRA_ROLE_DIRS}" ]; then
if ! grep -q "roles_path.*${ANSIBLE_EXTRA_ROLE_DIRS}" "${ANSIBLE_CFG_PATH}"; then
sed -i "s|HOME/.ansible/roles.*|HOME/.ansible/roles:${ANSIBLE_EXTRA_ROLE_DIRS}|" "${ANSIBLE_CFG_PATH}"
sed -i "s|HOME/.ansible/roles.*|HOME/.ansible/roles:${ANSIBLE_ROLE_DIR}:${ANSIBLE_EXTRA_ROLE_DIRS}|" "${ANSIBLE_CFG_PATH}"
fi
fi

View File

@ -41,5 +41,8 @@ echo "ANSIBLE_LINT_PARAMS: ${ANSIBLE_LINT_PARAMS}"
# Ensure that the Ansible environment is properly prepared
source "${COMMON_TESTS_PATH}/test-ansible-env-prep.sh"
# Execute ansible-lint
ansible-lint ${ANSIBLE_LINT_PARAMS} -R -r ${COMMON_TESTS_PATH}/ansible-lint/ ${TEST_PLAYBOOK}
# Execute ansible-lint. We do not want to test dependent roles located
# in $HOME/.ansible/roles since we only care about the role we are currently
# testing.
ansible-lint ${ANSIBLE_LINT_PARAMS} --exclude=$HOME/.ansible/roles \
-R -r ${COMMON_TESTS_PATH}/ansible-lint/ ${TEST_PLAYBOOK}

View File

@ -26,4 +26,4 @@ host_key_checking = False
control_path = /tmp/%%h-%%r
ssh_args = -o ControlMaster=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=64 -o ServerAliveCountMax=1024 -o Compression=no -o TCPKeepAlive=yes -o VerifyHostKeyDNS=no -o ForwardX11=no -o ForwardAgent=yes
library = $HOME/.ansible/plugins/library
roles_path = $HOME/.ansible/roles
roles_path = $HOME/.ansible/roles:$HOME/.ansible/testing-role