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