Commit 340f10a4 authored by Kevin Atkinson's avatar Kevin Atkinson

Add support for returning more detailed information in the case of a

swap failure in the xmlrpc server.  To use it, the extra option
"extrainfo" needs to be set to true.  This will cause "value" to be a
structure (in the XML-RPC sence) with useful information instead of
just the exit value of the script.  The structure will contain at
least the following fields:
  cause: "temp", "user", etc
  cause_desc
  mesg: more specific error information
  exitval: script return value
  log: activity log
Note, that value may still be an integer in the case of some other
failure that is not swap related.

To support this, the "-X" option was added to swapexp and batchexp
which will output a RPC-XML method response to stdout when possible.
parent 752040a4
......@@ -9,6 +9,7 @@ use Getopt::Std;
use POSIX qw(isatty setsid);
use POSIX qw(strftime);
use Errno qw(EDQUOT);
use RPC::XML;
#
# Create an experiment. The experiment is either run immediately, or
......@@ -59,7 +60,7 @@ sub CheckCopyArgs();
sub CopyInArchive();
sub fatal($;$);
my $optlist = "iE:g:e:p:S:L:a:l:sfwqt:nzc:bx:y:h:jkN"; # Enough options?
my $optlist = "iE:g:e:p:S:L:a:l:sfwqt:nzc:bx:y:h:jkNX"; # Enough options?
my $batchmode= 1;
my $frontend = 0;
my $waitmode = 0;
......@@ -163,6 +164,7 @@ my $committed = 0;
my $experiment;
my $copy_experiment;
my $noemail = 0;
my $xmlout = 0;
#
# Verify user and get his DB uid and other info for later.
......@@ -565,7 +567,22 @@ if (my $childpid = TBBackGround($logname)) {
if ($exit_code != 0) {
my $d = tblog_lookup_error();
print tblog_format_error($d);
my $output = tblog_format_error($d);
if ($xmlout) {
use libtblog '*SOUT'; # to avoid an unnecessary, and large,
# log entry
if (open(IN, "$logname")) {
$d->{log} = '';
while (<IN>) {
$d->{log} .= $_;
}
close IN;
}
$d->{output} = $output;
print SOUT RPC::XML::response->new($d)->as_string(), "\n";
} else {
print $output;
}
}
exit $exit_code;
......@@ -1170,6 +1187,10 @@ sub ParseArgs()
if (defined($options{"N"})) {
$noemail = 1;
}
if (defined($options{"X"})) {
$quiet = 1;
$xmlout = 1;
}
}
#
......
......@@ -9,6 +9,7 @@
use English;
use Getopt::Std;
use POSIX qw(isatty setsid);
use RPC::XML;
#
# This gets invoked from the Web interface.
......@@ -33,7 +34,7 @@ sub usage()
"<nsfile> - Optional NS file to parse for experiment modify\n");
exit(-1);
}
my $optlist = "biafres:wqxgN";
my $optlist = "biafres:wqxgNX";
#
# Exit codes are important; they tell the web page what has happened so
......@@ -112,6 +113,7 @@ my $modifySwapped = 0;
my $robotexp = 0;
my $template_node = 0;
my $noemail = 0;
my $xmlout = 0;
my $inout;
my $logfile;
......@@ -189,6 +191,10 @@ if (defined($options{"x"})) {
if (defined($options{"N"})) {
$noemail = 1;
}
if (defined($options{"X"})) {
$quiet = 1;
$xmlout = 1;
}
if (defined($options{"s"})) {
$inout = $options{"s"};
......@@ -854,9 +860,23 @@ if (! $batch && ! $template_mode && !$genimode) {
if ($exit_code != 0) {
my $d = tblog_lookup_error();
print tblog_format_error($d);
my $output = tblog_format_error($d);
if ($xmlout) {
use libtblog '*SOUT'; # to avoid an unnecessary, and large,
# log entry
if (open(IN, "$logname")) {
$d->{log} = '';
while (<IN>) {
$d->{log} .= $_;
}
close IN;
}
$d->{output} = $output;
print SOUT RPC::XML::response->new($d)->as_string(), "\n";
} else {
print $output;
}
}
exit $exit_code;
}
......
......@@ -1133,6 +1133,7 @@ class experiment:
nsfilename = None
argstr = "-q"
extrainfo = False
for opt, val in argdict.items():
if opt == "batch":
......@@ -1217,14 +1218,32 @@ class experiment:
argstr += " -N "
pass
pass
elif opt == "extrainfo":
if xbool(val):
argstr += " -X "
extrainfo = True
pass
pass
pass
if nsfilename:
argstr += " " + nsfilename
pass
(exitval, output) = runcommand(TBDIR + "/bin/batchexp " + argstr)
if exitval:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
if extrainfo:
try:
value = xmlrpclib.loads(output)[0][0]
except:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
value["exitval"] = exitval >> 8
output = value["output"]
del value["output"]
return EmulabResponse(RESPONSE_ERROR, value, output=output)
else:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
return EmulabResponse(RESPONSE_SUCCESS, output=output)
......@@ -1270,6 +1289,8 @@ class experiment:
output="direction must be 'in' or 'out'");
argstr = "-q"
extrainfo = False
for opt, val in argdict.items():
if opt == "wait":
if xbool(val):
......@@ -1281,6 +1302,12 @@ class experiment:
argstr += " -N "
pass
pass
elif opt == "extrainfo":
if xbool(val):
argstr += " -X "
extrainfo = True
pass
pass
pass
argstr += " -s " + escapeshellarg(argdict["direction"])
......@@ -1289,7 +1316,17 @@ class experiment:
(exitval, output) = runcommand(TBDIR + "/bin/swapexp " + argstr)
if exitval:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
if extrainfo:
try:
value = xmlrpclib.loads(output)[0][0]
except:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
value["exitval"] = exitval >> 8
output = value["output"]
del value["output"]
return EmulabResponse(RESPONSE_ERROR, value, output=output)
else:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
return EmulabResponse(RESPONSE_SUCCESS, output=output)
......@@ -1326,6 +1363,7 @@ class experiment:
nsfilename = None
argstr = "-q"
extrainfo = False
for opt, val in argdict.items():
if opt == "wait":
......@@ -1364,6 +1402,12 @@ class experiment:
argstr += " -N "
pass
pass
elif opt == "extrainfo":
if xbool(val):
argstr += " -X "
extrainfo = True
pass
pass
pass
argstr += " -s modify"
......@@ -1376,7 +1420,17 @@ class experiment:
(exitval, output) = runcommand(TBDIR + "/bin/swapexp " + argstr)
if exitval:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
if extrainfo:
try:
value = xmlrpclib.loads(output)[0][0]
except:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
value["exitval"] = exitval >> 8
output = value["output"]
del value["output"]
return EmulabResponse(RESPONSE_ERROR, value, output=output)
else:
return EmulabResponse(RESPONSE_ERROR, exitval >> 8, output=output)
return EmulabResponse(RESPONSE_SUCCESS, output=output)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment