tbprerun.in 2.07 KB
Newer Older
1
#!/usr/bin/perl -w
2
use English;
3 4 5

# tbprerun

Leigh B. Stoller's avatar
Leigh B. Stoller committed
6 7 8 9 10
# This is the first program in the
# tbprerun/tbswapin/tbswapout/.../tbend sequences.  It's main purpose
# is to interpret the NS file and create the appropriate entries in
# virt_nodes and virt_lans.  After this script ends successfully the
# NS file is no longer necessary.
11

12 13 14 15
#
# Configure variables
#
my $TBROOT   = "@prefix@";
16

17
# Untaint the path
Leigh B. Stoller's avatar
Leigh B. Stoller committed
18 19 20
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" . 
    ":$TBROOT/sbin:$TBROOT/bin";

21 22 23
#
# Testbed Support libraries
#
24
use lib "@prefix@/lib";
25 26
use libdb;
use libtestbed;
27

28 29 30 31
#
# Turn off line buffering on output
#
$| = 1;
32

33 34
if ($#ARGV != 2) {
    print STDERR "Syntax: $0 pid eid ns_file\n";
35 36
    exit(1);
}
37
my ($pid,$eid,$nsfile) = @ARGV;
38 39

if (! -r $nsfile) {
40
    print STDERR "*** NS File '$nsfile' does not exist!\n";
41 42 43
    exit(1);
}

44 45 46 47 48 49
my $state;

print "Beginning pre run for $pid/$eid. " . TBTimeStamp() . "\n";

if (! ($state = ExpState($pid, $eid))) {
    print STDERR "*** No such experiment $pid/$eid\n";
50 51
    exit(1);
}
52 53
if ($state ne EXPTSTATE_NEW) {
    print STDERR "*** Experiment is not in the proper state: $state\n";
54 55
    exit(1);
}
56 57
if (! SetExpState($pid, $eid, EXPTSTATE_PRERUN)) {
    print STDERR "*** Failed to set intermediate experiment state.\n";
58 59 60
    exit(1);
}

61 62 63
#
# Cleanup if something goes wrong. 
# 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
64
sub cleanup {
65 66 67 68 69
    print STDERR "Cleaning up after errors.\n";
    DBQueryWarn("DELETE from virt_nodes where pid='$pid' and eid='$eid'");
    DBQueryWarn("DELETE from virt_lans  where pid='$pid' and eid='$eid'");
    SetExpState($pid, $eid, EXPTSTATE_NEW);
}
70

Leigh B. Stoller's avatar
Leigh B. Stoller committed
71 72
# This setups virt_nodes, virt_names including all IP address calculation
# and tb-* handling.
73 74 75 76
print "Running parser ... " . TBTimeStamp() . "\n";
if (system("parse.tcl $pid $eid $nsfile")) {
    print STDERR "*** Parsing failed.\n";
    cleanup();
77 78
    exit(1);
}
79
print "Parser done! Marking as prerunned. " . TBTimeStamp() . "\n";
80

81 82 83
if (!SetExpState($pid, $eid, EXPTSTATE_SWAPPED)) {
    print STDERR "*** Failed to set experiment state!\n";
    cleanup();
84 85 86
    exit(1);
}

87 88
print "Pre run finished. " . TBTimeStamp() . "\n";
exit(0);
89