#!/usr/software/bin/perl # $Id: //depot/prod/test/Rsierranevada/storage/hdd/NADQ_SEA/NDATE/SUPPORT_SCRIPTS/check_setup.thpl#2 $ # Copyright (c) 2005 Network Appliance, Inc. # All rights reserved # ## @summary Mode ## Check filer ontap version ## @description ## Check the filer ontap version with the supplied one ## @param FILER Required: Hostid of filer ## @param ONTAP_VERSION Optional: OnTap Version to verify. ## @example ntest FILER=FILERA ONTAP_VERSION=mainN_031202_23 check_version ## @status public ## @author maji@netapp.com ## #use strict; use boot; use San; use Storage::Common_Lib; use Storage::SASUtils qw(disable_dbg_msgs); use Net::Ping::External qw(ping); my $ping_host = Net::Ping->new(); sub trim($); sub check_version($$); sub pnate_versions($); ######################################## ### Initialization/declaration ######################################### use vars qw( $FILER $FILER_CONN $MAINT_PRMPT $MODE $LOGDIR $TEST_MODE $FILER_TYPE $DISABLESHELL $MINI_CREATE_SIZE $MINI_CREATE $BOOT_TYPE ); param('FILER', '-mesg', 'HostID of filer'); param("FILER_CONN", '-default', '#console'); param("MODE", '-default' , 'MAINT'); param("MAINT_PRMPT", '-default', '\*>'); param("STEST_FILE" , '-default', 'FILER'); param('LOGDIR', -mesg, "Log directory of the test"); param("TEST_MODE", '-default', 'DEV'); param("FILER_TYPE", '-mesg', 'Filer type'); param("DISABLESHELL", '-default', '2'); param( 'MINI_CREATE_SIZE', '-default', '1' ); param( 'MINI_CREATE', '-default', 'n' ); param('BOOT_TYPE', '-default', 'A'); print "FILER: $FILER"; my $host = host($FILER); print "host:$host"; my $TC_name = "check_setup"; my $diskname = 0; my $fcchannel = 1; my $numberofvols = 1; my $numraidgroups = 1; my $spares = 1; my $bootmode = "5"; my $bootup; my $filer = $host->hostname; my $filerip = $host->default_ip(); my $gateway = $host->{GATEWAY}; my $netmask = "255.255.255.0"; my $ONTAP_VERSION; my $bootfile; my $tftp_ip; my $netboot; my $mount_ip; my @filers; my $def_password; my $mini_present; my $boot_after_mini_present; if ( $FILER_TYPE eq 'IC') { $ONTAP_VERSION = $host->{NETBOOT_FILE}; $bootfile = $host->bootimage(); $tftp_ip = $host->{TFTPHOST_IP}; $netboot = $host->{NETBOOT}; $bootup = "main"; } elsif ( $FILER_TYPE eq 'BR') { $ONTAP_VERSION = $host->{VERSION}; $bootup = $host->{BOOT_IMAGE}; $def_password = $host->{default_password}; } my $terminal_ip = ""; my $san_obj = new San(\*ntest::NTEST_STDOUT); if ($san_obj->error()) { logresult('FATAL', "Failed to instantiate San object" . $san_obj->errmsg()); } sleep 2; $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => "FILER- $filer : Log PATH for this filer $LOGDIR "); $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => "FILER- $filer : Loading and checking filer version , expected completion time 10 Min:" . scalar(localtime())); my $Home=$ENV{HOME}; $Home = trim($Home); my $NDATE_path = "$Home/NDATE_ver"; # Creating text file and writing $LOGDIR value into the file if ($DISABLESHELL == 2 ) { my $TEMP_LOGDIR = $LOGDIR ; $TEMP_LOGDIR =~ /(\d+_\d+_)([^\/]+)/; my $temp_val = "$Home/NDATE/shell_$2.txt"; open(SHELL_TXT, ">$temp_val") or die "write:Failed opening $temp_val\n"; print(SHELL_TXT "LOGDIR=$LOGDIR\n"); close SHELL_TXT; my $dir=`mkdir $LOGDIR`; } # End of Creating text file # Reading NDATE_ver file to get the version number and build date my $major, $minor, $patch, $date; my @ver_arr = (); open(NDATEVER, "$NDATE_path"); while () { $_ =~ s/^\s+//; $_ =~ s/\s+$//; @ver_arr = split("=", $_); if ($_ =~ /NDTE_MAJOR_VERSION/) { $major = $ver_arr[1]; } elsif ($_ =~ /NDTE_MINOR_VERSION/) { $minor = $ver_arr[1]; } elsif ($_ =~ /NDTE_PATCH_VERSION/) { $patch = $ver_arr[1]; } elsif ($_ =~ /DATE/) { $date = $ver_arr[1]; } } my $VERSION = "$major.$minor.$patch"; my $BUILD_DATE = "$date"; my ($staf_ver, $osversion, $build_date); #Sending the default values if this appers then it fails to found. $staf_ver = 3; $build_date = 2011; $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => "NDATE Build Version used : $VERSION "); $san_obj->sanlog(-msg => "NDATE Build Date : $BUILD_DATE "); # print if installend via pNATE if ((-e "$Home/.pnate_ndate_debug") || (-d "$Home/NDATE/pnate")) { #push(@INC, "$Home/archives/install/lib"); # Req for old pnate installation if (-d "$Home/NDATE/pnate/lib") { push(@INC, "$Home/NDATE/pnate/lib"); require PNATE; } if (-d "$Home/NDATE/pnate/bin") { $osversion = `$Home/NDATE/pnate/bin/sfwmnt`; $osversion = trim($osversion); logcomment("Running on the OS: $osversion"); } ($staf_ver, $build_date) = pnate_versions($osversion); logcomment("pNATE is installed - Following are pNATE versions"); $san_obj->sanlog(-msg => "PNATE Build Date : ". $build_date); $san_obj->sanlog(-msg => "PNATE Build Version : ". PNATE::version_string()); $san_obj->sanlog(-msg => "PNATE NATE Version : ". NATE::version_string()); $san_obj->sanlog(-msg => "PNATE STAF Version : ". $staf_ver); }## end of if (-e "$Home/.pnate_ndate_debug") $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); logcomment "------------------------------------------------------------------------------------------"; logcomment "NDATE Build Version used : $VERSION "; logcomment "NDATE Build Date : $BUILD_DATE "; logcomment "------------------------------------------------------------------------------------------"; ### ######################################### ## Pre-test processes ######################################### ######################################### ## Test starts here ########################################## logcomment("Checking filer parameters "); chomp($gateway); chomp($filerip); if ($gateway =~ /$filerip/) { $san_obj->sanlog(-msg => "FILER- $filer :The Gateway IP $gateway is same as filer ip $filerip. Please check the Gateway/Filer IP address mentioned against 'GATEWAY/default_ip' field in ~/NDATE/FILER_INFO/$filer file\n" . scalar(localtime())); logresult('INSPECT',"Exiting from rest of the tests"); logresult('FATAL',"Exiting from rest of the tests"); } logcomment("test_mode : $TEST_MODE"); my $pingStatus = 0; my $filer_config = `cat $Home/NDATE/FILER_INFO/$FILER`; foreach my $line (split /\n/, $filer_config) { if ( $line =~ /(.*)connhost=(.*)\;(.*)/ ) { if ($2 ne $filerip) { $terminal_ip = $2; } } if (!($netboot ==1)) { if ( $line =~ /(.*)ethernet:(.*)\,(.*)\,(.*)\'/ ) { $ONTAP_VERSION = $3; $tftp_ip = $2; $filerip = $4; } } if ($line =~ /default_ip\=(.*)/) { $mount_ip = $1; $mount_ip = trim($mount_ip); } } chomp($gateway); chomp($filerip); if ($gateway =~ /$filerip/) { $san_obj->sanlog(-msg => "FILER- $filer :The Gateway IP $gateway is same as filer ip $filerip. Please check the Gateway/Filer IP address mentioned against 'GATEWAY/default_ip' field in ~/NDATE/FILER_INFO/$filer file\n" . scalar(localtime())); logresult('INSPECT',"Exiting from rest of the tests"); logresult('FATAL',"Exiting from rest of the test"); } if (!ping('host' => $gateway)) { $san_obj->sanlog(-msg => "FILER- $filer :The Gateway IP $gateway is not accessible. Please check the Gateway IP address mentioned against 'GATEWAY' field in ~/NDATE/FILER_INFO/$filer file OR network setup correctly\n" . scalar(localtime())); } else { logcomment("Gateway IP $gateway is accessible "); } if (!ping('host' => $terminal_ip)) { $san_obj->sanlog(-msg => "FILER- $filer :The Terminal server IP $terminal_ip is not accessible. Please check the Terminal server IP address mentioned against 'connhost' field in ~/NDATE/FILER_INFO/$filer file OR network setup correctly\n" . scalar(localtime())); $pingStatus = 1; } else { logcomment("Terminal IP $terminal_ip is accessible "); } if ( $FILER_TYPE eq "IC") { if (!ping('host' => $tftp_ip)) { $san_obj->sanlog(-msg => "FILER- $filer :The TFTP server IP $tftp_ip is not accessible. Please check the TFTP server IP address mentioned against 'TFTPHOST_IP/bootimage' field in ~/NDATE/FILER_INFO/$filer file OR network setup correctly\n" . scalar(localtime())); $pingStatus = 1; } else { logcomment("TFTP server IP $tftp_ip is accessible "); } if ($pingStatus == 1) { $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => "FILER- $filer :Exiting from rest of the test cases :" . scalar(localtime())); $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); logresult('INSPECT',"Exiting from rest of the tests"); logresult('FATAL',"Exiting from rest of the test"); } } my $filer_conn = connect($FILER . $FILER_CONN); $filer_conn->timeout([300]); $filer_conn->prompts($MAINT_PRMPT); my $result = 0; my $filer_state = boot_state($filer_conn); #Removing the stale NFS handlers if any. if ($filer_state =~ /^UP/) { umount_filer($mount_ip, $FILER); } if ($filer_state =~ /^(UP|MAINT)/) { my ($match, undef, $version); my $timeout = 60; logcomment("Filer already in $filer_state mode \n"); if ($BOOT_TYPE eq "N") { logcomment("FILER- $filer : Test will not perform version check as -b=6 is selected"); } else { $version = ""; eval { ($match, undef, $version) = say($filer_conn, "version", -eval_error, '-timeout', $timeout); }; $result = check_version($filer_conn, $ONTAP_VERSION); if ($result == 1) { if ($filer_state =~ /^(UP)/) { say($filer_conn, "priv set -q test", '-timeout', 30) } $san_obj->sanlog(-msg => "FILER- $filer : Filer is loaded with correct Kernel version : $ONTAP_VERSION :" . scalar(localtime())); } elsif ( $result != 1 ) { if ( ($FILER_TYPE eq "BR") && ( ($version =~ /ic/i) || ($version =~ /ironcity/i) || ($ONTAP_VERSION =~/(br|boil)/i && (($version =~ /rolling/i) ||($version =~ /(R8|rr)/i)))|| ($version =~/(br|boil)/i && (($ONTAP_VERSION =~ /rolling/i) ||($ONTAP_VERSION=~ /(R8|rr)/i))) )) { logcomment("The kernel present in filer and the user provided filer kernel differs; so halting the filer"); say($filer_conn, "halt -f -t 0", -timeout, 120, -ok); } elsif ( ($FILER_TYPE eq "IC") && ( ($version =~ /br/i) || ($version =~ /boil/i) || ($version =~ /7-Mode/i) || ($version =~ /rolling/i) ||($version =~ /(R8|rr)/i) )) { say($filer_conn, "halt -f -t 0", -timeout, 120, -ok); } else { $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => "FILER- $filer : Filer booted with Kernel version : $ONTAP_VERSION :" . scalar(localtime())); $san_obj->sanlog(-msg => "FILER- $filer : May be name of the kernel file and the kernel version are different :" . scalar(localtime())); $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); logresult('FAIL',"Boot Filer with Kernel version : $ONTAP_VERSION"); } } else { if ($TEST_MODE eq 'DEV' || ($result != 1) ) { logcomment("Different KERNEL loaded"); } elsif ($TEST_MODE eq 'QUAL') { $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => "FILER- $filer : Exiting from rest of the tests.\n Please do one of the followings: \n 1> Halt the filer and update the correct kernel file mentioned against 'NETBOOT_FILE/bootimage' field in ~/NDATE/FILER_INFO/$filer file \n 2> Rename the Data ONTAP kernel name(mentioned in step 1 above) same as kernel version \n 3> Disable this check by re-setting the 'TEST MODE' parameter to 'DEV' while invoking ndate tool (./ndate -m=DEV).\n \n At reboot the filer loads the kernel file mentioned in the filer config file.\n" . scalar(localtime())); $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); logresult('INSPECT',"Different KERNEL loaded"); } } } } $filer_state = boot_state($filer_conn); if ($filer_state =~ /^(FIRMWARE|HALTED|BOOT_MENU|CFE_BANNER|LOADER_BANNERFIRMWARE)/) { logcomment("Filer in $filer_state mode "); logcomment("Booting the Filer MAINT mode"); $bootmode = 5; bootitgood($filer_conn, $bootup, $bootmode, $numberofvols, $spares, $numraidgroups, $filer, $filerip, $gateway, $netmask,$FILER_TYPE); $filer_state = boot_state($filer_conn); if ($filer_state =~ /^MAINT/) { logcomment("Filer booted in maintenance mode "); ##Removing the version check because the filer is booted with kernel file from filer config file # $result = check_version($filer_conn, $ONTAP_VERSION); # if ($result == 1) { # $san_obj->sanlog(-msg => "FILER- $filer : Filer is loaded with correct Kernel version : $ONTAP_VERSION :" . scalar(localtime())); # } else { # $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); # $san_obj->sanlog(-msg => "FILER- $filer : Filer booted with Kernel version : $ONTAP_VERSION :" . scalar(localtime())); # $san_obj->sanlog(-msg => "FILER- $filer : May be name of the kernel file and the kernel version are different :" . scalar(localtime())); # $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); # logresult('FAIL',"Boot Filer with Kernel version : $ONTAP_VERSION"); # } } else { $san_obj->sanlog(-msg => "FILER- $filer : Not able to boot the Filer in MAINT mode with Kernel version : $ONTAP_VERSION :" . scalar(localtime())); logresult('FAIL',"Not able to boot the Filer with Kernel version : $ONTAP_VERSION "); } } elsif ($filer_state =~ /^(MAINT|UP)/) { logcomment("Filer is in already $filer_state mode "); } else { logresult('FATAL',"Not supported filer prompt"); } $san_obj->sanlog(-msg => "FILER- $filer : $TC_name : completed : " . scalar(localtime())); ######################################### # Test stops here ######################################### sub check_version($$) { my ($conn, $ontap_ver) = @_; $ontap_ver = trim($ontap_ver); if ($ontap_ver =~ /(.*)\.(.*)/) { $ontap_ver = $1; } my $version = "Not found"; my $timeout = 60; my ($match, undef, $text); sleep(2); say($conn, "", -timeout, 30, -ok); eval { ($match, undef, $text, undef) = say($conn, "version", -eval_error, '-timeout', $timeout); }; if ($text and $text =~ /(?:NetApp|Data ONTAP) Release (\d+\.\d+\S*)\s*:/) { $version = $1; } elsif ($text and $text =~ /(?:NetApp|Data ONTAP) Release (\w+\S+)\s*:/) { $version = $1; } elsif ($text and $text =~ /(?:NetApp|Data ONTAP) Release (.*)/) { $version = $1; } else { } logcomment("FILER- $filer : Version installed on the filer : $version"); if (($version =~ /.*$ontap_ver/) || ($ontap_ver =~ /.*$version/)){ return 1; } else { $san_obj->sanlog(-msg => "FILER- $filer : filer is loaded with wrong kernel version : $version , expected: $ontap_ver " . scalar(localtime())); return 0; } } #Create Mini disk ############################################# # Creating mini disks on the filers - BEGIN # ############################################# push( @filers, $filer_conn ); if ($BOOT_TYPE ne "N") { if ($MINI_CREATE =~ /y/) { $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => "Fast test mode ( -f=1 ) has been selected while invoking ndate (or) the selected test by the user requires minidisks creation, Hence proceeding to check mini disks"); $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); my ($max_size, $filer_state, $filer_stateB) = (); foreach $Filer_con (@filers) { $FILER_C = $FILER; $filer_state = boot_state($Filer_con); } if (($filer_state =~ /^(MAINT)/) || ($filer_stateB =~ /^(MAINT)/)) { logcomment ("$FILER : The filer is in Maintainence Mode. Proceeding with creation of mini disks"); } else { logcomment ("$FILER : The filer is not in Maintainence Mode. Proceeding with booting the filer in MAINT Mode and creation of mini disks"); $bootmode = 5; bootitgood($filer_conn, $bootup, $bootmode, $numberofvols, $spares, $numraidgroups, $filer, $filerip, $gateway, $netmask,$FILER_TYPE); #Disabling debug messages logcomment("$FILER : Dissable all storage debug messages"); disable_dbg_msgs( host => $host, filermode => "maint" ); } foreach $Filer_con (@filers) { $FILER_C = $FILER; $Host = $host; logcomment("Checking for mini disk"); $san_obj->sanlog(-msg => "Checking for mini disk"); say( $Filer_con, "priv set -q test", '-timeout', 30); my ( $val1, $val2, $val3, $val4 ) = say( $Filer_con, "mini_disk list", "-prompt", '\*>', -timeout, 1800 ); if ( ( $val1 !~ /(No minidisks are present)/ ) && ( $val2 !~ /(No minidisks are present)/ ) && ( $val3 !~ /(No minidisks are present)/ ) && ( $val4 !~ /(No minidisks are present)/ ) ) { 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"); } } if ($mini_present == 0 ){ logcomment("Creating mini disk on the filer : $FILER_C"); $san_obj->sanlog(-msg => "Creating mini disk on $FILER_C"); createMini( $Filer_con, $MINI_CREATE_SIZE, "n", $Host); } if (($mini_present == 0 ) || ($boot_after_mini_present == 1)){ boot_after_mini(); } } } } ########################################### # Creating mini disks on the filers - END # ########################################### #Boot in 4d mode sub boot_after_mini() { my $bootmode_4; if ($FILER_TYPE eq "IC") { if ( "$SSD" eq "no" ) { $bootmode_4 = "4"; } else { $bootmode_4 = "4a"; } } else { $bootmode_4 = "4d"; } $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); $san_obj->sanlog(-msg => " Booting filer in $bootmode_4 mode after creating mini disk "); $san_obj->sanlog(-msg => "------------------------------------------------------------------------------------------"); bootitgood($filer_conn, $bootup, $bootmode_4, $numberofvols, $spares, $numraidgroups, $filer, $filerip, $gateway, $netmask,$FILER_TYPE, $def_password); } sub trim($) { my $string = shift; $string =~ s/^\s+|\s+$//gm; s/^\"(.*)\"$/$1/ || s/^\'(.*)\'$/$1/; return $string; } sub pnate_versions($) { my ($staf_os) = @_; my ($stf_ver, $dirs, $inst); my @staf; ##get the staf version #opendir(READDIR, "$Home/NDATE/pSTAF/$staf_os");# Req for old pnate installtion opendir(READDIR, "$Home/NDATE/pSTAF"); @staf = readdir(READDIR); closedir(READDIR); foreach $dirs (@staf) { #if ($dirs =~ /staf\-/){ #Req for old pnate install if ($dirs =~ /startSTAF/){ $dirs = trim($dirs); #$path = "$Home/NDATE/pSTAF/$staf_os/" . $dirs; # Req for old pnate install $path = "$Home/NDATE/pSTAF"; logcomment("Presently I am in directry '$path'"); open(INST, "$path/install.properties"); while ($inst = ) { if ($inst =~ /version=(\S+)/i) { $stf_ver = $1; logcomment("Installed STAF version '$stf_ver'"); close(INST); last; } } close(INST); last; } } # Get the pNATE build version open(READ, "$Home/README") || logcomment("Failed to read the README file"); while ($inst = ) { #if ($inst =~ /pnate\_(\w+)\.zip(?:.*)PNATE/) { if ($inst =~ /pnate\_(\w+)\.zip(?:.*)PNATE/) { $pbuild = $1; last; } } close(READ); #HARD CODED need to be modified $pbuild = "12-21-2012"; return ($stf_ver, $pbuild); } ## sub pnate_versions($)