2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-21 19:22:05 +00:00

fix issue [fvt]2.13.4 nodeset osimage have no right output if command wrong #2971 (#3147)

* fix issue#2971:  one CLI arguments validation issue is not correct for nodeset/rinstall/winstall
This commit is contained in:
yangsong 2017-05-31 04:36:09 -05:00 committed by Bin Xu
parent 358eefed2a
commit 5c4dd31844
7 changed files with 91 additions and 21 deletions

View File

@ -622,3 +622,41 @@ sub parseCommand {
return "";
}
#------------------------------------------------------------------------------
=head3 validateArgs
This function validates the arguments of the specified command
Arguments:
command
arguments(array @)
Returns:
$ref: a reference to array of [$retcode(integer),$info(string)]
$ref->[0]=0 : validation passed
$ret->[0]!=0: validation failed, the error info is returned in $ref->[1]
=cut
#-------------------------------------------------------------------------------
sub validateArgs {
my $command=shift;
if ($command =~ /xCAT::Usage/) { $command = shift; }
my $count=0;
my @extrargs=@_;
if($command =~ m/^(nodeset|rinstall|winstall)$/ ){
#suppose that argument like "-p foo" have been processed and
#filtered by GetOpt subroutine
#fortunately the commands in this branch does not have such options
foreach(@extrargs){
if($_ !~ m/^-[-]?\S+/){
$count+=1;
}
}
if ($count!=1) {
return [1,"Invalid argument: '".join(" ",@extrargs)."'"];
}
}
return [0];
}

View File

@ -187,8 +187,15 @@ sub setdestiny {
chomp($state);
my $target;
my $action;
my $rawstate=$state;
if ($state =~ /=/) {
($state, $target) = split '=', $state, 2;
if(!$target){
$callback->({ error => "invalid argument: \"$rawstate\"", errorcode => [1] });
return;
}
if ($target =~ /:/) {
($target, $action) = split ':', $target, 2;
}

View File

@ -12,7 +12,7 @@ use File::Path;
use Socket;
use Getopt::Long;
use xCAT::Table;
use xCAT::Usage;
my $request;
my %breaknetbootnodes;
our %normalnodes;
@ -426,10 +426,13 @@ sub preprocess_request {
return;
}
if (@ARGV == 0) {
my $ret=xCAT::Usage->validateArgs($command,@ARGV);
if ($ret->[0]!=0) {
if ($usage{$command}) {
my %rsp;
$rsp{data}->[0] = $usage{$command};
$rsp{error}->[0] = $ret->[1];
$rsp{data}->[1] = $usage{$command};
$rsp{errorcode}->[0] = $ret->[0];
$callback1->(\%rsp);
}
return;

View File

@ -6,7 +6,7 @@ use Getopt::Long;
use xCAT::Table;
use Sys::Syslog;
use xCAT::Scope;
use xCAT::Usage;
my $globaltftpdir = xCAT::TableUtils->getTftpDir();
my %usage = (
@ -322,11 +322,14 @@ sub preprocess_request {
return;
}
if (@ARGV == 0) {
if ($usage{$command}) {
my %rsp;
$rsp{data}->[0] = $usage{$command};
$callback1->(\%rsp);
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;
}

View File

@ -18,6 +18,7 @@ require xCAT::Utils;
require xCAT::MsgUtils;
use xCAT::NodeRange;
use xCAT::Table;
use xCAT::Usage;
use Data::Dumper;
use Getopt::Long;
@ -96,6 +97,16 @@ sub rinstall {
}
if (($command =~ /rinstall/) or ($command =~ /winstall/)) {
my $ret=xCAT::Usage->validateArgs($command,@ARGV);
if ($ret->[0]!=0) {
my $rsp={};
$rsp->{error}->[0] = $ret->[1];
$rsp->{errorcode}->[0] = $ret->[0];
xCAT::MsgUtils->message("E", $rsp, $callback);
&usage($command,$callback);
return;
}
my $state = $ARGV[0];
my $reststates;
($state, $reststates) = split(/,/, $state, 2);

View File

@ -11,6 +11,7 @@ use Getopt::Long;
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::ServiceNodeUtils;
use xCAT::Usage;
my $dhcpconf = "/etc/dhcpd.conf";
@ -367,11 +368,14 @@ sub preprocess_request {
return;
}
if (@ARGV == 0) {
if ($usage{$command}) {
my %rsp;
$rsp{data}->[0] = $usage{$command};
$callback1->(\%rsp);
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;
}

View File

@ -12,6 +12,7 @@ use File::Path;
use Socket;
use Getopt::Long;
use xCAT::Table;
use xCAT::Usage;
my %breaknetbootnodes;
our %normalnodes;
@ -422,15 +423,18 @@ sub preprocess_request {
return;
}
if (@ARGV == 0) {
if ($usage{$command}) {
my %rsp;
$rsp{data}->[0] = $usage{$command};
$callback1->(\%rsp);
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;
}
}
#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