Commit 0adf77f0 authored by Srikanth Raju's avatar Srikanth Raju Committed by Leigh B Stoller
Browse files

Some error handling

parent 96226848
...@@ -101,7 +101,7 @@ if __FILE__ == $0 ...@@ -101,7 +101,7 @@ if __FILE__ == $0
rescue Exception => e rescue Exception => e
print "Error while creating an image: \n" print "Error while creating an image: \n"
puts e.message puts e.message
print e.backtrace.join("\n") puts e.backtrace.join("\n")
ensure ensure
ex.finalize() ex.finalize()
end end
......
...@@ -56,7 +56,6 @@ my $TAR = "tar"; ...@@ -56,7 +56,6 @@ my $TAR = "tar";
my $sudo; my $sudo;
my $zipper = "/usr/local/bin/imagezip"; my $zipper = "/usr/local/bin/imagezip";
my $uploader = "/usr/local/etc/emulab/frisupload"; my $uploader = "/usr/local/etc/emulab/frisupload";
my $error = 0;
for my $path (qw#/usr/local/bin /usr/bin#) { for my $path (qw#/usr/local/bin /usr/bin#) {
if (-e "$path/sudo") { if (-e "$path/sudo") {
...@@ -94,16 +93,20 @@ my $workdir = $WORK_BASE . $project . "/" . $user . "/" . $osid . "-tmp"; ...@@ -94,16 +93,20 @@ my $workdir = $WORK_BASE . $project . "/" . $user . "/" . $osid . "-tmp";
# Remotely execute the export script # Remotely execute the export script
if(system("scp export-template-remote.rb $ruser\@$remote:~/export.rb")){ if(system("scp export-template-remote.rb $ruser\@$remote:~/export.rb")){
print STDOUT "scp export-template-remote.rb $ruser\@$remote:~/export.rb"; print STDERR "Couldn't scp exporter script into $remote\n";
goto cleanup; goto cleanup;
} }
if(system("ssh -t -t -l $ruser $remote 'sudo ruby < ~/export.rb'")){ if(system("ssh -t -t -l $ruser $remote 'sudo ruby < ~/export.rb'")){
print STDERR "Remote image creation failed\n";
goto cleanup; goto cleanup;
} }
# SCP back the generated image file # SCP back the generated image file
system("scp $ruser\@$remote:~/emulab.tar.gz $infile"); if(system("scp $ruser\@$remote:~/emulab.tar.gz $infile")){
print STDERR "Couldn't scp image back into ops\n";
goto cleanup;
}
# Process the tar blah image # Process the tar blah image
if (! -e $infile){ if (! -e $infile){
...@@ -113,8 +116,15 @@ if (! -e $infile){ ...@@ -113,8 +116,15 @@ if (! -e $infile){
} }
# Unzip into the working dir # Unzip into the working dir
system("mkdir -p $workdir"); if (system("mkdir -p $workdir")){
system("tar -xvzf $infile -C $workdir"); print STDERR "Couldn't mkdir $workdir \n";
goto cleanup;
}
if (system("tar -xvzf $infile -C $workdir")){
print STDERR "Failed to extract $infile \n";
goto cleanup;
}
# TODO: Proper sda size based on image size? # TODO: Proper sda size based on image size?
# TODO: Maybe handle bootopts # TODO: Maybe handle bootopts
...@@ -139,8 +149,7 @@ close(FH); ...@@ -139,8 +149,7 @@ close(FH);
# Image zip the raw image # Image zip the raw image
if (system("$zipper -o -l $workdir/image $workdir/sda")) { if (system("$zipper -o -l $workdir/image $workdir/sda")) {
print STDERR "*** Failed to greate image!\n"; print STDERR "*** Failed to greate image!\n";
print STDERR " command: $zipper -o -l $workdir/image $workdir/sda"; print STDERR " command: $zipper -o -l $workdir/image $workdir/sda\n";
$error = 1;
} }
...@@ -150,11 +159,10 @@ my $cmd = "$TAR zcf - -C $workdir sda xm.conf kernel initrd | $zipper -f - $osid ...@@ -150,11 +159,10 @@ my $cmd = "$TAR zcf - -C $workdir sda xm.conf kernel initrd | $zipper -f - $osid
if (system("$cmd")) { if (system("$cmd")) {
print STDERR "*** Failed to create image!\n"; print STDERR "*** Failed to create image!\n";
print STDERR " command: '$cmd'\n"; print STDERR " command: '$cmd'\n";
$error = 1;
goto cleanup; goto cleanup;
} }
cleanup: cleanup:
# Clean up the directory. # Clean up the directory.
system("$sudo /bin/rm -rf $workdir"); system("$sudo /bin/rm -rf $workdir 2>/dev/null");
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