#!/usr/software/bin/perl # $Id: ## ## Copyright (c) 2005 Network Appliance, Inc. ## All rights reserved ## ## @summary Mode ## Create mini_disk . ## ## @description ## Create mini disk ## ## @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 ); 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( 'BOOT_TYPE', '-default', 'A'); 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 mini_disk exist or not" ); $san_obj->sanlog( -msg =>"------------------------------------------------------------------------------------------"); logcomment("Checking for mini_disk exist or not" ); #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 $mini_present = 0; my $boot_after_mini_present = 0; my $filer_type = $FILER_TYPE; 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."); # } #} ############################################# # Creating mini disks on the filers - BEGIN # ############################################# if ( $BOOT_TYPE ne "N" ) { 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(\&create_mini_main, -runid, "create_mini_disk_$FILER", -bg, "--", $filer_con, $FILER, $bootmode, $bootfile, $numberofvols,$spares,$numraidgroups, $filerip, $gateway, $netmask,$filer_type, $def_password, $host) ); push(@subtests, subtest(\&create_mini_main, -runid, "create_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(\&create_mini_main, -runid, "create_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); } ########################################### # Creating mini disks on the filers - END # ########################################### sub move_log_files { my ($complete_log_dir) = @_; my $main_log_dir; my $temp; if($complete_log_dir =~ /(\S+)\/HDD\/(\S+)/){ $main_log_dir = $1; } opendir(DIRA, $complete_log_dir); @filesA = readdir(DIRA); foreach my $fileA (@filesA) { if ($fileA =~ /\./){ next; } if (($fileA =~ /\d+_create_mini_disk/) || ($fileA =~ /create_mini_disk/)){ $temp = $fileA; } } $DIR = "$complete_log_dir" . "/" . "$temp"; 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 create_mini_main { my ( $Filer_con, $FILER_C, $bootmode, $bootfile, $numberofvols, $spares, $numraidgroups,$filerip, $gateway, $netmask, $filer_type, $def_password, $host_obj ) = @_; my ( $filer_state, $filer_stateB ) = (); my $mini_present = 0; my $normal_present = 0; my $cmd_not_found = 0; $san_obj->sanlog( -msg => "Checking for mini disk on filer - $FILER_C "); logcomment("Checking for mini disk on filer - $FILER_C "); say( $Filer_con, "priv set -q test", '-timeout', 30); my ( $val1, $val2, $val3, $val4 ) = say( $Filer_con, "mini_disk list", "-prompt", '\*>', -timeout, 1800 ); foreach my $line ( split( /\n/, $val3 ) ) { if ($line =~ /NORMAL/){ $normal_present = 1; } elsif ($line =~ /mini_disk not found/i){ $cmd_not_found = 1; } elsif ( $line =~ /No minidisks are present/i){ $mini_present = 0; } } #Adding command not found if ($cmd_not_found == 1){ logcomment("- $FILER_C - mini_disk list command not found in UP state, Checking mini_disk list in maintenance mode"); my $filer_state_cmd = boot_state($Filer_con); logcomment("- $FILER_C - Filer is in $filer_state_cmd state"); if ( $filer_state !~ /^(MAINT)/ ) { logcomment("- $FILER_C - Filer is not in maintenance mode, Booting in maintenance mode to check mini_disk"); bootitgood( $Filer_con, $bootfile, "5", $numberofvols, $spares, $numraidgroups, $FILER_C, $filerip, $gateway, $netmask, $filer_type, $def_password, $host_obj ); } my $filer_state = boot_state($Filer_con); if ( $filer_state !~ /^(MAINT)/ ) { logresult( 'FATAL',"Failed to bring the filer in MAINT Mode. Exiting from the script"); } logcomment("- $FILER_C - Checking for mini_disk in maintenance mode"); my ( $val1, $val2, $val3, $val4 ) = say( $Filer_con, "mini_disk list", "-prompt", '\*>', -timeout, 1800 ); foreach my $line ( split( /\n/, $val3 ) ) { if ($line =~ /NORMAL/i){ $normal_present = 1; } } } if ($normal_present == 1){ $mini_present = 0; logcomment("- $FILER_C -Normal disk are present on the filer, Creating mini disk"); $san_obj->sanlog( -msg => "- $FILER_C -Normal disk are present on the filer, Creating mini disk"); }else{ logcomment(" Mini disk already present on filer - $FILER_C"); $san_obj->sanlog( -msg => "Mini disk already present on filer - $FILER_C"); $mini_present = 1; } if ($mini_present == 1){ my ( undef, undef, $after, undef ) = say( $Filer_con, "aggr status -r", -timeout, 1000, -ok ); foreach my $line ( split( /\n/, $after ) ) { if ( $line =~ /not zeroed|zeroing,/ ) { $boot_after_mini_present = 1; }elsif (( $line =~ /No root aggregate or root traditional volume found/) || ($line =~ /No root aggregate/)){ $boot_after_mini_present = 1; } } } if ($boot_after_mini_present == 1){ logcomment("WARNING: Mini disk already created, but not zeroed. Booting filer in 4d to zero mini disk"); $san_obj->sanlog( -msg => "WARNING :Mini disk already created, but not zeroed. Booting filer in 4d to zero mini disk"); } #Createin mini disk as mini disk is not present : if ($mini_present == 0){ $filer_state = boot_state($Filer_con); $san_obj->sanlog( -msg => "FILER- $FILER_C State is - $filer_state"); if ( ( $filer_state =~ /^(MAINT)/ ) || ( $filer_stateB =~ /^(MAINT)/ ) ){ logcomment("$FILER : The filer is in maintenance mode. Proceeding with creating of mini disks"); }else { logcomment("$FILER : The filer is not in maintenance mode. Proceeding with booting the filer in MAINT Mode"); } if ( $filer_state !~ /^(MAINT)/ ) { bootitgood( $Filer_con, $bootfile, "5", $numberofvols, $spares, $numraidgroups, $FILER_C, $filerip, $gateway, $netmask, $filer_type, $def_password, $host_obj ); my $filer_state = boot_state($Filer_con); if ( $filer_state !~ /^(MAINT)/ ) { logresult( 'FATAL',"Failed to bring the filer in MAINT Mode. Exiting from the script"); } } $san_obj->sanlog( -msg => "FILER- $FILER_C : Creating mini disk ..." ); logcomment("Creating mini disk on the filer : $FILER_C"); createMini( $Filer_con, $MINI_CREATE_SIZE, "n", $host_obj ); logcomment("Creating of mini disk completed : $FILER_C"); $san_obj->sanlog( -msg => "FILER- $FILER_C : Creating of mini disk completed : $FILER_C"); } if (($mini_present == 0) || ($boot_after_mini_present == 1)){ my $bootmode_4; $san_obj->sanlog( -msg => "Filer - $FILER_C : Booting filer in 4d Mode, Re-initializing after creating mini disk"); logcomment("Filer - $FILER_C : Booting filer in 4d Mode, Re-initializing after creating mini disk"); 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 ); my $filer_state = boot_state($Filer_con); if ( $filer_state !~ /^(UP)/ ) { logresult( 'FATAL',"Failed to bring the filer in UP Mode. Exiting from the script"); } logcomment("Filer - $FILER_C : Booted filer in 4d Mode"); $san_obj->sanlog( -msg => "Filer - $FILER_C : Booted filer in 4d Mode"); } } sub trim($) { my $string = shift; $string =~ s/^\s+|\s+$//gm; s/^\"(.*)\"$/$1/ || s/^\'(.*)\'$/$1/; return $string; }