nodenetwork sequels
[tests.git] / system / selftest
1 #!/bin/bash
2
3 SELF_HOST=$1
4 SELF_IP=$2
5 # all below addresses are those of the qemu host
6 [ -z "$SELF_HOST" ] && SELF_HOST="selftest.$(hostname)"
7 [ -z "$SELF_IP"   ] && SELF_IP="10.1.159.48"
8
9
10 ####################################################
11 # setup MyPLC
12
13 # install from repo
14 rpm -q myplc-native > /dev/null
15 installed=$?
16 [ $installed -eq 1 ] && yum -y install myplc-native
17
18 # setup qemu to run the node from the bootcd
19 rpm -q qemu > /dev/null
20 installed=$?
21 [ $installed -eq 1 ] && yum -y install qemu
22
23
24 exit 0
25
26
27 # make sure its stopped
28 service plc stop
29
30 # turn off plc until its been configured
31 chkconfig plc off
32
33 ####################################################
34 # configure myplc for testing purposes
35 config=$(mktemp)
36
37 function genpassword()
38 {
39         len=$1
40         [ -z "$len" ] && len=8
41         python <<EOF
42 import crypt, random, string
43 salt = [random.choice(string.letters + string.digits + "./") for i in range(0,$len)]
44 print "".join(salt)
45 EOF
46 }
47
48 # create new 16 char random password
49 PW=$(genpassword 16)
50
51 cat > $config <<EOF
52 e PLC_ROOT_PASSWORD
53 $PW
54
55 e PLC_NAME
56 selftest
57
58 e PLC_ROOT_USER
59 root@localhost.localdomain
60
61 e PLC_MAIL_ENABLED
62 0
63
64 e PLC_MAIL_SUPPORT_ADDRESS
65 build@lists.planet-lab.org
66
67 e PLC_DB_HOST
68 $SELF_HOST
69
70 e PLC_API_HOST
71 $SELF_HOST
72
73 e PLC_WWW_HOST
74 $SELF_HOST
75
76 e PLC_BOOT_HOST
77 $SELF_HOST
78
79 e PLC_DB_IP
80 $SELF_IP
81
82 e PLC_API_IP
83 $SELF_IP
84
85 e PLC_WWW_IP
86 $SELF_IP
87
88 e PLC_BOOT_IP
89 $SELF_IP
90
91 w
92 q
93 EOF
94
95 plc-config-tty < $config
96
97 echo "$PW" > /etc/planetlab/pw
98 chmod 400 /etc/planetlab/pw
99
100 # remove temporary config file
101 rm -f $config
102
103 service plc start
104
105 ####################################################
106 QA_TESTSUITE="qaapi"
107 SVNPATH="http://svn.planet-lab.org/svn/"
108
109 # check out test suite
110 # temporarily disabling -- mef
111 #svn export ${SVNPATH}/tests/trunk/${QA_TESTSUITE} /tmp/${QA_TESTSUITE}
112 #cd /tmp/${QA_TESTSUITE}/
113 #chmod +x runtests.py
114 #chmod +x qa/tests/*
115 #./runtests.py
116
117 ####################################################
118 # configure a site and a node @ the local myplc for qemu testing
119
120 # configure a selftest site
121 TESTVERS="3.4"
122 TESTHOST="qemu-1.$(hostname)"
123 TESTSITE="st"
124 TESTNAME="Self Test"
125 TESTABR="selftest"
126 TESTURL="http://selftest.doesnotexist"
127 TESTDISK="/selftest.img"
128 TESTCONF="/selftest.txt"
129 config=$(mktemp)
130 cat > $config <<EOF
131 # create a test site
132 DeleteSite("$TESTSITE")
133 AddSite({"name":"$TESTNAME","url":"$TESTURL","max_slices":10,"login_base":"$TESTSITE","is_public":True,"abbreviated_name":"$TESTABR"})
134 # create a test node for qemu
135 AddNode("st",{"boot_state":"rins","model":"qemu/minhw","hostname":"$TESTHOST","version":"$TESTVERS"})
136 # set up the interface setting for qemu
137 AddInterface("$TESTHOST",{"network":"10.0.2.0","hostname":"$TESTHOST","is_primary":True,"dns1":"$SELF_IP","method":"static","type":"ipv4","netmask":"255.255.255.0","broadcast":"10.0.2.255","gateway":"10.0.2.2"})
138 # Download the node's boot cd iso
139 GetBootMedium("$TESTHOST","node-floppy","$TESTCONF")
140 EOF
141 cat $config | plcsh
142 rm -f $config
143
144 # generate custom iso
145 SERIAL="ttyS0:115200:n:8"
146 /usr/share/bootcd/build.sh -s $SERIAL -O selftest -f $TESTCONF -t iso_cramfs
147 SNAME=$(echo $SERIAL | sed 's,:,,g')
148 TESTISO="./selftest-serial-$SNAME-cramfs.iso"
149
150 qemu-img create -f qcow $TESTDISK 5GB
151
152 # run qemu
153 # -nographic -> for serial line console
154 # -boot d -> to boot from cdrom 
155 # -cdrom -> specifies iso file to serve as cdrom
156 # -m 512 -> 512MB memory
157
158 [ -f "$TESTDISK" -a -f "$TESTISO" ] && qemu-system-x86_64 -boot d -nographic -m 512 -cdrom $TESTISO $TESTDISK
159
160 # run node tests
161
162 exit 0