summaryrefslogtreecommitdiffstats
path: root/test/test-it.sh
blob: 76c3cf2c5d174c4c8fd993e85edfc321f2319d9b (plain)
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
#!/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=Y

# should we backup existing func pki setup, since
# we are going to be deleting it from the normal spot?
BACKUP_FUNC_PKI="N"

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
}



build_rpm()
{
    PKG=$1
    BRT=$2
    echo;echo;echo
    echo "======================================"
    echo "Building $PKG in $BRT"
    echo "======================================"
    echo
    pushd $BUILD_PATH/$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()
{
	# just one package for now, easy enough
	rpm -e func
}

install_the_func()
{
	rpm -Uvh $RPM_PATH/rpms/func*
	STATUS=$?
	# do something with the status	
}


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

}


if [ "$BUILD" == "Y" ] ; then
	if [ "$BUILD_FROM_FRESH_CHECKOUT" == "Y" ] ; then
		check_out_code
	else
		# assume we are running from the test dir
		BUILD_PATH="`pwd`/../../"
	fi
	
	# 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

	install_the_func
fi

# see if func is install
# see if funcd is install
find_the_func

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

stop_the_func
# see if funcd is running
# see if certmaster is installed
# see if cermtasterd is running

# setup certs
## see if we have certs set up properly



### probably do some stuff to test bad/no/malformed/unauthed certs as well

# see if we can connect to funcd with the overloard

# see what modules we have available
# for each module, call the info stuff on them

# / start walking over the modules, doing commandliney stuff to each, and
# trying to check return data and return code as much as possible 

# test shut down of init scripts