diff --git a/perl-xCAT-2.0/xCAT/Template.pm b/perl-xCAT-2.0/xCAT/Template.pm index 8d8ce1da0..defb0a52d 100755 --- a/perl-xCAT-2.0/xCAT/Template.pm +++ b/perl-xCAT-2.0/xCAT/Template.pm @@ -9,6 +9,7 @@ use File::Path; use Data::Dumper; use Sys::Syslog; +my $tmplerr; my $table; my $key; my $field; @@ -25,12 +26,12 @@ sub subvars { $idir = dirname($inf); open($inh,"<",$inf); unless ($inh) { - return undef; + return "Unable to open $inf, aborting"; } mkpath(dirname($outf)); open($outh,">",$outf); unless($outh) { - return undef; + return "Unable to open $outf for writing/creation, aborting"; } my $inc; #First load input into memory.. @@ -72,9 +73,13 @@ sub subvars { $inc =~ s/#CRYPT:([^:]+):([^:]+):([^#]+)#/crydb($1,$2,$3)/eg; $inc =~ s/#XCATVAR:([^#]+)#/envvar($1)/eg; $inc =~ s/#ENV:([^#]+)#/envvar($1)/eg; + if ($tmplerr) { + close ($outh); + return $tmplerr; + } print $outh $inc; close($outh); - return 1; + return 0; } sub includefile { @@ -152,6 +157,13 @@ sub tabdb my $key = shift; my $field = shift; my $tabh = xCAT::Table->new($table); + unless ($tabh) { + $tmplerr="Unable to open table named $table"; + if ($table =~ /\.tab/) { + $tmplerr .= " (.tab should not be specified as part of the table name in xCAT 2, as it seems to be the case here)"; + } + return ""; + } my $ent; if ($key eq "THISNODE" or $key eq '$NODE') { $ent = $tabh->getNodeAttribs($node,[$field]); @@ -167,6 +179,7 @@ sub tabdb } $tabh->close; unless($ent and defined($ent->{$field})) { + $tmplerr="Unable to find requested $field from $table in this context"; return ""; #return "#TABLEBAD:$table:field $field not found#"; } diff --git a/xCAT-server-2.0/lib/xcat/plugins/centos.pm b/xCAT-server-2.0/lib/xcat/plugins/centos.pm index 2a73b6b65..9c03154c1 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/centos.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/centos.pm @@ -158,7 +158,11 @@ sub mkinstall { next; } #Call the Template class to do substitution to produce a kickstart file in the autoinst dir - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/centos/".$ent->{profile}.".tmpl","/install/autoinst/".$node,$node); + my $tmperr = xCAT::Template->subvars($::XCATROOT."/share/xcat/install/centos/".$ent->{profile}.".tmpl","/install/autoinst/".$node,$node); + if ($tmperr) { + $callback->({node=>[{name=>[$node],error=>[$tmperr],errorcode=>[1]}]}); + next; + } mkpath "/install/postscripts/"; xCAT::Postage->writescript($node,"/install/postscripts/".$node); if (-r "/install/$os/$arch/images/pxeboot/vmlinuz" diff --git a/xCAT-server-2.0/lib/xcat/plugins/fedora.pm b/xCAT-server-2.0/lib/xcat/plugins/fedora.pm index 9577f7024..2235d630b 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/fedora.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/fedora.pm @@ -195,14 +195,24 @@ sub mkinstall { } #Call the Template class to do substitution to produce a kickstart file in the autoinst dir + my $tmperr; if ( -r $::XCATROOT."/share/xcat/install/fedora/$profile.$os.$arch.tmpl" ) { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/$profile.$os.$arch.tmpl","/install/autoinst/".$node,$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/$profile.$os.$arch.tmpl","/install/autoinst/".$node,$node); } elsif ( -r $::XCATROOT."/share/xcat/install/fedora/$profile.$arch.tmpl" ) { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/$profile.$arch.tmpl","/install/autoinst/".$node,$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/$profile.$arch.tmpl","/install/autoinst/".$node,$node); } elsif ( -r $::XCATROOT."/share/xcat/install/fedora/$profile.$os.tmpl" ) { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/$profile.$os.tmpl","/install/autoinst/".$node,$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/$profile.$os.tmpl","/install/autoinst/".$node,$node); } else { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/".$ent->{profile}.".tmpl","/install/autoinst/".$node,$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/".$ent->{profile}.".tmpl","/install/autoinst/".$node,$node); + } + if ($tmperr) { + $callback->({ + node => [ { + name=> [ $node ], + error=> [ $tmperr ], + errorcode => [ 1 ] + } ]}); + next; } mkpath "/install/postscripts/"; xCAT::Postage->writescript($node,"/install/postscripts/".$node); diff --git a/xCAT-server-2.0/lib/xcat/plugins/rhel.pm b/xCAT-server-2.0/lib/xcat/plugins/rhel.pm index cb00af502..0ac38dab8 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/rhel.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/rhel.pm @@ -156,14 +156,24 @@ sub mkinstall { } #Call the Template class to do substitution to produce a kickstart file in the autoinst dir + my $tmperr; if ( -r $::XCATROOT."/share/xcat/install/rh/$profile.$os.$arch.tmpl" ) { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/$profile.$os.$arch.tmpl","/install/autoinst/".$node,$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/$profile.$os.$arch.tmpl","/install/autoinst/".$node,$node); } elsif ( -r $::XCATROOT."/share/xcat/install/rh/$profile.$arch.tmpl" ) { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/$profile.$arch.tmpl","/install/autoinst/".$node,$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/$profile.$arch.tmpl","/install/autoinst/".$node,$node); } elsif ( -r $::XCATROOT."/share/xcat/install/rh/$profile.$os.tmpl" ) { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/$profile.$os.tmpl","/install/autoinst/".$node,$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/$profile.$os.tmpl","/install/autoinst/".$node,$node); } else { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/".$ent->{profile}.".tmpl","/install/autoinst/".$node,$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/".$ent->{profile}.".tmpl","/install/autoinst/".$node,$node); + } + if ($tmperr) { + $callback->({ + node => [ { + name=> [ $node ], + error=> [ $tmperr ], + errorcode => [ 1 ] + } ]}); + next; } mkpath "/install/postscripts/"; xCAT::Postage->writescript($node,"/install/postscripts/".$node); diff --git a/xCAT-server-2.0/lib/xcat/plugins/sles.pm b/xCAT-server-2.0/lib/xcat/plugins/sles.pm index 83f64c596..98ae4e592 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/sles.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/sles.pm @@ -62,14 +62,24 @@ sub mkinstall { next; } #Call the Template class to do substitution to produce a kickstart file in the autoinst dir + my $tmperr; if (-r $::XCATROOT."/share/xcat/install/sles/$profile.$os.$arch.tmpl") { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.$os.$arch.tmpl","/install/autoinst/$node",$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.$os.$arch.tmpl","/install/autoinst/$node",$node); } elsif (-r $::XCATROOT."/share/xcat/install/sles/$profile.$arch.tmpl") { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.$arch.tmpl","/install/autoinst/$node",$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.$arch.tmpl","/install/autoinst/$node",$node); } elsif (-r $::XCATROOT."/share/xcat/install/sles/$profile.$os.tmpl") { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.$os.tmpl","/install/autoinst/$node",$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.$os.tmpl","/install/autoinst/$node",$node); } elsif (-r $::XCATROOT."/share/xcat/install/sles/$profile.tmpl") { - xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.tmpl","/install/autoinst/$node",$node); + $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.tmpl","/install/autoinst/$node",$node); + } + if ($tmperr) { + $callback->({ + node => [ { + name=> [ $node ], + error=> [ $tmperr ], + errorcode => [ 1 ] + } ]}); + next; } mkpath "/install/postscripts/"; xCAT::Postage->writescript($node,"/install/postscripts/".$node);