Implement overcloud sanity checks role

Add a new role "validate-sanity-checks" for making some smoke tests
on an overcloud deployment depending on the services enabled
It makes some basic tests throught the openstack CLI

Change-Id: I81a39b717a74a09c095a95f09a6f330dc08f12ef
This commit is contained in:
Mathieu Bultel 2017-02-06 15:02:08 +01:00 committed by Ronelle Landy
parent 26059822f4
commit 5acdf7a2c4
7 changed files with 246 additions and 0 deletions

View File

@ -0,0 +1,50 @@
Validate-Sanity-Checks
======================
This role provides a script for executing sanity checks on an overcloud
deployment. The role creates basic checks using openstack CLI depending
on the services enabled on the overcloud deployment. These sanity checks
are useful when a full overcloud is not deployed and the overcloud
validation roles cannot be run.
Requirements
------------
This role requires that the overcloud is deployed and the services of interest
are available for testing.
Role Variables
--------------
* `sanity_content_name`: <sanity_test> - The sanity tests to be run in checks
* `sanity_scripts`: <validate-sanity-checks.sh.j2> - Script to create the sanity checks tests
* `sanity_checks_log`: <validate_sanity_test.log> - Log file to store the output of the sanity checks
* `sanitytest_create`: <true> - Boolean variable whether to create the artifacts to test enabled services
* `sanitytest_cleanup`: <true> - Boolean variable whether to clean up the artifacts created by the sanity checks
* `sanity_step_sanity_checks`: <true> - Boolean variable whether to execute the sanity checks test
Dependencies
------------
No dependencies.
Example Playbook
----------------
# Execute sanity checks against the overcloud deployment
- name: Sanity check the overcloud services
hosts: undercloud
roles:
- { role: validate-sanity-checks, when: run_sanity_checks|bool}
License
-------
Apache 2.0
Author Information
------------------
TripleO CI Team

View File

@ -0,0 +1,9 @@
---
sanity_content_name: sanity_test
sanity_scripts: validate-sanity-checks.sh.j2
sanity_checks_log: validate_sanity_test.log
# sanitytest step
sanitytest_create: true
sanitytest_cleanup: true
# step
sanity_step_sanity_checks: true

View File

@ -0,0 +1,2 @@
dependencies:
- extras-common

View File

@ -0,0 +1,6 @@
---
- name: Create Sanity Checks scripts
template:
src: "{{ sanity_scripts }}"
dest: "{{ working_dir }}/validate-sanity-check.sh"
mode: 0755

View File

@ -0,0 +1,5 @@
---
- include: create-scripts.yml
- include: sanity-checks.yml
when: sanity_step_sanity_checks|bool

View File

@ -0,0 +1,4 @@
---
- name: Run sanity checks
shell: >
{{ working_dir }}/validate-sanity-check.sh > {{ sanity_checks_log }} 2>&1

View File

