# Copyright (c) 2016 NetApp, Inc., All Rights Reserved # @summary Detect SRAM dumps during tests # @author abowden@netapp.com, ng-san-qa-rtp@netapp.com # @status shared # @pod here =head1 NAME NACL::MTask:SRAMDetector =head1 DESCRIPTION C provides methods to check for SRAM dumps during tests. SRAM dumps are produced when there is a failure in the driver or firmware of QLogic/Emulex HBAs. =head1 METHODS =head2 new # Example for creating a SRAMDetector object my $SRAMDetector_obj = NACL::MTask::SRAMDetector->new( 'nodes' => \@nodes, ); This method will simply return a SRAMDetector object to allow method calls for defined methods. =over =item C<< nodes => \@nodes >> (Required) An ARRAYREF of the NACL::C::NODE objects on which the defined methods can be called. =back =cut =head2 setup This method is designed to save the list of dumps already on the system. =over =item C<< nodes => \@nodes >> (Optional) An ARRAYREF of the nodes on which to check for SRAM dumps. =back =cut =head2 check This method is designed to check for new SRAM dumps after running setup. =over =item C<< nodes => \@nodes >> (Optional) An ARRAYREF of the nodes on which to check for SRAM dumps. =back =cut package NACL::MTask::SRAMDetector; use strict; use warnings; use base qw/NACL::MTask::MTask/; use NATE::Log qw(log_global); use Params::Validate qw(validate_with SCALAR SCALARREF ARRAYREF HASHREF BOOLEAN OBJECT); use NACL::APISet; use NACL::APISet::Node::CLI; use NACL::MTask::Exceptions::SRAMDumpDetected; use Data::Dumper; my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Class::MethodMaker [new => ['-hash', '-init', 'new'], array => 'nodes',]; ################################################################################ ## Name : init ## Description : Use the init method to validate that required options were ## passed in. ################################################################################ sub init { $Log->enter() if $may_enter; my ($self, @params) = @_; my %opts = validate_with( params => \@params, spec => {nodes => {type => ARRAYREF, optional => 0,},}, ); my $nodes = $opts{nodes}; foreach my $node (@{$nodes}) { $self->{$node->name()}->{sram_dumps} = []; } $Log->exit() if $may_exit; } ## end sub init ################################################################################ ## Name : setup ## Description : Store initial set of dumps on the controller(s) ################################################################################ sub setup { $Log->enter() if $may_enter; my ($self, @args) = @_; my $nodes; my %opts = validate_with( params => \@args, spec => {nodes => {type => ARRAYREF, default => $self->nodes}}, ); $nodes = $opts{nodes}; foreach my $node (@{$nodes}) { my @sram_dumps = $self->_execute_dump_list($node); $self->{$node->name()}->{sram_dumps} = [@sram_dumps]; } } ## end sub setup ################################################################################ ## Name : check ## Description : Checks to see if any new SRAM dumps have been generated ## since the save point ################################################################################ sub check { $Log->enter() if $may_enter; my ($self, @args) = @_; my $nodes; my %opts = validate_with( params => \@args, spec => {nodes => {type => ARRAYREF, default => $self->nodes}}, ); $nodes = $opts{nodes}; foreach my $node (@{$nodes}) { my $nodename = $node->name(); my @previous_dumps = @{$self->{$nodename}->{sram_dumps}}; # get a list of dumps in the /mroot/etc/log directory my @sram_dumps = $self->_execute_dump_list($node); # determine differences my @difference = (); my %array_one = map { $_, 1 } @previous_dumps; @difference = grep { !$array_one{$_} } @sram_dumps; if (scalar(@difference) > 0) { my $diff_string = join("\n", @difference); NACL::MTask::Exceptions::SRAMDumpDetected->throw( "Found new SRAM dump(s) on node $nodename: $diff_string" . "\n"); } # update with current list of dumps to compare versus next time $self->{$nodename}->{sram_dumps} = [@sram_dumps]; } ## end foreach my $node (@{$nodes}) $Log->exit() if $may_exit; } ## end sub check ################################################################################ # Subroutine Name: _execute_dump_listing() # Objective: Find dump(s) saved on a node ################################################################################ sub _execute_dump_list { $Log->enter() if $may_enter; my ($self, $nacl_node_obj) = @_; my $apiset = $nacl_node_obj->get_systemshell_apiset(); my $raw_response = $apiset->execute_raw_command(command => 'ls /mroot/etc/log | cat | grep -E \'ispfct|ispcna|fctsli\''); my @sram_dumps = split(/\n/, $raw_response); $Log->exit() if $may_exit; return @sram_dumps; } ## end sub _execute_dump_list 1;