# Copyright (c) 2014 NetApp, Inc., All Rights Reserved # @summary Clobber the CSM sessions on the nodes after setting the bomb point MTask module # @author bramya@netapp.com, dl-ptefit-automation-core@netapp.com # @status shared # @pod here =head1 NAME NACL::MTask:ClobberCSM =head1 DESCRIPTION C provides methods to set a bomb point on a node, clobber the CSM sessions and unset the bomb point. =head1 METHODS =head2 new # Example for creating a ClobberCSM object my $ClobberCSM_obj = NACL::MTask::ClobberCSM->new( 'nodes' => \@nodes, ); This method will simply return a ClobberCSM 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 set_bomb This method is designed to set bomb point on the nodes. =over =item C<< nodes => \@nodes >> (Optional) An ARRAYREF of the nodes on which bomb point is to be set. If this parameter is not passed in, the bomb point will be set on all the nodes in the cluster by default. =item C<< bomb_name => $bomb_name >> (Optional) This represents the name of the bomb point to be set on the nodes. The default value for this parameter is "spinnp_bind_fail". =item C<< bomb_forever => $bomb_forever >> (Optional) This is a BOOLEAN value that represents the bomb point to be set on the nodes is to be set forever or not. The default value for this parameter is 1. =back =cut =head2 unset_bomb This method is designed to unset bomb point which has been set on the nodes. =over =item C<< nodes => \@nodes >> (Optional) An ARRAYREF of the nodes on which bomb point is to be unset. If this parameter is not passed in, the bomb point will be unset on all the nodes in the cluster by default. =item C<< bomb_name => $bomb_name >> (Optional) This represents the name of the bomb point to be unset on the nodes. The default value for this parameter is "spinnp_bind_fail". =back =cut =head2 clobber_kcs This method sets the value of the uniquifier to "b0*|100*|f0*" for FS.X and "b0*" for SN.X and calls clobber_csm_sessions(). =cut =head2 get_kcs_sessions_hash This method sets the value of the uniquifier to "b0*|100*|f0*" for FS.X and "b0*" for SN.X and calls get_csm_sessions_hash(). =cut =head2 get_csm_sessions_hash This method is designed to obtain the csm sessions and returns a hash ref to the sessions. =over =item C<< nodes => \@nodes >> (Optional) An ARRAYREF to the nodes on which csm sessions need to be clobbered. =item C<< uniquifier => $uniquifier >> (Required) A SCALAR value which is used to filter the CSM sessions on the node. =back =cut =head2 clobber_csm_sessions This method is designed to obtain the csm sessions and clobber them. =over =item C<< nodes => \@nodes >> (Optional) An ARRAYREF to the nodes on which csm sessions need to be clobbered. =item C<< uniquifier => $uniquifier >> (Required) A SCALAR value which is used to filter the CSM sessions on the node. Either uniquifier or sessions_hash should be provided, but not both. =item C<< sessions_hash => $uniquifier_hash >> (Required) A HASHREF to the uniquifiers which are used to filter the CSM sessions on the node. Either uniquifier or sessions_hash should be provided, but not both. =back =cut package NACL::MTask::ClobberCSM; 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::Exceptions::InvalidParam; use NACL::C::DebugCsmCt; use NACL::CS::DebugCsmCt; use NACL::C::DebugCsmSession; 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) = @_; validate_with( params => \@params, spec => { nodes => { type => ARRAYREF , optional => 0,}, }, ); $Log->exit() if $may_exit; } ####################################################################################### ## Name : set_bomb ## Description : This method is used to set a CSM bomb point on a node's systemshell. ####################################################################################### sub set_bomb { $Log->enter() if $may_enter; my ($self, @args) = @_; my $nodes; my %opts = validate_with( params => \@args, spec => { nodes => { type => ARRAYREF , default => $self->nodes}, bomb_number => {type => SCALAR , default => 0}, bomb_name => { type => SCALAR , default => "spinnp_bind_fail"}, bomb_forever => { type => BOOLEAN , default => 1}, }, ); $nodes = $opts{nodes}; my @commands = ( {name => 'sysvar.csm.bomb.'.$opts{bomb_number}.'.name', value => $opts{bomb_name}}, {name => 'sysvar.csm.bomb.'.$opts{bomb_number}.'.forever', value => $opts{bomb_forever}}, {name => 'sysvar.csm.bomb.'.$opts{bomb_number}.'.set', value => '1'}, {name => 'sysvar.csm.bomb.enable', value => '1'}, ); #set the bomd point on each node's system shell. Therefore loop through each node passed. foreach my $node (@{$nodes}) { my $nacl_node_obj = $node; my $apiset = $nacl_node_obj->get_systemshell_apiset(); foreach my $cmd (@commands){ $apiset->sysctl('privilege-level' => 'root', %$cmd); } } $Log->exit() if $may_exit; } ####################################################################################### ## Name : unset_bomb ## Description : This method is used to unset a CSM bomb point on a node's systemshell. ####################################################################################### sub unset_bomb { $Log->enter() if $may_enter; my ($self, @args) = @_; my $nodes; my %opts = validate_with( params => \@args, spec => { nodes => { type => ARRAYREF , default => $self->nodes}, bomb_number => {type => SCALAR , default => 0}, bomb_forever => { type => BOOLEAN , default => 0}, }, ); $nodes = $opts{nodes}; my @commands = ( {name => 'sysvar.csm.bomb.enable', value => '0'}, {name => 'sysvar.csm.bomb.'.$opts{bomb_number}.'.set', value => '0'}, {name => 'sysvar.csm.bomb.'.$opts{bomb_number}.'.forever', value => $opts{bomb_forever}}, ); #unset the bomd point on each node's system shell. loop through each node passed. foreach my $node (@{$nodes}) { my $nacl_node_obj = $node; my $apiset = $nacl_node_obj->get_systemshell_apiset(); foreach my $cmd (@commands){ $apiset->sysctl('privilege-level' => 'root', %$cmd); } } $Log->exit() if $may_exit; } ######################################################################################### ## Name : clobber_kcs ## Description : This method is used to set a kcs uniquifier and calls clobber_csm_sessions. ######################################################################################### sub clobber_kcs { $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}; my $uniquifier = "b0*|100*|f0*"; $self->clobber_csm_sessions(uniquifier => $uniquifier, nodes => $nodes); $Log->exit() if $may_exit; } ######################################################################################### ## Name : get_kcs_sessions_hash ## Description : This method is used to get a list of uniquifiers for existing kcs sessions. ######################################################################################### sub get_kcs_sessions_hash { $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}; my $uniquifier = "b0*|100*|f0*"; my $sessions_hash = $self->get_csm_sessions_hash(uniquifier => $uniquifier, nodes => $nodes); $Log->exit() if $may_exit; return $sessions_hash; } ####################################################################################################### ## Name : clobber_csm_sessions ## Description : This method is used to get a list of existing CSM sessions and Clobber those sessions. ####################################################################################################### sub clobber_csm_sessions { $Log->enter() if $may_enter; my ($self, @args) = @_; my %opts = validate_with( params => \@args, spec => { uniquifier => { type => SCALAR, optional => 1}, sessions_hash => { type => HASHREF, optional => 1}, nodes => { type => ARRAYREF, default => $self->nodes}, }, ); if ((defined($opts{uniquifier}) && defined($opts{sessions_hash})) || (!defined($opts{uniquifier}) && !defined($opts{sessions_hash}))) { NACL::Exceptions::InvalidParam->throw("Either uniquifier or sessions_hash must be specified but not both."); } if (defined($opts{uniquifier})) { my %session = (); my @DebugCsmCtCS; foreach my $node (@{$opts{nodes}}) { my $nacl_node_obj = $node; my $node_name = $nacl_node_obj->node(); @DebugCsmCtCS = NACL::CS::DebugCsmCt->fetch(command_interface => $nacl_node_obj, filter => {"uniquifier" => $opts{uniquifier},"node" => $node_name}, requested_fields => ['node','uniquifier'], ); #We get a list of uniquifiers here from the csm sessions. We eliminate the duplicates and save the unique uniquifiers in an array. my @uniquifier = (); foreach my $DebugSession (@DebugCsmCtCS){ push(@uniquifier,$DebugSession->{uniquifier}); } my %temp_hash = map { $_, 0 } @uniquifier; my @filtered_uniquifier = keys %temp_hash; @{$session{$node_name}} = @filtered_uniquifier; } foreach my $node (@{$opts{nodes}}) { my $nacl_node_obj = $node; my $node_name = $nacl_node_obj->node(); for (keys %session) { my @uniquifier = @{$session{$node_name}}; foreach my $uniquifier (@uniquifier){ NACL::C::DebugCsmSession->clobber(command_interface => $nacl_node_obj, node => $node_name, uniquifier => $uniquifier); } } } } else { my %session = %{$opts{sessions_hash}}; foreach my $node (@{$opts{nodes}}) { my $nacl_node_obj = $node; my $node_name = $nacl_node_obj->node(); for (keys %session) { my @uniquifier = @{$session{$node_name}}; foreach my $uniquifier (@uniquifier){ NACL::C::DebugCsmSession->clobber(command_interface => $nacl_node_obj, node => $node_name, uniquifier => $uniquifier); } } } } $Log->exit() if $may_exit; } ####################################################################################################### ## Name : get_csm_sessions_hash ## Description : This method is used to get a list of uniquifiers for existing CSM sessions. ####################################################################################################### sub get_csm_sessions_hash { $Log->enter() if $may_enter; my ($self, @args) = @_; my %opts = validate_with( params => \@args, spec => { uniquifier => { type => SCALAR, optional => 0}, nodes => { type => ARRAYREF, default => $self->nodes}, }, ); my %session = (); my @DebugCsmCtCS; foreach my $node (@{$opts{nodes}}) { my $nacl_node_obj = $node; my $node_name = $nacl_node_obj->node(); @DebugCsmCtCS = NACL::CS::DebugCsmCt->fetch(command_interface => $nacl_node_obj, filter => {"uniquifier" => $opts{uniquifier},"node" => $node_name}, requested_fields => ['node','uniquifier'], ); #We get a list of uniquifiers here from the csm sessions. We eliminate the duplicates and save the unique uniquifiers in an array. my @uniquifier = (); foreach my $DebugSession (@DebugCsmCtCS){ push(@uniquifier,$DebugSession->{uniquifier}); } my %temp_hash = map { $_, 0 } @uniquifier; my @filtered_uniquifier = keys %temp_hash; @{$session{$node_name}} = @filtered_uniquifier; } $Log->exit() if $may_exit; return \%session; } 1;