Skip to contentSkip to conversation

standalone: refactor out some useful bits of standalone-reset

PATCH In review Ian Campbell 2 participants 5 messages Mar 21, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 standalone: refactor out some useful bits of standalone-reset

I sometimes want just these bits.

I went with a new "sa" prefix, but I left standalone-reset alone since it is already reasonably well known.

---
v2: correct usage and argument parsing

---
 README           |  3 +++
 sa-forget-flight | 39 +++++++++++++++++++++++++++++++++++++++
 sa-init-db       | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 standalone-reset | 30 ++----------------------------
 4 files changed, 100 insertions(+), 28 deletions(-)
 create mode 100755 sa-forget-flight
 create mode 100755 sa-init-db
README +3 -0
index a4d5aac..9a85549 100644
@@ -158,6 +158,9 @@ sg-*:   ?
 
 ts-*:   Test Step scripts.
 
+sa-*:	Standalone mode.
+
+
 Jobs
 ====
 
sa-forget-flight new file +39 -0
new file mode 100755
index 0000000..8b005f1
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2014 Citrix Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+usage(){
+	cat <<END
+usage: ./sa-forget-flight <database> <flight>
+END
+}
+
+if [ $# -ne 2 ] ; then
+	usage >&2
+	exit 1
+fi
+
+db="$1"
+flight="$2"
+
+sqlite3 "$db" <<END
+	DELETE FROM runvars WHERE flight='$flight';
+	DELETE FROM jobs    WHERE flight='$flight';
+	DELETE FROM flights WHERE flight='$flight';
+END
sa-init-db new file +56 -0

56 lines not on this page · raw message

standalone-reset +2 -28
index e978b6b..09c0269 100755
@@ -131,35 +131,9 @@ case $# in
 esac
 
 if test -f standalone.db; then
-	sqlite3 standalone.db <<END
-		DELETE FROM runvars WHERE flight='$flight';
-		DELETE FROM jobs    WHERE flight='$flight';
-		DELETE FROM flights WHERE flight='$flight';
-END
+	./sa-forget-flight standalone.db "$flight"
 else
-	sqlite3 standalone.db <<END
-		CREATE TABLE flights (
-			flight TEXT PRIMARY KEY,
-			blessing TEXT,
-			intended TEXT,
-			branch TEXT
-			);
-		CREATE TABLE jobs (
-			flight TEXT NOT NULL,
-			job TEXT NOT NULL,
-			recipe TEXT NOT NULL,
-			status TEXT NOT NULL,
-			PRIMARY KEY(flight,job)
-			);
-		CREATE TABLE runvars (
-			flight TEXT NOT NULL,
-			job TEXT NOT NULL,
-			name TEXT NOT NULL,
-			val TEXT NOT NULL,
-			synth BOOLEAN NOT NULL,
-			PRIMARY KEY(flight,job,name)
-			);
-END
+	./sa-db-init standalone.db
 fi
 
 : ${BUILD_LVEXTEND_MAX:=50}
Signature · 1 line
1.8.5.2
#1 lore raw

PATCH v2 2/2 standalone mode convenience frontend

I can never remember all the various env vars which I can/should set so this tool provides a command line veneer over the basics.

It also does some sanity checks for things which keep tripping me up (inability to read apache logs, lack of ssh-agent) which fail in more or less obscure ways.

---
v2: Remove redundant use of env
Add a helper for logging and error checking
Log the make-flight output

---
 standalone | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 232 insertions(+)
 create mode 100755 standalone
standalone new file +232 -0
new file mode 100755
index 0000000..ab4f2bc
@@ -0,0 +1,232 @@
+#!/bin/bash
+
+set -e
+
+usage() {
+    cat >&2 <<EOF
+usage: standalone [operations] [options...]
+
+Operations:
+
+* make-flight [cf] [BRANCH]
+
+  Create a flight testing the named branch.
+
+* set-paths [cf] [JOB]
+
+  Setup dist path runvars for JOB from existing build results. Useful
+  after recreating a flight to avoid the need to rebuild.
+
+* run-job [cfhrR] [JOB]
+
+  Run the named JOB.
+
+  Required options: -h HOST
+
+* run-test [cfhrR] [JOB] [TEST]
+
+  Run the named TEST as part of JOB.
+
+  Required options: -h HOST
+
+Options:
+
+-c FILE, --config=FILE        Use FILE as configuration file
+-f FLIGHT, --flight=FLIGHT    Operate on FLIGHT
+-h HOST, --host=HOST          Test host
+-r, --reuse                   Do not wipe test host (default)
+-R, --noreuse, --noreinstall  Wipe the test host (if job or test does so)
+
+--help                        This message
+
+EOF
+}
+
+if [ $# -lt 1 ] ; then
+    echo "Need an operation" >&2
+    usage
+    exit 1
+fi
+
+op=$1 ; shift
+
+if [ x$op = x--help ] ; then
+    usage
+    exit 0
+fi
+
+TEMP=$(getopt -o c:f:h:rR --long config:,flight:,host:,reuse,noreuse,reinstall,help -- "$@")
+
+eval set -- "$TEMP"
+
+config=
+flight="standalone"
+host=
+reuse=1 # Don't blow away machines by default
+
+while true ; do
+    case "$1" in
+	-c|--config) config=$2; shift 2;;
+	-f|--flight) flight=$2; shift 2;;
+	-h|--host)   host=$2;   shift 2;;
+	-r|--reuse)  reuse=1;   shift 1;;
+	-R|--noreuse|--reinstall)reuse=0;shift 1;;
+	--help)      usage; exit 0;;
+        --) shift ; break ;;
+        *) echo "Internal error!" ; exit 1 ;;
+
+    esac
+done
+
+if [ ! -r /var/log/apache2/access.log ] ; then
+    echo "WARNING: Cannot read apache logs. Some tests may fail" >&2
+fi
+
+if ! ssh-add -l >/dev/null ] ; then
+    echo "WARNING: Unable to access ssh-agent. Some tests may fail" >&2
+fi
+
+if [ $reuse -eq 0 ]; then
+    echo "WARNING: Will blow away machine..."
+    echo "Press ENTER to confirm."
+    read
+fi
+
+if [ ! -f standalone.db ] ; then
+    echo "No standalone.db? Run standalone-reset." >&2
+    exit 1
+fi
+
+need_flight() {
+    if [ -z "$flight" ] ; then
+	echo "run-job: Need a flight" >&2
+	exit 1
+    fi
+}
+need_host() {
+    if [ -z "$host" ] ; then
+	echo "run-job: Need a host" >&2
+	exit 1
+    fi
+}
+
+ensure_logs() {
+    if [ ! -d "logs" ] ; then
+	mkdir "logs"
+    fi
+    if [ ! -d "logs/$flight" ] ; then
+	mkdir "logs/$flight"
+    fi
+}
+
+with_logging() {
+    local log=$1; shift
+    $@ 2>&1 | tee "$log"
+    rc=${PIPESTATUS[0]}
+    if [ $rc -ne 0 ] ; then
+	echo "FAILED rc=${rc}" >&2
+    fi
+}
+
+# other potential ops:
+# - run standalone reset
+
+case $op in
+    help)
+        usage
+	exit 0
+	;;
+
+    make-flight)
+        need_flight
+
+        if [ $# -lt 1 ] ; then
+            echo "make-flight: Need branch" >&2
+            exit 1
+        fi
+
+        branch=$1; shift
+
+        DAILY_BRANCH_PREEXEC_HOOK=exit\ 0 \
+        OSSTEST_USE_HEAD=y \
+        BRANCHES_ALWAYS="$branch" \
+        OSSTEST_FLIGHT=$flight \
+        OSSTEST_CONFIG=$config \
+        OSSTEST_NO_BASELINE=y \
+            with_logging logs/$flight/make-flight.log ./cr-daily-branch $@ $branch
+        ;;
+
+    set-paths)
+	need_flight
+
+	if [ $# -lt 1 ] ; then
+	    echo "set-paths: Need job" >&2
+	    exit 1
+	fi
+
+#build-amd64                       path_dist                    build/dist.tar.gz                                               
+#build-amd64                       path_kerndist                build/kerndist.tar.gz                                           
+#build-amd64-pvops                 path_kerndist                build/kerndist.tar.gz                                           
+#build-amd64                       path_xendist                 build/xendist.tar.gz
+
+	job=$1; shift
+
+	for d in '' xen kern ; do
+	    runvar="path_${d}dist"
+ 	    path="build/${d}dist.tar.gz"
+	    if [ -f "logs/$flight/$job/$path" ] ; then
+		./cs-adjust-flight -v $flight runvar-set $job $runvar $path
+	    fi
+	done
+
+	if [ -f "logs/$flight/$job/build/kerndist.tar.gz" ] ; then
+	    KERNEL_VER=$(tar tzf logs/$flight/$job/build/kerndist.tar.gz |\
+		sed -n -e 's,^lib/modules/\(.*\)/modules.dep$,\1,p')
+	    if [ -n "$KERNEL_VER" ]; then
+		./cs-adjust-flight -v $flight \
+		    runvar-set $job kernel_ver $KERNEL_VER
+	    fi
+	fi
+	;;
+
+    run-job)
+	need_flight; need_host
+
+	if [ $# -lt 1 ] ; then
+	    echo "run-job: Need job" >&2
+	    exit 1
+	fi
+
+	job=$1; shift
+
+	ensure_logs
+
+        OSSTEST_CONFIG=$config \
+	OSSTEST_FLIGHT=$flight \
+	OSSTEST_HOST_HOST=$host \
+	OSSTEST_HOST_REUSE=$reuse \
+	    with_logging logs/$flight/$job.log ./sg-run-job $job
+	;;
+    run-test)
+	need_flight; need_host
+
+	if [ $# -lt 2 ] ; then
+	    echo "run-test: Need job + test" >&2
+	    exit 1
+	fi
+
+	job=$1; shift
+	ts=$1; shift
+
+	ensure_logs
+
+	OSSTEST_CONFIG=$config \
+	OSSTEST_FLIGHT=$flight \
+	OSSTEST_CONFIG=$config \
+	OSSTEST_HOST_REUSE=$reuse \
+	OSSTEST_JOB=$job \
+	    with_logging logs/$flight/$job.$ts.log ./$ts host=$host $@
+	;;
+    *)
+	echo "Unknown op $op" ; exit 1 ;;
+esac
Signature · 1 line
1.8.5.2
Acked-by on v2 2/2
#2 lore raw

