-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·145 lines (124 loc) · 3.13 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
set -e
export UTIL_TRACE=1
source util.sh
puppet=puppet8
provider=docker
usage () {
echo "Usage: $0 [OPTION [OPTION...]] COMMAND [COMMAND...]"
echo ""
echo "OPTION may by one of:"
echo " --docker use docker for tests [default]"
echo " --vagrant use vagrant for tests"
echo " --puppet7 -7 run tests in Puppet 7"
echo " --puppet8 -8 run tests in Puppet 8 [default]"
echo ""
echo "COMMAND may be one of:"
echo " init initialize test set up"
echo " update reinstall module"
echo " run run tests"
echo " destroy destroy virtual machines or docker images"
echo ""
echo "If vagrant is used, the following additional commands are supported:"
echo " snapshot save a snapshot called 'general'"
echo " restore restore a snapshot called 'general'"
echo " fast-init restore to post-init state and reinstall the module"
echo ""
echo "Examples:"
echo " $0 init run destroy"
echo " $0 --vagrant -7 init run"
echo " $0 --vagrant -7 fast-init run"
}
init () {
# FIXME sometimes we just want to ensure that things are set up, and not
# actually recreate everything
destroy
rake "litmus:provision_list[${provider}]"
if [[ $provider = vagrant ]] ; then
# There’s a bug in Litmus that prevents Puppet from being updated when a
# package is already available in the distro, e.g. on Ubuntu.
bolt_task_run puppet_agent::install "collection=${puppet}" version=latest
bolt_task_run provision::fix_secure_path path=/opt/puppetlabs/bin
snapshot fresh
else
rake "litmus:install_agent[${puppet}]"
fi
rake litmus:install_module
}
snapshot () {
local name=${1:-general}
if [[ $provider != 'vagrant' ]] ; then
echo 'snapshot command can only be used with vagrant.' >&2
exit 1
fi
for box in .vagrant/*/Vagrantfile ; do
(
cd "$(dirname "$box")"
vagrant snapshot save "$name"
)
done
}
restore () {
local name=${1:-general}
if [[ $provider != 'vagrant' ]] ; then
echo 'restore command can only be used with vagrant.' >&2
exit 1
fi
for box in .vagrant/*/Vagrantfile ; do
(
cd "$(dirname "$box")"
vagrant snapshot restore "$name"
)
done
}
fast-init () {
if [[ $provider != 'vagrant' ]] ; then
echo 'fast-init command can only be used with vagrant.' >&2
exit 1
fi
restore fresh
rake litmus:install_module
}
update () {
rake litmus:reinstall_module
}
run () {
rake litmus:acceptance:parallel
}
destroy () {
if [ -f spec/fixtures/litmus_inventory.yaml ] ; then
# If there’s no inventory, there’s nothing to tear down.
rake litmus:tear_down
rm -f spec/fixtures/litmus_inventory.yaml
fi
}
if [[ -z "$*" ]] ; then
usage >&2
exit 1
fi
for action in "$@" ; do
case "$action" in
--vagrant)
provider=vagrant
;;
--docker)
provider=docker
;;
-7|--puppet7)
puppet=puppet7
;;
-8|--puppet8)
puppet=puppet8
;;
--help)
usage
;;
init|snapshot|restore|fast-init|update|run|destroy)
"$action"
;;
*)
usage >&2
exit 1
;;
esac
done