# $Id: //depot/prod/test/nacldev/lib/NACL/STask/ShelfFirmwareUpdate.pm#1 $ # # Copyright (c) 2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary ShelfFirmwareUpdate Task Module ## @author sangavai.p@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here package NACL::STask::ShelfFirmwareUpdate; use strict; use warnings; use base qw(NACL::STask::STask NACL::C::StorageFirmware); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Params::Validate qw(OBJECT BOOLEAN SCALAR HASHREF validate_with); use NATE::Exceptions::Argument qw(:try); use NATE::BaseException; use NACL::C::CommandInterface; use NACL::MTask::EventLogDetector; use NATE::Time qw(timeout2time); use NACL::ComponentUtils qw(Dumper _ontap_ci_validate_spec); =head1 NAME NACL::STask::ShelfFirmwareUpdate =head1 DESCRIPTION NACL::STask::ShelfFirmwareUpdate provides a well-defined but potentially complex or multi-step method related to Shelf firmware in ONTAP. The functionality related to shelf present in L will also be present in this STask. (functionality which is multi-step will have overridden implementations defined here, single step functionality will be directly re-used from the component) Supports 7mode CLI & Cmode CLI. The task has private method. It performs the below steps 1. Downloads new firmware to disk shelves. 2. Check EMS file for proper keyword logged. =head1 ATTRIBUTES =head2 command_interface (Required) Represents NACL::C::CommandInterface::ONTAP on the filer. =head1 METHODS =head2 download_and_verify =over =item Example 1: perform storage download shelf on all adapter. Applicable on 7mode only. my $status = NACL::STask::ShelfFirmwareUpdate->download_and_verify( command_interface => $command_interface, ); =item Example 2: perform storage download shelf using package_url Applicable for Cmode. For Nodescope, the filename is fetched from the package_url. my $status = NACL::STask::ShelfFirmwareUpdate->download_and_verify( command_interface => $command_interface, package_url => $package_url ); =item Example 3: perform storage download shelf using options The options can be start(-Q), stop(-S), revert(-R) and file-name(-F). Applicable for 7mode only. my $status = NACL::STask::ShelfFirmwareUpdate->download_and_verify( command_interface => $command_interface, nacltask_cmd_opts => { 'file-name' => IOM6E.0112.SFW }, ); (Class method) This method performs above operations on the supportive mode based on options provided to it. On success status message displayed, else throw error message. =back =over =item Options =over =item C<< package_url => $package_url >> (Optional) pathname to the web server. =item C<< nacltask_cmd_opts => \%options >> nacltask_cmd_opts => { 'start' => 1, 'channel-name' => 0c, 'enclosure-type' => SAS, 'enclosure-id' => 1 } (Optional for 7mode|Nodescope) Options can be start => $boolean (Optional) starts download qualification test. Default is 0. stop => $boolean (Optional) stops download qualification test. revert => $boolean (Optional) allows the firmware to be reverted to the version shipped with the current Data ONTAP release. Default is 0 'file-name' => $filename (Optional) forces download of specific firmware files to matching modules. Default is filename fetched from the package_url 'channel-name' => $channel_name (Optional) Adapter to which shelves are attached. If the parameter not specified, then the firmware downloaded to shelves attached to adapters. 'enclosure-type' => $enclosure_type (Optional) Enclosure type 'enclosure-id' => $enclosure_id (Optional) Shelf id =item C<< nacltask_polling_interval => $interval >> (Optional) Check the firmware downloaded success message is displayed for every 120 seconds. Default is 120 seconds =item C<< nacltask_timeout => $timeout >> (Optional) Controls how long the command will wait before completing. Default is 600 seconds. =back =back =over =item Exceptions =over =item C This type of exception is thrown when filer failed to download firmware to shelves. =back =back =cut sub download_and_verify { $Log->enter() if $may_enter; my $pkg = shift; my %opts = $pkg->_common_validate_with( params => \@_, additional_spec => { command_interface => _ontap_ci_validate_spec(), package_url => { type => SCALAR, optional => 1 }, nacltask_cmd_opts => { type => HASHREF, optional => 1 }, nacltask_timeout => { type => SCALAR, default => 600 }, nacltask_polling_interval => { type => SCALAR, default => 120 }, }, ); if ( $opts{nacltask_cmd_opts} ) { validate_with( params => $opts{nacltask_cmd_opts}, spec => { 'start' => { type => BOOLEAN, optional => 1 }, 'stop' => { type => BOOLEAN, optional => 1 }, 'revert' => { type => BOOLEAN, optional => 1 }, 'file-name' => { type => SCALAR, optional => 1 }, }, allow_extra => 1, ); } if ( $opts{nacltask_cmd_opts}->{'start'} ) { $opts{nacltask_cmd_opts}->{'qual-mode'} = delete $opts{nacltask_cmd_opts}->{'start'}; } my $command_interface = $opts{command_interface}; $opts{'package-type'} = 'shelf'; if ( $command_interface->mode() eq "CMode" ) { # To download firmware file from server to the filer in /etc/shelf_fw path if ( defined $opts{'package_url'} ) { $Log->comment( "Downloading the firmware file to the filer from server"); my $package_url = delete $opts{'package_url'}; NACL::C::StorageFirmware->download( command_interface => $command_interface, node => $command_interface->node(), user => $command_interface->hostrec->{default_username}, password => $command_interface->hostrec->{default_password}, 'package-type' => $opts{'package-type'}, 'package-url' => $package_url, ); my @fields = split( "\/", $package_url ); $opts{nacltask_cmd_opts}->{'file-name'} = $1 if ( $fields[-1] =~ /(.*)\.zip/ ); } $opts{apiset_must} = { set => 'Nodescope' }; } _shelf_fw(%opts); $Log->exit() if $may_exit; } ## end sub download_and_verify ######################################################################## # Method: _shelf_fw # Objective: To download the firmware to the shelves & verify download # Description: The download is performed, when any previous download # is in progress in the filer(the current download operation # cannot be performed), in that case the status of download # is checked for every 2 minutes by default(with overall time # time for download is 10 minutes by default), then the current # download is done. # While the current download starts, the log detector is started # & stopped after 10 minutes, where the sfu download success # & summary is obtained , when download done properly else # error message is obtained. # Options: # nacltask_polling_interval - required - checks the status of download # nacltask_timeout - required - timeout for download # nacltask_cmd_opts - optional - start,stop,revert,file # Output: 'Firmware downloaded to its shelves' message. ######################################################################## sub _shelf_fw { $Log->enter() if $may_enter; $Log->debug("Starting the firmware download to shelves"); my (%opts) = @_; my $polling_interval = delete $opts{nacltask_polling_interval}; my $timeout = delete $opts{nacltask_timeout}; my $command_interface = $opts{command_interface}; my $cmds = {}; $cmds = delete $opts{nacltask_cmd_opts} if ( $opts{nacltask_cmd_opts} ); my $end_time = timeout2time($timeout); my $count = 0; while ( time() < $end_time ) { my $shelf_obj = NACL::C::StorageFirmware->download( %opts, %$cmds ); if ( $shelf_obj && ( $shelf_obj->{status} =~ /in progress/ ) && ( $count < 6 ) ) { Tharn::snooze($polling_interval); $count++; } elsif ( !$shelf_obj ) { $end_time = 0; } elsif ( $shelf_obj && ( $shelf_obj->{status} =~ /QUAL MODE DISABLED/ ) ) { $end_time = 0; $Log->comment("Storage download qualification test stopped"); } else { $Log->exit() if $may_exit; NATE::BaseException->throw( "Filer failed to download firmware to shelves"); } } if ( !$cmds->{stop} ) { my $detector = NACL::MTask::EventLogDetector->new( command_interface => $command_interface, check_for_any_presence => [ 'sfu.downloadSuccess', 'sfu.downloadSummary' ], ); # Calling start on EventLogDetector object $detector->start(); try { #Time to prcoess the download & load the ems messages Tharn::snooze($timeout); # Stop and check for presence of all the event messagenames my @messages = $detector->stop( 'check' => 1 ); $Log->comment( "Matching events are : " . Dumper( \@messages ) ); $Log->comment("Filer downloaded the firmware to its shelves"); $end_time = 0; } catch NACL::Exceptions::EventCheckFailure with { my $exception_obj = shift; $Log->comment( "Download failed: \n" . $exception_obj->text() ); $Log->exit() if $may_exit; NATE::BaseException->throw( "Filer failed to download firmware to shelves"); }; } } ## end sub _shelf_fw 1;