sg-run-job: Document run-ts and spawn-ts argument syntaxes
PATCH 6/6 Debian: Pass sylog server details to debian-installer
In reply to Ian JacksonThis logs the installer output, even during a failed install.
--- Osstest/Debian.pm | 5 +++++ 1 file changed, 5 insertions(+)
Osstest/Debian.pm +5 -0
@@ -690,6 +690,11 @@ sub di_installcmdline_core ($$;@) { if defined $debconf_priority; push @cl, "rescue/enable=true" if $xopts{RescueMode}; + if ($r{syslog_server}) { + $r{syslog_server} =~ m/:(\d+)$/ or die "$r{syslog_server} ?"; + push @cl, "log_host=$`", "log_port=$1"; + } + return @cl; }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 5/6 sg-run-job: Spawn ts-syslog-server
In reply to Ian JacksonEvery job now gets a syslog server, which starts up after host allocation.
The server's address and port are recorded by ts-syslog-server in a runvar and can be used by subsequent test steps.
--- sg-run-job | 4 ++++ 1 file changed, 4 insertions(+)
sg-run-job +4 -0
@@ -73,6 +73,8 @@ proc run-job {job} { if {$ok} { setstatus running } + set syslog [spawn-ts !broken . ts-syslog-server] + per-host-ts broken host-install/@(*) ts-host-install-twice per-host-prep
@@ -93,6 +95,8 @@ proc run-job {job} { run-ts !broken capture-logs ts-logs-capture + host } + reap-ts $syslog + if {$ok} { if {[jobdb::job-check-escaped-steps $flight $job]} { set ok 0
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 4/6 ts-syslog-server: New test script
In reply to Ian JacksonThis is a "complete implementation of the UDP syslog protocol".
In fact, the UDP syslog protocol is trivial: the UDP packets contain newline-terminated unix text strings. We can simply chomp them and log them (along with the sending address and port).
This script is designed to be run with the new "|" spawn-ts mode: it will keep running until it is reaped.
Currently it is not part of any jobs.
--- ts-syslog-server | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 ts-syslog-server
ts-syslog-server new file +85 -0
@@ -0,0 +1,85 @@ +#!/usr/bin/perl -w +# This is part of "osstest", an automated testing framework for Xen. +# Copyright (C) 2009-2013 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/>. + +use strict; + +unshift @INC, qw(.); +use Osstest; +use Osstest::TestSupport; + +use POSIX; +use Fcntl; +use Socket qw(PF_INET SOCK_DGRAM INADDR_ANY + pack_sockaddr_in unpack_sockaddr_in inet_aton inet_ntoa); + +tsreadconfig(); + +die if @ARGV && $ARGV[0] =~ m/^-/; + +logm("starting syslog server ..."); + +socket S, PF_INET, SOCK_DGRAM, 0 or die $!; + +my $sockname = pack_sockaddr_in(0, inet_aton(controller_ipaddr())); +bind S, $sockname or die $!; +$sockname = getsockname S or die $!; +my ($port,$myaddr) = unpack_sockaddr_in($sockname) or die $!; +$myaddr = inet_ntoa($myaddr); + +store_runvar('syslog_server',"$myaddr:$port"); + +my @fhs = qw(S STDIN); + +foreach my $fh (@fhs) { + my $fl = fcntl($fh, F_GETFL, 0) // die $!; + fcntl($fh, F_SETFL, $fl | O_NONBLOCK) // die $!; +} + +logm("syslog server running on $myaddr:$port"); + +for (;;) { + my $rfds = ''; + foreach my $fh (@fhs) { + vec($rfds, fileno($fh), 1) = 1; + } + my $efds = $rfds; + select($rfds, undef, $efds, undef); + if (vec($rfds, fileno(STDIN), 1)) { + my $d; + my $r = sysread STDIN, $d, 1; + if (defined $r) { + die "read something from stdin!" if $r>0; + last; + } else { + die $! unless $!==EAGAIN || $!==EWOULDBLOCK; + } + } + if (vec($rfds, fileno(S), 1)) { + my $d; + my $sender = recv S, $d, 1024, 0; + if (defined $sender) { + my ($sport,$saddr) = unpack_sockaddr_in($sender) or die $!; + $saddr = inet_ntoa($saddr) // die $!; + chomp $d; + logm("$saddr:$sport $d"); + } else { + die $! unless $!==EAGAIN || $!==EWOULDBLOCK; + } + } +} + +logm("stopping.");
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/6 sg-run-job: Document run-ts and spawn-ts argument syntaxes
--- sg-run-job | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+)
sg-run-job +93 -0
@@ -146,6 +146,99 @@ proc testid_matches_globs {testid globs} { #---------- test script handling ---------- +# spwan-ts IFFAIL TESTID SCRIPT-ARGS... +# +# Spawns the test script as a test step, and leaves it running. +# Returns token to pass to reap-ts. +# +# reap-ts TOKEN [WANTSTATUS] +# +# Waits for the test script to finish. +# +# The step status is set to "pass" (if the script exits zero) or +# IFFAIL (otherwise). (But it is not set if the script, +# or something else, already set it to "aborted" or "broken".) +# +# Return value is true if that step status matches the glob +# WANTSTATUS (which defaults to "pass"). Test failures do not +# become Tcl exceptions and do not affect other test execution. +# +# run-ts IFFAIL TESTID SCRIPT-ARGS... +# +# Runs the test script, waiting for it to finish. +# The step status is set as for reap-ts. +# +# If that step status is not "pass", throws a Tcl exception. +# +# Normally (eg, within the recipe), an exception causes the job +# to be stopped as a failure (and proceed to log collection). +# Specifically: +# "ok" is set to "0" (which prevents most other +# general steps from running) +# The job status is set to IFFAIL. +# +# per-host-ts IFFAIL TESTID SCRIPT-ARGS... +# +# Runs the script (as a separate step) for each test host ident. +# The host ident is appended to SCRIPT-ARGS. (SCRIPT-ARGS +# should contain an even number of + items for proper testid +# generation.) +# +# The scripts are run in parallel for all host idents. +# +# If any of the step statuses is not "pass", sets the job +# status to IFFAIL and stops the job as a failure (as above). +# +# IFFAIL can be +# +# [-][!]. +# [-][!]STATUS +# +# where STATUS is the job/step status to be used if the step +# status is not as expected, and the special meanings are: +# +# - Only for run-ts; suprresses exception on failure. +# ! Run this even if the "ok" is false (ie after failure) +# . Shorthand for "fail" +# +# TESTID specifies the unique ID for this test step. +# +# The testid must be unique within the job; but for steps which +# actual tests (ie, which might be subject to regression +# analsysis, or bisection) must be stable - ie, it must not +# change due to races nor due to future osstest changes. +# Normally this is acheived by computing it from the +# SCRIPT-ARGS by specifying something involving "=" or "/@". +# +# TESTID is processed with some substitutions (in this order): +# +# = at the start is replaced with "SCRIPTBASIS/@" +# where SCRIPTBASIS is the first entry in SCRIPT-ARGS +# with ts- removed. +# +# * as the whole TESTID is replaced with "SCRIPTBASIS/@(*)" +# +# /@ anywhere is replaced with "/ARG/ARG..." +# (ie, "/ARG" for each ARG in SCRIPT-ARGS after the +# script name, but see note about "+" in SCRIPT-ARGS, +# below.) +# +# (*) at the end is replaced by (STEPNO) +# where STEPNO is the step number within the job (which +# is unique within the job, but not stable). +# +# SCRIPT-ARGS is the script name and its arguments, but is also +# subject to some special processing: +# +# The script name should not include the ./ which is necessary +# to find the script in the current directory. This will be +# added implicitly. +# +# An argument which is precisely "+" toggles whether the +# subsequent items in SCRIPT-ARGS are added to the expansion of +# /@ in TESTID. (The "+" itself is not added to the arguments +# or the testid.) + proc run-ts {iffail args} { set wantstatus pass if {[regsub {^-} $iffail {} iffail]} { set wantstatus * }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 3/6 TestSupport: Provide controller_ipaddr
--- Osstest/TestSupport.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Osstest/TestSupport.pm +10 -1
@@ -92,7 +92,7 @@ BEGIN { git_massage_url sshopts authorized_keys - cfg_tftp_di_version + cfg_tftp_di_version controller_ipaddr remote_perl_script_open remote_perl_script_done host_reboot target_reboot target_reboot_hard target_choose_vg target_umount_lv target_await_down
@@ -2401,6 +2401,15 @@ sub cfg_tftp_di_version ($) { return $c{"TftpDiVersion_$suite"} // $c{TftpDiVersion}; } +sub controller_ipaddr () { + my $addr = $c{ControllerIpAddress}; + return $addr if defined $addr; + $?=$!=0; my $hn = `hostname -f` // die "$? $!"; + chomp $hn; + my $ip = gethostbyname($hn) // die "$hn ?"; + return inet_ntoa($ip); +} + #---------- webspace for installer ---------- sub await_webspace_fetch_byleaf ($$$$$) {
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/6 sg-run-job: Support scripts which need to be told when to quit
In reply to Ian JacksonWe give them a pipe on stdin, whose writing end we close when we want to reap them.
--- sg-run-job | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
sg-run-job +17 -2
@@ -234,6 +234,11 @@ proc testid_matches_globs {testid globs} { # to find the script in the current directory. This will be # added implicitly. # +# If the very first item is "|" (before the script name), the +# script will get a pipe as its standard input rather than +# /dev/null; this pipe will give EOF when sg-run-job wants to +# end the script (ie, when reap-ts is called). +# # An argument which is precisely "+" toggles whether the # subsequent items in SCRIPT-ARGS are added to the expansion of # /@ in TESTID. (The "+" itself is not added to the arguments
@@ -289,6 +294,12 @@ proc spawn-ts {iffail testid args} { set real_args {} set adding 1 set testid_args {} + set child_pipe_mode r + + if {![string compare | [lindex $args 0]]} { + set child_pipe_mode w + lshift args + } foreach arg $args { if {![string compare + $arg]} { set adding [expr {!$adding}]
@@ -335,12 +346,16 @@ proc spawn-ts {iffail testid args} { 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} + set redirects {} if {[string length $log]} { lappend redirects 2> $log } else { lappend redirects 2>@ stderr } + switch -exact $child_pipe_mode { + r { lappend redirects < /dev/null } + w { lappend redirects >@ stderr } + } set cmd [concat \ [list sh -xc "
@@ -353,7 +368,7 @@ proc spawn-ts {iffail testid args} { exit \$rc " x $testid ./$ts] \ $real_args $redirects] - set fh [open |$cmd r] + set fh [open |$cmd $child_pipe_mode] return [list fh $fh $details] }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel