From 04015bd64d5ae0688f727dd88657c2d3b8dc7d1b Mon Sep 17 00:00:00 2001 From: lissav Date: Tue, 25 Feb 2014 11:41:15 -0500 Subject: [PATCH 1/7] defect 3994 --- perl-xCAT/xCAT/TableUtils.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/perl-xCAT/xCAT/TableUtils.pm b/perl-xCAT/xCAT/TableUtils.pm index d1538b454..9f026379c 100644 --- a/perl-xCAT/xCAT/TableUtils.pm +++ b/perl-xCAT/xCAT/TableUtils.pm @@ -1824,8 +1824,8 @@ sub enableSSH } else { # if not a service node we need to check, before enabling - if (defined($groups_hash)) { - if ($groups_hash->{ALLGROUPS} == 1) + if (keys %$groups_hash) { # not empty + if ($groups_hash->{ALLGROUPS} == 1) { $enablessh=1; } From 55a90fc1b9fd934833cbaf531d77a307c91c096e Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 26 Feb 2014 08:12:11 -0500 Subject: [PATCH 2/7] fix ENABLESSHBETWEENNODES setting in mypostscript file when zones --- perl-xCAT/xCAT/Zone.pm | 82 +++++++++++++++++++++++++++- xCAT-server/lib/perl/xCAT/Postage.pm | 67 +++++++++++++++++++++-- 2 files changed, 142 insertions(+), 7 deletions(-) diff --git a/perl-xCAT/xCAT/Zone.pm b/perl-xCAT/xCAT/Zone.pm index 64fa1d5c3..f666f5979 100644 --- a/perl-xCAT/xCAT/Zone.pm +++ b/perl-xCAT/xCAT/Zone.pm @@ -192,9 +192,85 @@ sub iszonedefined my ($class,$zonename) = @_; # checks the zone table to see if input zonename already in the table my $tab = xCAT::Table->new("zone"); - my $zone = $tab->getAttribs({zonename => $zonename},'sshkeydir'); $tab->close(); - if (defined($zone)) { + my $zonehash = $tab->getAttribs({zonename => $zonename},'sshkeydir'); + if ( keys %$zonehash) { + return 1; + }else{ + return 0; + } +} +#-------------------------------------------------------------------------------- + +=head3 enableSSHbetweennodes + Arguments: + zonename + Returns: + 1 if the sshbetweennodes attribute is yes/1 or undefined + 0 if the sshbetweennodes attribute is no/0 + Example: + xCAT::Zone->enableSSHbetweennodes($zonename); +=cut + +#-------------------------------------------------------------------------------- +sub enableSSHbetweennodes +{ + my ($class,$node,$callback) = @_; + # finds the zone of the node + my $enablessh = 1; # default + my @node; + push @node,$node; + my $nodelisttab = xCAT::Table->new("nodelist"); + my $nodehash = $nodelisttab->getNodesAttribs(\@node, ['zonename']); + $nodelisttab->close(); + my $zonename; + $zonename=$nodehash->{$node}->[0]->{zonename}; + # reads the zone table + my $tab = xCAT::Table->new("zone"); + $tab->close(); + # read both keys, want to know zone is in the zone table. If sshkeydir is not there + # it is either missing or invalid anyway + my $zonehash = $tab->getAttribs({zonename => $zonename},'sshbetweennodes','sshkeydir'); + if (! ( keys %$zonehash)) { + my $rsp = {}; + $rsp->{error}->[0] = + "$node has a zonename: $zonename that is not define in the zone table. Remove the zonename from the node, or create the zone using mkzone. The generated mypostscript may not reflect the correct setting for ENABLESSHBETWEENNODES"; + xCAT::MsgUtils->message("E", $rsp, $callback); + return $enablessh; + } + my $sshbetweennodes=$zonehash->{sshbetweennodes}; + if (defined ($sshbetweennodes)) { + if (($sshbetweennodes =~ /^no$/i) || ($sshbetweennodes eq "0")) { + $enablessh = 0; + } else { + $enablessh = 1; + } + } else { # not defined default yes + $enablessh = 1 ; # default + } + return $enablessh; +} +#-------------------------------------------------------------------------------- + +=head3 usingzones + Arguments: + none + Returns: + 1 if the zone table is not empty + 0 if empty + Example: + xCAT::Zone->usingzones; +=cut + +#-------------------------------------------------------------------------------- +sub usingzones +{ + my ($class) = @_; + # reads the zonetable + my $tab = xCAT::Table->new("zone"); + my @zone = $tab->getAllAttribs('zonename'); + $tab->close(); + if (@zone) { return 1; }else{ return 0; @@ -275,7 +351,7 @@ sub getzoneinfo unless ( xCAT::Zone->iszonedefined($zonename)) { my $rsp = {}; $rsp->{error}->[0] = - "$node has a zonenane: $zonename that is not define in the zone table. Remove the zonename from the node, or create the zone using mkzone."; + "$node has a zonename: $zonename that is not define in the zone table. Remove the zonename from the node, or create the zone using mkzone."; xCAT::MsgUtils->message("E", $rsp, $callback); $::GETZONEINFO_RC =1; return; diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index 49f5fcd1c..6d542a1bf 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -16,6 +16,7 @@ use xCAT::Utils; use xCAT::TableUtils; use xCAT::Template; use xCAT::SvrUtils; +use xCAT::Zone; #use Data::Dumper; use File::Basename; use Socket; @@ -367,6 +368,16 @@ sub makescript { } $cloudinfo_hash = getcloudinfo($cloud_module_name, $cloud_exists); } + + # see if we are using zones. If we are then sshbetweennodes comes from the zone table not + # from the site table + my $usingzones; + if (xCAT::Zone->usingzones) { + $usingzones=1; + } else { + $usingzones=0; + } + foreach my $n (@$nodes ) { $node = $n; @@ -477,9 +488,15 @@ sub makescript { # for #INCLUDE_POSTBOOTSCRIPTS_LIST# my $postbootscripts; $postbootscripts = getPostbootScripts($node, $osimgname, $script_hash); - - my $enablesshbetweennodes = enableSSHbetweennodes($node, \%::GLOBAL_SN_HASH, $groups_hash); - + + # if using zones then must go to the zone.sshbetweennodes + # else go to site.sshbetweennodes + my $enablesshbetweennodes; + if ($usingzones) { + $enablesshbetweennodes = enableSSHbetweennodeszones($node,$callback); + } else { + $enablesshbetweennodes = enableSSHbetweennodes($node, \%::GLOBAL_SN_HASH, $groups_hash); + } my @clients; my $cfgres; my $cloudres; @@ -792,7 +809,7 @@ sub getsshbetweennodes Error: none Example: - my $enable = xCAT::TableUtils->enableSSH($node); + my $enable = xCAT::TableUtils->enableSSHbetweennodes($node,$sn_hash, $groups_hash); Comments: =cut @@ -818,6 +835,48 @@ sub enableSSHbetweennodes } +#------------------------------------------------------------------------------- + +=head3 enableSSHbetweennodeszones + Description: return how to fill in the ENABLESSHBETWEENNODES export in the mypostscript file + based on the setting in the zone table sshbetweennodes attribute + Arguments: + $node + $callback + Returns: + 1 = enable ssh + 0 = do not enable ssh + Globals: + none + Error: + none + Example: + my $enable = xCAT::TableUtils->enableSSHbetweennodeszones($node); + Comments: + +=cut + +#----------------------------------------------------------------------------- + +sub enableSSHbetweennodeszones +{ + + my $node = shift; + my $callback = shift; + my $result; + + my $enablessh=xCAT::Zone->enableSSHbetweennodes($node,$callback); + if ($enablessh == 1) { + $result = "'YES'"; + } else { + $result = "'NO'"; + } + + return $result; +} + + + From d8dedfb3b14e62984661bf65dae839b5fa93c7ff Mon Sep 17 00:00:00 2001 From: daniceexi Date: Wed, 26 Feb 2014 13:26:01 -0500 Subject: [PATCH 3/7] defect 3961: make domain name keep without . at beginning --- xCAT-server/lib/xcat/plugins/ddns.pm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/ddns.pm b/xCAT-server/lib/xcat/plugins/ddns.pm index ee048d0ad..3569b450d 100755 --- a/xCAT-server/lib/xcat/plugins/ddns.pm +++ b/xCAT-server/lib/xcat/plugins/ddns.pm @@ -389,7 +389,8 @@ sub process_request { # - need domain for this node my $host = $nodehash{$n}{host}; $domain=$nodedomains{$host}; - unless ($domain =~ /^\./) { $domain = '.'.$domain; } + # remove the first . at domain name since it's not accepted by high dns parser + if ($domain =~ /^\./) { $domain =~ s/^\.//;; } ($canonical,$aliasstr) = split /[ \t]+/,$names,2; if ($aliasstr) { @@ -403,13 +404,13 @@ sub process_request { xCAT::SvrUtils::sendmsg(":Handling $node in /etc/hosts.", $callback); unless ($canonical =~ /$domain/) { - $canonical.=$domain; + $canonical.=".".$domain; } # for only the sake of comparison, ensure consistant dot suffix unless ($canonical =~ /\.\z/) { $canonical .= '.' } foreach my $alias (@aliases) { unless ($alias =~ /$domain/) { - $alias .= $domain; + $alias .= ".".$domain; } unless ($alias =~ /\.\z/) { $alias .= '.'; @@ -504,9 +505,11 @@ sub process_request { $ctx->{slaves}=\@slave_ips; } + $ctx->{domain} =~ s/^\.//; # remove . if it's the first char of domain name $ctx->{zonestotouch}->{$ctx->{domain}}=1; foreach (@networks) { if ($_->{domain}) { + $_->{domain} =~ s/^\.//; # remove . if it's the first char of domain name $ctx->{zonestotouch}->{$_->{domain}}=1; } } @@ -792,11 +795,11 @@ sub update_zones { xCAT::SvrUtils::sendmsg("Updating zones.", $callback); - unless ($domain =~ /^\./) { - $domain = '.'.$domain; + if ($domain =~ /^\./) { # remove . if it's the first char of domain name + $domain =~ s/^\.//; } unless ($name =~ /\./) { - $name .= $domain; + $name .= ".".$domain; } unless ($name =~ /\.\z/) { $name .= '.'; @@ -1161,9 +1164,9 @@ sub add_or_delete_records { } my $domain = $nodedomains{$node}; - unless ($domain =~ /^\./) { $domain = '.'.$domain; } + if ($domain =~ /^\./) { $domain =~ s/^\.//; } # remove . if it's the first char of domain name - unless ($name =~ /$domain/) { $name .= $domain } # $name needs to represent fqdn, but must preserve $node as a nodename for cfg lookup + unless ($name =~ /$domain/) { $name .= ".".$domain } # $name needs to represent fqdn, but must preserve $node as a nodename for cfg lookup if ($ctx->{hoststab} and $ctx->{hoststab}->{$node} and $ctx->{hoststab}->{$node}->[0]->{ip}) { @ips = ($ctx->{hoststab}->{$node}->[0]->{ip}); From f2f814016dcb449025d61daad3dd64d045c37ad2 Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 26 Feb 2014 10:34:25 -0500 Subject: [PATCH 4/7] adding routines for support --- perl-xCAT/xCAT/Zone.pm | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/perl-xCAT/xCAT/Zone.pm b/perl-xCAT/xCAT/Zone.pm index f666f5979..e712d2dd1 100644 --- a/perl-xCAT/xCAT/Zone.pm +++ b/perl-xCAT/xCAT/Zone.pm @@ -145,7 +145,7 @@ sub genSSHRootKeys Returns: Name of the current default zone from the zone table Example: - my $defaultzone =xCAT::Zone->getdefaultzone(); + my $defaultzone =xCAT::Zone->getdefaultzone($callback); =cut #-------------------------------------------------------------------------------- @@ -202,6 +202,34 @@ sub iszonedefined } #-------------------------------------------------------------------------------- +=head3 getmyzonename + Arguments: + $node -one nodename + Returns: + $zonename + Example: + my $zonename=xCAT::Zone->getmyzonename($node); +=cut + +#-------------------------------------------------------------------------------- +sub getmyzonename +{ + my ($class,$node,$callback) = @_; + my @node; + push @node,$node; + my $zonename; + my $nodelisttab = xCAT::Table->new("nodelist"); + my $nodehash = $nodelisttab->getNodesAttribs(\@node, ['zonename']); + $nodelisttab->close(); + if ( defined ($nodehash->{$node}->[0]->{zonename})) { # it was defined in the nodelist table + $zonename=$nodehash->{$node}->[0]->{zonename}; + } else { # get the default zone + $zonename =xCAT::Zone->getdefaultzone($callback); + } + return $zonename; +} +#-------------------------------------------------------------------------------- + =head3 enableSSHbetweennodes Arguments: zonename @@ -218,13 +246,7 @@ sub enableSSHbetweennodes my ($class,$node,$callback) = @_; # finds the zone of the node my $enablessh = 1; # default - my @node; - push @node,$node; - my $nodelisttab = xCAT::Table->new("nodelist"); - my $nodehash = $nodelisttab->getNodesAttribs(\@node, ['zonename']); - $nodelisttab->close(); - my $zonename; - $zonename=$nodehash->{$node}->[0]->{zonename}; + my $zonename=xCAT::Zone->getmyzonename($node); # reads the zone table my $tab = xCAT::Table->new("zone"); $tab->close(); From 4483b709da22c0211ecc3322079c165d9143d59d Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 26 Feb 2014 10:35:26 -0500 Subject: [PATCH 5/7] adding routines for support --- xCAT-server/lib/perl/xCAT/Postage.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index 6d542a1bf..5f81c2db0 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -492,8 +492,14 @@ sub makescript { # if using zones then must go to the zone.sshbetweennodes # else go to site.sshbetweennodes my $enablesshbetweennodes; + my $zonename; if ($usingzones) { $enablesshbetweennodes = enableSSHbetweennodeszones($node,$callback); + my $tmpzonename = xCAT::Zone->getmyzonename($node,$callback); + $zonename="\'"; + $zonename .= $tmpzonename; + $zonename .="\'"; + } else { $enablesshbetweennodes = enableSSHbetweennodes($node, \%::GLOBAL_SN_HASH, $groups_hash); } @@ -529,6 +535,7 @@ sub makescript { $inc =~ s/#CLOUDINFO_EXPORT#/$cloudres/eg; $inc =~ s/\$ENABLESSHBETWEENNODES/$enablesshbetweennodes/eg; + $inc =~ s/\$ZONENAME/$zonename/eg; $inc =~ s/\$NSETSTATE/$nodesetstate/eg; #$inc =~ s/#COMMAND:([^#]+)#/command($1)/eg; From a35f118cd966644b5f10b0ed10d06587aa7c8126 Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 26 Feb 2014 10:37:05 -0500 Subject: [PATCH 6/7] adding zonename --- xCAT/templates/mypostscript/mypostscript.tmpl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xCAT/templates/mypostscript/mypostscript.tmpl b/xCAT/templates/mypostscript/mypostscript.tmpl index eaecb4670..70d6bc4b0 100755 --- a/xCAT/templates/mypostscript/mypostscript.tmpl +++ b/xCAT/templates/mypostscript/mypostscript.tmpl @@ -9,6 +9,9 @@ ENABLESSHBETWEENNODES=$ENABLESSHBETWEENNODES export ENABLESSHBETWEENNODES +ZONENAME=$ZONENAME +export ZONENAME + ## tabdump() is used to get all the information ## in the table ## The should only be non-"node key" table From e77ef4eed3968aba043a7caa1fc5f547309a938c Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 26 Feb 2014 11:33:39 -0500 Subject: [PATCH 7/7] initialize if no zones --- xCAT-server/lib/perl/xCAT/Postage.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index 5f81c2db0..6e3543825 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -492,7 +492,7 @@ sub makescript { # if using zones then must go to the zone.sshbetweennodes # else go to site.sshbetweennodes my $enablesshbetweennodes; - my $zonename; + my $zonename="\'\'"; if ($usingzones) { $enablesshbetweennodes = enableSSHbetweennodeszones($node,$callback); my $tmpzonename = xCAT::Zone->getmyzonename($node,$callback);