summaryrefslogtreecommitdiffstats
path: root/Tasks/distribution/beaker/setup/runtest.sh
blob: 9ec2ed88bc862719ebafbad74b92070b406045a8 (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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/bin/sh

# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material 
# is made available to anyone wishing to use, modify, copy, or
# redistribute it subject to the terms and conditions of the GNU General
# Public License v.2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Author: Bill Peck <bpeck@redhat.com>

# source the test script helpers
. /usr/bin/rhts-environment.sh

# Assume the test will fail.
result=FAIL

# Helper functions
# control where to log debug messages to:
# devnull = 1 : log to /dev/null
# devnull = 0 : log to file specified in ${DEBUGLOG}
devnull=0

# Create debug log
DEBUGLOG=`mktemp -p /mnt/testarea -t DeBug.XXXXXX`

# locking to avoid races
lck=$OUTPUTDIR/$(basename $0).lck

# Log a message to the ${DEBUGLOG} or to /dev/null
function DeBug ()
{
    local msg="$1"
    local timestamp=$(date '+%F %T')
    if [ "$devnull" = "0" ];then
	lockfile -r 1 $lck
	if [ "$?" = "0" ];then
	    echo -n "${timestamp}: " >>$DEBUGLOG 2>&1
	    echo "${msg}" >>$DEBUGLOG 2>&1
	    rm -f $lck >/dev/null 2>&1
	fi
    else
	echo "${msg}" >/dev/null 2>&1
    fi
}

function SubmitLog ()
{
    LOG=$1
    rhts_submit_log -S $RESULT_SERVER -T $TESTID -l $LOG
}

function result_fail()
{
    echo "***** End of runtest.sh *****" | tee -a $OUTPUTFILE
    report_result $TEST FAIL 1
    SubmitLog $DEBUGLOG
    CleanUp
    exit 0
}

function result_pass ()
{
    echo "***** End of runtest.sh *****" | tee -a $OUTPUTFILE
    report_result $TEST PASS 0
    CleanUp
    exit 0
}

function BuildBeaker ()
{
    yum install -y TurboGears python-setuptools-devel python-devel
    git clone git://git.fedorahosted.org/beaker
    pushd beaker
    make snaparchive
    make rpm
    popd
}

function InstallInventory_git()
{
    BuildBeaker
    yum install --nogpg -y  /rpmbuild/RPMS/noarch/beaker-server-*.rpm
}

function InstallInventory_repo()
{
    yum install -y beaker-server
}

function InstallLabController_git()
{
    BuildBeaker
    yum install --nogpg -y /rpmbuild/RPMS/noarch/beaker-lab-controller-*.rpm
}

function InstallLabController_repo()
{
    yum install -y beaker-lab-controller
}

function CleanUp ()
{
    echo "no clean up method yet"
}

#Function below will report if a prev command failed
function estatus_fail()
{
    if [ "$?" -ne "0" ];then
	DeBug "$1 Failed"
	echo "***** "$1" Failed: *****" | tee -a $OUTPUTFILE
        rhts-sync-set -s ABORT
	result_fail
    fi
}

function generate_beaker_cfg()
{
    cat << __EOF__ > /etc/beaker/server.cfg
[global]
# This is where all of your settings go for your production environment.
# You'll copy this file over to your production server and provide it
# as a command-line option to your start script.
# Settings that are the same for both development and production
# (such as template engine, encodings, etc.) all go in 
# beaker/server/config/app.cfg

# DATABASE

# pick the form for your database
# sqlobject.dburi="postgres://username@hostname/databasename"
# sqlobject.dburi="mysql://username:password@hostname:port/databasename"
# sqlobject.dburi="sqlite:///file_name_and_path"

# If you have sqlite, here's a simple default to get you started
# in development
#sqlalchemy.dburi="sqlite:///devdata.sqlite"
sqlalchemy.dburi="mysql://beaker:beaker@localhost/beaker"
sqlalchemy.pool_recycle = 3600


# if you are using a database or table type without transactions
# (MySQL default, for example), you should turn off transactions
# by prepending notrans_ on the uri
# sqlobject.dburi="notrans_mysql://username:password@hostname:port/databasename"

# for Windows users, sqlite URIs look like:
# sqlobject.dburi="sqlite:///drive_letter:/path/to/file"


# Authentication

identity.provider='ldapsa'
identity.ldap.enabled=$LDAPENABLED
identity.soldapprovider.uri="ldaps://ldap.bos.redhat.com"
identity.soldapprovider.basedn="dc=redhat,dc=com"
identity.soldapprovider.autocreate=True
identity.krb_auth_principal='HTTP/$HOSTNAME@REDHAT.COM'
identity.krb_auth_keytab='/etc/httpd/conf/httpd.keytab'

# SERVER

server.socket_port=8084
server.environment="development"
server.webpath=""
server.log_file = "/var/log/beaker/server.log"
server.log_to_screen = True

autoreload.package="beaker.server"
tg.strict_parameters = True

# Sets the number of threads the server uses
# server.thread_pool = 1

# Set to True if you are deploying your App behind a proxy
# e.g. Apache using mod_proxy
# base_url_filter.on = False

# Set to True if your proxy adds the x_forwarded_host header
# base_url_filter.use_x_forwarded_host = True

# If your proxy does not add the x_forwarded_host header, set
# the following to the *public* host url.
# (Note: This will be overridden by the use_x_forwarded_host option
# if it is set to True and the proxy adds the header correctly.
# base_url_filter.base_url = "http://www.example.com"

tg.include_widgets = ['turbogears.mochikit']

[/static]
static_filter.on = True
static_filter.dir = "/usr/share/beaker/server/static"

[/favicon.ico]
static_filter.on = True
static_filter.file = "/usr/share/beaker/server/static/images/favicon.ico"

# LOGGING
# Logging configuration generally follows the style of the standard
# Python logging module configuration. Note that when specifying
# log format messages, you need to use *() for formatting variables.
# Deployment independent log configuration is in beaker/server/config/log.cfg
[logging]

[[handlers]]

[[[access_out]]]
# set the filename as the first argument below
args="('/var/log/beaker/server.log',)"
class='FileHandler'
level='INFO'
formatter='message_only'

[[loggers]]
[[[server]]]
level='ERROR'
qualname='beaker.server'
handlers=['error_out']

[[[access]]]
level='INFO'
qualname='turbogears.access'
handlers=['access_out']
propagate=0
__EOF__
}

function Inventory()
{
    # We only want the first one
    CLIENT=$(echo $CLIENTS| awk '{print $1}')
    PACKAGES="mysql-server MySQL-python python-twill"
    yum install -y $PACKAGES
    estatus_fail "**** Yum Install of $PACKAGES Failed ****"
    InstallInventory$SOURCE
    service mysqld start
    estatus_fail "**** Failed to start mysqld ****"

    echo "create database beaker;" | mysql || result_fail
    echo "grant all on beaker.* to 'beaker'@'localhost' IDENTIFIED BY 'beaker';" | mysql || result_fail

    if [ -z "$LDAPENABLED" ]; then
        LDAPENABLED="False"
    fi
    # Add in Kerberos config
    generate_beaker_cfg

    beaker-init -u admin -p testing -e $SUBMITTER
    estatus_fail "**** Failed to initialize beaker DB ****"
    # beaker-init creates the server.log as root.  this prevents apache from 
    #  working since it can't write to it.
    /bin/rm -f /var/log/beaker/server.log
    service iptables stop
    service httpd start
    estatus_fail "**** Failed to start httpd ****"
    # Add the lab controller
    ./add_labcontroller.py -l $CLIENT
    ./add_user.py -u host/$CLIENT
    estatus_fail "**** Failed to add lab controller ****"
    rhts-sync-set -s READY
    rhts-sync-block -s DONE -s ABORT $CLIENT
    result_pass 
}

function LabController()
{
    # We only want the first one
    SERVER=$(echo $SERVERS| awk '{print $1}')
    ipaddress=$(host $HOSTNAME | awk '{print $NF}')
    yum install -y python-twill
    InstallLabController$SOURCE
    chkconfig httpd on
    chkconfig xinetd on
    chkconfig tftp on
    chkconfig cobblerd on
    #FIXME edit /etc/cobbler/settings
     perl -pi -e "s|^server: 127.0.0.1|server: $HOSTNAME|g" /etc/cobbler/settings
     perl -pi -e "s|^next_server: 127.0.0.1|next_server: $ipaddress|g" /etc/cobbler/settings
     perl -pi -e "s|^pxe_just_once: 0|pxe_just_once: 1|g" /etc/cobbler/settings
     perl -pi -e "s|^anamon_enabled: 0|anamon_enabled: 1|g" /etc/cobbler/settings
     perl -pi -e "s|^anamon_enabled: 0|anamon_enabled: 1|g" /etc/cobbler/settings
     perl -pi -e "s|^redhat_management_server: .*|redhat_management_server: \"https://testuser:testpassword\@$SERVER\"|g" /etc/cobbler/settings
    #FIXME edit /etc/cobbler/modules.conf
     # enable testing auth module
     perl -pi -e "s|^module = authn_denyall|module = authn_testing|g" /etc/cobbler/modules.conf
    setsebool -P httpd_can_network_connect true
    semanage fcontext -a -t public_content_t "/var/lib/tftpboot/.*"
    semanage fcontext -a -t public_content_t "/var/www/cobbler/images/.*"
    service httpd start
    service xinetd start
    service cobblerd start
    #service autofs start
    service iptables stop
    rhts-sync-set -s READY
    abort=$(rhts-sync-block -s READY -s ABORT $SERVER)
    echo "abort=$abort"
    # Add some distros
    # NFS format HOSTNAME:DISTRONAME:NFSPATH
    if [ -z "$NFSDISTROS" ]; then
        echo "Missing NFS Distros to test with" | tee -a $OUTPUTFILE
        report_result $TEST Warn
        exit 1
    fi
    ln -s /fakenet /var/www/html/fakenet
    for distro in $NFSDISTROS; do
        NFSSERVER=$(echo $distro| awk -F: '{print $1}')
        DISTRONAME=$(echo $distro| awk -F: '{print $2}')
        NFSPATH=$(echo $distro| awk -F: '{print $3}')
        NFSDIR=$(dirname $NFSPATH)
        mkdir -p /fakenet/${NFSSERVER}${NFSDIR}
        mount ${NFSSERVER}:${NFSDIR} /fakenet/${NFSSERVER}${NFSDIR}
        result="FAIL"
        echo cobbler import --path=/fakenet/${NFSSERVER}${NFSPATH} \
                       --name=${DISTRONAME}_nfs \
                       --available-as=nfs://${NFSSERVER}:${NFSPATH}
        cobbler import --path=/fakenet/${NFSSERVER}${NFSPATH} \
                       --name=${DISTRONAME}_nfs \
                       --available-as=nfs://${NFSSERVER}:${NFSPATH}
        score=$?
        if [ "$score" -eq "0" ]; then
            result="PASS"
        fi
        report_result $TEST/ADD_DISTRO/${DISTRONAME}_NFS $result $score
        result="FAIL"
        echo cobbler import --path=/fakenet/${NFSSERVER}${NFSPATH} \
                       --name=${DISTRONAME}_http \
                       --available-as=http://${HOSTNAME}/fakenet/${NFSSERVER}${NFSPATH}
        cobbler import --path=/fakenet/${NFSSERVER}${NFSPATH} \
                       --name=${DISTRONAME}_http \
                       --available-as=http://${HOSTNAME}/fakenet/${NFSSERVER}${NFSPATH}
        score=$?
        if [ "$score" -eq "0" ]; then
            result="PASS"
        fi
        report_result $TEST/ADD_DISTRO/${DISTRONAME}_HTTP $result $score
    done
    # Import Rawhide
    if [ -n "$RAWHIDE_NFS" ]; then
        NFSSERVER=$(echo $RAWHIDE_NFS| awk -F: '{print $1}')
        NFSDIR=$(echo $RAWHIDE_NFS| awk -F: '{print $2}')
        mkdir -p /fakenet/${NFSSERVER}${NFSDIR}
        mount ${NFSSERVER}:${NFSDIR} /fakenet/${NFSSERVER}${NFSDIR}
        for distro in $(find /fakenet/${NFSSERVER}${NFSDIR} -maxdepth 1 -name rawhide\* -type d); do 
            DISTRO=$(basename $distro)
            DISTRONAME=Fedora-$(basename $distro)
            result="FAIL"
            echo cobbler import \
                           --path=/fakenet/${NFSSERVER}${NFSDIR}/${DISTRO} \
                           --name=${DISTRONAME}_nfs \
                           --available-as=nfs://${NFSSERVER}:${NFSDIR}/${DISTRO}
            cobbler import --path=/fakenet/${NFSSERVER}${NFSDIR}/${DISTRO} \
                           --name=${DISTRONAME}_nfs \
                           --available-as=nfs://${NFSSERVER}:${NFSDIR}/${DISTRO}
            score=$?
            if [ "$score" -eq "0" ]; then
                result="PASS"
            fi
            report_result $TEST/ADD_DISTRO/${DISTRONAME}_NFS $result $score
            echo cobbler import \
                            --path=/fakenet/${NFSSERVER}${NFSDIR}/${DISTRO} \
                           --name=${DISTRONAME}_http \
                           --available-as=http://${HOSTNAME}/fakenet/${NFSSERVER}${NFSDIR}/${DISTRO}
            cobbler import --path=/fakenet/${NFSSERVER}${NFSDIR}/${DISTRO} \
                           --name=${DISTRONAME}_http \
                           --available-as=http://${HOSTNAME}/fakenet/${NFSSERVER}${NFSDIR}/${DISTRO}
            score=$?
            if [ "$score" -eq "0" ]; then
                result="PASS"
            fi
            report_result $TEST/ADD_DISTRO/${DISTRONAME}_NFS $result $score
        done
    fi
    cobbler distro report
    /var/lib/cobbler/triggers/sync/post/osversion.trigger | tee -a $OUTPUTFILE
    estatus_fail "**** Failed to run osversion.trigger ****"
    rhts-sync-set -s DONE
    result_pass 
}

if [ -z "$SERVERS" -o -z "$CLIENTS" ]; then
    echo "Can not determine my Role! Client/Server Failed:" | tee -a $OUTPUTFILE
    echo "If you are running in developer mode try setting" | tee -a $OUTPUTFILE
    echo "the environment variables CLIENTS and SERVERS"    | tee -a $OUTPUTFILE
    report_result $TEST Warn
fi

if $(echo $CLIENTS | grep -q $HOSTNAME); then
    echo "Running test as Lab Controller" | tee -a $OUTPUTFILE
    TEST="$TEST/lab_controller"
    LabController
fi

if $(echo $SERVERS | grep -q $HOSTNAME); then
    echo "Running test as Inventory" | tee -a $OUTPUTFILE
    TEST="$TEST/inventory"
    Inventory
fi