forked from mjura/automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaasp-devenv
executable file
·204 lines (161 loc) · 4.24 KB
/
caasp-devenv
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/sh
set -euo pipefail
# This script should be as dumb as possible, it should
# contain the most commonly used options for each of the
# other tools, and no more. If you need to customize the
# options for a tool, use that tool directly instead!
# options
HAS_ACTION=false
RUN_SETUP=false
RUN_BUILD=false
RUN_BOOTSTRAP=false
RUN_TESTINFRA=false
RUN_DESTROY=false
MASTERS=1
WORKERS=2
PROXY=${CAASP_HTTP_PROXY:-}
PARALLELISM=1
# READ THIS BEFORE ADDING ANYTHING HERE.
#
# This script should remain as simple as possible, with
# options only for the most commonly used options of the
# tools it orchestrates. If it's not something most
# developers would use at least once a week, then it doesn't
# belong here.
USAGE=$(cat <<USAGE
Usage:
* Setup your workstation
--setup Install Dev Env Dependencies
* Building a cluster
-b|--build Run the CaaSP KVM Build Step
-m|--masters <INT> Number of masters to build
-w|--workers <INT> Number of workers to build
-d|--destroy Run the CaaSP KVM Destroy Step
* Bootstraping a cluster
Velum Username: [email protected]
Velum Password: password
-B|--bootstrap Bootstrap CaaSP cluster
* Testing a cluster
-T|--testinfra Run testinfra tests
* Common options
-p|--parallelism Set terraform parallelism
-P|--proxy Set HTTP Proxy (Default: CAASP_HTTP_PROXY)
* Examples:
Build, Bootstrap and Test a cluster
$0 --build -m 1 -w 2 --bootstrap --testinfra
Bootstrap and Test a pre-made cluster
$0 --bootstrap --testinfra
USAGE
)
# Utility methods
log() { (>&2 echo ">>> [caasp-devenv] $@") ; }
warn() { log "WARNING: $@" ; }
error() { log "ERROR: $@" ; exit 1 ; }
check_file() { if [ ! -f $1 ]; then error "File $1 doesn't exist!"; fi }
# parse options
while [[ $# > 0 ]] ; do
case $1 in
--setup)
RUN_SETUP=true
HAS_ACTION=true
;;
-b|--build)
RUN_BUILD=true
HAS_ACTION=true
;;
-m|--masters)
MASTERS="$2"
shift
;;
-w|--workers)
WORKERS="$2"
shift
;;
-d|--destroy)
RUN_DESTROY=true
HAS_ACTION=true
;;
-B|--bootstrap)
RUN_BOOTSTRAP=true
HAS_ACTION=true
;;
-T|--testinfra)
RUN_TESTINFRA=true
HAS_ACTION=true
;;
-p|--parallelism)
PARALLELISM="$2"
shift
;;
-P|--proxy)
PROXY="$2"
shift
;;
-h|--help)
echo "$USAGE"
exit 0
;;
esac
shift
done
# Core methods
setup() {
log "Installing CaaSP Development Environment Requiemnts"
local dist=$(lsb-release -sd | tr -d '"' | tr " " "_")
if ! zypper lr -dU | grep --quiet "opensuse.org/repositories/Virtualization:/containers"; then
log "Adding Virtualization:containers Zypper repo"
sudo zypper ar --refresh http://download.opensuse.org/repositories/Virtualization:/containers/${dist}/Virtualization:containers.repo
fi
# || : is necessary, as Zypper exits non-zero for "no changes".
sudo zypper in --no-confirm jq python-tox python-openstackclient python-novaclient python-heatclient terraform terraform-provider-libvirt || :
pushd velum-bootstrap
./velum-interactions --setup
popd
}
build() {
pushd caasp-kvm
log "Starting CaaSP KVM Environment"
./caasp-kvm --build -m $MASTERS -w $WORKERS --parallelism=$PARALLELISM --proxy "${PROXY}"
popd
}
bootstrap() {
log "Bootstrap CaaSP Environment"
export ENVIRONMENT=$(realpath caasp-kvm/environment.json)
pushd velum-bootstrap
./velum-interactions --configure --bootstrap
popd
}
testinfra() {
log "Testing CaaSP Environment using testinfra"
export ENVIRONMENT_JSON=$(realpath caasp-kvm/environment.json)
pushd testinfra
tox
popd
}
destroy() {
pushd caasp-kvm
log "Destroy CaaSP KVM Environment"
./caasp-kvm --destroy --parallelism=$PARALLELISM --proxy "${PROXY}"
popd
}
# main
if [ "$HAS_ACTION" != true ]; then
echo "$USAGE"
error "No action arguments were supplied"
fi
if [ "$RUN_SETUP" = true ]; then
setup
fi
if [ "$RUN_BUILD" = true ]; then
build
fi
if [ "$RUN_BOOTSTRAP" = true ] ; then
bootstrap
fi
if [ "$RUN_TESTINFRA" = true ] ; then
testinfra
fi
if [ "$RUN_DESTROY" = true ] ; then
destroy
fi
log "Done"