Commit 890c180b authored by Leigh B Stoller's avatar Leigh B Stoller

Export a very Emulab specific function; InjectEvent. This is a gateway

into the per-experiment event scheduler for the experiment underneath
the sliver. An example of how to use this is the new test script
called injectevent.py, which you run like:

users> injectevent.py now geni1-program start COMMAND='/bin/ls >& /tmp/foo'

which injects an event for the program agent on your geni1 node.

Note that you have to contact the specfic CM for the node; if you have
multiple nodes spread across several CMs, you have to call this method
at the CM where the node lives.
parent 1b84c1dc
......@@ -1130,11 +1130,11 @@ sub GetTicketAuxAux($$$$$$$$$)
# Stub program agent.
$virtexperiment->NewTableRow("virt_programs",
{"vnode" => $node_nickname,
"vname" => "program",
"vname" => "${node_nickname}-program",
"command" => ""});
$virtexperiment->NewTableRow("virt_agents",
{"vnode" => $node_nickname,
"vname" => "program",
{"vnode" => $node_nickname,
"vname" => "${node_nickname}-program",
"objecttype" => "4"});
# Store reference so we can munge it below.
......
......@@ -55,6 +55,7 @@ my $CREATEEXPT = "$TB/bin/batchexp";
my $ENDEXPT = "$TB/bin/endexp";
my $NALLOC = "$TB/bin/nalloc";
my $NFREE = "$TB/bin/nfree";
my $TEVC = "$TB/bin/tevc";
my $AVAIL = "$TB/sbin/avail";
my $PTOPGEN = "$TB/libexec/ptopgen";
my $TBSWAP = "$TB/bin/tbswap";
......@@ -2093,5 +2094,82 @@ sub Credential2SliceAggregate($)
return ($slice, $aggregate);
}
#
# Emulab specific function to inject events into the experiment event scheduler.
#
sub InjectEvent($)
{
my ($argref) = @_;
my $slice_urn = $argref->{'slice_urn'};
my $credentials = $argref->{'credentials'};
my $time = $argref->{'time'};
my $name = $argref->{'name'};
my $event = $argref->{'event'};
my $args = "";
my $waitmode = 0;
if (! (defined($credentials) && defined($slice_urn))) {
return GeniResponse->MalformedArgsResponse("Missing arguments");
}
if (! (defined($time) && defined($name) && defined($event))) {
return GeniResponse->MalformedArgsResponse("Missing arguments");
}
if (! ($time eq "now" || $time =~ /^\+\d*$/)) {
return GeniResponse->MalformedArgsResponse("Improper time argument");
}
if (! ($name =~ /^[-\w]*$/)) {
return GeniResponse->MalformedArgsResponse("Improper name argument");
}
if (! ($event =~ /^[-\w]*$/)) {
return GeniResponse->MalformedArgsResponse("Improper event argument");
}
if (exists($argref->{'args'})) {
if (ref($argref->{'args'}) ne "ARRAY") {
return
GeniResponse->MalformedArgsResponse("Improper args argument");
}
my @args = @{ $argref->{'args'} };
# Sanitize for shell.
foreach my $arg (@args) {
$arg =~ s/(')/'\\''/g;
$args .= "'$arg' ";
}
}
$waitmode = 1
if (exists($argref->{'waitmode'}) && $argref->{'waitmode'});
my $credential = CheckCredentials($credentials);
return $credential
if (GeniResponse::IsResponse($credential));
my ($slice, $aggregate) = Credential2SliceAggregate($credential);
return $slice
if (defined($slice) && GeniResponse::IsResponse($slice));
if (! (defined($slice) && defined($aggregate))) {
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"Sliver does not exist");
}
if ($slice_urn ne $slice->urn()) {
return GeniResponse->Create(GENIRESPONSE_FORBIDDEN(), undef,
"Credential does not match the URN");
}
my $experiment = $slice->GetExperiment();
if (!defined($experiment)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"No local experiment for slice");
}
my $pid = $experiment->pid();
my $eid = $experiment->eid();
my $opt = ($waitmode ? "-w" : "");
my $output =
GeniUtil::ExecQuiet("$TEVC $opt -e $pid/$eid $time $name $event $args");
if ($?) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef, $output);
}
return GeniResponse->Create(GENIRESPONSE_SUCCESS);
}
# _Always_ make sure that this 1 is at the end of the file...
1;
#! /usr/bin/env python
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2011 University of Utah and the Flux Group.
# All rights reserved.
#
# Permission to use, copy, modify and distribute this software is hereby
# granted provided that (1) source code retains these copyright, permission,
# and disclaimer notices, and (2) redistributions including binaries
# reproduce the notices in supporting documentation.
#
# THE UNIVERSITY OF UTAH ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
# CONDITION. THE UNIVERSITY OF UTAH DISCLAIMS ANY LIABILITY OF ANY KIND
# FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#
#
#
import sys
import pwd
import getopt
import os
import time
import re
ACCEPTSLICENAME=1
debug = 0
impotent = 1
rspec = None
execfile( "test-common.py" )
if len(REQARGS) < 3:
Usage()
sys.exit(1)
pass
#
# Get a credential for myself, that allows me to do things at the SA.
#
mycredential = get_self_credential()
print "Got my SA credential"
#
# Lookup slice.
#
params = {}
params["credential"] = mycredential
params["type"] = "Slice"
params["hrn"] = SLICENAME
rval,response = do_method("sa", "Resolve", params)
if rval:
Fatal("No such slice at SA");
pass
else:
#
# Get the slice credential.
#
print "Asking for slice credential for " + SLICENAME
myslice = response["value"]
slicecred = get_slice_credential( myslice, mycredential )
print "Got the slice credential"
pass
print "Injecting the event ..."
params = {}
params["slice_urn"] = SLICEURN
params["credentials"] = (slicecred,)
params["time"] = REQARGS[0]
params["name"] = REQARGS[1]
params["event"] = REQARGS[2]
if (len(REQARGS) > 3):
params["args"] = [REQARGS[3]]
pass
rval,response = do_method("cm", "InjectEvent", params, version="2.0")
if rval:
Fatal("Could not inject event")
pass
......@@ -75,6 +75,7 @@ elsif ($GENI_VERSION eq "2.0") {
"ListUsage" => \&GeniCMV2::ListUsage,
"ListHistory" => \&GeniCMV2::ListHistory,
"ReserveVlanTags" => \&GeniCMV2::ReserveVlanTags,
"InjectEvent" => \&GeniCMV2::InjectEvent,
};
}
......
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