-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
166 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,3 @@ install: | |
|
||
script: | ||
- tox -e travis | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# file: primogen/tests/tasks | ||
# | ||
# Test tasks to verify role execution. | ||
# | ||
|
||
- debug: | ||
msg="You need to define tests here!" | ||
tags: | ||
- debug | ||
- test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
# file: primogen/tests/vagrant.yml | ||
|
||
- name: set host entries play | ||
hosts: 127.0.0.1 | ||
connection: local | ||
gather_facts: no | ||
|
||
vars: | ||
hosts_file: /etc/hosts | ||
|
||
tasks: | ||
- name: set entry in /etc/hosts | ||
lineinfile: | ||
dest="{{ hosts_file }}" | ||
line="{{ item.value.network.ip }} {{ item.key }}" | ||
state=present | ||
follow=yes | ||
insertafter=EOF | ||
with_dict: vagrant | ||
when: item.value.enabled | ||
sudo: yes | ||
tags: | ||
- vagrant | ||
|
||
|
||
- name: tests play | ||
hosts: all | ||
gather_facts: yes | ||
|
||
roles: | ||
- primogen | ||
- tests | ||
|
||
|
||
- name: clear host entries play | ||
hosts: 127.0.0.1 | ||
connection: local | ||
gather_facts: no | ||
|
||
vars: | ||
hosts_file: /etc/hosts | ||
|
||
tasks: | ||
- name: clear entry in /etc/hosts | ||
lineinfile: | ||
dest="{{ hosts_file }}" | ||
regexp=".*{{ item.key }}$" | ||
state=absent | ||
follow=yes | ||
with_dict: vagrant | ||
sudo: yes | ||
tags: | ||
- vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,28 @@ | |
# | ||
# Bash script to run idempotence tests. | ||
# | ||
# version: 1.0 | ||
# version: 1.2 | ||
# | ||
# mandatory variables: | ||
# usage: | ||
# | ||
# from environment.sh | ||
# - INVENTORY : the inventory to be used to run the test against. | ||
# - PLAYBOOK : the path to the Ansible playbook. | ||
# test_idempotence [options] | ||
# | ||
# from <playbook_name>.sh | ||
# - BOX : the name of the vagrant box | ||
# options: | ||
# | ||
# optional variables: | ||
# --box The name of the Vagrant box or host name | ||
# --inventory The Ansible inventory in the form of a file or string "host," | ||
# --playbook The path to the Ansible test playbook | ||
# | ||
# example: | ||
# | ||
# # on localhost | ||
# bash test_idempotence.sh | ||
# | ||
# # on a Vagrant box | ||
# bash test_idempotence.sh \ | ||
# --box precise64 | ||
# --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory | ||
# | ||
# - VIRTUALENV_NAME : the name of the virtualenv being used. | ||
# | ||
# author(s): | ||
# - Pedro Salgado <[email protected]> | ||
|
@@ -30,11 +38,58 @@ GREEN='\033[0;32m' | |
RED='\033[0;31m' | ||
# SGR code to set text color (foreground) to no color. | ||
NC='\033[0m' | ||
# The idempotence pass criteria. | ||
PASS_CRITERIA="changed=0.*failed=0" | ||
|
||
# the name of the virtualenv | ||
VIRTUALENV_NAME=$(which python | awk -F / 'NF && NF-2 { print ( $(NF-2) ) }') | ||
|
||
|
||
while [[ $# > 1 ]] | ||
do | ||
key="$1" | ||
|
||
case $key in | ||
|
||
--box) | ||
# the name of the Vagrant box or host name | ||
BOX="$2" | ||
shift;; | ||
|
||
--inventory) | ||
# the Ansible inventory in the form of a file or string "host," | ||
INVENTORY="$2" | ||
shift;; | ||
|
||
--playbook) | ||
# the path to the Ansible test playbook | ||
PLAYBOOK="$2" | ||
shift;; | ||
|
||
*) | ||
# unknown option | ||
;; | ||
|
||
esac | ||
shift | ||
done | ||
|
||
# the name of the Vagrant box or host name | ||
BOX=${1:-localhost} | ||
# the Ansible inventory in the form of a file or string "host," | ||
INVENTORY=${2:-'localhost,'} | ||
# the path to the Ansible test playbook | ||
PLAYBOOK=${3:-test.yml} | ||
# the logfile to hold the output of the playbook run | ||
LOGFILE="log/${BOX}_${VIRTUALENV_NAME}.log" | ||
|
||
EXTRA_ARGS='' | ||
if [ $BOX == "localhost" ]; then | ||
EXTRA_ARGS="--skip-tags=vagrant --connection=local" | ||
fi | ||
|
||
echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running idempotence test..." | ||
ansible-playbook -i ${INVENTORY} --limit ${BOX} ${PLAYBOOK} 2>&1 | tee ${LOGFILE} | \ | ||
ansible-playbook -i ${INVENTORY} --limit ${BOX} ${PLAYBOOK} ${EXTRA_ARGS} 2>&1 | tee ${LOGFILE} | \ | ||
grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \ | ||
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN}PASS${NC}\n" || \ | ||
(echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && exit 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,16 @@ | |
# | ||
# Bash script to run the test suite against the Vagrant environment. | ||
# | ||
# version: 1.0 | ||
# version: 1.2 | ||
# | ||
# usage: | ||
# | ||
# $ bash vagrant.sh --python 27 --ansible 1901 | ||
# # run tests against all enabled Vagrant boxes | ||
# $ bash vagrant.sh | ||
# | ||
# # run tests against a single Vagrant box | ||
# $ bash vagrant.sh --box precise64.vagrant.dev | ||
# | ||
# $ bash vagrant.sh --virtualenv ../.tox/py27-ansible1901 --virtualenv-name py27-ansible1901 | ||
# | ||
# author(s): | ||
# - Pedro Salgado <[email protected]> | ||
|
@@ -20,13 +23,10 @@ DIR="$(dirname "$0")" | |
|
||
cd $DIR | ||
|
||
source environment.sh | ||
|
||
# The filename of the Ansible playbook to be used on the test. | ||
# NOTE: PLAYBOOK must be the same value as defined in the Vagrantfile. | ||
PLAYBOOK="vagrant.yml" | ||
# force Ansible to ask for sudo password when running tests against Vagrant | ||
ANSIBLE_ASK_SUDO_PASS=True | ||
|
||
# Inventory file to run tests againt (points to Vagrant generated inventory) | ||
# the path to the Ansible inventory generated by Vagrant | ||
INVENTORY=${DIR}/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory | ||
|
||
|
||
|
@@ -36,26 +36,9 @@ key="$1" | |
|
||
case $key in | ||
|
||
--python) | ||
# The Python version to be used on the test. | ||
# NOTE: PYTHON_VERSION must be set to a Python version defined in tox. | ||
PYTHON_VERSION="$2" | ||
shift;; | ||
|
||
--ansible) | ||
# The Ansible version to be used on the test. | ||
# ANSIBLE_VERSION must be set to a Ansible version defined in tox. | ||
ANSIBLE_VERSION="$2" | ||
shift;; | ||
|
||
--virtualenv-name) | ||
# The tox virtualenv name | ||
VIRTUALENV_NAME="$2" | ||
shift;; | ||
|
||
--virtualenv) | ||
# The virtualenv directory to be used on the test. | ||
VIRTUALENV="$2" | ||
--box) | ||
# the name of the Vagrant box to run tests against | ||
BOX="$2" | ||
shift;; | ||
|
||
*) | ||
|
@@ -66,32 +49,20 @@ key="$1" | |
shift | ||
done | ||
|
||
if [[ ! -z ${PYTHON_VERSION} ]] && [[ ! -z ${ANSIBLE_VERSION} ]]; then | ||
echo '[INFO] loading Python / Ansible virtualenv...' | ||
VIRTUALENV="../.tox/py${PYTHON_VERSION}-ansible${ANSIBLE_VERSION}" | ||
VIRTUALENV_NAME="py${PYTHON_VERSION}-ansible${ANSIBLE_VERSION}" | ||
fi | ||
|
||
source ${VIRTUALENV}/bin/activate | ||
|
||
|
||
. install_role_dependencies.sh | ||
|
||
# force Ansible to ask for sudo password when running tests against Vagrant | ||
export ANSIBLE_ASK_SUDO_PASS=True | ||
|
||
for BOX in `grep vagrant.dev group_vars/all.yml | sed 's/://g'` | ||
for VAGRANT_BOX in `grep vagrant.dev boxes.yml | sed 's/://g'` | ||
do | ||
if [ -n ${BOX} ] && [ "${BOX}" == "${VAGRANT_BOX}" ]; then | ||
|
||
echo "[INFO] preparing ${BOX}..." | ||
vagrant up ${BOX} 2> /dev/null | ||
if [ $? -ne 0 ]; then | ||
# box not enabled | ||
continue | ||
fi | ||
echo "[INFO] preparing ${VAGRANT_BOX}..." | ||
vagrant up ${VAGRANT_BOX} 2> /dev/null | ||
if [ $? -ne 0 ]; then | ||
# box not enabled | ||
continue | ||
fi | ||
|
||
. test_idempotence.sh | ||
. ${DIR}/test_idempotence.sh --box ${VAGRANT_BOX} --inventory $INVENTORY | ||
|
||
echo "[INFO] destroy ${BOX}..." | ||
vagrant destroy -f ${BOX} | ||
echo "[INFO] destroy ${VAGRANT_BOX}..." | ||
vagrant destroy -f ${VAGRANT_BOX} | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters