summaryrefslogtreecommitdiffstats
path: root/xci/files/install-lib.sh
diff options
context:
space:
mode:
authorMarkos Chandras <mchandras@suse.de>2018-03-26 11:34:33 +0100
committerMarkos Chandras <mchandras@suse.de>2018-03-26 20:47:18 +0100
commitc36c6b152290c6fc671355253d61fac0ad8b44b3 (patch)
treec46df4bd3bdc3af7091e73b6f4111fe7120c8af0 /xci/files/install-lib.sh
parent9e1d3d6e62abf5d0da26a296bcd235f37a54d9c6 (diff)
xci: Check XCI playbooks using ansible-lint
The ansible-lint tool can help with maintaining consistency across all the XCI playbooks, so lets introduce it early in the process to capture common mistakes before the actual XCI deployment is executed. This however needs to run after all the scenarios repositories have been cloned and configured. Change-Id: I28104429e3ac0cdbc48a003b163f4fb8c3acd8a7 Link: https://github.com/willthames/ansible-lint Signed-off-by: Markos Chandras <mchandras@suse.de>
Diffstat (limited to 'xci/files/install-lib.sh')
-rw-r--r--xci/files/install-lib.sh40
1 files changed, 39 insertions, 1 deletions
diff --git a/xci/files/install-lib.sh b/xci/files/install-lib.sh
index 48233968..92d1f065 100644
--- a/xci/files/install-lib.sh
+++ b/xci/files/install-lib.sh
@@ -135,12 +135,50 @@ function install_ansible() {
set -u
# We are inside the virtualenv now so we should be good to use pip and python from it.
- pip -q install --upgrade -c $uc ara virtualenv pip setuptools ansible==$XCI_ANSIBLE_PIP_VERSION
+ pip -q install --upgrade -c $uc ara virtualenv pip setuptools ansible==$XCI_ANSIBLE_PIP_VERSION ansible-lint==3.4.21
ara_location=$(python -c "import os,ara; print(os.path.dirname(ara.__file__))")
export ANSIBLE_CALLBACK_PLUGINS="/etc/ansible/roles/plugins/callback:${ara_location}/plugins/callbacks"
}
+ansible_lint() {
+ set -eu
+ # Use the upper-constraints file from the pinned requirements repository.
+ local requirements_sha=$(awk '/requirements_git_install_branch:/ {print $2}' ${XCI_PATH}/xci/installer/osa/files/openstack_services.yml)
+ local uc="https://raw.githubusercontent.com/openstack/requirements/${requirements_sha}/upper-constraints.txt"
+ local playbooks_dir=(xci/playbooks xci/installer/osa/playbooks xci/installer/kubespray/playbooks)
+ # Extract role from scenario information
+ local testing_role=$(sed -n "/^- scenario: ${DEPLOY_SCENARIO}/,/^$/p" ${XCI_PATH}/xci/opnfv-scenario-requirements.yml | grep role | rev | cut -d '/' -f -1 | rev)
+
+ # Clone OSA rules too
+ git clone --quiet --depth 1 https://github.com/openstack/openstack-ansible-tests.git \
+ ${XCI_CACHE}/repos/openstack-ansible-tests
+
+ # Because of https://github.com/willthames/ansible-lint/issues/306, ansible-lint does not understand
+ # import and includes yet so we need to trick it with a fake playbook so we can test our roles. We
+ # only test the role for the scenario we are testing
+ echo "Building testing playbook for role: ${testing_role}"
+ cat > ${XCI_PATH}/xci/playbooks/test-playbook.yml << EOF
+ - name: Testing playbook
+ hosts: localhost
+ roles:
+ - ${testing_role}
+EOF
+
+ # Only check our own playbooks
+ for dir in ${playbooks_dir[@]}; do
+ for play in $(ls ${XCI_PATH}/${dir}/*.yml); do
+ echo -en "Checking '${play}' playbook..."
+ ansible-lint --nocolor -R -r \
+ ${XCI_CACHE}/repos/openstack-ansible-tests/ansible-lint ${play}
+ echo -en "[OK]\n"
+ done
+ done
+
+ # Remove testing playbook
+ rm ${XCI_PATH}/xci/playbooks/test-playbook.yml
+}
+
collect_xci_logs() {
echo "----------------------------------"
echo "Info: Collecting XCI logs"