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
|
#!/bin/bash
set +e
set -u
set -x
on_exit() {
# Exit Handler
if [ -z ${RETCODE} ] || [ ${RETCODE} != 0 ]; then
[ ! -z "$machine_name" ] && [ -d "$SHARED_IMG_PATH"/"$machine_name" ] && delete_vm $machine_name
exit "${RETCODE:=1}"
else
echo SUCCESS!!!!
exit 0
fi
}
delete_vm() {
# $1: machine name to delete
sudo virsh destroy $1 && sudo virsh undefine $1
}
trap on_exit EXIT INT QUIT ABRT PIPE TERM
usage() {
# Display script usage
cat<<EOF
Usage: $(basename $0) [OPTIONS...]
Run a specified iso test using utah
Options:
-h, --help This help.
-t, --test The test to execute.
-r, --release The image release to use.
-v, --variant The variant to use, can be: desktop, server.
-a, --arch The arch to use: amd64, i386.
-i, --iso The ISO file to test (optional)
EOF
exit 1
}
machine_name="${machine_name:-}"
machine_prefix="${machine_prefix:-}"
iso="${iso:-}"
TEMP=$(getopt -o ht:r:v:a:i: --long help,test:,release:,variant:,arch:,iso: -- "$@")
eval set -- "$TEMP"
while true ; do
case "$1" in
-h|--help)
usage;;
-t|--test)
test=$2
shift 2;;
-r|--release)
release=$2
shift 2;;
-v|--variant)
variant=$2
shift 2;;
-a|--arch)
arch=$2
shift 2;;
-i|--iso)
iso=$2
shift 2;;
--) shift ; break ;;
*) usage;;
esac
done
cd $WORKSPACE
#TODO: Packaging for this?
bzr export scripts lp:ubuntu-test-cases/$variant/scripts
export SHARED_IMG_PATH=/var/lib/utah/vm
# Create custom configuration file and separate per-job log files
UTAH_CONFIG_DIR="$WORKSPACE/config"
mkdir -p "$UTAH_CONFIG_DIR"
UTAH_CONFIG_FILE="$UTAH_CONFIG_DIR/utah.cfg"
LOG_DIR="$WORKSPACE/log"
mkdir -p "$LOG_DIR"
chmod a+w "$LOG_DIR"
UTAH_LOG_FILE="$LOG_DIR/utah-server.log"
UTAH_DEBUGLOG_FILE="$LOG_DIR/utah-server-debug.log"
UTAH_SSH_LOG_FILE="$LOG_DIR/utah-server-ssh.log"
cat <<EOF > "$UTAH_CONFIG_FILE"
{
"debuglog": "$UTAH_DEBUGLOG_FILE",
"logfile": "$UTAH_LOG_FILE",
"ssh_logfile": "$UTAH_SSH_LOG_FILE",
"logpath": "$LOG_DIR"
}
EOF
for file in "$UTAH_LOG_FILE" "$UTAH_DEBUGLOG_FILE" "$UTAH_SSH_LOG_FILE"; do
touch $file
chmod a+w $file
done
if [ -n "$iso" ]; then
cmd="./scripts/$test.sh -i $iso"
else
cmd="./scripts/$test.sh -i /var/cache/utah/iso/$release-$variant-$arch.iso"
fi
if [ ! -z "$machine_prefix" ] ; then
machine_name="${machine_prefix}-$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)"
cmd="$cmd -n $machine_name"
rm -f $WORKSPACE/ust-parameters.txt
export PROPERTIES_FILE_PATH=$WORKSPACE/ust-parameters.txt
cat >> $PROPERTIES_FILE_PATH <<EOF
SHARED_IMG_PATH=$SHARED_IMG_PATH/$machine_name/disk0.qcow2
EOF
fi
case $arch in
ppc64el)
xml=default-vm-ppc64.xml
;;
s390x)
xml=default-vm-s390x.xml
;;
*)
xml=bridged-network-vm.xml
;;
esac
sudo -u utah -i UTAH_CONFIG_DIR=$UTAH_CONFIG_DIR $($cmd) -f /var/log/installer -x /etc/utah/$xml --outputpreseed > $LOG_DIR/utah-server-stdout.log
RETCODE=$?
[ ! -z "$machine_name" ] && sudo chmod 777 "$SHARED_IMG_PATH"/"$machine_name"/disk0.qcow2
# Make sure syslog file is readable to add it as artifact
[ -n "$(find "$LOG_DIR" -name '*.syslog.log')" ] && sudo chmod a+r "$LOG_DIR"/*.syslog.log
# Move yaml file directory to the workspace since it's not a log file, but a
# results file
[ -n "$(find "$LOG_DIR" -name '*.yaml')" ] && mv "$LOG_DIR"/*.yaml "$WORKSPACE"
if [ "$RETCODE" -gt "100" ] ; then # utah client had an error, probably a test failure
exit $RETCODE
elif [ "$RETCODE" -eq "0" ] ; then
echo "<testsuite><testcase classname=\"utah\" name=\"utah\"></testcase></testsuite>" > "$WORKSPACE"/utah.xml
else
echo "<testsuite><testcase classname=\"utah\" name=\"utah\"><failure>utah exited with status $RETCODE</failure></testcase></testsuite>" > "$WORKSPACE"/utah.xml
fi
|