Skip to content

Commit afafdca

Browse files
committed
add ansible tests, use common docker image
1 parent 51505a5 commit afafdca

20 files changed

+369
-48
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ before_install:
1212
- sudo apt-get install -y xmlstarlet jq
1313
- sudo chsh --shell $(which bash)
1414
script:
15-
- './gradlew clean build && groovy testbuild.groovy -gradle && make TAG=SNAPSHOT BUILD_NUM=$TRAVIS_BUILD_NUMBER rpm deb && bash run-api-tests.sh && bash run-docker-tests.sh && bash run-docker-ssl-tests.sh && DOCKER_COMPOSE_SPEC=docker-compose-api-mysql.yaml bash run-docker-api-tests.sh'
15+
- './gradlew clean build && groovy testbuild.groovy -gradle && make TAG=SNAPSHOT BUILD_NUM=$TRAVIS_BUILD_NUMBER rpm deb && bash run-api-tests.sh && DOCKER_COMPOSE_SPEC=docker-compose-api-mysql.yaml bash run-docker-api-tests.sh && bash run-docker-tests.sh && bash run-docker-ssl-tests.sh && bash run-docker-ansible-tests.sh'
1616
addons:
1717
hostname: rdbuild
1818
apt:

run-docker-ansible-tests.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
#/ trigger local ci test run
3+
4+
5+
. rd_versions.sh
6+
7+
8+
set -euo pipefail
9+
IFS=$'\n\t'
10+
readonly ARGS=("$@")
11+
DOCKER_DIR=$PWD/test/docker
12+
13+
usage() {
14+
grep '^#/' <"$0" | cut -c4- # prints the #/ lines above as usage info
15+
}
16+
die(){
17+
echo >&2 "$@" ; exit 2
18+
}
19+
20+
check_args(){
21+
if [ ${#ARGS[@]} -gt 0 ] ; then
22+
DOCKER_DIR=$1
23+
fi
24+
}
25+
copy_jar(){
26+
local FARGS=("$@")
27+
local DIR=${FARGS[0]}
28+
local -a VERS=( $( rd_get_version ) )
29+
local JAR=rundeck-launcher-${VERS[0]}-${VERS[2]}.jar
30+
local buildJar=$PWD/rundeck-launcher/launcher/build/libs/$JAR
31+
test -f $buildJar || die "Jar file not found $buildJar"
32+
mkdir -p $DIR
33+
cp $buildJar $DIR/rundeck-launcher.jar
34+
echo $DIR/$JAR
35+
}
36+
run_tests(){
37+
local FARGS=("$@")
38+
local DIR=${FARGS[0]}
39+
40+
cd $DIR
41+
bash $DIR/test-ansible.sh
42+
}
43+
run_docker_test(){
44+
local FARGS=("$@")
45+
local DIR=${FARGS[0]}
46+
local launcherJar=$( copy_jar $DIR ) || die "Failed to copy jar"
47+
run_tests $DIR
48+
}
49+
50+
51+
main() {
52+
check_args
53+
run_docker_test $DOCKER_DIR
54+
}
55+
main
56+

test/docker/common.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
export RUNDECK_VERSION=${RUNDECK_VERSION:-2.7.0}
3+
export RUNDECK_VERSION=${RUNDECK_VERSION:-2.9.2}
44
export LAUNCHER_URL=${LAUNCHER_URL:-http://dl.bintray.com/rundeck/rundeck-maven/rundeck-launcher-${RUNDECK_VERSION}.jar}
55
export CLI_DEB_URL=${CLI_DEB_URL:-https://dl.bintray.com/rundeck/rundeck-deb}
6-
export CLI_VERS=${CLI_VERS:-1.0.0-1}
6+
export CLI_VERS=${CLI_VERS:-1.0.15-1}

test/docker/docker-compose-ansible-test.yaml

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
version: '3'
1+
version: '2'
22

33
services:
44
rundeck1:
55
hostname: rundeck1
66
build:
77
context: dockers/rundeckansible/
8-
args:
9-
CLI_DEB_URL: ${CLI_DEB_URL}
10-
CLI_VERS: ${CLI_VERS}
11-
LAUNCHER_URL: ${LAUNCHER_URL}
128
links:
139
- hostnode
1410
environment:
@@ -22,6 +18,7 @@ services:
2218
- CONFIG_SCRIPT_PRESTART=scripts/config-ansible.sh
2319
- SETUP_TEST_PROJECT=atest
2420
- CONFIG_TEST_PROJECT_FILE=atest/atest-project.properties
21+
- NODE_CACHE_FIRST_LOAD_SYNCH=1
2522
volumes:
2623
- logs:/home/rundeck/logs:rw
2724
- resources:/home/rundeck/resources:rw

test/docker/docker-compose-api-mysql.yaml

+1-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ services:
1717
- ./dockers/mysql/conf:/etc/mysql/conf.d
1818
rundeck1:
1919
hostname: rundeck1
20-
build:
21-
context: dockers/rundeck/
22-
args:
23-
CLI_DEB_URL: ${CLI_DEB_URL}
24-
CLI_VERS: ${CLI_VERS}
25-
LAUNCHER_URL: ${LAUNCHER_URL}
20+
image: rdtest:latest
2621
# entrypoint: bash /home/rundeck/run.sh
2722
links:
2823
- mysql

test/docker/docker-compose-api-test.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ version: '2'
33
services:
44
rundeck1:
55
hostname: rundeck1
6-
build:
7-
context: dockers/rundeck/
8-
args:
9-
CLI_DEB_URL: ${CLI_DEB_URL}
10-
CLI_VERS: ${CLI_VERS}
11-
LAUNCHER_URL: ${LAUNCHER_URL}
6+
image: rdtest:latest
127
# entrypoint: bash /home/rundeck/run.sh
138
environment:
149
- RUNDECK_NODE=rundeck1

test/docker/docker-compose-multinode-test.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ version: '2'
33
services:
44
rundeck1:
55
hostname: rundeck1
6-
build:
7-
context: dockers/rundeck/
8-
args:
9-
CLI_DEB_URL: ${CLI_DEB_URL}
10-
CLI_VERS: ${CLI_VERS}
11-
LAUNCHER_URL: ${LAUNCHER_URL}
6+
image: rdtest:latest
127
links:
138
- hostnode
149
# entrypoint: bash /home/rundeck/run.sh

test/docker/docker-compose-ssl-test.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ version: '2'
33
services:
44
rundeck1:
55
hostname: rundeck1
6-
build:
7-
context: dockers/rundeck/
8-
args:
9-
CLI_DEB_URL: ${CLI_DEB_URL}
10-
CLI_VERS: ${CLI_VERS}
11-
LAUNCHER_URL: ${LAUNCHER_URL}
6+
image: rdtest:latest
127
# entrypoint: bash /home/rundeck/run.sh
138
environment:
149
- RUNDECK_NODE=rundeck1

test/docker/dockers/rundeck/scripts/config-ansible.sh

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
#/ does something ...
33
#/ usage: [..]
44

5-
set -euo pipefail
5+
#set -euo pipefail
66
IFS=$'\n\t'
7-
readonly ARGS=("$@")
87
# <http://www.kfirlavi.com/blog/2012/11/14/defensive-bash-programming/>
98
# <http://redsymbol.net/articles/unofficial-bash-strict-mode/>
109

@@ -31,10 +30,9 @@ check_args(){
3130
# # set -x
3231
#}
3332
setup_ansible(){
34-
cat >/etc/ansible/hosts <<END
33+
sudo cat >/home/rundeck/resources/ansibleinv.ini <<END
3534
[ansible-nodes]
36-
$NODE1 ansible_host=$NODE1 ansible_port=22
37-
test-ansible-node ansible_connection=local ansible_host=127.0.0.1
35+
test-ansible-node ansible_connection=local
3836
$RUNDECK_NODE ansible_connection=local
3937
END
4038

test/docker/dockers/rundeck/scripts/run_tests.sh

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ set -e
44

55
TEST_DIR=$1
66
TEST_SCRIPT=${2:-/tests/run-tests.sh}
7+
TEST_PROJECT=${3:-testproj1}
78

8-
: ${TEST_DIR?"Argument required"}
9-
echo "run_tests with $TEST_DIR"
9+
: ${TEST_DIR?"Dir required"}
10+
: ${TEST_SCRIPT?"Script required"}
11+
: ${TEST_PROJECT?"Project required"}
12+
echo "run_tests with $TEST_DIR and $TEST_SCRIPT for project $TEST_PROJECT"
1013

1114
export API_KEY=letmein99
1215
# define env vars used by rd tool
@@ -69,11 +72,12 @@ echo "starting tests"
6972

7073
set +e
7174
chmod -w $TEST_SCRIPT
75+
chmod +x $TEST_SCRIPT
7276
sync
7377

7478
$TEST_SCRIPT \
7579
--rdeck-base $HOME \
76-
--rundeck-project testproj1 \
80+
--rundeck-project $TEST_PROJECT \
7781
--rundeck-user $USERNAME \
7882
--test-dir $TEST_DIR
7983
EC=$?

test/docker/dockers/rundeck/scripts/start_rundeck.sh

+5
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ if [ -n "$SETUP_SSL" ] ; then
241241
setup_ssl $RDECK_BASE
242242
fi
243243

244+
if [ -n "$NODE_CACHE_FIRST_LOAD_SYNCH" ] ; then
245+
cat - >>$RDECK_BASE/server/config/rundeck-config.properties <<END
246+
rundeck.nodeService.nodeCache.firstLoadAsynch=false
247+
END
248+
fi
244249

245250
### PRE CONFIG
246251
# RUN TEST PRESTART SCRIPT

test/docker/dockers/rundeckansible/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ RUN mkdir -p $HOME/atest
1010
COPY config $HOME/atest
1111
VOLUME $HOME/atest
1212

13+
RUN mkdir -p $HOME/ansible-tests
14+
COPY tests $HOME/ansible-tests
15+
VOLUME $HOME/ansible-tests
16+
1317
EXPOSE 4440

test/docker/dockers/rundeckansible/config/ansible-jobs.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ echo "DATE ----"
9595
date
9696
echo "-----"
9797
98-
echo "IFCONFIG ----"
99-
ifconfig -a
98+
echo "UNAME ----"
99+
uname -a
100100
echo "------"]]></script>
101101
<scriptargs />
102102
</command>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
resources.source.2.config.ansible-become=false
22
resources.source.2.config.ansible-gather-facts=true
33
resources.source.2.config.ansible-ignore-errors=true
4-
resources.source.2.config.ansible-inventory=/etc/ansible/hosts
5-
resources.source.2.type=com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory
4+
resources.source.2.config.ansible-inventory=/home/rundeck/resources/ansibleinv.ini
5+
resources.source.2.type=com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory
6+
project.ansible-inventory=/home/rundeck/resources/ansibleinv.ini
7+
project.ansible-executable=/bin/bash
8+
service.FileCopier.default.provider=com.batix.rundeck.plugins.AnsibleFileCopier
9+
service.NodeExecutor.default.provider=com.batix.rundeck.plugins.AnsibleNodeExecutor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env roundup
2+
#
3+
4+
: ${RUNDECK_USER?"environment variable not set."}
5+
: ${RUNDECK_PROJECT?"environment variable not set."}
6+
: ${REMOTE_NODE?"environment variable not set."}
7+
8+
# Let's get started
9+
# -----------------
10+
11+
# Helpers
12+
# ------------
13+
14+
#. ./include.sh
15+
16+
17+
# The Plan
18+
# --------
19+
describe "load jobs: valid use of ansible plugin"
20+
JOBID="4fd7f51b-ed22-479e-8785-8393411c0106"
21+
RUN_MODULE_JOB="$JOBID"
22+
JOBID2="72d84cce-0eac-49dc-9a16-1515453e3604"
23+
RUN_PLAYBOOK_JOB="$JOBID2"
24+
JOBID3="df5fa3e8-5891-456e-a8da-7d3f81f7b644"
25+
RUN_SCRIPT_JOB="$JOBID3"
26+
27+
it_should_list_ansible_nodes() {
28+
29+
30+
bash -c "rd nodes list -p $RUNDECK_PROJECT "
31+
32+
}
33+
it_should_have_test_ansible_node() {
34+
35+
# Parse lines into array elements.
36+
IFS=$'\n\t'
37+
38+
cmdout=($(bash -c "rd nodes list -p $RUNDECK_PROJECT -F test-ansible-node | grep -v '^#' "))
39+
expout=( test-ansible-node )
40+
echo "${cmdout[@]}"
41+
if ! test ${#expout[*]} = ${#cmdout[*]}
42+
then
43+
echo "FAIL: command output did not contain ${#expout[*]} lines. Contained ${#cmdout[*]}: ${cmdout[*]}"
44+
echo cmdout was: ${cmdout[@]}
45+
exit 1
46+
fi
47+
test "${cmdout[@]}" = "${expout[@]}"
48+
}
49+
it_should_have_two_ansible_nodes() {
50+
51+
# Parse lines into array elements.
52+
IFS=$'\n\t'
53+
54+
cmdout=($(bash -c "rd nodes list -p $RUNDECK_PROJECT -F tags:ansible-nodes | grep -v '^#' "))
55+
expout=( $RUNDECK_NODE test-ansible-node )
56+
echo "${cmdout[@]}"
57+
if ! test ${#expout[*]} = ${#cmdout[*]}
58+
then
59+
echo "FAIL: command output did not contain ${#expout[*]} lines. Contained ${#cmdout[*]}: ${cmdout[*]}"
60+
echo cmdout was: ${cmdout[@]}
61+
exit 1
62+
fi
63+
let max=$(( ${#cmdout[*]} - 1 ))
64+
for i in $(seq 0 $max) ; do
65+
test "${cmdout[$i]}" = "${expout[$i]}"
66+
done
67+
}
68+
it_should_load_ansible_jobs() {
69+
70+
# load job file
71+
bash -c "rd jobs load -p $RUNDECK_PROJECT --format xml -f $HOME/atest/ansible-jobs.xml"
72+
73+
74+
# verify jobs exist
75+
76+
bash -c "rd jobs list -p $RUNDECK_PROJECT -i $JOBID -% '%id'"
77+
bash -c "rd jobs list -p $RUNDECK_PROJECT -i $JOBID2 -% '%id'"
78+
bash -c "rd jobs list -p $RUNDECK_PROJECT -i $JOBID3 -% '%id'"
79+
}
80+
81+
it_should_run_ansible_module_step(){
82+
bash -c "rd run -p $RUNDECK_PROJECT -i $RUN_MODULE_JOB -f | grep -v ^#" > test.output
83+
# diff with expected
84+
cat >expected.output <<END
85+
86+
Using /etc/ansible/ansible.cfg as config file
87+
test-ansible-node | SUCCESS => {
88+
"changed": false,
89+
"ping": "pong"
90+
}
91+
rundeck1 | SUCCESS => {
92+
"changed": false,
93+
"ping": "pong"
94+
}
95+
END
96+
# set +e
97+
# diff expected.output test.output
98+
# result=$?
99+
# set -e
100+
cat test.output
101+
grep 'test-ansible-node | SUCCESS => {' test.output || ( echo "Expected output not seen" && exit 2 )
102+
grep "$RUNDECK_NODE | SUCCESS => {" test.output || ( echo "Expected output not seen" && exit 2 )
103+
}
104+
it_should_run_ansible_playbook_step(){
105+
bash -c "rd run -p $RUNDECK_PROJECT -i $RUN_PLAYBOOK_JOB -f | grep -v ^#" > test.output
106+
# diff with expected
107+
108+
cat test.output
109+
grep 'PLAY \[An example playbook\]' test.output || ( echo "Expected output not seen" && exit 2 )
110+
grep 'ok: \[test-ansible-node\]' test.output || ( echo "Expected output not seen" && exit 2 )
111+
grep "ok: \[$RUNDECK_NODE\]" test.output || ( echo "Expected output not seen" && exit 2 )
112+
grep "TASK \[print the current date and time\]" test.output || ( echo "Expected output not seen" && exit 2 )
113+
grep "changed: \[$RUNDECK_NODE\] =>" test.output || ( echo "Expected output not seen" && exit 2 )
114+
grep "changed: \[test-ansible-node\] =>" test.output || ( echo "Expected output not seen" && exit 2 )
115+
116+
}
117+
it_should_run_ansible_script_step(){
118+
bash -c "rd run -p $RUNDECK_PROJECT -i $RUN_SCRIPT_JOB -f --outformat '%node: %log' | grep -v ^#" > test.output
119+
# diff with expected
120+
121+
grep "$RUNDECK_NODE: DATE" test.output || ( echo "Expected output not seen" && exit 2 )
122+
grep "$RUNDECK_NODE: UNAME" test.output || ( echo "Expected output not seen" && exit 2 )
123+
grep "test-ansible-node: DATE" test.output || ( echo "Expected output not seen" && exit 2 )
124+
grep "test-ansible-node: UNAME" test.output || ( echo "Expected output not seen" && exit 2 )
125+
126+
}

0 commit comments

Comments
 (0)