From c8c1fc276f0c561fae65af9e5cbcd239424edd8c Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Mon, 21 Aug 2017 15:12:41 -0400 Subject: [PATCH] Allow -d flag for rflash --- .../admin-guides/references/man1/rflash.1.rst | 8 +-- perl-xCAT/xCAT/Usage.pm | 2 +- xCAT-client/pods/man1/rflash.1.pod | 6 +- xCAT-server/lib/xcat/plugins/ipmi.pm | 59 ++++++++++++------- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/docs/source/guides/admin-guides/references/man1/rflash.1.rst b/docs/source/guides/admin-guides/references/man1/rflash.1.rst index dbece0af2..f5800fc38 100644 --- a/docs/source/guides/admin-guides/references/man1/rflash.1.rst +++ b/docs/source/guides/admin-guides/references/man1/rflash.1.rst @@ -50,7 +50,7 @@ OpenPOWER BMC specific (using IPMI): ==================================== -\ **rflash**\ \ *noderange*\ [\ *hpm_file_path*\ | \ **-d=**\ \ *data_directory*\ ] [\ **-c | -**\ **-check**\ ] [\ **-**\ **-retry=**\ \ *count*\ ] [\ **-V**\ ] +\ **rflash**\ \ *noderange*\ [\ *hpm_file_path*\ | \ **-d**\ \ *data_directory*\ ] [\ **-c | -**\ **-check**\ ] [\ **-**\ **-retry=**\ \ *count*\ ] [\ **-V**\ ] OpenPOWER OpenBMC specific : @@ -172,11 +172,11 @@ The command will update firmware for OpenPOWER OpenBMC when given an OpenPOWER n \ **-d**\ \ *data_directory*\ + PPC (without HMC, using Direct FSP Management) specific: + Specifies the directory where the raw data from rpm packages for each CEC/Frame are located. The default directory is /tmp. The option is only used in Direct FSP/BPA Management. - - -\ **-d=**\ \ *data_directory*\ + OpenPOWER BMC specific (using IPMI): Used for IBM Power S822LC for Big Data systems only. Specifies the directory where the \ **pUpdate**\ utility and at least one of BMC or PNOR update files are located. The utility and update files can be downloaded from FixCentral. diff --git a/perl-xCAT/xCAT/Usage.pm b/perl-xCAT/xCAT/Usage.pm index b41fa6ab9..244142d14 100755 --- a/perl-xCAT/xCAT/Usage.pm +++ b/perl-xCAT/xCAT/Usage.pm @@ -343,7 +343,7 @@ my %usage = ( rflash [--commit | --recover] [-V|--verbose] rflash [--bpa_acdl] OpenPOWER BMC specific (using IPMI): - rflash [|-d=] [-c|--check] [--retry=] [-V] + rflash [|-d ] [-c|--check] [--retry=] [-V] OpenPOWER OpenBMC specific: rflash {[-c|--check] | [-l|--list]} rflash {[-c|--check] | [-u|--upload]} diff --git a/xCAT-client/pods/man1/rflash.1.pod b/xCAT-client/pods/man1/rflash.1.pod index ac2de5adc..79c21a313 100644 --- a/xCAT-client/pods/man1/rflash.1.pod +++ b/xCAT-client/pods/man1/rflash.1.pod @@ -24,7 +24,7 @@ B I I =head2 OpenPOWER BMC specific (using IPMI): -B I [I | B<-d=>I] [B<-c>|B<--check>] [B<--retry=>I] [B<-V>] +B I [I | B<-d> I] [B<-c>|B<--check>] [B<--retry=>I] [B<-V>] =head2 OpenPOWER OpenBMC specific : @@ -115,9 +115,11 @@ Specifies the directory where the packages are located. =item B<-d> I +PPC (without HMC, using Direct FSP Management) specific: + Specifies the directory where the raw data from rpm packages for each CEC/Frame are located. The default directory is /tmp. The option is only used in Direct FSP/BPA Management. -=item B<-d=>I +OpenPOWER BMC specific (using IPMI): Used for IBM Power S822LC for Big Data systems only. Specifies the directory where the B utility and at least one of BMC or PNOR update files are located. The utility and update files can be downloaded from FixCentral. diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index 666e3bfd6..2e9f4f582 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -1930,6 +1930,13 @@ sub do_firmware_update { $buffer_size = "15000"; } + my $directory_name; + if (@{ $sessdata->{extraargs} } > 1) { + @ARGV = @{ $sessdata->{extraargs} }; + use Getopt::Long; + GetOptions('d:s' => \$directory_name); + } + # check verbose, buffersize, and retry options for my $opt (@{$sessdata->{'extraargs'}}) { if ($opt =~ /-V{1,4}/) { @@ -1962,28 +1969,24 @@ sub do_firmware_update { } } } - if ($opt =~ /-d=/) { - my ($attribute, $directory_name) = split(/=/, $opt); - if (defined $directory_name) { - unless (File::Spec->file_name_is_absolute($directory_name)) { - # Directory name was passed in as relative path, prepend current working dir - $directory_name = xCAT::Utils->full_path($directory_name, $::cwd); - } - # directory was passed in, verify it is valid - if (-d $directory_name) { - # Passed in directory name exists - $pUpdate_directory = $directory_name; - } - else { - $exit_with_error_func->($sessdata->{node}, $callback, - "Can not access data directory $directory_name"); - } + + if (defined $directory_name) { + unless (File::Spec->file_name_is_absolute($directory_name)) { + # Directory name was passed in as relative path, prepend current working dir + $directory_name = xCAT::Utils->full_path($directory_name, $::cwd); + } + # directory was passed in, verify it is valid + if (-d $directory_name) { + # Passed in directory name exists + $pUpdate_directory = $directory_name; } else { - $exit_with_error_func->($sessdata->{node}, $callback, - "Data directory must be specified."); + $exit_with_error_func->($sessdata->{node}, $callback, "Can not access data directory $directory_name"); } } + else { + $exit_with_error_func->($sessdata->{node}, $callback, "Data directory must be specified."); + } } # For IBM Power S822LC for Big Data (Supermicro) machines such as @@ -1997,10 +2000,15 @@ sub do_firmware_update { "Directory name is required to update Boston or Briggs machines."); } + # Verify specified directory contains pUpdate utility + unless (-e "$pUpdate_directory/pUpdate") { + $exit_with_error_func->($sessdata->{node}, $callback, + "Can not find pUpdate utility in data directory $pUpdate_directory."); + } # Verify specified directory contains executable pUpdate utility unless (-x "$pUpdate_directory/pUpdate") { $exit_with_error_func->($sessdata->{node}, $callback, - "Can not find executable pUpdate utility in data directory $pUpdate_directory."); + "Execute permission is not set for pUpdate utility in data directory $pUpdate_directory."); } # Verify there is at least one of update files inside data directory - .bin or .pnor @@ -2389,6 +2397,7 @@ RETRY_UPGRADE: sub rflash { my $sessdata = shift; + my $directory_flag = 0; if (isopenpower($sessdata)) { # Do firmware update for firestone here. @@ -2397,10 +2406,16 @@ sub rflash { if ($opt =~ /^(-c|--check)$/i) { $sessdata->{subcommand} = "check"; # support verbose options for ipmitool command - } elsif ($opt !~ /.*\.hpm$/i && $opt !~ /^-V{1,4}$|^--buffersize=|^--retry=|^-d=/) { - $callback->({ error => "The option $opt is not supported or invalid update file specified", + } elsif ($opt =~ /^-d$/) { + # special handling if -d option which can be followed by a directory name + $directory_flag = 1; # set a flag that directory option was given + } elsif ($opt !~ /.*\.hpm$/i && $opt !~ /^-V{1,4}$|^--buffersize=|^--retry=/) { + # An unexpected flag was passed, but it could be a directory name. Display error only if not -d option + unless ($directory_flag) { + $callback->({ error => "The option $opt is not supported or invalid update file specified", errorcode => 1 }); - return; + return; + } } }