Improve lint test flexibility

Currently the ansible-syntax and ansible-lint tests
assume the playbook to be tested against, the role
requirements file location and a single path for all
roles. This patch allows these to be modified so that
the tests can be used for the integrated repo which
does not have the same structure as the roles.

Various lint failures are no being picked up with
these modifications, so they're resolved using quick
hacks.

Change-Id: I8bea90082dbde7de49c5e2e86d298c017b16591d
This commit is contained in:
Jesse Pretorius 2017-11-15 19:09:35 +00:00 committed by Jesse Pretorius (odyssey4me)
parent f69d088d1d
commit d861c3902d
6 changed files with 30 additions and 6 deletions

View File

@ -225,6 +225,7 @@
- zuul_version == "3"
vars:
role_file: "{{ toxinidir }}/tests/ansible-role-requirements.yml"
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"

View File

@ -33,13 +33,14 @@ export TESTING_HOME=${TESTING_HOME:-$HOME}
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
export ROLE_NAME=${ROLE_NAME:-''}
export ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY:-$WORKING_DIR/tests/inventory}
export ANSIBLE_ROLE_REQUIREMENTS_PATH=${ANSIBLE_ROLE_REQUIREMENTS_PATH:-$WORKING_DIR/tests/ansible-role-requirements.yml}
export ANSIBLE_EXTRA_ROLE_DIRS=${ANSIBLE_EXTRA_ROLE_DIRS:-''}
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_REQUIREMENTS_PATH="${WORKING_DIR}/tests/ansible-role-requirements.yml"
export COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
export OSA_OPS_DIR="${WORKING_DIR}/openstack-ansible-ops"
@ -155,7 +156,6 @@ fi
if [ ! -d "${ANSIBLE_ROLE_DIR}" ] && [ -f "${ANSIBLE_ROLE_REQUIREMENTS_PATH}" ]; then
ansible-playbook -i ${ANSIBLE_INVENTORY} \
${COMMON_TESTS_PATH}/get-ansible-role-requirements.yml \
-e "toxinidir=${WORKING_DIR} homedir=${TESTING_HOME}" \
-v
fi
@ -183,3 +183,11 @@ if [ ! -f "${ANSIBLE_CFG_PATH}" ]; then
else
echo "Found ${ANSIBLE_CFG_PATH} so there's nothing more to do."
fi
# Adjust the Ansible configuration file to include the extra
# 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}"
fi
fi

View File

@ -30,6 +30,7 @@ set -e
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
export COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
export TEST_PLAYBOOK=${TEST_PLAYBOOK:-$WORKING_DIR/tests/test.yml}
## Main ----------------------------------------------------------------------
@ -37,4 +38,4 @@ export COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
source "${COMMON_TESTS_PATH}/test-ansible-env-prep.sh"
# Execute ansible-lint
ansible-lint ${WORKING_DIR} -R -r ${WORKING_DIR}/ansible-lint/
ansible-lint -R -r ${COMMON_TESTS_PATH}/ansible-lint/ ${TEST_PLAYBOOK}

View File

@ -31,6 +31,7 @@ set -e
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
export COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
export ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY:-$WORKING_DIR/tests/inventory}
export TEST_PLAYBOOK=${TEST_PLAYBOOK:-$WORKING_DIR/tests/test.yml}
## Main ----------------------------------------------------------------------
@ -40,4 +41,4 @@ source "${COMMON_TESTS_PATH}/test-ansible-env-prep.sh"
# Execute the Ansible syntax check
ansible-playbook --syntax-check \
--list-tasks \
${WORKING_DIR}/tests/test.yml
${TEST_PLAYBOOK}

View File

@ -76,5 +76,7 @@
command: "/openstack/venvs/keystone-{{ keystone_venv_tag }}/bin/keystone-manage db_sync --contract"
become: yes
become_user: keystone
tags:
- skip_ansible_lint
vars_files:
- test-vars.yml

View File

@ -22,7 +22,10 @@
- include: "common-tasks/test-set-nodepool-vars.yml"
- name: Clear iptables rules
shell: "{{ playbook_dir }}/iptables-clear.sh"
- set_fact:
tags:
- skip_ansible_lint
- name: Set ssh key fact
set_fact:
lxc_container_ssh_key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}"
- name: Ensure roots new public ssh key is in authorized_keys
authorized_key:
@ -192,15 +195,23 @@
- name: Determine iptables path
shell: which iptables
register: _iptables_path
tags:
- skip_ansible_lint
- name: Add iptables rule to ensure traffic checksum is correct
command: "{{ _iptables_path.stdout }} -A POSTROUTING -t mangle -p tcp -j CHECKSUM --checksum-fill"
tags:
- skip_ansible_lint
- name: Add iptables rule to provide internet connectivity to instances
command: "{{ _iptables_path.stdout }} -t nat -A POSTROUTING -o eth0 -j MASQUERADE"
tags:
- skip_ansible_lint
- name: Add iptables rules for lxc natting
command: /usr/local/bin/lxc-system-manage iptables-create
tags:
- skip_ansible_lint
vars_files:
- test-vars.yml