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

Last change on this file since 3016 was 3016, checked in by Bruno Cornec, 8 years ago
  • Substitue a complex awk expression by a more simpler perl one in analyze-my-lvm
  • Fix a bug on RHEL 5 where lvdisplay doesn't support redirection. Adds a | cat in between, as was done for vgdisplay
  • Property svn:executable set to *
File size: 7.8 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
14#TESTVMDIST="rhel-6-x86_64"
15TESTVMDIST="rhel-5-x86_64"
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"
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
61sudocmd "rm -rf $MRTEST/* $MRTEST/.??*"
62sudocmd "rmdir $MRTEST"
63sudocmd "killall -u $MRUSER"
64sudocmd "userdel $MRUSER"
65sudocmd "useradd $MRUSER -d $MRTEST"
66sudocmd "grep -q $MRUSER /etc/sudoers"
67if [ $? -ne 0 ]; then
68    cat > /tmp/sudoers << EOF
69# This is for the $MRUSER account for the VM only
70$MRUSER ALL=NOPASSWD:/usr/sbin/mondoarchive
71$MRUSER ALL=NOPASSWD:/usr/bin/qemu-kvm
72EOF
73    sudocmd "cat /etc/sudoers /tmp/sudoers" | grep -v "INFO " > /tmp/sudoers2
74    sudocmd "chmod 440 /tmp/sudoers2"
75    sudocmd "chown root:root /tmp/sudoers2"
76    sudocmd "mv /tmp/sudoers2 /etc/sudoers"
77    rm -f /tmp/sudoers /tmp/sudoers2
78fi
79# Force $MRUSER (for now mruser hardcoded!) account passwd is pbtest
80sudocmd "perl -pi -e 's|^mrtest:.*|mrtest:$2a$08$2Q.tEty4v/fU0RyPeDelk.AjLAtXUXU3DpSs/l/8YrFmau1LJRCqC:15483:0:99999:7:::|' /etc/shadow"
81sudomrtest "echo export PBPROJ=$PBPROJ >> $MRTEST/.bash_profile"
82sudomrtest "env | grep PBPROJ"
83
84sudomrtest "mkdir -p $MRTEST/{ftp,vm,.ssh,mr/images}"
85sudocmd "grep -q $MRUSER /etc/exports"
86if [ $? -ne 0 ]; then
87    cat > /tmp/exports << EOF
88$MRTEST/mr  *(rw,no_root_squash,async,insecure)
89EOF
90    sudocmd "cat /etc/exports /tmp/exports" | grep -v "INFO " > /tmp/exports2
91    sudocmd "chmod 640 /tmp/exports2"
92    sudocmd "chown root:root /tmp/exports2"
93    sudocmd "mv /tmp/exports2 /etc/exports"
94    sudocmd "exportfs -a"
95    rm -f /tmp/exports2 /tmp/exports
96fi
97sudomrtest "chmod 700 $MRTEST/.ssh"
98
99sudomrtest "pb clean 2>&1 > /dev/null" 1
100
101cat > /tmp/.pbrc << EOF
102# Projects
103pbdefdir default = \$ENV{'HOME'}/mr
104pburl mondorescue = svn://svn.mondorescue.org/mondorescue/branches
105pbconfurl mondorescue = svn://svn.project-builder.org/pb/projects/mondorescue/pbconf
106pbprojdir mondorescue = $ENV{'HOME'}/mr/svn
107pbconfdir mondorescue = $ENV{'HOME'}/mr/pbconf
108sshhost mondorescue = localhost
109sshlogin mondorescue = $MRUSER
110sshdir mondorescue = \$ENV{'HOME'}/ftp
111#
112pbpackager default = Big Chief <bigchief@hp.com>
113vmport mondorescue = 2300
114pbparallel mondorescue = 6
115vmpath default = $MRTEST/vm
116EOF
117sudocmd "mv /tmp/.pbrc $MRTEST/.pbrc"
118
119cat > /tmp/.pbrc << EOF
120vmtype default = kvm
121vmcmd default = qemu-kvm
122vmsize fedora = 10G
123vmmonport default = 4000
124vmlogin default = $MRUSER
125vmmem default = 1024
126EOF
127echo "vmlist default = $VMCOMMADIST" >> /tmp/.pbrc
128sudocmd "mv /tmp/.pbrc $MRTEST/vm/.pbrc"
129
130sudocmd "chown ${MRUSER}:$MRUSER $MRTEST/.pbrc $MRTEST/vm/.pbrc"
131
132sudocmd "cp -a /users/bruno/.ssh/pb* $MRTEST/.ssh"
133sudocmd "chown $MRUSER $MRTEST/.ssh/pb_dsa.pub $MRTEST/.ssh/pb_dsa"
134sudomrtest "chmod 600 $MRTEST/.ssh/pb*"
135sudomrtest "ssh-keygen -f $MRTEST/.ssh/id_rsa -t rsa -b 768 -v -N ''"
136sudomrtest "cp $MRTEST/.ssh/id_rsa.pub $MRTEST/.ssh/authorized_keys"
137sudomrtest "chmod 600 $MRTEST/.ssh/authorized_keys $MRTEST/.ssh/id_rsa.pub"
138sudomrtest "ssh localhost touch $MRTEST/ftp/README"
139
140#pb -r branches/3.0 -m $VMCOMMADIST sbx2vm
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    cd /etc/yum.repos.d
161    wget ftp://ftp.mondorescue.org/test/$dd/$vv/$aa/mondorescue-test.repo
162    wget ftp://ftp.mondorescue.org/$dd/$vv/$aa/mondorescue.repo
163    rpm --import ftp://ftp.mondorescue.org/$dd/$vv/$aa/mondorescue.pubkey
164    if [ -f /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release ]; then
165        # Import Red Hat keys for deps
166        rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
167    fi
168fi
169echo "$updcmd" | grep -w apt-get
170if [ \$? -eq 0 ]; then
171    cd /etc/apt/sources.list.d
172    wget ftp://ftp.mondorescue.org/test/$dd/$vv/mondorescue-test.sources.list
173    wget ftp://ftp.mondorescue.org/$dd/$vv/mondorescue.sources.list
174    cat >> /etc/apt/preferences << EOT
175Package: mindi
176Pin: version 2.1.*
177Pin-Priority: 1001
178
179Package: mondo
180Pin: version 3.0.*
181Pin-Priority: 1001
182EOT
183fi
184
185$updcmd mondo
186
187TEMP_PATH=$MRTEST/mr/tmp
188SCRATCH_PATH=$MRTEST/mr/scratch
189
190NFS_HOST=10.0.2.2
191NFS_MOUNT=$MRTEST/mr
192MOUNT_PATH=/mnt
193
194mount | grep \$MOUNT_PATH | wc -l
195if [ \$? -ne 0 ]; then
196    umount \$MOUNT_PATH;
197fi
198
199# Relative path that will be used locally and remotely on the NFS server
200BCKUP_PATH=images
201
202if [ ! -d \$MOUNT_PATH ]; then
203    mkdir -p \$MOUNT_PATH;
204    echo "Mount directory \$MOUNT_PATH created"
205fi
206
207echo "Try to mount NFS point \$NFS_HOST:\$NFS_MOUNT on \$MOUNT_PATH..."
208
209mount \$NFS_HOST:\$NFS_MOUNT \$MOUNT_PATH
210if [ \$? -eq 0 ]; then
211    echo "NFS point \$NFS_HOST:\$NFS_MOUNT mounted on \$MOUNT_PATH"
212else
213    echo "Unable to mount \$NFS_HOST:\$NFS_MOUNT on \$MOUNT_PATH"
214    exit -1
215fi
216
217mkdir -p \$TEMP_PATH;
218echo "Temp directory \$TEMP_PATH created"
219
220mkdir -p \$SCRATCH_PATH;
221echo "Scratch directory \$SCRATCH_PATH created"
222
223if [ ! -d \$MOUNT_PATH/\$BCKUP_PATH ]; then
224    mkdir -p \$MOUNT_PATH/\$BCKUP_PATH;
225    echo "Backup directory \$MOUNT_PATH/\$BCKUP_PATH created"
226fi
227
228BCKUP_NAME=$d-$date
229echo "Backup name: \$BCKUP_NAME"
230
231CMD_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"
232echo "Will run command: \$CMD_LINE"
233
234\$CMD_LINE
235echo "Mondorescue terminated"
236
237umount \$MOUNT_PATH
238echo "Backup directory \$MOUNT_PATH unmounted"
239
240rm -rf \$TEMP_PATH
241echo "Temp directory \$TEMP_PATH removed"
242
243rm -rf \$SCRATCH_PATH
244echo "Scratch directory \$SCRATCH_PATH removed"
245
246echo "Backup over"
247
248echo "Halting system"
249#halt -p
250EOF
251    chmod 755 /tmp/script
252    sudocmd "chmod 666 /dev/kvm"
253    #sudocmd "chmod 622 /dev/tty0"
254    port=2300
255    sudomrtest "qemu-kvm --nographic -m 1024 -redir tcp:${port}:10.0.2.15:22 $MRTEST/vm/$d.qemu"&
256    sleep 60
257    sudomrtest "scp -i $MRTEST/.ssh/pb_dsa -P $port /tmp/script root@localhost:"
258    sudomrtest "ssh -i $MRTEST/.ssh/pb_dsa -p $port root@localhost ./script"
259    sudomrtest "qemu-img create -f qcow2 $MRTEST/vm/$d.rest 8G"
260    sudomrtest "chmod 666 $MRTEST/vm/$d.rest"
261    #sudomrtest "ssh -i $MRTEST/.ssh/pb_dsa -p $port root@localhost /sbin/halt -p" &
262    /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
263    /usr/bin/qemu-kvm -m 1024 -drive file=$MRTEST/vm/$d.rest,media=disk -redir tcp:2400:10.0.2.15:22
264done
265
266# cleanup
267sudomrtest "pb clean"
268exit
Note: See TracBrowser for help on using the repository browser.