#!/usr/software/bin/perl # $Id: ## ## Copyright (c) 2005 Network Appliance, Inc. ## All rights reserved ## ## @summary Mode ## Create mini_disk . ## ## @description ## Create mini disk ## ## ## ## ## @status Automated ## @auther arjun.lavu@netapp.com ## @change YY/MM/DD from auther: Description of the change ## ############################################################################# # Compiler directives. use strict; use warnings; # # Module import. # use Subtest; # # Import exceptions # use Storage::Common_Lib; use Storage::Common_Lib_Cmode; #subroutines sub _unique(@); ######################################## ### Initialization/declaration ######################################### use vars qw( $FILER $STEST_DEBUG $STEST_FILE $LOGLVL $LOGDIR $MAIL_TO $MAIL_FROM $MAIL_MSG $EMAIL $TEST_SUITE_NAME $TEST_CONFIG $FILERA $FILERB $FILER_CONN $TEST_SETUP $MODE $MINI_CREATE_SIZE $MINI_CREATE $FILER_TYPE $BOOT_MODE $FILER_PROMPT $BOOT_TYPE $EOE $RE_INIT $Primary_Node ); param( 'FILER', '-mesg', 'HostID of filer' ); param( "FILERA", '-default', '' ); param( "FILERB", '-default', '' ); param( "FILER_CONN", '-default', '#rsh' ); param( "MODE", '-default', 'normal' ); param( 'TEST_SETUP', '-default', 'FC' ); param( 'TEST_CONFIG', '-default', 'D' ); param( 'BOOT_MODE', '-default', '1' ); param( 'FILER_TYPE', '-default', 'BR' ); param( 'MINI_CREATE_SIZE', '-default', '1' ); param( 'MINI_CREATE', '-default', 'n' ); param( 'STEST_DEBUG', '-default', '1' ); param( 'STEST_FILE', '-mesg', 'Runlist file' ); param( 'LOGDIR', '-default', '' ); param( 'LOGLVL', '-default', '2' ); param( 'MAIL_TO', '-default', 'default' ); param( 'MAIL_FROM', '-default', 'default' ); param( 'MAIL_MSG', '-default', 'n' ); param( 'EMAIL', '-default', 'n' ); param( 'TEST_SUITE_NAME', '-mesg', 'Test_Suite_Name' ); param( "FILER_PROMPT", '-default', '\*>' ); param( 'BOOT_TYPE', '-default', 'A'); param( 'EOE', '-default', 'default' ); param( 'RE_INIT', '-default', '0' ); param( 'Primary_Node', '-default', 'N' ); my $email_subject; my $email_body; my $host; my $hostB; my $filer; my $filerB; my $filer_con; my $filer_conB; my $filerip; my $fileripB; my $bootfile; my $bootfileB; my $gateway; my $gatewayB; my @filers; my @hosts; my $filer_con_rsh = ""; my $filer_conB_rsh = ""; my $priv = "test"; my $def_password; my $def_passwordB; my $bootup; #####################################################333 my $Mode; my @Nodes; my $test_status = 0; #Set test fail parameter to 0 my $filer_names; my %Node_Api; my @create_mini; my @boot_4d; my @Nodes_all; my $numberofvols = 1; my $numraidgroups = 1; my $spares = 1; my $bootmode = "5"; my $netmask = "255.255.0.0"; ######################################### ## Pre-test processes ######################################### my $TC_name = "DELETE_MINI_DISK"; my @Testcases = ( MINI_DISK_DELETE => "MINI_DISK DELETION" ); &main(); sub main { # Debug break point $DB::single = 2; # Create Test Case Driver object $Test = new TCD( -testcases => [@Testcases] ); if ( $Test->error ) { $Test->log( $Test->errmsg ); $test_status = 1; $email_subject = "$TC_name : Test FAILED: FAIL"; $email_body = "Failed to instantiate Test object.\nLog Location : $LOGDIR\n"; send_message( mail_subject => $email_subject, mail_body => $email_body, MAIL_FROM => $MAIL_FROM, MAIL_TO => $MAIL_TO, EOE => $EOE, EMAIL => $EMAIL ); return $TCD::FAIL; } # Performs method callbacks $Test->run_test(); if ( $Test->error ) { $Test->log( $Test->errmsg ); return $TCD::FAIL; } exit(0); } ## end sub main ############################################################################## # Function: init # Purpose: init() is automatically called before executing tests to get test # parameters and to create any needed resources ############################################################################## sub init() { return $TCD::PASS if( $BOOT_TYPE eq "N"); $Test->description( "Initialising all required variables and FILER connections " ); $filer_names = $Test->get_param("FILER"); # Capturing Filer names from the param(Test_Suite) ##Check for duplicate node object and push unique node object in Nodes array. my @temp_nodes = NACL::C::Node->find(); # Find Nodes/Filers used in the test, Based on FILER param. my %nodes_filer; foreach my $Node(@temp_nodes){ my $FILER_C = $Node->name(); $nodes_filer{$FILER_C}=$Node; } @Nodes = values(%nodes_filer); # Contains Node object used for test execution. $Mode = $Nodes[0]->mode(); # gets mode(7mode/cmode) of the nodes used in test execution. @Nodes_all = @Nodes; $Mode = $Nodes[0]->mode(); # gets mode(7mode/cmode) of the nodes used in test execution. if(($TEST_CONFIG == 'E')&&($Primary_Node!~/^N$/)){ modify_cmode_as_dual(Node_ref =>\@Nodes,Test => $Test,primary_filer_name => $Primary_Node); logcomment("Test will run only on node $Primary_Node"); } return $TCD::PASS; } # end init() ############################################################################## # Function: setup # Purpose: setup() is automatically called before executing tests ############################################################################## sub setup() { return $TCD::PASS if( $BOOT_TYPE eq "N"); $Test->description( "Inside SETUP changing filer state to MAINT mode"); disk_remv_assign_ownership(Node_ref =>\@Nodes,Test => $Test); if ( $Mode eq '7Mode' ) { if ( "$TEST_CONFIG" eq "C" ) { $host = host($FILERA); $filer_con = connect("$FILERA#console"); $hostB = host($FILERB); $filer_conB = connect("$FILERB#console"); $FILER = $FILERA; $filer_con->timeout("1200"); $filer_con->prompts($FILER_PROMPT); $filer_conB->timeout("1200"); $filer_conB->prompts($FILER_PROMPT); $filer = $host->hostname; $filerip = $host->default_ip(); $gateway = $host->{GATEWAY}; $filerB = $hostB->hostname; $fileripB = $hostB->default_ip(); $def_password = $host->{default_password}; $def_passwordB = $hostB->{default_password}; if ( $FILER_TYPE eq "IC" ) { $bootfileB = $hostB->bootimage(); $bootfile = $host->bootimage(); } elsif ( $FILER_TYPE eq "BR" ) { $bootfile = $host->{BOOT_IMAGE}; $bootfileB = $hostB->{BOOT_IMAGE}; } $gatewayB = $hostB->{GATEWAY}; push( @filers, $filer_con ); push( @filers, $filer_conB ); push( @hosts, $host ); push( @hosts, $hostB ); } else { $host = host($FILER); $filer = $host->hostname; $filerip = $host->default_ip(); $def_password = $host->{default_password}; if ( $FILER_TYPE eq "IC" ) { $bootfile = $host->bootimage(); } elsif ( $FILER_TYPE eq "BR" ) { $bootfile = $host->{BOOT_IMAGE}; } $gateway = $host->{GATEWAY}; $filer_con = connect("$FILER#console"); $filer_con->timeout("1200"); $filer_con->prompts($FILER_PROMPT); push( @filers, $filer_con ); push( @hosts, $host ); } } my @change_states; foreach my $node(@Nodes){ my $FILER = $node->name(); my $Host = host($FILER); my $transit_obj = NACL::Transit->new(name => $Host); #my $filer_state = $transit_obj->get_state(); my $filer_state = $Transit_obj->get_state( 'timeout' => 3600, 'get_state_timeout' => 7200); if($filer_state =~/(UP|CLI)/i){ $Test->nlog("$FILER : Filer is not in Maintenance Mode, So booting in Maintenance mode"); push(@change_states,$FILER); }elsif($filer_state =~/MAINT/i){ $Test->nlog("$FILER : Filer is already in Maintenance Mode"); }else{ push(@change_states,$FILER); } } my @subtests; foreach my $filer_name (@change_states){ push(@subtests, subtest( \&boot_filer_in_req_state, -runid, "boot_filer_in_MAINT_" . "$filer_name", -bg, "--", Test => $Test, filer_name => $filer_name, change_state_to => "MAINT", ) ); } $Test->nlog("Subtest @subtests"); Subtest::wait_finish( subtest => [@subtests] ); ##Creating API objects foreach my $node(@Nodes){ my $FILER = $node->name(); my $Host = host($FILER); my $console = Tharn::connect("$FILER#console"); # Set the properties for the Connectrec used for creating the APIset $console->{prompts} = [qr/\*>/]; $console->{max_idle} = 5; $console->{on_idle} = sub { $console->execute(""); }; my $API_obj = NACL::APISet->new(connection => $console, category => "Node", interface => "CLI", set => "Maintenance"); $Node_Api{$node}=$API_obj; } return $TCD::PASS; } sub MINI_DISK_DELETE { return $TCD::PASS if( $BOOT_TYPE eq "N"); $Test->description("Deleting mini_disks if present"); #Deletion of mini disk foreach my $node(@Nodes){ my $FLAG; my $FILER_C = $node->name(); $FLAG = delete_mini_disk(node => $node); if($FLAG ==1){ push(@boot_4d,$node); } my $API = $Node_Api{$node}; my $output = $API->execute_raw_command('command' =>"aggr status -r"); if(( $output =~ /No root aggregate or root traditional volume found/) || ($output =~ /No root aggregate/)||($output =~/not zeroed|zeroing/)){ push(@boot_4d,$node); #if no root aggregate found boot in 4d mode } } return $TCD::PASS; } sub cleanup() { return $TCD::PASS if(( $BOOT_TYPE eq "N")||($RE_INIT == 0)); $Test->description("Booting the filers in 4d if required"); my @subtests; @boot_4d = _unique(@boot_4d); if(@boot_4d){ ##Boot in 4d if only mini-disks are present array @boot_4d will contain the nodes where mini-disks were deleted if($Mode=~/7Mode/i){ ##if 7 Mode use bootitgood sub-routine if(scalar @boot_4d == 1){ my $FILER_C = $boot_4d[0]->name(); my $FILER_C_con = connect("$FILER_C#console"); $Test->nlog("Booting the filer $FILER_C in 4d"); push(@subtests, subtest(\&bootitgood, -runid, "boot_4d_$FILER", -bg, "--", $FILER_C_con,$bootfile,'4d',$numberofvols,$spares,$numraidgroups, $FILER_C, $filerip, $gateway, $netmask,$FILER_TYPE, $def_password, $host) ); Subtest::wait_finish( subtest => [@subtests] ); }elsif(scalar @boot_4d == 2){ $Test->description("Booting the filer $FILER in 4d"); $Test->description("Booting the filer $FILERB in 4d"); push(@subtests, subtest(\&bootitgood, -runid, "boot_4d_$FILER", -bg, "--", $filer_con,$bootfile,'4d',$numberofvols,$spares,$numraidgroups, $FILER, $filerip, $gateway, $netmask,$FILER_TYPE, $def_password, $host) ); push(@subtests, subtest(\&bootitgood, -runid, "boot_4d_$FILERB", -bg, "--", $filer_conB,$bootfileB,'4d', $numberofvols,$spares,$numraidgroups,$FILERB, $fileripB, $gateway, $netmask,$FILER_TYPE, $def_passwordB, $hostB) ); Subtest::wait_finish(subtest => [@subtests]); } }else{ ##IF Cmode if($BOOT_MODE == 1){ logcomment("Complete setup of filers"); setup_cmode_filers(node_present => \@Nodes_all,Test =>$Test,delete_mini_disk =>'NO',remove_assign_disk => 'NO'); }else{ foreach(@boot_4d){ my $Filer = $_->name(); $Test->nlog("$Filer : Booting the filer in 4d"); push(@subtests, subtest(\&boot_filer_in_4d, -runid, "boot_filer_in_4d_" . "$Filer", -bg, "--", node => $_, ) ); } logcomment("Subtest @subtests"); Subtest::wait_finish( subtest => [@subtests]); } } } @subtests =(); my $mode; $mode = 'CLI' if( $BOOT_MODE == 1); $mode = 'MAINT' if( $BOOT_MODE == 5); logcomment("Filers are not booted in 4d mode, as there is no mini-disks to delete"); logcomment("Mini-disks are not created, so filer is booting in $BOOT_MODE mode if necessary"); foreach my $node (@Nodes){ my $FILER = $node->name(); my $Host = host($FILER); my $transit_obj = NACL::Transit->new(name => $Host); #my $filer_state = $transit_obj->get_state(); my $filer_state = $Transit_obj->get_state( 'timeout' => 3600, 'get_state_timeout' => 7200); if($filer_state=~/$mode/){ logcomment("$FILER : Filer is in required state i,e $mode"); next; }else{ push(@subtests, subtest( \&boot_filer_in_req_state, -runid, "boot_filer_in_$mode"."_" . "$FILER", -bg, "--", Test => $Test, filer_name => $FILER, change_state_to => $mode,) ); } } Subtest::wait_finish(subtest => [@subtests]); return $TCD::PASS; } sub _unique(@) { my %nodes_filer; foreach my $Node(@_){ my $FILER_C = $Node->name(); $nodes_filer{$FILER_C}=$Node; } return values(%nodes_filer); }