From 1be7b6c2d539d731bef5f95ba7b3254042550030 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Thu, 3 Aug 2017 14:40:18 -0400 Subject: [PATCH 1/2] Implement openbmc image delete function --- xCAT-server/lib/xcat/plugins/openbmc.pm | 34 ++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index c7450095b..c9c2bfdb3 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -179,6 +179,14 @@ my %status_info = ( RFLASH_SET_PRIORITY_RESPONSE => { process => \&rflash_response, }, + RFLASH_DELETE_IMAGE_REQUEST => { + method => "POST", + init_url => "$openbmc_project_url/software", + data => "[]", + }, + RFLASH_DELETE_IMAGE_RESPONSE => { + process => \&rflash_response, + }, RINV_REQUEST => { method => "GET", @@ -874,6 +882,7 @@ sub parse_command_status { $status_info{RFLASH_UPDATE_ACTIVATE_REQUEST}{init_url} .= "/$update_file/attr/RequestedActivation"; $status_info{RFLASH_SET_PRIORITY_REQUEST}{init_url} .= "/$update_file/attr/Priority"; $status_info{RFLASH_UPDATE_CHECK_STATE_REQUEST}{init_url} .= "/$update_file"; + $status_info{RFLASH_DELETE_IMAGE_REQUEST}{init_url} .= "/$update_file/action/Delete"; } } } @@ -888,11 +897,12 @@ sub parse_command_status { $next_status{RFLASH_LIST_REQUEST} = "RFLASH_LIST_RESPONSE"; } if ($delete) { - xCAT::SvrUtils::sendmsg("Delete option is not yet supported.", $callback); - return 1; + # Delete uploaded image from BMC + $next_status{LOGIN_RESPONSE} = "RFLASH_DELETE_IMAGE_REQUEST"; + $next_status{RFLASH_DELETE_IMAGE_REQUEST} = "RFLASH_DELETE_IMAGE_RESPONSE"; } if ($upload) { - # Upload specified update file to BMC + # Upload specified update file to BMC $next_status{LOGIN_RESPONSE} = "RFLASH_FILE_UPLOAD_REQUEST"; $next_status{"RFLASH_FILE_UPLOAD_REQUEST"} = "RFLASH_FILE_UPLOAD_RESPONSE"; } @@ -1013,6 +1023,9 @@ sub gen_send_request { # Handle boolean values by create the json objects without wrapping with quotes if ($status_info{ $node_info{$node}{cur_status} }{data} =~ /^1$|^true$|^True$|^0$|^false$|^False$/) { $content = '{"data":' . $status_info{ $node_info{$node}{cur_status} }{data} . '}'; + } elsif ($status_info{ $node_info{$node}{cur_status} }{data} =~ /^\[\]$/) { + # Special handling of empty data list + $content = '{"data":[]}'; } else { $content = '{"data":"' . $status_info{ $node_info{$node}{cur_status} }{data} . '"}'; } @@ -1799,7 +1812,7 @@ sub rflash_response { print Dumper(%{$response_info->{data}}); my $update_id; - my $update_activation; + my $update_activation = "Unknown"; my $update_purpose; my $update_version; my $update_priority = -1; @@ -1898,9 +1911,8 @@ sub rflash_response { if ($activation_state =~ /Software.Activation.Activations.Failed/) { # Activation failed. Report error and exit xCAT::SvrUtils::sendmsg([1,"Activation of firmware failed"], $callback, $node); - } - - if ($activation_state =~ /Software.Activation.Activations.Active/) { + } + elsif ($activation_state =~ /Software.Activation.Activations.Active/) { if (scalar($priority_state) == 0) { # Activation state of active and priority of 0 indicates the activation has been completed xCAT::SvrUtils::sendmsg("Firmware update successfully activated", $callback, $node); @@ -1913,8 +1925,7 @@ sub rflash_response { $next_status{ $node_info{$node}{cur_status} } = "RFLASH_SET_PRIORITY_REQUEST"; } } - - if ($activation_state =~ /Software.Activation.Activations.Activating/) { + elsif ($activation_state =~ /Software.Activation.Activations.Activating/) { # Activation still going, sleep for a bit, then print the progress value sleep(15); xCAT::SvrUtils::sendmsg("Activating firmware update. $progress_state\%", $callback, $node); @@ -1922,6 +1933,11 @@ sub rflash_response { # Set next state to come back here to chect the activation status again. $next_status{ $node_info{$node}{cur_status} } = "RFLASH_UPDATE_CHECK_STATE_REQUEST"; } + + } + + if ($node_info{$node}{cur_status} eq "RFLASH_DELETE_IMAGE_RESPONSE") { + xCAT::SvrUtils::sendmsg("Firmware update successfully removed", $callback, $node); } if ($next_status{ $node_info{$node}{cur_status} }) { From 0ca911b9f3cbf33fdb04a23d6ce0e203dd542c02 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Thu, 3 Aug 2017 14:50:46 -0400 Subject: [PATCH 2/2] Usage and man page update --- .../guides/admin-guides/references/man1/rflash.1.rst | 8 +++++++- perl-xCAT/xCAT/Usage.pm | 2 +- xCAT-client/pods/man1/rflash.1.pod | 6 +++++- 3 files changed, 13 insertions(+), 3 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 5f688c7ac..84d176e49 100644 --- a/docs/source/guides/admin-guides/references/man1/rflash.1.rst +++ b/docs/source/guides/admin-guides/references/man1/rflash.1.rst @@ -57,7 +57,7 @@ OpenPOWER OpenBMC specific : ============================ -\ **rflash**\ \ *noderange*\ [\ *tar_file_path*\ | \ *image_id*\ ] [\ **-c | -**\ **-check**\ ] [\ **-a | -**\ **-activate**\ ] [\ **-l | -**\ **-list**\ ] [\ **-u | -**\ **-upload**\ ] +\ **rflash**\ \ *noderange*\ [\ *tar_file_path*\ | \ *image_id*\ ] [\ **-c | -**\ **-check**\ ] [\ **-a | -**\ **-activate**\ ] [\ **-l | -**\ **-list**\ ] [\ **-u | -**\ **-upload**\ ] [\ **-d | -**\ **-delete**\ ] @@ -220,6 +220,12 @@ The command will update firmware for OpenPOWER OpenBMC when given an OpenPOWER n +\ **-d|-**\ **-delete**\ + + Delete update image from BMC + + + \ **-v|-**\ **-version**\ Displays the command's version. diff --git a/perl-xCAT/xCAT/Usage.pm b/perl-xCAT/xCAT/Usage.pm index 871d3802b..dd40450e3 100755 --- a/perl-xCAT/xCAT/Usage.pm +++ b/perl-xCAT/xCAT/Usage.pm @@ -345,7 +345,7 @@ my %usage = ( PPC64LE (using IPMI Management) specific: rflash [-c|--check] [--retry=] [-V] [|-d=] PPC64LE (using OpenBMC Management) specific: - rflash [-c|--check] [-l|--list] [-a|--activate] [-u|--upload] [|]", + rflash [-c|--check] [-l|--list] [-a|--activate] [-u|--upload] [-d|--delete] [|]", "mkhwconn" => "Usage: mkhwconn [-h|--help] diff --git a/xCAT-client/pods/man1/rflash.1.pod b/xCAT-client/pods/man1/rflash.1.pod index 283b35381..70c964d15 100644 --- a/xCAT-client/pods/man1/rflash.1.pod +++ b/xCAT-client/pods/man1/rflash.1.pod @@ -28,7 +28,7 @@ B I [I | B<-d=>I] [B<-c>|B<--c =head2 OpenPOWER OpenBMC specific : -B I [I | I] [B<-c>|B<--check>] [B<-a>|B<--activate>] [B<-l>|B<--list>] [B<-u>|B<--upload>] +B I [I | I] [B<-c>|B<--check>] [B<-a>|B<--activate>] [B<-l>|B<--list>] [B<-u>|B<--upload>] [B<-d>|B<--delete>] =head1 B @@ -145,6 +145,10 @@ List currently uploaded update images. "(*)" indicates currently active image. Upload update image. Specified file must be in .tar format. +=item B<-d|--delete> + +Delete update image from BMC + =item B<-v|--version> Displays the command's version.