Re: [PATCH OSSTEST v2 2/2] standalone mode convenience frontend

Ian Campbell writes ("[PATCH OSSTEST v2 2/2] standalone mode convenience frontend"):

Quoted 7 lines

I can never remember all the various env vars which I can/should set so this tool provides a command line veneer over the basics.

It also does some sanity checks for things which keep tripping me up (inability to read apache logs, lack of ssh-agent) which fail in more or less obscure ways.

Quoted 5 lines

---
v2: Remove redundant use of env
Add a helper for logging and error checking
Log the make-flight output

#3 lore raw

Re: [PATCH OSSTEST v2 2/2] standalone mode convenience frontend

Quoted 8 lines · Ian Jackson

Ian Campbell writes ("[PATCH OSSTEST v2 2/2] standalone mode convenience frontend"):

Quoted 7 lines

I can never remember all the various env vars which I can/should set so this tool provides a command line veneer over the basics.

It also does some sanity checks for things which keep tripping me up (inability to read apache logs, lack of ssh-agent) which fail in more or less obscure ways.

Quoted 7 lines
Quoted 5 lines

---
v2: Remove redundant use of env
Add a helper for logging and error checking
Log the make-flight output

Thanks I have applied both. git am complained about the whitespace in some leftover comments which shouldn't have been there anyway, so I've dropped them as I committed.

+#build-amd64                       path_dist                    build/dist.tar.gz                                               
+#build-amd64                       path_kerndist                build/kerndist.tar.gz                                           
+#build-amd64-pvops                 path_kerndist                build/kerndist.tar.gz                                           
+#build-amd64                       path_xendist                 build/xendist.tar.gz
Acked-by on v2 1/2
#4 lore raw
In reply to Ian Campbell

Ian Campbell writes ("[PATCH OSSTEST v2 1/2] standalone: refactor out some useful bits of standalone-reset"):

Quoted 4 lines

I sometimes want just these bits.

I went with a new "sa" prefix, but I left standalone-reset alone since it is already reasonably well known.

Thanks,