2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-22 03:32:04 +00:00
Bin Xu eea661e405 merge from master to 2.13 branch for 2.13.9 release. (1) (#4525)
* fix issueNode range not specified, see man page for syntax. return with no output when site.master is not set #4299

* Fix issue 4246, record rflash process in log file

* dodiscovery: better disksize - ordered by major,minor and no `\n` (#4219)

* better disksize: ordered by major,minor and no `\n`

* nodediscover:`disksize` sent correctly: no need to `split`,`join`

* general sort with explicit key columns, fix search pattern

* dodiscovery: Fix bugs

* dodiscovery: Fix ShellCheck SC2007,SC2004

* dodiscovery: simpler kcmdline parsing, disksize as IEC binary prefix

* Add test case - switch_to_dns_forward_mode

* Modify timeout of login by curl command for OpenBMC

* Add makegocons command

This patch enable goconserver service and manage the node sessions
with a new `makegocons` command.

Implement: #4215

* Refine the Cumulus Linux Section of the Doc (#4249)

* No content in the switches subdirectory in docs, remove

* Change the Network topic to Networking

* Refine and reformat the Cumulus Linux documentation

* Modify the script to build xCAT-genesis-base package (#4292)

* Verify hash ID

* change log messages

* Timeout the ntpd process if ntpd service is not running on ntpserver (#4321)

* enhance nodediscovery process: don't write "NOIP" if the node can not be resloved to an IP (#3995)

* enhance nodediscovery process, if only 1 mac and have \*NOIP\* append, don't write mac table and don't generate dhcp lease entry

* Enhance PR 3995: enhance nodediscovery process: don't write "NOIP" if the node can not be resloved to an IP

* modified depending on comments

* natural_sort_cmp: recursion to iterative implementation (#4314)

* natural_sort_cmp: recursion to iterative implementation

* natural_sort_cmp: correct prototype with parameters, as per `man perlfunc`

* Task 3339, rspconfig ip/netmask/gateway/vlan support

*   * Minor enhance on xcatperftest to put all logs into one file
  * Fix a bug in simulatorctl.sh, and it cause the script cannot be found

* modified depending on comments

* QA list for makehosts (#4284)

* QA list for makehosts

* Fix some bus in makegocons

* Revise test case - switch_to_dns_forward_mode

* Enhancements after the review

* Use IO::Socket to check BMC console port

* Revise test case - switch_to_dns_forward_mode

* modified depending on comments

* Add messages to inform the user of the general action started via xCAT for flashing firmware

* Fix bug, anything in the functional array is the one that's really active, priority will not be 0 if there is pending firmware

* Fix 4338, remove all of  in child process

* fix issue #4354 :The XCATTEST_CN in xcattest can not detect HCP as config file (#4355)

* Fix #4330, close the socket

* Add image name to /opt/xcat/xcatinfo on compute node (#4359)

* Integrate congo console from goconserver with rcons

Enhance the original implement of rcons to support goconserver.
`rcons` will help the user choose from one of the console backend
service based on the console server status of management node.

Implement #4216

* Fix 4363 - discovery broken (#4364)

* do not set exit_code to 1 when the clock is not synced before the timeout (#4362)

* Fix check for MTM values with spaces

* modified depending on comments

* rspconfig admin_password for OpenBMC

* Fix merging in xdcpmerge.sh (#4328)

* Fixes in xdcpmerge.sh

Two fixes:
1. The grep pattern when finding duplicate usernames is missing ":" at the end. So, for example user "test" would also match "test2, etc.". Adding the ":" delimiter fixes the issue.
2. Another issue happens when the file to be merged is a superset of the files on the nodes. For example, if a new user is added and entire passwd file (that is otherwise identical) is sent to be merged. In this case, the $filebackup.nodups file, i.e. the original file with duplicates removed, becomes empty and the condition "if [ -s "$filebackup.nodups" ]" does not execute. Then the merged file ends up being original file with the merge file fully appended, clearly not what was intended.

This is solved by changing the condition to check for file existence "-a" rather then for size. Additionally, I also turn the logic around so that the duplicates are removed from the merge file and then added to the original file. I think this makes logic a bit cleaner and also ensures that existing entries are not reordered or changed in any way.

* Streamlining previous commit

Adjustment to previous commit, streamlining and simplifying logic. Once $mergefile.nodups is created, just concatenate it the original file.

* Update to xdcpmerge

No need to copy $filebackup to $curfile, they are the same.

* Modify for debug conveniently

* add new cases and delete outdated test cases

* Modify genesis build script for centos x86_64

* Add space between at and the time

* Add a print out of the firmware levels for the various UT cases

* Add unit test cases for rspconfig

* rspconfig fix for set hostname

* Enhance the testing case for rspconfig setting hostname

* modified depending on comments

* modified depending on comments

* Add %pretrans script in <lua>. Handle directory to symlink change properly. See comment #3 of https://bugs.launchpad.net/rpm/+bug/633636

* Make xCAT-genesis-base confliects with early version of xCAT-genesis-scripts

* rspconfig dump to allow admins capture logs

* Adding comment

* Improve the error message when BMC does not return a dump ID

* Improve some messages and add timestamp for downloaded dump file

* Improve the message to help Admin figure out where the file is missing

* Leave a log file there when xCAT upgrade in case to debug issue while upgrading (#4389)

* Listen on 0.0.0.0 instead of the hostname

This patch modify the configuration of `makegocons` and `rcons`
for goconserver.

`cat /etc/goconserver/server.conf`
```
global:
  host: 0.0.0.0
  ssl_key_file: /etc/xcat/cert/server-key.pem
  ssl_cert_file: /etc/xcat/cert/server-cert.pem
  ssl_ca_cert_file: /etc/xcat/cert/ca.pem
  logfile: /var/log/goconserver/server.log
api:
  port: 12429
console:
  port: 12430
```

* Support hostname=* for openbmc

* Relay action and snmp configuration support for Coral PDU

* ddns.pm: specify the "directory" option for DNS slaves too (cf. bug #4392)

* Fix issue 4361, modify some sendmsg to message

* 1. add "makeconserver -d" to "rmdef -C", 2. add "makeconserver -C|--cleanup" to remove entries for removed nodes

* When there is a problem with the login, do not hide the message on debug mode. BMCReady does not make sense if the admin does not know how to find that state

* Change function from login_logout_request to login_request, not doing any logout here

* Check that RC is 200 to prevent unknown issues, handle the response generically

* OpenBMC rspconfig dump timeout fixes

* Fix issue 4408, modify error for rspconfig dump

* Clear all BMC Dump logs when BMC firmware flash

* modified depending on comments

* More modifications for pr 4386, to deal with the conflicts

* To handle one case which have 2 implementations, which one is for specific platform, on is for all platforms

* return when current status is RSPCONFIG_DUMP_DOWNLOAD_REQUEST

* fix issue 4417, delete 'clear next_status'

* fix issue 4353: rspconfig needs to support multiple IPs on the BMC and ignore ZeroConfigIPs

* Wait 15 seconds after OpenBMC interface with vlan tag to be activated

* Fix issue #4397: rspconfig <> hostname=xxx show error message when there is multiple network in bmc

* Some sentence modify for makeconservercf -C|--cleanup

* OpenBMC rspconfig dump better dump file name formatting

* Removed the --check and --ipsource option with PR 4258, update the man page

* Improve the message on the HTTP response

* modified depending on comments

* Only handle 404 and 504 in the login request code, defer the rest to deal_with_response()

* rflash stream support

* 1. configure ip/netmask/gateway only on the NIC whose IP match node BMC attribute, 2. add some information for LinkLocal address

* Fix confignetwork bond nic_type detection with multiple bonds

* Modified configonie --ntp command (#4436)

* Add man page for makegocons

This is the guide about how to make goconserver as
a replacement for conserver to help slove the issues reported
for conserver, like: #4043, #3543. For openbmc, the solution of
goconserver is much light-weighted than the conserver which could
help save the system resource. In addition, sshpass is not needed
for openbmc with goconserver.

Implement: #4337

* Add another key for node_info in order not to after the content of $node_info{$node}{bmc}

* enhance rflash stream

* makedhcp does not work well when all service nodes not running dhcp but disjointdhcps=1 (#4426) (#4440)

- if all service nodes not running dhcp, to treat it as disjointdhcps=0
- nodeset will send request to MN by default even if disjointdhcps=1
- Move out of the dhcp service checking from opts pre-check, and do it just before real makedhcp handling.

* rspconfig configure bmc vlan will hung because of PR 4383

* OpenBMC rspconfig dump enhancements

* Changes due to review comments

* Print debug message before login attempt

* Add warning when xCAT throttles SSL connections

* Display first [openbmc_debug] when entering openbmc.pm

* modified error msg

* Make sure credential files have a trailing newline (#4442)

* modified depending on comments

* Fix the typo in the man page of makegocons

* Update the print out based on the review comment, should not use  since the regular expression is removed

* Modify the nodeset disjoint test case accordingly for #4426

* Use short hostname in rcons for goconserver

As the certificate of xcat is signed with short hostname, this
commit force to use the short hostname in  the environment variable for
`congo console`.

* Fix issue 3497, make sense for reventlog msg

* Give summary after flash active when no debugmode

* Fix the issue that the IP configuration will fail if bmc attribute is a hostname

* enhance genimage for sles12sp2 (#4450)

* Add dhcp-client-identifier to lease block (#4429)

Machines that use Infiniband for PXE booting need to have the
dhcp-client-identifier set in the lease block.
Without it, they will not get the lease from the server.

* Support multiple bonds on bring-up

* modified depending on comments

* fix the check for rc to 1 on error cases

* modify response for bmcdiscover when error

* Ignore syslog error in monitorctrl when setNodeStatusAttributes (#4459)

* fix issue https://github.com/xcat2/xcat-core/issues/4411 (#4462)

* fix issue Compute nodes fail to get provisioned #4411: covert imgsrv and xcatmaster to their ip addresses in case the hostname cannot be resolved inside initrd for diskless

* More strict check to tell if it is a chroot env to avoid modify DB (#4463)

when genimage for SN image (#4365)

* issues for install license file on accton switches (#4460)

* Add test cases for rflash regular usage against openbmc

* modify depending on xuwei's comment

* add 2 more cases for option d

* enhance rflash upload message

* Do not display message for clearing dumps when only PNOR

* Display hostname even if multiple IP addresses

* modified depending on comments

* polished message

* Modify the default consoleondemand based on the global setting

This commit fix the bug that consoleondemand works incorrectly.

* modify depending on comments

* modified depending on comments

* enhance rflash error messages

* Modify documenation for servicenode attributes

* build rst file from Schema.pm by db2man

* change status back to starts

* modified depending on comments

* rm openbmcevents

* Usage and man page update for rspconfig dump

* let rflash error message flexible

* Add support for the "file -> (noderange) file" syntax in synclist with ServiceNodes (#4445)

* Add support for "file -  (noderange) file" in synclist when using
hierarchical mode. Fixes #4425

  This patch ensures that:
  1. the synclist is correctly parsed when running on a Service Node
  2. all files are synchronized to SNs in hierarchical mode

* Better test condition for #4425, addresses issue in
https://github.com/xcat2/xcat-core/pull/4445#issuecomment-349472901

* Fix issue 4477, if has node-<mac> will not create node-<mtms> for the same node

* fix issue updatenode -f loses directories when copying files to SN #4456 (#4494)

* comment from ErTao

* Crude attempt at including external configuration files in named.conf

* Fixes after the review

* Fix issue 4490, record any error when rflash active process

* add -d usage and manpage

* updatenode -F not work in hierachy env as the user name is FQDN of MN (#4484)

* updatenode -F not work in hierachy env (#4455)
 - add trace when -V is enabled
 - get the DSH_FROM_USERID from updatenode client

*  - when 'updatenode -F' need to push SN first, using root as non-root does not have permission write to 'SNsyncfiledir'
 - move the set DSH_FROM_USERID code out of the loop, and also cover remote client case.

* fix issue for command rspconfig hostname=*

* enhance rflash

* Adjust the server used for kernel/initrd and imgurl for petitboot (#4416)
 - URL for kernel/initrd, get the value from below value tftpserver -> xcatmaster -> myipfn
 - URL for image, get the value from below value nfsserver -> tftpserver -> xcatmaster -> myipfn

* NODE attribute didn't populate in /opt/xcat/xcatinfo after reboot (#4428)

* NODE attribute didn't populate in /opt/xcat/xcatinfo after reboot

* Get NODE from mypostscripts

* Improve the output message for reventlog, use a global variable to set PolicyFile Path

* If debug_msg is not provided, use an empty string

* Check for LinkLocal as well as 169.254 IP address

* Fix issue 4507, add parameter check for rspconfig admin_passwd

* record more information when rflash upload error

* Fix the error when using array ref in updatenode with old version perl, it is introduced by PR#4484 (#4518)

* Do not restart conserver if goconserver was started

If goconserver was enabled, do not start conserver when restart
xcatd on service node.

* remove the /etc/localtime before copy timezone file

* Use CONGO_CLIENT_TYPE to tell goconserver the source of client (#4501)

goconserver could send back message based on the client type
this commit set CONGO_CLIENT_TYPE to xcat to make the message
from goconserver more friendly.

* add rflash -d doc

* only ignore 169.254.x.x for OpenBMC

* Fix issue 4513, print out better error msg for reventlog -s

* Modify or add openbmc test cases or bundle

* add test cases for updatenode -f/F in hierarchy environment, covers issues #4456,#4455 and PR #4425 (#4500)
2017-12-14 05:03:34 -06:00

721 lines
26 KiB
Perl

# IBM(c) 2014 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT_plugin::petitboot;
use File::Path;
use Getopt::Long;
use xCAT::Table;
use Sys::Syslog;
use xCAT::Scope;
use xCAT::Usage;
my $globaltftpdir = xCAT::TableUtils->getTftpDir();
my %usage = (
"nodeset" => "Usage: nodeset <noderange> osimage[=<imagename>]",
);
my $httpmethod = "http";
my $httpport = "80";
sub handled_commands {
return {
nodeset => "noderes:netboot"
}
}
sub check_dhcp {
return 1;
#TODO: omapi magic to do things right
my $node = shift;
my $dhcpfile;
open($dhcpfile, $dhcpconf);
while (<$dhcpfile>) {
if (/host $node\b/) {
close $dhcpfile;
return 1;
}
}
close $dhcpfile;
return 0;
}
sub _slow_get_tftpdir { #make up for paths where tftpdir is not passed in
my $node = shift;
my $nrtab = xCAT::Table->new('noderes', -create => 0); #in order to detect per-node tftp directories
unless ($nrtab) { return $globaltftpdir; }
my $ent = $nrtab->getNodeAttribs($node, ["tftpdir"]);
if ($ent and $ent->{tftpdir}) {
return $ent->{tftpdir};
} else {
return $globaltftpdir;
}
}
sub getstate {
my $node = shift;
my $tftpdir = shift;
unless ($tftpdir) { $tftpdir = _slow_get_tftpdir($node); }
if (check_dhcp($node)) {
if (-r $tftpdir . "/petitboot/" . $node) {
my $fhand;
open($fhand, $tftpdir . "/petitboot/" . $node);
my $headline = <$fhand>;
close $fhand;
$headline =~ s/^#//;
chomp($headline);
return $headline;
} else {
# There is no boot configuration file, node must be offline
return "offline";
}
} else {
return "discover";
}
}
sub setstate {
=pod
This function will manipulate the petitboot structure to match what the noderes/chain tables indicate the node should be booting.
=cut
my $node = shift;
my %bphash = %{ shift() };
my %chainhash = %{ shift() };
my %machash = %{ shift() };
my $tftpdir = shift;
my %nrhash = %{ shift() };
my $linuximghash = shift();
my $kern = $bphash{$node}->[0];
if ($kern->{kernel} !~ /^$tftpdir/) {
my $nodereshash = $nrhash{$node}->[0];
my $installsrv;
if ($nodereshash and $nodereshash->{tftpserver}) {
$installsrv = $nodereshash->{tftpserver};
} elsif ($nodereshash->{xcatmaster}) {
$installsrv = $nodereshash->{xcatmaster};
} else {
$installsrv = '!myipfn!';
}
$kern->{kernel} = "$httpmethod://$installsrv:$httpport$tftpdir/" . $kern->{kernel};
$kern->{initrd} = "$httpmethod://$installsrv:$httpport$tftpdir/" . $kern->{initrd};
}
if ($kern->{kcmdline} =~ /!myipfn!/ or $kern->{kernel} =~ /!myipfn!/) {
my $ipfn;
my @ipfnd = xCAT::NetworkUtils->my_ip_facing($node);
if ($ipfnd[0] == 1) {
return (1, $ipfnd[1]);
}
elsif ($ipfnd[0] == 2) {
my $servicenodes = $nrhash{$node}->[0];
if ($servicenodes and $servicenodes->{servicenode}) {
my @sns = split /,/, $servicenodes->{servicenode};
foreach my $sn (@sns) {
# We are in the service node pools, print error if no facing ip.
if (xCAT::InstUtils->is_me($sn)) {
return (1, "$::myxcatname: $ipfnd[1] on service node $sn");
}
}
} else {
return (1, "$::myxcatname: $ipfnd[1]");
}
} else {
$ipfn = $ipfnd[1];
$kern->{kernel} =~ s/!myipfn!/$ipfn/g;
$kern->{initrd} =~ s/!myipfn!/$ipfn/g;
$kern->{kcmdline} =~ s/!myipfn!/$ipfn/g;
}
}
if ($kern->{addkcmdline}) {
$kern->{kcmdline} .= " " . $kern->{addkcmdline};
}
if ($linuximghash and $linuximghash->{'addkcmdline'})
{
unless ($linuximghash->{'boottarget'})
{
$kern->{kcmdline} .= " " . $linuximghash->{'addkcmdline'};
}
}
my $bootloader_root = "$tftpdir/petitboot";
unless (-d "$bootloader_root") {
mkpath("$bootloader_root");
}
my $cref = $chainhash{$node}->[0];
unless ($cref->{currstate}) { # the currstate should be set during 'setdestiny'
return (1, "Cannot determine current state for this node");
}
my $pcfg;
# remove the old boot configuration file and create a new one, but only if not offline directive
unlink("$bootloader_root/" . $node);
if ($cref and $cref->{currstate} ne "offline") {
open($pcfg, '>', "$bootloader_root/" . $node);
print $pcfg "#" . $cref->{currstate} . "\n";
}
if ($cref and $cref->{currstate} eq "boot") {
close($pcfg);
} elsif ($kern and $kern->{kernel} and $cref and $cref->{currstate} ne "offline") {
#It's time to set petitboot for this node to boot the kernel, but only if not offline directive
my $label = "xCAT";
if ($cref->{currstate} eq "shell") {
$label = "xCAT Genesis shell";
}
print $pcfg "default $label\n";
print $pcfg "label $label\n";
print $pcfg "\tkernel $kern->{kernel}\n";
if ($kern and $kern->{initrd}) {
print $pcfg "\tinitrd " . $kern->{initrd} . "\n";
}
if ($kern and $kern->{kcmdline}) {
print $pcfg "\tappend \"" . $kern->{kcmdline} . "\"\n";
}
close($pcfg);
} else { #TODO: actually, should possibly default to xCAT image?
#print $pcfg "bye\n";
close($pcfg);
}
my $ip = xCAT::NetworkUtils->getipaddr($node);
unless ($ip) {
return (1, "xCAT unable to resolve IP for $node in petitboot plugin.");
}
my @ipa = split(/\./, $ip);
my $pname = sprintf("%02x%02x%02x%02x", @ipa);
$pname = uc($pname);
# remove the old boot configuration file and copy (link) a new one, but only if not offline directive
unlink("$tftpdir/" . $pname);
if ($cref and $cref->{currstate} ne "offline") {
link("$bootloader_root/" . $node, "$tftpdir/" . $pname);
}
return (0, "");
}
my $errored = 0;
sub pass_along {
my $resp = shift;
return unless ($resp);
my $failure = 0;
if ($resp->{errorabort}) { # Global error, it normally means to stop the parent execution. For example, DB operation error.
$failure = 2;
delete $resp->{errorabort};
} elsif (($resp->{errorcode} and $resp->{errorcode}->[0]) or ($resp->{error} and $resp->{error}->[0])) {
$failure = 1;
}
$callback->($resp);
if ($failure > 1) { # quick abort
$errored = $failure;
return;
}
# Partial error on nodes, it allows to continue the rest of business on the sucessful nodes.
foreach (@{ $resp->{node} }) {
if ($_->{error} or $_->{errorcode}) {
$failure = 1;
if ($_->{name}) {
$failurenodes{$_->{name}->[0]} = 2;
}
}
}
if ( $failure ) {
$errored = $failure;
}
}
sub preprocess_request {
my $req = shift;
if ($req->{_xcatpreprocessed}->[0] == 1) { return [$req]; }
my $callback1 = shift;
my $command = $req->{command}->[0];
my $sub_req = shift;
my @args = ();
if (ref($req->{arg})) {
@args = @{ $req->{arg} };
} else {
@args = ($req->{arg});
}
@ARGV = @args;
my $nodes = $req->{node};
#use Getopt::Long;
my $HELP;
my $ALLFLAG;
my $VERSION;
my $VERBOSE;
Getopt::Long::Configure("bundling");
Getopt::Long::Configure("pass_through");
if (!GetOptions('h|?|help' => \$HELP,
'v|version' => \$VERSION,
'a' =>\$ALLFLAG,
'V' => \$VERBOSE #>>>>>>>used for trace log>>>>>>>
)) {
if ($usage{$command}) {
my %rsp;
$rsp{data}->[0] = $usage{$command};
$callback1->(\%rsp);
}
return;
}
#>>>>>>>used for trace log start>>>>>>
my $verbose_on_off = 0;
if ($VERBOSE) { $verbose_on_off = 1; }
#>>>>>>>used for trace log end>>>>>>>
if ($HELP) {
if ($usage{$command}) {
my %rsp;
$rsp{data}->[0] = $usage{$command};
$callback1->(\%rsp);
}
return;
}
if ($VERSION) {
my $ver = xCAT::Utils->Version();
my %rsp;
$rsp{data}->[0] = "$ver";
$callback1->(\%rsp);
return;
}
my $ret=xCAT::Usage->validateArgs($command,@ARGV);
if ($ret->[0]!=0) {
if ($usage{$command}) {
my %rsp;
$rsp{error}->[0] = $ret->[1];
$rsp{data}->[1] = $usage{$command};
$rsp{errorcode}->[0] = $ret->[0];
$callback1->(\%rsp);
}
return;
}
if ($ARGV[0] ne "stat" && $ALLFLAG) {
my %rsp;
$rsp{error}->[0] = "'-a' could only be used with 'stat' subcommand.";
$rsp{errorcode}->[0] = 1;
$callback1->(\%rsp);
return;
}
#Assume shared tftp directory for boring people, but for cool people, help sync up tftpdirectory contents when
#if they specify no sharedtftp in site table
my @entries = xCAT::TableUtils->get_site_attribute("sharedtftp");
my $t_entry = $entries[0];
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: sharedtftp = $t_entry");
if (defined($t_entry) and ($t_entry == 0 or $t_entry =~ /no/i)) {
# check for computenodes and servicenodes from the noderange, if so error out
my @SN;
my @CN;
xCAT::ServiceNodeUtils->getSNandCPnodes(\@$nodes, \@SN, \@CN);
unless (($args[0] eq 'stat') or ($args[0] eq 'enact')) {
if ((@SN > 0) && (@CN > 0)) { # there are both SN and CN
my %rsp;
$rsp{errorcode}->[0] = 1;
$rsp{error}->[0] =
"Nodeset was run with a noderange containing both service nodes and compute nodes. This is not valid. You must submit with either compute nodes in the noderange or service nodes. \n";
$callback1->(\%rsp);
return;
}
}
$req->{'_disparatetftp'} = [1];
if ($req->{inittime}->[0]) {
return [$req];
}
if (@CN > 0) { # if compute nodes only, then broadcast to servic enodes
my @sn = xCAT::ServiceNodeUtils->getSNList();
unless ( @sn > 0 ) {
return xCAT::Scope->get_parallel_scope($req)
}
my $mynodeonly = 0;
my @entries = xCAT::TableUtils->get_site_attribute("disjointdhcps");
my $t_entry = $entries[0];
if (defined($t_entry)) {
$mynodeonly = $t_entry;
}
$req->{'_disjointmode'} = [$mynodeonly];
xCAT::MsgUtils->trace(0, "d", "petitboot: disjointdhcps=$mynodeonly");
if ($mynodeonly == 0 || $ALLFLAG) { # broadcast to all service nodes
return xCAT::Scope->get_broadcast_scope_with_parallel($req, \@sn);
}
my $sn_hash = xCAT::ServiceNodeUtils->getSNformattedhash(\@CN, "xcat", "MN");
my @dhcpsvrs = ();
my $ntab = xCAT::Table->new('networks');
if ($ntab) {
foreach (@{ $ntab->getAllEntries() }) {
next unless ($_->{dynamicrange});
push @dhcpsvrs, $_->{dhcpserver} if ($_->{dhcpserver} && xCAT::NetworkUtils->nodeonmynet($_->{dhcpserver}));
}
}
return xCAT::Scope->get_broadcast_disjoint_scope_with_parallel($req, $sn_hash, \@dhcpsvrs);
}
}
# Do not dispatch to service nodes if non-sharedtftp or the node range contains only SNs.
return xCAT::Scope->get_parallel_scope($req);
}
sub process_request {
$request = shift;
$callback = shift;
$::callback = $callback;
$sub_req = shift;
my $command = $request->{command}->[0];
undef %failurenodes;
#>>>>>>>used for trace log start>>>>>>>
my @args = ();
my %opt;
my $verbose_on_off = 0;
if (ref($request->{arg})) {
@args = @{ $request->{arg} };
} else {
@args = ($request->{arg});
}
@ARGV = @args;
GetOptions('V' => \$opt{V});
if ($opt{V}) { $verbose_on_off = 1; }
#>>>>>>>used for trace log end>>>>>>>
if ($::XCATSITEVALS{"httpmethod"}) { $httpmethod = $::XCATSITEVALS{"httpmethod"}; }
if ($::XCATSITEVALS{"httpport"}) { $httpport = $::XCATSITEVALS{"httpport"}; }
my @hostinfo = xCAT::NetworkUtils->determinehostname();
$::myxcatname = $hostinfo[-1];
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: running on $::myxcatname");
my @rnodes;
if (ref($request->{node})) {
@rnodes = @{ $request->{node} };
} else {
if ($request->{node}) { @rnodes = ($request->{node}); }
}
unless (@rnodes) {
if ($usage{ $request->{command}->[0] }) {
$callback->({ data => $usage{ $request->{command}->[0] } });
}
return;
}
if ($args[0] eq 'stat') {
my $noderestab = xCAT::Table->new('noderes'); #in order to detect per-node tftp directories
my %nrhash = %{ $noderestab->getNodesAttribs(\@rnodes, [qw(tftpdir)]) };
foreach my $node (@rnodes) {
my %response;
my $tftpdir;
if ($nrhash{$node}->[0] and $nrhash{$node}->[0]->{tftpdir}) {
$tftpdir = $nrhash{$node}->[0]->{tftpdir};
} else {
$tftpdir = $globaltftpdir;
}
$response{node}->[0]->{name}->[0] = $node;
$response{node}->[0]->{data}->[0] = getstate($node, $tftpdir);
$callback->(\%response);
}
return;
}
my @nodes = ();
# Filter those nodes which have bad DNS: not resolvable or inconsistent IP
my %preparednodes = ();
foreach (@rnodes) {
my $ipret = xCAT::NetworkUtils->checkNodeIPaddress($_);
my $errormsg = $ipret->{'error'};
my $nodeip = $ipret->{'ip'};
if ($errormsg) {# Add the node to failure set
xCAT::MsgUtils->trace(0, "E", "petitboot: Defined IP address of $_ is $nodeip. $errormsg");
unless ($nodeip) {
$failurenodes{$_} = 1;
}
}
if ($nodeip) {
$preparednodes{$_} = $nodeip;
}
}
#if not shared tftpdir, then filter, otherwise, set up everything
if ($request->{'_disparatetftp'}->[0]) { #reading hint from preprocess_command
# Filter those nodes not in the same subnet, and print error message in log file.
foreach (keys %preparednodes) {
# Only handle its boot configuration files if the node in same subnet
if (xCAT::NetworkUtils->nodeonmynet($preparednodes{$_})) {
push @nodes, $_;
} else {
xCAT::MsgUtils->trace(0, "W", "petitboot: configuration file was not created for [$_] because the node is not on the same network as this server");
delete $preparednodes{$_};
}
}
} else {
@nodes = keys %preparednodes;
}
my $str_node = join(" ", @nodes);
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: nodes are $str_node") if ($str_node);
# Return directly if no nodes in the same network, need to report error on console if its managed nodes are not handled.
unless (@nodes) {
xCAT::MsgUtils->message("S", "xCAT: petitboot netboot: no valid nodes. Stop the operation on this server.");
# If non-shared tftproot and non disjoint mode, need to figure out if no nodes here is a normal case.
if ($request->{'_disparatetftp'}->[0] && $request->{'_disjointmode'}->[0] != 1) {
# Find out which nodes are really mine only when not sharedtftp and not disjoint mode.
my %iphash = ();
# flag the IPs or names in iphash
foreach (@hostinfo) { $iphash{$_} = 1; }
# Get managed node list under current server
# The node will be under under 'site.master' if no 'noderes.servicenode' is defined
my $sn_hash = xCAT::ServiceNodeUtils->getSNformattedhash(\@rnodes, "xcat", "MN");
my $req2manage = 0;
foreach (keys %$sn_hash) {
if (exists($iphash{$_})) {
$req2manage = 1;
last;
}
}
if ($req2manage == 0) {
#No nodes are required to be handled, quit without error.
return;
}
}
# Okay, now report error as no nodes are handled.
my $rsp;
$rsp->{errorcode}->[0] = 1;
$rsp->{error}->[0] = "Failed to generate petitboot configurations for some node(s) on $::myxcatname. Check xCAT log file for more details.";
$callback->($rsp);
return;
}
#now run the begin part of the prescripts
unless ($args[0] eq '') { # or $args[0] eq 'enact') {
$errored = 0;
if ($request->{'_disparatetftp'}->[0]) { #the call is distrubuted to the service node already, so only need to handle my own children
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: the call is distrubuted to the service node already, so only need to handle my own children");
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: issue runbeginpre request");
$sub_req->({ command => ['runbeginpre'],
node => \@nodes,
arg => [ $args[0], '-l' ] }, \&pass_along);
} else { #nodeset did not distribute to the service node, here we need to let runednpre to distribute the nodes to their masters
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: nodeset did not distribute to the service node");
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: issue runbeginpre request");
$sub_req->({ command => ['runbeginpre'],
node => \@nodes,
arg => [ $args[0] ] }, \&pass_along);
}
if ($errored) {
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: Failed in running begin prescripts.");
return if ($errored > 1);
}
}
#back to normal business
my $inittime = 0;
if (exists($request->{inittime})) { $inittime = $request->{inittime}->[0]; }
if (!$inittime) { $inittime = 0; }
my %bphash;
unless ($args[0] eq '') { # or $args[0] eq 'enact') {
$errored = 0;
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: issue setdestiny request");
$sub_req->({ command => ['setdestiny'],
node => \@nodes,
inittime => [$inittime],
arg => \@args,
bootparams => \%bphash},
\&pass_along);
if ($errored) {
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: Failed in processing setdestiny.");
return if ($errored > 1);
}
}
# Fix the bug 4611: PowerNV stateful CN provision will hang at reboot stage#
if ($args[0] eq 'next') {
$sub_req->({ command => ['rsetboot'],
node => \@nodes,
arg => ['default'],
#workaround the bug 3026, to ignore it for openbmc
_xcat_ignore_flag => ['openbmc'],
#todo: do not need to pass the XCAT_OPENBMC_DEVEL after the openbmc dev work finish
#this does not hurt anything for other plugins
environment => {XCAT_OPENBMC_DEVEL=>"YES"}
});
xCAT::MsgUtils->message("S", "xCAT: petitboot netboot: clear node(s): $str_node boot device setting.");
}
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: starting to handle configuration...");
my $chaintab = xCAT::Table->new('chain', -create => 1);
my $chainhash = $chaintab->getNodesAttribs(\@nodes, ['currstate']);
my $noderestab = xCAT::Table->new('noderes', -create => 1);
my $nodereshash = $noderestab->getNodesAttribs(\@nodes, [ 'tftpdir', 'xcatmaster', 'tftpserver', 'servicenode' ]);
my $typetab = xCAT::Table->new('nodetype', -create => 1);
my $typehash = $typetab->getNodesAttribs(\@nodes, [ 'os', 'provmethod', 'arch', 'profile' ]);
my $linuximgtab = xCAT::Table->new('linuximage', -create => 1);
my $osimagetab = xCAT::Table->new('osimage', -create => 1);
my %machash = ();
my $rc;
my $errstr;
my @normalnodeset = ();
foreach (@nodes) {
next if (exists($failurenodes{$_}));
my $tftpdir = $globaltftpdir;
if ($nodereshash->{$_} and $nodereshash->{$_}->[0] and $nodereshash->{$_}->[0]->{tftpdir}) {
$tftpdir = $nodereshash->{$_}->[0]->{tftpdir};
}
my %response;
$response{node}->[0]->{name}->[0] = $_;
if ($args[0]) { # send it on to the destiny plugin, then setstate
my $ent = $typehash->{$_}->[0];
my $osimgname = $ent->{'provmethod'};
my $linuximghash = $linuximgtab->getAttribs({ imagename => $osimgname }, 'boottarget', 'addkcmdline');
($rc, $errstr) = setstate($_, \%bphash, $chainhash, $machash, $tftpdir, $nodereshash, $linuximghash);
if ($rc) {
$response{node}->[0]->{errorcode}->[0] = $rc;
$response{node}->[0]->{error}->[0] = $errstr;
$failurenodes{$_} = 1;
$callback->(\%response);
} else {
push @normalnodeset, $_;
}
}
} # end of foreach node
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: Finish to handle configurations");
#Don't bother to try dhcp binding changes if sub_req not passed, i.e. service node build time
unless ($inittime) {
#dhcp stuff
my $do_dhcpsetup = 1;
my @entries = xCAT::TableUtils->get_site_attribute("dhcpsetup");
my $t_entry = $entries[0];
if (defined($t_entry)) {
if ($t_entry =~ /0|n|N/) { $do_dhcpsetup = 0; }
}
# For offline operation, remove the dhcp entries whatever dhcpset is disabled in site ( existing code logic, just keep it as is)
if ($do_dhcpsetup || $args[0] eq 'offline') {
my @parameter;
push @parameter, '-l' if ($request->{'_disparatetftp'}->[0]);
push @parameter, '-d' if ($args[0] eq 'offline');
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: issue makedhcp request");
$sub_req->({ command => ['makedhcp'],
arg => \@parameter,
node => \@normalnodeset }, $callback);
} else {
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: dhcpsetup=$do_dhcpsetup");
}
}
#now run the end part of the prescripts
unless ($args[0] eq '') { # or $args[0] eq 'enact')
$errored = 0;
if ($request->{'_disparatetftp'}->[0]) { #the call is distrubuted to the service node already, so only need to handles my own children
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: issue runendpre request");
$sub_req->({ command => ['runendpre'],
node => \@normalnodeset,
arg => [ $args[0], '-l' ] }, \&pass_along);
} else { #nodeset did not distribute to the service node, here we need to let runednpre to distribute the nodes to their masters
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: issue runendpre request");
$sub_req->({ command => ['runendpre'],
node => \@normalnodeset,
arg => [ $args[0] ] }, \&pass_along);
}
if ($errored) {
xCAT::MsgUtils->trace($verbose_on_off, "d", "petitboot: Failed in running end prescripts.");
}
}
# Return error codes if there are failed nodes
if (%failurenodes) {
my $rsp;
$rsp->{errorcode}->[0] = 1;
$rsp->{error}->[0] = "Failed to generate petitboot configurations for some node(s) on $::myxcatname. Check xCAT log file for more details.";
$callback->($rsp);
return;
}
}
#----------------------------------------------------------------------------
=head3 getNodesetStates
returns the nodeset state for the given nodes. The possible nodeset
states are: netboot, install, boot and discover.
Arguments:
nodes --- a pointer to an array of nodes
states -- a pointer to a hash table. This hash will be filled by this
function.The key is the nodeset status and the value is a pointer
to an array of nodes.
Returns:
(return code, error message)
=cut
#-----------------------------------------------------------------------------
sub getNodesetStates {
my $noderef = shift;
if ($noderef =~ /xCAT_plugin::petitboot/) {
$noderef = shift;
}
my @nodes = @$noderef;
my $hashref = shift;
my $noderestab = xCAT::Table->new('noderes'); #in order to detect per-node tftp directories
my %nrhash = %{ $noderestab->getNodesAttribs(\@nodes, [qw(tftpdir)]) };
if (@nodes > 0) {
foreach my $node (@nodes) {
my $tftpdir;
if ($nrhash{$node}->[0] and $nrhash{$node}->[0]->{tftpdir}) {
$tftpdir = $nrhash{$node}->[0]->{tftpdir};
} else {
$tftpdir = $globaltftpdir;
}
my $tmp = getstate($node, $tftpdir);
my @a = split(' ', $tmp);
my $stat = $a[0];
if (exists($hashref->{$stat})) {
my $pa = $hashref->{$stat};
push(@$pa, $node);
}
else {
$hashref->{$stat} = [$node];
}
}
}
return (0, "");
}
1;