source: branches/3.0/mondo/test/mondo-test

Last change on this file was 3174, checked in by bruno, 5 years ago
  • Increase wait time for VM in test
  • Property svn:executable set to *
File size: 8.0 KB
Line 
1#!/bin/bash
2#
3# MondoRescue test suite
4#
5# $Id$
6#
7# Copyright B. Cornec 2012
8# Provided under the GPL v2
9
10# First create a dummy account for testing
11# In order for this script to run well, you should have sudo access
12
13# You may have multiple distros here
14TESTVMDIST="rhel-6-x86_64"
15#TESTVMDIST="ubuntu-11.04-i386"
16#TESTVMDIST="debian-6.0-x86_64 ubuntu-11.04-i386 fedora-16-x86_64 opensuse-12.1-x86_64 mageia-2-i386 mandriva-2010.1-i386 rhel-6-x86_64 rhel-5-i386 fedora-17-i386 ubuntu-12.10-x86_64"
17VMCOMMADIST=`echo $TESTVMDIST | sed 's/ /,/g'`
18MRUSER=mrtest
19MRTEST="/users/$MRUSER"
20export PBPROJ=mondorescue
21
22# Sub function to handle execution as mrtest
23# doesn't change to the home dir of the user as su - can't be used to get env var correct
24sudomrtest() {
25
26cmd=$1
27msg=$2
28
29echo " "
30if [ _"$cmd" == _"/tmp/mrtestcmd" ]; then
31    echo "INFO (as $MRUSER): Now running `head -1 $cmd` [$msg]"
32else
33    echo "INFO (as $MRUSER): Now running $cmd [$msg]"
34fi
35sudo -n -E su - $MRUSER -c "$cmd"
36ret=$?
37if [ $ret -ne 0 ] && [ _"$msg" == _"" ]; then
38    echo "================================"
39    echo "ERROR: Command $cmd failed: $ret"
40    echo "================================"
41fi
42return $ret
43}
44
45sudocmd() {
46cmd=$1
47
48echo " "
49echo "INFO (as root): Now running $cmd"
50sudo -n $cmd
51ret=$?
52if [ $ret -ne 0 ]; then
53    echo "================================"
54    echo "ERROR: Command $cmd failed: $ret"
55    echo "================================"
56fi
57return $ret
58}
59
60# First start building for all these distro we want
61pb -p mondorescue -g -r branches/3.0 -m $VMCOMMADIST sbx2vm mondo mindi mindi-busybox
62
63sudocmd "rm -rf $MRTEST/* $MRTEST/.??*"
64sudocmd "rmdir $MRTEST"
65sudocmd "killall -u $MRUSER"
66sudocmd "userdel $MRUSER"
67sudocmd "useradd $MRUSER -d $MRTEST"
68sudocmd "grep -q $MRUSER /etc/sudoers"
69if [ $? -ne 0 ]; then
70    cat > /tmp/sudoers << EOF
71# This is for the $MRUSER account for the VM only
72$MRUSER ALL=NOPASSWD:/usr/sbin/mondoarchive
73$MRUSER ALL=NOPASSWD:/usr/bin/qemu-kvm
74EOF
75    sudocmd "cat /etc/sudoers /tmp/sudoers" | grep -v "INFO " > /tmp/sudoers2
76    sudocmd "chmod 440 /tmp/sudoers2"
77    sudocmd "chown root:root /tmp/sudoers2"
78    sudocmd "mv /tmp/sudoers2 /etc/sudoers"
79    rm -f /tmp/sudoers /tmp/sudoers2
80fi
81# Force $MRUSER (for now mruser hardcoded!) account passwd is pbtest
82sudocmd "perl -pi -e 's|^mrtest:.*|mrtest:$2a$08$2Q.tEty4v/fU0RyPeDelk.AjLAtXUXU3DpSs/l/8YrFmau1LJRCqC:15483:0:99999:7:::|' /etc/shadow"
83sudomrtest "echo export PBPROJ=$PBPROJ >> $MRTEST/.bash_profile"
84sudomrtest "env | grep PBPROJ"
85
86sudomrtest "mkdir -p $MRTEST/{ftp,vm,.ssh,mr/images}"
87sudocmd "grep -q $MRUSER /etc/exports"
88if [ $? -ne 0 ]; then
89    cat > /tmp/exports << EOF
90$MRTEST/mr  *(rw,no_root_squash,async,insecure)
91EOF
92    sudocmd "cat /etc/exports /tmp/exports" | grep -v "INFO " > /tmp/exports2
93    sudocmd "chmod 640 /tmp/exports2"
94    sudocmd "chown root:root /tmp/exports2"
95    sudocmd "mv /tmp/exports2 /etc/exports"
96    sudocmd "exportfs -a"
97    rm -f /tmp/exports2 /tmp/exports
98fi
99sudomrtest "chmod 700 $MRTEST/.ssh"
100
101sudomrtest "pb clean 2>&1 > /dev/null" 1
102
103cat > /tmp/.pbrc << EOF
104# Projects
105pbdefdir default = \$ENV{'HOME'}/mr
106pburl mondorescue = svn://svn.mondorescue.org/mondorescue/branches
107pbconfurl mondorescue = svn://svn.project-builder.org/pb/projects/mondorescue/pbconf
108pbprojdir mondorescue = $ENV{'HOME'}/mr/svn
109pbconfdir mondorescue = $ENV{'HOME'}/mr/pbconf
110sshhost mondorescue = localhost
111sshlogin mondorescue = $MRUSER
112sshdir mondorescue = \$ENV{'HOME'}/ftp
113#
114pbpackager default = Big Chief <bigchief@hp.com>
115vmport mondorescue = 2300
116pbparallel mondorescue = 6
117vmpath default = $MRTEST/vm
118EOF
119sudocmd "mv /tmp/.pbrc $MRTEST/.pbrc"
120
121cat > /tmp/.pbrc << EOF
122vmtype default = kvm
123vmcmd default = qemu-kvm
124vmsize fedora = 10G
125vmmonport default = 4000
126vmlogin default = $MRUSER
127vmmem default = 1024
128EOF
129echo "vmlist default = $VMCOMMADIST" >> /tmp/.pbrc
130sudocmd "mv /tmp/.pbrc $MRTEST/vm/.pbrc"
131
132sudocmd "chown ${MRUSER}:$MRUSER $MRTEST/.pbrc $MRTEST/vm/.pbrc"
133
134sudocmd "cp -a /users/bruno/.ssh/pb* $MRTEST/.ssh"
135sudocmd "chown $MRUSER $MRTEST/.ssh/pb_dsa.pub $MRTEST/.ssh/pb_dsa"
136sudomrtest "chmod 600 $MRTEST/.ssh/pb*"
137sudomrtest "ssh-keygen -f $MRTEST/.ssh/id_rsa -t rsa -b 768 -v -N ''"
138sudomrtest "cp $MRTEST/.ssh/id_rsa.pub $MRTEST/.ssh/authorized_keys"
139sudomrtest "chmod 600 $MRTEST/.ssh/authorized_keys $MRTEST/.ssh/id_rsa.pub"
140sudomrtest "ssh localhost touch $MRTEST/ftp/README"
141
142for d in $TESTVMDIST; do
143    sudomrtest "qemu-img create -f qcow2 -b /users/qemu/$d.qemu $MRTEST/vm/$d.qemu"
144    #sudocmd "cp /users/qemu/$d.qemu $MRTEST/vm"
145    #sudocmd "chown $MRUSER:$MRUSER $MRTEST/vm/$d.qemu"
146    # pb isue workaround
147    sudomrtest "mkdir -p $MRTEST/mr/$PBPROJ/delivery"
148    sudomrtest "touch $MRTEST/mr/$PBPROJ/delivery/pbrc"
149    updcmd=`pbdistrocheck -s $d | cut -d, -f9`
150    dd=`echo $d | cut -d'-' -f1`
151    vv=`echo $d | cut -d'-' -f2`
152    aa=`echo $d | cut -d'-' -f3`
153    date=`date +%Y%m%d%H%M`
154    cat > /tmp/script << EOF
155#!/bin/bash
156#
157set -x
158echo "$updcmd" | grep -w yum
159if [ \$? -eq 0 ]; then
160    $updcmd nfs-utils
161    cd /etc/yum.repos.d
162    wget ftp://ftp.mondorescue.org/test/$dd/$vv/$aa/mondorescue-test.repo
163    wget ftp://ftp.mondorescue.org/$dd/$vv/$aa/mondorescue.repo
164    rpm --import ftp://ftp.mondorescue.org/$dd/$vv/$aa/mondorescue.pubkey
165    if [ -f /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release ]; then
166        # Import Red Hat keys for deps
167        rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
168    fi
169fi
170echo "$updcmd" | grep -w apt-get
171if [ \$? -eq 0 ]; then
172    $updcmd nfs-common
173    cd /etc/apt/sources.list.d
174    wget ftp://ftp.mondorescue.org/test/$dd/$vv/mondorescue-test.sources.list
175    wget ftp://ftp.mondorescue.org/$dd/$vv/mondorescue.sources.list
176    cat >> /etc/apt/preferences << EOT
177Package: mindi
178Pin: version 2.1.*
179Pin-Priority: 1001
180
181Package: mondo
182Pin: version 3.0.*
183Pin-Priority: 1001
184EOT
185fi
186
187$updcmd mondo
188
189TEMP_PATH=$MRTEST/mr/tmp
190SCRATCH_PATH=$MRTEST/mr/scratch
191
192NFS_HOST=10.0.2.2
193NFS_MOUNT=$MRTEST/mr
194MOUNT_PATH=/mnt
195
196mount | grep \$MOUNT_PATH | wc -l
197if [ \$? -ne 0 ]; then
198    umount \$MOUNT_PATH;
199fi
200
201# Relative path that will be used locally and remotely on the NFS server
202BCKUP_PATH=images
203
204if [ ! -d \$MOUNT_PATH ]; then
205    mkdir -p \$MOUNT_PATH;
206    echo "Mount directory \$MOUNT_PATH created"
207fi
208
209echo "Try to mount NFS point \$NFS_HOST:\$NFS_MOUNT on \$MOUNT_PATH..."
210
211mount \$NFS_HOST:\$NFS_MOUNT \$MOUNT_PATH
212if [ \$? -eq 0 ]; then
213    echo "NFS point \$NFS_HOST:\$NFS_MOUNT mounted on \$MOUNT_PATH"
214else
215    echo "Unable to mount \$NFS_HOST:\$NFS_MOUNT on \$MOUNT_PATH"
216    exit -1
217fi
218
219mkdir -p \$TEMP_PATH;
220echo "Temp directory \$TEMP_PATH created"
221
222mkdir -p \$SCRATCH_PATH;
223echo "Scratch directory \$SCRATCH_PATH created"
224
225if [ ! -d \$MOUNT_PATH/\$BCKUP_PATH ]; then
226    mkdir -p \$MOUNT_PATH/\$BCKUP_PATH;
227    echo "Backup directory \$MOUNT_PATH/\$BCKUP_PATH created"
228fi
229
230BCKUP_NAME=$d-$date
231echo "Backup name: \$BCKUP_NAME"
232
233CMD_LINE="mondoarchive -O -n \$NFS_HOST:\$NFS_MOUNT -p \$BCKUP_NAME -d \$BCKUP_PATH -s 4380m -S \$SCRATCH_PATH -T \$TEMP_PATH -G -N -E '/var/log|/usr/share/doc|/var/cache|/usr/src|/usr/share/texfm|/share/games|/usr/share/webmin|/var/tmp|/tmp' -H -z"
234echo "Will run command: \$CMD_LINE"
235
236\$CMD_LINE
237echo "Mondorescue terminated"
238
239umount \$MOUNT_PATH
240echo "Backup directory \$MOUNT_PATH unmounted"
241
242rm -rf \$TEMP_PATH
243echo "Temp directory \$TEMP_PATH removed"
244
245rm -rf \$SCRATCH_PATH
246echo "Scratch directory \$SCRATCH_PATH removed"
247
248echo "Backup over"
249
250echo "Halting system"
251halt -p
252EOF
253    chmod 755 /tmp/script
254    sudocmd "chmod 666 /dev/kvm"
255    #sudocmd "chmod 622 /dev/tty0"
256    port=2300
257    sudomrtest "qemu-kvm --nographic -m 2048 -redir tcp:${port}:10.0.2.15:22 $MRTEST/vm/$d.qemu"&
258    sleep 240
259    sudomrtest "scp -i $MRTEST/.ssh/pb_dsa -P $port /tmp/script root@localhost:"
260    sudomrtest "ssh -i $MRTEST/.ssh/pb_dsa -p $port root@localhost ./script"
261    sudomrtest "qemu-img create -f qcow2 $MRTEST/vm/$d.rest 8G"
262    sudomrtest "chmod 666 $MRTEST/vm/$d.rest"
263    #sudomrtest "ssh -i $MRTEST/.ssh/pb_dsa -p $port root@localhost /sbin/halt -p" &
264    /usr/bin/qemu-kvm -m 1024 -drive file=$MRTEST/vm/$d.rest,media=disk -redir tcp:2400:10.0.2.15:22 -boot d -cdrom $MRTEST/mr/images/$d-$date-1.iso
265    /usr/bin/qemu-kvm -m 1024 -drive file=$MRTEST/vm/$d.rest,media=disk -redir tcp:2400:10.0.2.15:22
266done
267
268# cleanup
269sudomrtest "pb clean"
270exit
Note: See TracBrowser for help on using the repository browser.