From 3408e93e6bd3915de7664054465d13e3e40208ef Mon Sep 17 00:00:00 2001 From: chenglch Date: Mon, 25 Sep 2017 11:51:54 +0800 Subject: [PATCH] Do not query noderes table in subvars subroutine This patch refactor the interface to get xcatmaster and tftpserver attributes in the subvars subroutine to improve the performance. partial-issue: #3958 --- xCAT-server/lib/perl/xCAT/Template.pm | 11 ++++------- xCAT-server/lib/xcat/plugins/anaconda.pm | 8 +++++++- xCAT-server/lib/xcat/plugins/debian.pm | 24 ++++++++++++++++++++---- xCAT-server/lib/xcat/plugins/esx.pm | 14 +++++++++++--- xCAT-server/lib/xcat/plugins/sles.pm | 13 +++++++++++-- xCAT-server/lib/xcat/plugins/windows.pm | 12 +++++++++++- 6 files changed, 64 insertions(+), 18 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 012163b8b..0fd80d9ef 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -56,6 +56,7 @@ sub subvars { my $media_dir = shift; my $platform = shift; my $partitionfileval = shift; + my $tmpl_hash = shift; my %namedargs = @_; #further expansion of this function will be named arguments, should have happened sooner. unless ($namedargs{reusemachinepass}) { @@ -88,10 +89,8 @@ sub subvars { my $master; #the "xcatmaster" attribute of the node - my $noderestab = xCAT::Table->new('noderes'); - my $et = $noderestab->getNodeAttribs($node, ['xcatmaster']); - if ($et and $et->{'xcatmaster'}) { - $master = $et->{'xcatmaster'}; + if ($tmpl_hash->{'xcatmaster'}) { + $master = $tmpl_hash->{'xcatmaster'}; } unless ($master) { @@ -375,9 +374,7 @@ sub subvars { $inc =~ s/#UNCOMMENTOENABLESSH#/ /g; } - my $nrtab = xCAT::Table->new("noderes"); - my $tftpserver = $nrtab->getNodeAttribs($node, ['tftpserver']); - my $sles_sdk_media = "http://" . $tftpserver->{tftpserver} . $media_dir . "/sdk1"; + my $sles_sdk_media = "http://" . $tmpl_hash->{tftpserver} . $media_dir . "/sdk1"; $inc =~ s/#SLES_SDK_MEDIA#/$sles_sdk_media/eg; diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index 1507b768f..c5d79e7d0 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -1021,7 +1021,7 @@ sub mkinstall my $mactab = xCAT::Table->new('mac'); my %osents = %{ $ostab->getNodesAttribs(\@nodes, [ 'profile', 'os', 'arch', 'provmethod' ]) }; my %rents = %{ $restab->getNodesAttribs(\@nodes, - [ 'xcatmaster', 'nfsserver', 'tftpdir', 'primarynic', 'installnic' ]) }; + [ 'xcatmaster', 'nfsserver', 'tftpdir', 'primarynic', 'installnic', 'tftpserver' ]) }; my %hents = %{ $hmtab->getNodesAttribs(\@nodes, [ 'serialport', 'serialspeed', 'serialflow' ]) }; my %macents = %{ $mactab->getNodesAttribs(\@nodes, ['mac']) }; @@ -1068,14 +1068,19 @@ sub mkinstall my $netdrivers; my $driverupdatesrc; my $osupdir; + my %tmpl_hash; my $ient = $rents{$node}->[0]; if ($ient and $ient->{xcatmaster}) { $xcatmaster = $ient->{xcatmaster}; + $tmpl_hash{"xcatmaster"} = $xcatmaster; } else { $xcatmaster = '!myipfn!'; } + if ($ient and $ient->{tftpserver}) { + $tmpl_hash{"tftpserver"} = $ient->{tftpserver}; + } my $osinst; if ($rents{$node}->[0] and $rents{$node}->[0]->{tftpdir}) { @@ -1330,6 +1335,7 @@ sub mkinstall $pkgdir, $platform, $partfile, + \%tmpl_hash, $os ); } diff --git a/xCAT-server/lib/xcat/plugins/debian.pm b/xCAT-server/lib/xcat/plugins/debian.pm index 374c37067..18b6dc4d7 100644 --- a/xCAT-server/lib/xcat/plugins/debian.pm +++ b/xCAT-server/lib/xcat/plugins/debian.pm @@ -496,7 +496,7 @@ sub mkinstall { my %osents = %{ $ostab->getNodesAttribs(\@nodes, [ 'profile', 'os', 'arch', 'provmethod' ]) }; my %rents = %{ $restab->getNodesAttribs(\@nodes, - [ 'xcatmaster', 'nfsserver', 'primarynic', 'installnic' ]) }; + [ 'xcatmaster', 'nfsserver', 'primarynic', 'installnic', 'tftpserver' ]) }; my %hents = %{ $hmtab->getNodesAttribs(\@nodes, [ 'serialport', 'serialspeed', 'serialflow' ]) }; @@ -537,6 +537,15 @@ sub mkinstall { my $pkglistfile; my $imagename; # set it if running of 'nodeset osimage=xxx' my $platform; + my %tmpl_hash; + + my $ient = $rents{$node}->[0]; + if ($ient and $ient->{xcatmaster}) { + $tmpl_hash{"xcatmaster"} = $ient->{xcatmaster}; + } + if ($ient and $ient->{tftpserver}) { + $tmpl_hash{"tftpserver"} = $ient->{tftpserver}; + } my $osinst; my $ent = $osents{$node}->[0]; #$ostab->getNodeAttribs($node, ['profile', 'os', 'arch']); @@ -732,7 +741,8 @@ sub mkinstall { $pkglistfile, $pkgdir, $platform, - $partitionfile + $partitionfile, + \%tmpl_hash ); } @@ -752,14 +762,20 @@ sub mkinstall { "", "", "", - $partitionfile + $partitionfile, + \%tmpl_hash ); } if (-r "$postscript") { $posterr = xCAT::Template->subvars($postscript, "$installroot/autoinst/" . $node . ".post", - $node + $node, + "", + "", + "", + "", + \%tmpl_hash ); } diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index fcdb09b0c..151611f96 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -4856,7 +4856,7 @@ sub esxi_kickstart_from_template { } my $tmperr; if (-r "$template") { - $tmperr = xCAT::Template->subvars($template, "$installdir/autoinst/" . $args{node}, $args{node}, undef); + $tmperr = xCAT::Template->subvars($template, "$installdir/autoinst/" . $args{node}, $args{node}, undef, undef, undef, $args{tmpl_hash}); } else { $tmperr = "Unable to find template in /install/custom/install/$plat or $::XCATROOT/share/xcat/install/$plat (for $args{profile}/$args{os}/$args{arch} combination)"; } @@ -4937,7 +4937,7 @@ sub mkcommonboot { my $restab = xCAT::Table->new('noderes', -create => 0); my $resents; if ($restab) { - $resents = $restab->getNodesAttribs(\@nodes, [ 'tftpdir', 'nfsserver' ]); + $resents = $restab->getNodesAttribs(\@nodes, [ 'tftpdir', 'nfsserver', 'xcatmaster', 'tftpserver']); } my %tablecolumnsneededforaddkcmdline; @@ -4967,6 +4967,8 @@ sub mkcommonboot { my $osver = $ent->{'os'}; my $tftpdir; my $ksserver; + my %tmpl_hash; + if ($resents and $resents->{$node}->[0]->{nfsserver}) { $ksserver = $resents->{$node}->[0]->{nfsserver}; } else { @@ -4978,6 +4980,12 @@ sub mkcommonboot { } else { $tftpdir = $globaltftpdir; } + if ($resents and $resents->{$node}->[0]->{xcatmaster} ) { + $tmpl_hash{"xcatmaster"} = $resents->{$node}->[0]->{xcatmaster}; + } + if ($resents and $resents->{$node}->[0]->{tftpserver}) { + $tmpl_hash{"tftpserver"} = $resents->{$node}->[0]->{tftpserver}; + } #if($arch ne 'x86'){ # xCAT::SvrUtils::sendmsg([1,"VMware ESX hypervisors are x86, please change the nodetype.arch value to x86 instead of $arch for $node before proceeding: @@ -5106,7 +5114,7 @@ sub mkcommonboot { $append .= " xcatd=$ksserver:3001"; if ($bootmode eq "install") { $append .= " ks=http://$ksserver/install/autoinst/$node"; - esxi_kickstart_from_template(node => $node, os => $osver, arch => $arch, profile => $profile); + esxi_kickstart_from_template(node => $node, os => $osver, arch => $arch, profile => $profile, tmpl_hash => \%tmpl_hash); } if ($bootmode ne "install" and $serialconfig->{$node}) { #don't do it for install, installer croaks currently my $comport = 1; diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index d367e07cf..2e5928183 100644 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -804,7 +804,7 @@ sub mkinstall \@nodes, [ 'nfsserver', 'tftpdir', 'xcatmaster', - 'primarynic', 'installnic' + 'primarynic', 'installnic', 'tftpserver' ] ); my $hments = @@ -868,6 +868,7 @@ sub mkinstall my $driverupdatesrc; my $osupdir; my $imagename; # set it if running of 'nodeset osimage=xxx' + my %tmpl_hash; if ($resents->{$node} and $resents->{$node}->[0]->{tftpdir}) { $tftpdir = $resents->{$node}->[0]->{tftpdir}; @@ -875,6 +876,13 @@ sub mkinstall $tftpdir = $globaltftpdir; } + if ($resents and $resents->{$node}->[0]->{xcatmaster} ) { + $tmpl_hash{"xcatmaster"} = $resents->{$node}->[0]->{xcatmaster}; + } + if ($resents and $resents->{$node}->[0]->{tftpserver}) { + $tmpl_hash{"tftpserver"} = $resents->{$node}->[0]->{tftpserver}; + } + xCAT::MsgUtils->trace($verbose_on_off, "d", "sles->mkinstall: tftpdir=$tftpdir"); if ($ent and $ent->{provmethod} and ($ent->{provmethod} ne 'install') and ($ent->{provmethod} ne 'netboot') and ($ent->{provmethod} ne 'statelite')) { @@ -1060,7 +1068,8 @@ sub mkinstall $pkglistfile, $tmppkgdir, $os, - $partfile + $partfile, + \%tmpl_hash ); } diff --git a/xCAT-server/lib/xcat/plugins/windows.pm b/xCAT-server/lib/xcat/plugins/windows.pm index 141949332..daba5e47a 100644 --- a/xCAT-server/lib/xcat/plugins/windows.pm +++ b/xCAT-server/lib/xcat/plugins/windows.pm @@ -243,6 +243,8 @@ sub mkinstall my $bootparams = ${$request->{bootparams}}; my $hmtab = xCAT::Table->new('nodehm'); my $vpdtab = xCAT::Table->new('vpd'); + my $restab = xCAT::Table->new('noderes'); + my $resents = $restab->getNodesAttribs(\@nodes, ['xcatmaster', 'tftpserver']); my $vpdhash = $vpdtab->getNodesAttribs(\@nodes, ['uuid']); my %img_hash = (); my $winimagetab; @@ -282,6 +284,14 @@ sub mkinstall my $partfile; my $installto; my $winpepath; + my %tmpl_hash; + + if ($resents and $resents->{$node}->[0]->{xcatmaster} ) { + $tmpl_hash{"xcatmaster"} = $resents->{$node}->[0]->{xcatmaster}; + } + if ($resents and $resents->{$node}->[0]->{tftpserver}) { + $tmpl_hash{"tftpserver"} = $resents->{$node}->[0]->{tftpserver}; + } my $ent = $osents->{$node}->[0]; if ($ent and $ent->{provmethod} and ($ent->{provmethod} ne 'install') and ($ent->{provmethod} ne 'netboot') and ($ent->{provmethod} ne 'statelite')) { @@ -465,7 +475,7 @@ sub mkinstall $tmplfile, "$installroot/autoinst/$node.xml", $node, - 0); + 0,undef ,undef, undef, \%tmpl_hash); } if ($tmperr) {