diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 530bc0d5a..cc03a05b5 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -4968,5 +4968,4 @@ sub console_sleep { sleep($time); } - 1; diff --git a/xCAT-server/lib/perl/xCAT/OPENBMC.pm b/xCAT-server/lib/perl/xCAT/OPENBMC.pm index ae19224c9..8984a7a10 100644 --- a/xCAT-server/lib/perl/xCAT/OPENBMC.pm +++ b/xCAT-server/lib/perl/xCAT/OPENBMC.pm @@ -22,6 +22,7 @@ use File::Path; use Fcntl ":flock"; use IO::Socket::UNIX qw( SOCK_STREAM ); use xCAT_monitoring::monitorctrl; +use xCAT::TableUtils; my $LOCK_DIR = "/var/lock/xcat/"; my $LOCK_PATH = "/var/lock/xcat/agent.lock"; @@ -201,8 +202,8 @@ sub wait_agent { sub is_openbmc_python { my $environment = shift; $environment = shift if (($environment) && ($environment =~ /OPENBMC/)); - # If XCAT_OPENBMC_PYTHON is YES, - # will return "ALL" and caller will run openbmc2.pm. + # If XCAT_OPENBMC_PYTHON is YES, + # will return "ALL" and caller will run openbmc2.pm. # If XCAT_OPENBMC_PYTHON is not set or is set to NO, return "NO" and caller # will run openbmc.pm # If XCAT_OPENBMC_PYTHON is a list of commands, return that list and caller @@ -215,7 +216,7 @@ sub is_openbmc_python { } else { $::OPENBMC_PYTHON = $environment->{XCAT_OPENBMC_PYTHON}; } - if (defined($::OPENBMC_PYTHON)) { + if (defined($::OPENBMC_PYTHON)) { if ($::OPENBMC_PYTHON eq "YES") { return "ALL"; } @@ -230,4 +231,53 @@ sub is_openbmc_python { return "NO"; } +#-------------------------------------------------------------------------------- + +=head3 is_support_in_perl + check if specified command is included in site attribute openbmcperl + The policy is: + Get value from `openbmcperl`, `XCAT_OPENBMC_DEVEL`, agent.py: + 1. If agent.py not exist: ==>Go Perl + 2. If `openbmcperl` not set or not include a command: + if `XCAT_OPENBMC_DEVEL` set to `NO`: ==> Go Perl + else if set to `YES` or not set: ==> Go Python + 3. If `openbmcperl` set and include a command + if `XCAT_OPENBMC_DEVEL` set to `YES`: == >Go Python + else ==> Go Perl +=cut + +#-------------------------------------------------------------------------------- +sub is_support_in_perl { + my ($class, $command, $env) = @_; + if (! -e $PYTHON_AGENT_FILE) { + return (1, ''); + } + my @entries = xCAT::TableUtils->get_site_attribute("openbmcperl"); + my $site_entry = $entries[0]; + my $support_obmc = undef; + if (ref($env) eq 'ARRAY' and ref($env->[0]->{XCAT_OPENBMC_DEVEL}) eq 'ARRAY') { + $support_obmc = $env->[0]->{XCAT_OPENBMC_DEVEL}->[0]; + } elsif (ref($env) eq 'ARRAY') { + $support_obmc = $env->[0]->{XCAT_OPENBMC_DEVEL}; + } else { + $support_obmc = $env->{XCAT_OPENBMC_DEVEL}; + } + if ($support_obmc and $support_obmc ne 'YES' and $support_obmc ne 'NO') { + return (-1, "Value $support_obmc is invalid for XCAT_OPENBMC_DEVEL, only support 'YES' and 'NO'"); + } + if ($site_entry and $site_entry =~ $command) { + if ($support_obmc and $support_obmc eq 'YES') { + return (0, ''); + } else { + return (1, ''); + } + } else { + if ($support_obmc and $support_obmc eq 'NO') { + return (1, ''); + } else { + return (0, ''); + } + } +} + 1; diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 02fc8598a..3d61835ad 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -758,21 +758,12 @@ sub preprocess_request { $callback = shift; my $command = $request->{command}->[0]; - my $python_env = xCAT::OPENBMC->is_openbmc_python($request->{environment}); - # Process command in this module only if PYTHON env is not ALL or command is - # listed in the PYTHON env list (without EXCEPT: prefix. - # All other cases => return - SWITCH: { - if ($python_env eq "ALL") {$request = {}; return;} - if ($python_env eq "NO") {last SWITCH;} - if ($python_env !~ $command) { - if ($python_env =~ /^EXCEPT:/) {$request = {}; return;} - else {last SWITCH;} - } - if ($python_env =~ $command) { - if ($python_env =~ /^EXCEPT:/) {last SWITCH;} - else {$request = {}; return;} - } + my ($rc, $msg) = xCAT::OPENBMC->is_support_in_perl($command, $request->{environment}); + if ($rc == 0) { $request = {}; return;} + if ($rc < 0) { + $request = {}; + $callback->({ errorcode => [1], data => [$msg] }); + return; } if ($::XCATSITEVALS{xcatdebugmode}) { $xcatdebugmode = $::XCATSITEVALS{xcatdebugmode} } diff --git a/xCAT-server/lib/xcat/plugins/openbmc2.pm b/xCAT-server/lib/xcat/plugins/openbmc2.pm index 1bcf513a0..0e6364b48 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc2.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc2.pm @@ -13,7 +13,6 @@ use warnings "all"; use JSON; use Getopt::Long; -use xCAT::Utils; use xCAT::Usage; use xCAT::SvrUtils; use xCAT::OPENBMC; @@ -63,23 +62,8 @@ sub preprocess_request { $callback = shift; my $command = $request->{command}->[0]; - my $python_env = xCAT::OPENBMC->is_openbmc_python($request->{environment}); - # Process command in this module only if PYTHON env is not NO or - # command is listed in the PYTHON env list (without EXCEPT: prefix). - # All other cases => return - - SWITCH: { - if ($python_env eq "NO") {$request = {}; return;} - if ($python_env eq "ALL") {last SWITCH;} - if ($python_env !~ $command) { - if ($python_env =~ /^EXCEPT:/) {last SWITCH} - else {$request = {}; return;} - } - if ($python_env =~ $command) { - if ($python_env =~ /^EXCEPT:/) {$request = {}; return;} - else {last SWITCH;} - } - } + my ($rc, $msg) = xCAT::OPENBMC->is_support_in_perl($command, $request->{environment}); + if ($rc != 0) { $request = {}; return;} my $noderange = $request->{node}; my $extrargs = $request->{arg};