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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
#!/bin/bash
# Copyright 2007, Red Hat, Inc
# Adrian Likins <alikins@redhat.com>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# this is pretty Red Hat distro specific at the moment
# I'll try to make it a bit more portable if there is
# interest
# where do we build stuff
BUILD_PATH="/tmp/func-build"
# more or less where we are running from, but also
# where to stash the rpms we build
RPM_PATH=`pwd`
# do we need to build package at all?
BUILD=Y
# do we do a fresh pull from git to build
BUILD_FROM_FRESH_CHECKOUT=N
# do we build/uninstall via rpms?
INSTALL_VIA_RPMS=N
# should we backup existing func pki setup, since
# we are going to be deleting it from the normal spot?
BACKUP_FUNC_PKI="N"
# do we want to run the unit tests as well
RUN_UNITTESTS="Y"
# you can put conf stuff in test-it.conf
# so you don't have to worry about checking in config stuff
if [ -f "test-it.conf" ] ; then
source test-it.conf
fi
show_config()
{
echo "BUILD_PATH=$BUILD_PATH"
echo "RPM_PATH=$RPM_PATH"
echo "BUILD=$BUILD"
echo "BUILD_FROM_FRESH_CHECKOUT=$BUILD_FROM_FRESH_CHECKOUT"
echo "INSTALL_VIA_RPMS=$INSTALL_VIA_RPMS"
echo "BACKUP_FUNC_PKL=$BACKUP_FUNC_PKI"
echo "RUN_UNITTESTS=$RUN_UNITTESTS"
}
rm -rf $RPM_PATH/rpms
rm -rf $RPM_PATH/srpms
rm -rf $RPM_PATH/tars
mkdir -p $RPM_PATH/rpms $RPM_PATH/srpms $RPM_PATH/tars
msg()
{
echo
echo "============ $1 ============"
echo
}
check_out_code()
{
echo "Build path is $BUILD_PATH"
rm -rf $BUILD_PATH
mkdir -p $BUILD_PATH
pushd $BUILD_PATH
git clone git://git.fedorahosted.org/func.git
echo $?
popd
}
copy_code_to_buildroot()
{
msg "Copying current build dir to $BUILD_PATH"
rm -rf $BUILD_PATH
mkdir -p $BUILD_PATH/func/
cp -var ../* $BUILD_PATH/func
}
build_rpm()
{
PKG=$1
BRT=$2
echo;echo;echo
echo "======================================"
echo "Building $PKG in $BRT"
echo "======================================"
echo
echo $BUILD_PATH/$PKG
pushd $BUILD_PATH/$PKG
echo "BRT" $BRT "PKK" $PKG
make clean
make rpms
if [ $? != 0 ]; then
echo "kaboom building $PKG"
exit 1
fi
mv rpm-build/*.src.rpm $RPM_PATH/srpms
mv rpm-build/*.rpm $RPM_PATH/rpms
mv rpm-build/*.tar.gz $RPM_PATH/tars
make clean
popd
if [ $? != 0 ]; then
echo "kaboom cleaning up $PKG"
exit 1
fi
}
uninstall_the_func_rpm()
{
msg "Removing the func rpm, if there is one"
# just one package for now, easy enough
rpm -e func
}
install_the_func_rpm()
{
msg "Installing the func rpm"
rpm -Uvh $RPM_PATH/rpms/func*
STATUS=$?
# do something with the status
}
install_the_func()
{
msg "Installing func directly from $1 $BUILD_PATH"
pushd $1/func
make install
}
find_the_func()
{
INSTALLED_FUNC=`rpm -q func`
STATUS=$?
if [ "$STATUS" == "1" ] ; then
msg "We were unable to find the func installed"
exit 1
fi
msg "$INSTALLED_FUNC was found"
}
stop_the_func()
{
/etc/init.d/funcd stop
/etc/init.d/certmaster stop
}
start_the_func()
{
# shut everything down first
stop_the_func
/etc/init.d/certmaster start
CERT_STATUS=$?
/etc/init.d/funcd start
FUNCD_STATUS=$?
if [ "$CERT_STATUS" != "0" ] ; then
msg "certmaster startup failed with code: $CERT_STATUS"
fi
if [ "$FUNCD_STATUS" != "0" ] ; then
msg "funcd startup failed with code: $FUNCD_STATUS"
fi
}
backup_the_secret_of_the_func()
{
# whatever, this should probably be some standard date format
# but I just wanted something sans spaces
DATE=`date "+%F_%R"`
tar -c /etc/pki/func/* /var/lib/func/* > func-pki-backup-$DATE.tar
}
#yes, I'm in a funny variable naming mood, I'll change them
#later
no_more_secrets()
{
rm -rf /etc/pki/func/*
rm -rf /var/lib/func/certmaster/*
}
find_certmaster_certs()
{
MINION_CERTS=`certmaster-ca --list`
STATUS=$?
echo "certmaster found the following certs:"
echo $MINION_CERTS
if [ "$MINION_CERTS" == "No certificates to sign" ] ; then
MINION_CERTS=""
fi
}
sign_the_certmaster_certs()
{
echo
echo $MINION_CERTS
for i in $MINION_CERTS
do
echo /usr/bin/certmaster-ca -s $i
/usr/bin/certmaster-ca -s $i
done
}
# just some random "poke at func and make sure it works stuff"
test_funcd()
{
# it seems to take a second for the signed certs to be
# ready, so this is here
sleep 10
func "*" list_minions
for i in $MINION_CERTS
do
func $i call system listMethods
func $i call test add "23" "45"
done
}
run_async_test()
{
msg "Running async_test.py to test async/forking"
pushd $BUILD_PATH/func/test
python async_test.py
}
run_unittests()
{
msg "Running the unittest suite"
pushd $BUILD_PATH/func/test
nosetests -v -w unittest/
}
# start doing stuff
show_config
if [ "$BUILD" == "Y" ] ; then
if [ "$BUILD_FROM_FRESH_CHECKOUT" == "Y" ] ; then
check_out_code
else
# assume we want to build a copy of the current
# source tree, we copy it else where and build
# so we dont 'splode any thing with the build process
copy_code_to_buildroot
fi
if [ "$INSTALL_VIA_RPMS" == "Y" ] ; then
# FIXME: red hat specifc
build_rpm func $BUILD_PATH
#if we are building, then we should remove the installed
# versiones as well, and install the new
uninstall_the_func_rpm
install_the_func_rpm
else
uninstall_the_func_rpm
install_the_func $BUILD_PATH
fi
fi
# see if func is install
# see if funcd is install
if [ "$INSTALL_VIA_RPMS" == "Y" ] ; then
find_the_func
fi
if [ "$BACKUP_FUNC_PKI" == "Y" ] ; then
backup_the_secret_of_the_func
fi
# remove any existing keys
no_more_secrets
# test start up of init scripts
start_the_func
#we seem to need to wait a bit for certmaster to create the certs and whatnot
sleep 5
find_certmaster_certs
sign_the_certmaster_certs
test_funcd
if [ "$RUN_UNITTESTS" == "Y" ] ; then
run_unittests
fi
run_async_test
stop_the_func
# leaving the test cases with func not running is kind of
# annoying, so restart it
start_the_func
### probably do some stuff to test bad/no/malformed/unauthed certs as well
|