[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH OSSTEST v2 1/2] tcl: Handle environment variables which are unset.



This allows wrappers such as the standalone wrapper to do
     OSSTEST_SIMULATE=$foo ./sg-run-job
and not worry if $foo is unset.

Do likewise for OSSTEST_TCL_JOBDB_DEBUG.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
v2:
- Was: "sg-run-job: Only consider $OSSTEST_SIMULATE > 0"
- Insert before "standalone: Add --dry-run option for run-job."
- Use var-or-default from Ian J
---
 sg-run-job              | 2 +-
 tcl/JobDB-Executive.tcl | 2 +-
 tcl/osstestlib.tcl      | 6 ++++++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/sg-run-job b/sg-run-job
index 0ec314f..eae159d 100755
--- a/sg-run-job
+++ b/sg-run-job
@@ -159,7 +159,7 @@ proc spawn-ts {iffail testid args} {
     jobdb::spawn-step-commit $flight $jobinfo(job) $stepno $testid
 
     set xprefix {}
-    if {[info exists env(OSSTEST_SIMULATE)]} { set xprefix echo }
+    if {[var-or-default env(OSSTEST_SIMULATE) 0]} { set xprefix echo }
 
     set log [jobdb::step-log-filename $flight $jobinfo(job) $stepno $ts]
     set redirects {< /dev/null}
diff --git a/tcl/JobDB-Executive.tcl b/tcl/JobDB-Executive.tcl
index 430ea84..7228712 100644
--- a/tcl/JobDB-Executive.tcl
+++ b/tcl/JobDB-Executive.tcl
@@ -117,7 +117,7 @@ proc db-update-1 {stmt} {
 }
 
 proc db-execute-debug {stmt} {
-    if {[info exists env(OSSTEST_TCL_JOBDB_DEBUG)]} {
+    if {[var-or-default env(OSSTEST_TCL_JOBDB_DEBUG) 0]} {
        puts stderr "EXECUTING >$stmt<"
     }
 }
diff --git a/tcl/osstestlib.tcl b/tcl/osstestlib.tcl
index a0413c4..61a6a09 100644
--- a/tcl/osstestlib.tcl
+++ b/tcl/osstestlib.tcl
@@ -74,3 +74,9 @@ proc lshift {listvar} {
     set list [lrange $list 1 end]
     return $head
 }
+
+proc var-or-default {varname {default {}}} {
+    upvar 1 $varname var
+    if {[info exists var]} { return $var }
+    return $default
+}
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.