#!/usr/software/bin/perl # $Id: ## ## Copyright (c) 2005 Network Appliance, Inc. ## All rights reserved ## ## @summary Mode ## Check for mini disk and delete mini disk. ## ## @description ## Checks and cleans up the filer by deleting mini disk and booting in 4a/4d mode. ## ## @param FILER Required: Hostid of filer ## @example ntest FILER=FILERA check_version ## @status public ## @status Automated ## @auther arunak@netapp.com ## @burt 494833 ## @change YY/MM/DD from auther: Description of the change ## ############################################################################# use Cwd qw(abs_path); use HTML::Mail; #use strict; use boot; use Subtest; use San; use Storage::Common_Lib; use Storage::SASUtils qw(disable_dbg_msgs); # Subroutines sub trim($); sub boot_after_mini($$); ######################################## ### 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 $RE_INIT ); 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', '-mesg', 'filer type'); 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("RE_INIT", '-default', '0'); my $host = host($FILER); my $Home = $ENV{HOME}; 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 @filers_rsh; my $filer_con_rsh = ""; my $filer_conB_rsh = ""; my $priv = "test"; my $def_password; my $def_passwordB; my $bootup; $Home = trim($Home); my $san_obj = new San(\*ntest::NTEST_STDOUT); if ($san_obj->error()) { logresult('FAIL', "Failed to instantiate San object" . $san_obj->errmsg()); } $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------" ); $san_obj->sanlog(-msg => "Checking for clean up mini disk option"); $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------" ); #Set filer param based on system type, C for cluster and D for dual setup 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); sort (@filers); push(@hosts, $host); push(@hosts, $hostB); sort (@hosts); } else { $host = host($FILER); $filer = $host->hostname; $filerip = $host->default_ip(); $def_password = $host->{default_password}; if ($FILER_TYPE eq "IC") { $bootfile = $host->bootimage(); $bootup = "main"; } elsif ($FILER_TYPE eq "BR") { $bootfile = $host->{BOOT_IMAGE}; $bootup = $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); } ## end else [ if ("$TEST_CONFIG" eq ... my $numberofvols = 1; my $numraidgroups = 1; my $spares = 1; my $bootmode = "5"; my $netmask = "255.255.0.0"; my $Filer_con = ""; my $Host = ""; my $FILER_C = ""; my $skip_on_fatal = 0; my $filerP; logcomment("TEST_CONFIG = $TEST_CONFIG"); logcomment("The filer hostname is: $FILER"); if ( "$TEST_CONFIG" eq "C" ) { logcomment("The filerB hostname is : $FILERB"); } #if ( "$TEST_CONFIG" eq "C" ) { # $filerP = $host->{part_host}; # logcomment("The partner filer is: $filerP"); # if ($FILER eq $filerP) { # logresult('INSPECT',"The partner host entered in FILER CONFIG file is incorrect. Please correct and restart the test."); # logresult('FATAL',"The partner host entered in FILER CONFIG file is incorrect. Please correct and restart the test."); # } #} ############################################ # Check for FATAL error in log file. ############################################ if ($LOGDIR =~ /(\S+)HDD(\S+)/){ my $MAIN = $1; chomp($MAIN); opendir(DIR_LOG, $MAIN); my @files_DIR_LOG = readdir(DIR_LOG); foreach my $file (@files_DIR_LOG){ if ( $file =~ /(.*_NADQ02.*)\.log/ ) { logcomment("Reading file - $file"); @ary = `tail -n 10 $MAIN/$file`; foreach my $line(@ary){ if ($line =~ /FATAL/i){ $skip_on_fatal = 1; } } } } } ############################################ # Check for FATAL error in log - End ############################################ ############################################# # Deleting mini disks on the filers - BEGIN # ############################################# if ($BOOT_TYPE ne "N") { if ($skip_on_fatal == 0 ) { my ($filer_state, $filer_stateB) = (); my $unowned = 0; my ( $val1, $val2, $output, $val4 ) = say( $filer_con, "disk show -n", "-prompt", '\*>', -timeout, 1800 ); foreach my $lin ( split( /\n/, $output ) ) { if ($lin =~ /Not Owned/){ $unowned = 1; } } if ($unowned == 1){ logcomment("Some of the disk are not owned on filer"); logcomment("Assigning un-owned drives to filer"); if ( "$TEST_CONFIG" eq "D" ) { remv_assign_ownership( con_obj => $filer_con, filer => $FILER,test_config => $TEST_CONFIG); }else{ remv_assign_ownership( con_obj => $filer_con, filer => $FILER, filerB => $FILERB, test_config => $TEST_CONFIG); } } if ("$TEST_CONFIG" eq "C") { push(@subtests, subtest(\&delete_mini_main, -runid, "delete_mini_disk_$FILER", -bg, "--", $filer_con, $FILER, $bootmode, $bootfile, $numberofvols,$spares,$numraidgroups, $filerip, $gateway, $netmask,$filer_type, $def_password, $host) ); push(@subtests, subtest(\&delete_mini_main, -runid, "delete_mini_disk_$FILERB", -bg, "--", $filer_conB,$FILERB,$bootmode, $bootfile,$numberofvols,$spares,$numraidgroups, $fileripB, $gateway, $netmask,$filer_type, $def_passwordB, $hostB) ); Subtest::wait_finish(subtest => [@subtests]); }else{ push(@subtests, subtest(\&delete_mini_main, -runid, "delete_mini_disk_$FILER", -bg, "--", $filer_con, $FILER, $bootmode, $bootfile, $numberofvols,$spares,$numraidgroups, $filerip, $gateway, $netmask,$filer_type, $def_password, $host) ); Subtest::wait_finish(subtest => [@subtests]); } move_log_files($LOGDIR); }else{ $san_obj->sanlog(-msg =>"------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => "FILER- $FILER_C : Test Script resulted in FATAL, Skipping cleanup of mini disk"); $san_obj->sanlog(-msg =>"------------------------------------------------------------------------------------------"); logcomment("FILER- $FILER_C : Test Script resulted in FATAL, Skipping cleanup of mini disk"); } } ## end if ($BOOT_TYPE ne "N") ########################################### # Deleting mini disks on the filers - END # ########################################### sub delete_mini_main { my ( $Filer_con, $FILER_C, $bootmode, $bootfile, $numberofvols, $spares, $numraidgroups,$filerip, $gateway, $netmask, $filer_type, $def_password, $host_obj ) = @_; $filer_state = boot_state($Filer_con); if (($filer_state =~ /^(MAINT)/)) { logcomment("$FILER : The filer is in Maintainence Mode. Proceeding with deletion of mini disks"); $san_obj->sanlog(-msg =>"$FILER : The filer is in Maintainence Mode. Proceeding with deletion of mini disks"); }else{ logcomment("$FILER : The filer is not in Maintainence Mode. Proceeding with booting the filer in MAINT Mode and deletion of mini disks"); $san_obj->sanlog(-msg =>"$FILER : The filer is not in Maintainence Mode. Proceeding with booting the filer in MAINT Mode and deletion of mini disks"); } if ($filer_state !~ /^(MAINT)/) { bootitgood($Filer_con, $bootfile, "5", $numberofvols, $spares, $numraidgroups, $FILER_C, $filerip, $gateway, $netmask, $FILER_TYPE, $def_password, $host_obj); } $san_obj->sanlog(-msg =>"------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => "FILER- $FILER_C : Deleting mini disk ..."); logcomment("FILER- $FILER_C : Deleting mini disk ..."); deleteMini($Filer_con); logcomment("FILER- $FILER_C : Deleted mini disk"); $san_obj->sanlog(-msg => "FILER- $FILER_C : Deleted mini disk"); if ($RE_INIT == 1){ $san_obj->sanlog(-msg =>"------------------------------------------------------------------------------------------"); logcomment("FILER- $FILER_C : User has selected re-initialization of filesystem, Re-initializing file system...."); $san_obj->sanlog(-msg => "FILER- $FILER_C : Booting in 4d to re-intialize filesystem"); logcomment("FILER- $FILER_C : Booting in 4d to re-intialize filesystem"); my $bootmode_4; if ($FILER_TYPE eq "IC") { if ("$SSD" eq "no") { $bootmode_4 = "4"; } else { $bootmode_4 = "4a"; } } else { $bootmode_4 = "4d"; } bootitgood($Filer_con, $bootfile, $bootmode_4, $numberofvols, $spares, $numraidgroups, $FILER_C, $filerip, $gateway, $netmask, $FILER_TYPE, $def_password, $host_obj); logcomment("FILER- $FILER_C : Re- initialized file system"); $san_obj->sanlog(-msg =>"FILER- $FILER_C : Re- initialized file system"); $san_obj->sanlog(-msg =>"------------------------------------------------------------------------------------------"); }else{ $san_obj->sanlog(-msg =>"------------------------------------------------------------------------------------------"); logcomment("FILER- $FILER_C : User selected option \"No\" to re-initialize filesystem, Skipping zeroing of drives"); $san_obj->sanlog(-msg => "FILER- $FILER_C :User selected option \"No\" to re-initialize filesystem, Skipping zeroing of drives"); $san_obj->sanlog(-msg =>"------------------------------------------------------------------------------------------"); } } sub move_log_files { my ($complete_log_dir) = @_; my $main_log_dir; if($complete_log_dir =~ /(\S+)\/HDD\/(\S+)/){ $main_log_dir = $1; } $DIR = "$complete_log_dir" . "/" . "cleanup_mini_disk"; opendir( LOG_DIR, $DIR ); my @files = readdir(LOG_DIR); foreach my $file(@files){ if( $file =~ /\.log/) { my $Lo_DIR = "$DIR" . "/" . "$file"; open(LOG,"$Lo_DIR") || die "Could not read log file..."; open(X_LOG,">$DIR/test.log"); foreach my $line () { $line =~ s/^ //; $line =~ s/\[\S+\]//; print X_LOG "$line"; } system ("sudo mv $DIR/test.log $Lo_DIR"); system ("sudo cp -rf $Lo_DIR $main_log_dir"); } } system("sudo rm -rf $complete_log_dir/*mini*"); } sub trim($) { my $string = shift; $string =~ s/^\s+|\s+$//gm; s/^\"(.*)\"$/$1/ || s/^\'(.*)\'$/$1/; return $string; }