Commit f2888e91 authored by Leigh Stoller's avatar Leigh Stoller

Some fixes to deal with older templates that do not have a CVS repo.

On modify, create the repo, but add checks to make sure that we do not
bother with operations on branches that do not exist cause they
predate the repo creation. This allows you to move forward after a
modifying an existing template. Also add checks for instantiating a
old template that has no repo at all cause it has not been modified since
adding the repo support.

A few other fixes to make sure that instances are cleaned up after errors.
parent 438ccf09
......@@ -45,6 +45,7 @@ my $waitmode = 0;
my $modify = 0;
my $repotag;
my $repobase;
my $needrepoinit = 0;
my $frompath;
my $description;
my $pid;
......@@ -326,7 +327,10 @@ my $template_dir = $template->path();
#
# Set up CVS repo on ops to use as alternate interface.
#
if (!$modify) {
if (!$modify || ! -e $cvsdir) {
$needrepoinit = 1
if (! -e $cvsdir);
if (! mkdir("$cvsdir", 0777)) {
fatal(-1, "Could not mkdir $cvsdir: $!");
}
......@@ -564,11 +568,11 @@ if (! -e "$template_dir/datastore/.ignore") {
# When the template is first created, import an initial vendor branch
# into the CVS repo so that there is something there.
#
if (!$modify) {
if (!$modify || $needrepoinit) {
System("cd $template_dir; ".
"$CVSBIN -d $cvsdir import ".
" -m 'Initialize new cvs repo for template $guid' ".
" $guid/setup T${guid}-1_import_branch T${guid}-1_import")
" -m 'Initialize new cvs repo for template $guid' $guid/setup ".
" T${guid}-${vers}_import_branch T${guid}-${vers}_import")
== 0 or fatal(-1, "Could not import new template into $cvsdir");
#
......@@ -641,6 +645,15 @@ elsif (defined($repotag)) {
else {
mkdir("$tmpdir", 0777) or
fatal(-1, "Could not mkdir $tmpdir: $!");
#
# To support older templates, see if the parent is in the CVS repo.
# If not, skip all this.
#
System("$RLOG -h $cvsdir/$guid/setup/.template,v | ".
" grep -q 'T${parent_guid}-${parent_vers}:'");
goto noparent
if ($?);
#
# Create a branch off the parent template.
......@@ -668,15 +681,15 @@ else {
# Need to clear the -b (default branch) or else the merge
# commit fails for some reason that makes no sense to me.
System("cd $tmpdir/setup; $CVSBIN -d $cvsdir admin -b $guid")
== 0 or fatal(-1, "Could not clear default branch (-b) on $cvsdir");
System("cd $tmpdir/setup; $CVSBIN -d $cvsdir admin -b $guid") == 0
or fatal(-1, "Could not clear default branch (-b) on $cvsdir");
# Commit ...
System("cd $tmpdir/setup; $CVSBIN -d $cvsdir commit -f -R ".
" -r T${parent_guid}-${vers}_branch ".
" -m 'Commit merge with head'")
" -r T${parent_guid}-${vers}_branch ".
" -m 'Commit merge with head'")
== 0 or fatal(-1, "Could not commit on $cvsdir");
#
# Clear the default branch so that "update -A" takes user to trunk.
#
......@@ -684,11 +697,14 @@ else {
== 0 or fatal(-1, "Could not clear default branch in $cvsdir");
#
# Now tag the CVS repo with the current guid/vers so we can find it easily.
# Now tag the CVS repo with the current guid/vers so we can
# find it easily.
#
System("$CVSBIN -d $cvsdir rtag -n ".
" -r T${parent_guid}-${vers}_branch T${guid}-${vers} $guid/setup")
" -r T${parent_guid}-${vers}_branch T${guid}-${vers} ".
" $guid/setup")
== 0 or fatal(-1, "Could not rtag final version in $cvsdir");
noparent:
}
System("/bin/rm -rf $tmpdir")
if (-e $tmpdir);
......@@ -856,6 +872,7 @@ sub ParseArgs()
}
if (defined($options{"f"})) {
tbdie("Commit from instance/template not supported right now!");
$frompath = $options{"f"};
# The Archive library has a nice routine to validate this path.
......
......@@ -762,16 +762,12 @@ sub ParseArgs()
#
sub cleanup()
{
if ($exptcreated) {
exit(-1)
if (!TBExptIDX($pid, $eid, \$exptidx));
if (defined($experiment)) {
# Before killing it, save off the user directory for debugging.
$experiment->BackupUserData();
system("$endexp -x -q -w $exptidx");
exit(-1)
if ($?);
$experiment->End("-x -q -w") == 0
or exit(-1);
}
$instance->Delete()
if (defined($instance));
......
......@@ -70,7 +70,7 @@ my $logname;
my @ExptStates = ();
# For the END block below.
my $cleaning = 0;
my $exptcreated = 0;
my $exptactive = 0;
my $justexit = 1;
# Programs we need
......@@ -81,6 +81,7 @@ my $endexp = "$TB/bin/endexp";
my $dbcontrol = "$TB/sbin/opsdb_control";
my $archcontrol = "$TB/bin/archive_control";
my $CVSBIN = "/usr/bin/cvs";
my $RLOG = "/usr/bin/rlog";
# Protos
sub ParseArgs();
......@@ -333,6 +334,9 @@ fatal($? >> 8, "Could not instantiate the experiment")
#
$justexit = 0;
# And we need to terminate the experiment!
$exptactive = 1;
#
# We will spew forth info to the user each time the batch daemon tries to
# swap it in.
......@@ -402,11 +406,19 @@ my $cvsdir = "$projroot/$pid/templates/$guid/cvsrepo";
my $instance_tag = "I${exptidx}";
my $template_tag = "T${guid}-$version";
# Tag the template with an instance tag. This tag is used to associate
# records with this instance with the actual template.
System("$CVSBIN -d $cvsdir rtag -n -r ".
" $template_tag $instance_tag $guid/setup") == 0
or fatal(-1, "Could not rtag with instance tag in $cvsdir");
if (-e $cvsdir) {
# Tag the template with an instance tag. This tag is used to associate
# records with this instance with the actual template.
# The rlog check is so we can deal with old templates that have an
# incomplete CVS repo.
System("$RLOG -h $cvsdir/$guid/setup/.template,v | ".
" grep -q '${template_tag}:'");
if (! $?) {
System("$CVSBIN -d $cvsdir rtag -n -r ".
" $template_tag $instance_tag $guid/setup") == 0
or fatal(-1, "Could not rtag with instance tag in $cvsdir");
}
}
$instance->StartRun(Template::STARTRUN_FLAGS_FIRSTRUN()) == 0
or fatal(-1, "Could not update start time in instance record!");
......@@ -534,6 +546,11 @@ sub cleanup()
$experiment->BackupUserData()
if (defined($experiment));
if ($exptactive) {
$experiment->Swap($Experiment::EXPT_SWAPOUT, "-x -q -w") == 0
or exit(-1);
}
$instance->DeleteCurrentRun()
if (defined($run));
......
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