Commit 4eb62dcb authored by Gary Wong's avatar Gary Wong

Add a test-reserve utility to help debug the reservation scheduler.

parent cf8c4d5a
......@@ -57,7 +57,7 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
node_exclude managetaint shutdown-shared imagerelease \
runsonxen pxelinux_makeconf attend atten \
addrfdevice addrfpath reserve announce createimagealias \
predict
predict test-reserve
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webwanodecheckin webspewimage webdumpdescriptor webemulabfeature \
......
#!/usr/bin/perl -w
#
# Copyright (c) 2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file 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 file 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 file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use strict;
use English;
use Getopt::Std;
use Date::Parse;
use POSIX;
use Data::Dumper;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use emdb;
use libtestbed;
use Project;
use Reservation;
sub usage()
{
print STDERR "Usage: test-reserve -t type -d\n" .
" test-reserve -t type -r\n" .
" -d Dump schedule\n" .
" -r Read and verify schedule\n";
exit( -1 );
}
my $optlist = "drt:";
my $type;
my $dump = 0;
my $read = 0;
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:";
#
# Verify user, must be admin or root. (We "eval" stdin later on, so
# the user had better not only be admin or root but also very careful!)
#
my $this_user;
if ($UID) {
$this_user = User->ThisUser();
if (! defined($this_user)) {
die("You ($UID) do not exist!");
}
if (!$this_user->IsAdmin()) {
die("You are not a testbed administrator!");
}
}
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{h})) {
usage();
}
if (defined($options{d})) {
$dump = 1;
}
if (defined($options{r})) {
$read = 1;
}
if (defined($options{t})) {
$type = $options{t};
unless( $type =~ /^[-\w]+$/ ) {
die( "Invalid node type." );
}
}
usage() if( @ARGV || !defined( $type ) );
if( $dump ) {
my $reservations = Reservation->LookupAll( $type );
print Dumper( $reservations );
}
if( $read ) {
local $/ = undef;
my $dumped = <>;
my $VAR1;
my $error;
eval $dumped;
if( Reservation->IsFeasible( $VAR1, \$error ) ) {
print "Schedule is feasible.\n";
exit( 0 );
} else {
print "Schedule is not feasible: $error\n";
exit( 1 );
}
}
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