From d861c3902dbda8323a9fa57c72bae720dfedf005 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Wed, 15 Nov 2017 19:09:35 +0000 Subject: [PATCH] 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 --- get-ansible-role-requirements.yml | 3 ++- test-ansible-env-prep.sh | 12 ++++++++++-- test-ansible-lint.sh | 3 ++- test-ansible-syntax.sh | 3 ++- test-install-keystone.yml | 2 ++ test-prepare-host.yml | 13 ++++++++++++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/get-ansible-role-requirements.yml b/get-ansible-role-requirements.yml index bef26ec9..24e97732 100644 --- a/get-ansible-role-requirements.yml +++ b/get-ansible-role-requirements.yml @@ -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" diff --git a/test-ansible-env-prep.sh b/test-ansible-env-prep.sh index 9105be34..dde6c1c3 100755 --- a/test-ansible-env-prep.sh +++ b/test-ansible-env-prep.sh @@ -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 diff --git a/test-ansible-lint.sh b/test-ansible-lint.sh index a2420457..76ea4569 100755 --- a/test-ansible-lint.sh +++ b/test-ansible-lint.sh @@ -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} diff --git a/test-ansible-syntax.sh b/test-ansible-syntax.sh index d5ed980c..60eaeb15 100755 --- a/test-ansible-syntax.sh +++ b/test-ansible-syntax.sh @@ -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} diff --git a/test-install-keystone.yml b/test-install-keystone.yml index bd034a05..3772c478 100644 --- a/test-install-keystone.yml +++ b/test-install-keystone.yml @@ -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 diff --git a/test-prepare-host.yml b/test-prepare-host.yml index 9a115e6c..b9021a74 100644 --- a/test-prepare-host.yml +++ b/test-prepare-host.yml @@ -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