@ -0,0 +1,170 @@
#!/bin/bash
set -eu
set -o pipefail
OVERCLOUD_NAME="overcloud"
SANITYTEST_CONTENT_NAME={{sanity_content_name}}
function source_rc {
if [ $1 = "stackrc" ]; then
cloud="Undercloud"
else
cloud="Overcloud"
fi
echo "You must source a $1 file for the $cloud."
echo "Attempting to source $HOME/$1"
source $HOME/$1
echo "Done"
}
function stackrc_check {
source_rc "stackrc"
}
function overcloudrc_check {
source_rc "overcloudrc"
}
function run_cmd {
if ! $@; then
echo "Command: $@ FAILED" >&2
exitval=1
else
echo "Command: $@ OK"
fi
}
function overcloud_sanitytest_create {
ENABLED_SERVICES=$@
for service in $ENABLED_SERVICES; do
case $service in
"keystone" )
run_cmd openstack user create ${SANITYTEST_CONTENT_NAME}
run_cmd openstack user list
;;
"glance_api" )
run_cmd openstack image create ${SANITYTEST_CONTENT_NAME}
run_cmd openstack image list
;;
"neutron_api" )
run_cmd openstack network create ${SANITYTEST_CONTENT_NAME}
run_cmd openstack network list
;;
"cinder_api" )
run_cmd openstack volume create ${SANITYTEST_CONTENT_NAME} --size 1
run_cmd openstack volume list
;;
"heat_api" )
echo "heat_template_version: newton" > /tmp/${SANITYTEST_CONTENT_NAME}.yaml
run_cmd openstack stack create ${SANITYTEST_CONTENT_NAME} --template /tmp/${SANITYTEST_CONTENT_NAME}.yaml
run_cmd openstack stack list
;;
"swift_proxy" )
run_cmd openstack container create ${SANITYTEST_CONTENT_NAME}
run_cmd openstack container list
;;
"sahara_api" )
# glance_api must also be enabled
run_cmd openstack image create sahara_${SANITYTEST_CONTENT_NAME}
run_cmd openstack dataprocessing image register sahara_${SANITYTEST_CONTENT_NAME} --username centos
run_cmd openstack dataprocessing image list
;;
esac
done
}
function overcloud_sanitytest_check {
ENABLED_SERVICES=$@
for service in $ENABLED_SERVICES; do
case $service in
"keystone" )
run_cmd openstack user show ${SANITYTEST_CONTENT_NAME}
;;
"glance_api" )
run_cmd openstack image show ${SANITYTEST_CONTENT_NAME}
;;
"neutron_api" )
run_cmd openstack network show ${SANITYTEST_CONTENT_NAME}
;;
"cinder_api" )
run_cmd openstack volume show ${SANITYTEST_CONTENT_NAME}
;;
"heat_api" )
run_cmd openstack stack show ${SANITYTEST_CONTENT_NAME}
# FIXME(shardy): It'd be good to add pre/post upgrade checks
# on the actual version, but this is still good for debugging
run_cmd openstack orchestration template version list
;;
"swift_proxy" )
run_cmd openstack container show ${SANITYTEST_CONTENT_NAME}
;;
"sahara_api" )
run_cmd openstack dataprocessing image show sahara_${SANITYTEST_CONTENT_NAME}
;;
esac
done
}
function overcloud_sanitytest_cleanup {
ENABLED_SERVICES=$@
for service in $ENABLED_SERVICES; do
case $service in
"keystone" )
echo "Sanity test keystone"
run_cmd openstack user delete ${SANITYTEST_CONTENT_NAME}
;;
"glance_api" )
run_cmd openstack image delete ${SANITYTEST_CONTENT_NAME}
;;
"neutron_api" )
run_cmd openstack network delete ${SANITYTEST_CONTENT_NAME}
;;
"cinder_api" )
run_cmd openstack volume delete ${SANITYTEST_CONTENT_NAME}
;;
"heat_api" )
run_cmd openstack stack delete --yes ${SANITYTEST_CONTENT_NAME}
;;
"swift_proxy" )
run_cmd openstack container delete ${SANITYTEST_CONTENT_NAME}
;;
"sahara_api" )
run_cmd openstack dataprocessing image unregister sahara_${SANITYTEST_CONTENT_NAME}
run_cmd openstack image delete sahara_${SANITYTEST_CONTENT_NAME}
;;
esac
done
}
echo "Overcloud sanitytest"
exitval=0
stackrc_check
if heat stack-show "$OVERCLOUD_NAME" | grep "stack_status " | egrep -q "(CREATE|UPDATE)_COMPLETE"; then
ENABLED_SERVICES=$(openstack stack output show overcloud EnabledServices -f json | \
jq -r ".output_value" | jq '.Controller | .[]' | tr "\n" " " | sed "s/\"//g")
echo "Sanity Test, ENABLED_SERVICES=$ENABLED_SERVICES"
overcloudrc_check
{% if sanitytest_create|bool %}
overcloud_sanitytest_create $ENABLED_SERVICES
{% endif %}
overcloud_sanitytest_check $ENABLED_SERVICES
{% if sanitytest_cleanup|bool %}
overcloud_sanitytest_cleanup $ENABLED_SERVICES
{% endif %}
if [ $exitval -eq 0 ]; then
echo "Overcloud sanitytest SUCCEEDED"
else
echo "Overcloud sanitytest FAILED"
fi
exit $exitval
else
echo "Overcloud sanitytest FAILED - No stack $OVERCLOUD_NAME."
exit 1
fi