# # Copyright (c) 2012-2014 NetApp, Inc., All Rights Reserved. # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary ilt_test - Test Script examples for NACLU Trainings ## ## @description Objective: ## This test script tests the following test items, ## based on the specification documents listed for each: ## ## ID Test Cases ## ===== =================================== ## test1 Test for disk add operation using stask object ## test2 Test for snapmirror create operation ## test3 Test for wafliron operations ## ## Steps for init ## 1- Get access to global log object ## 2- Get access to global parameters and read VSERVER name ## 3- Find node ## 4- Log parameters read ## ## Steps for setup ## 1- Create an aggregate, let STask name it and register it with ## global cleanup mgr ## 2- Log the name of the aggregate ## ## Steps for test1- ## 1- Add 1 disk to that aggregate ## 2- Get the number of disks aggregate has and confirm ## ## Steps for test2- ## 1- Create a RW volume and a DP volume using NATE Process ## 2- Create DP type Snapmirror using above volumes ## 3- Delete snapmirror relationship using purge ## 4- Purge the volumes ## ## Steps for test3- ## 1- Run wafliron on the aggregate ## 2- Wait for completion of wafliron ## ## Steps for test4- ## 1- Create an aggregate with cleanup enabled option ## 2- Purge aggregate using cleanup manager ## ## Because this test script is executed using the TCD.pm ## package, we will always execute methods in the following ## order: init(), setup(), , cleanup(), ## uninit() ## ## @synopsis ## ## For CLI : ## ntest -noconsole lib/NACL/UnitTest/STask/ilt_test.thpl \ ## FILER="user1-vsim1" ## ## For ZAPI : ## ntest -noconsole lib/NACL/UnitTest/STask/ilt_test.thpl \ ## FILER="user1-vsim1" FILER_APISET_SHOULD_INTERFACE=ZAPI ## ## @dependencies ## This assumes a Base Cluster license to have been installed and other ## basic hardware resources like spare disks etc. The setup creates the ## required components like aggregates, vservers, volumes etc, based on ## the input passed to the parameters rather than searching for them in ## the environment. # # Test Control Parameters # ## @param TESTCASES ## Optional: List of test cases to execute. This can be "all", a ## comma separated list of test cases, or the index/id of test cases. ## The user can include switches and multipliers as well. See the ## documentation for the TCD lib for a full description of this ## parameter. By default all test cases will be executed one time. ## ## @param LISTTESTCASES ## Optional: If this is set to yes, the script will not execute the ## test cases, but instead will print a list of the test cases ## and their descriptions that correspond to the other input ## parameters. Default is 0. # # Test Case Specific Parameters # ## @param FILER ## Required: Name of the filer. ## ## @param VSERVER ## Optional: Name of the vserver. ## ## @status public ## ## @author dl-nacl-dev@netapp.com use strict; use warnings; use TCD; use NACL::STask::Aggregate; use NACL::STask::Volume; use NACL::C::Node; use NACL::Cleanup; use NACL::MTask::Wafliron; use NATE::Log qw(log_global); use NATE::ParamSet; # Global Variables. our $Test; our $Node; our $Test_Aggr; our $Base_Diskcount; our $Aggr_Name; our $VSERVER_NAME; our $Aggr_Obj; our $Log; our $Mode; # Testcase available for execution my @Testcases = ( test1 => "Test for disk add operation using stask object", test2 => "Test for snapmirror create operation", test3 => "Test for wafliron operations", ); &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 ); return $TCD::FAIL; } # Performs method callbacks $Test->run_test(); if ( $Test->error ) { $Test->log( $Test->errmsg ); return $TCD::FAIL; } exit(0); } ## end sub main ########## INIT ################################################### # init automatically called before executing tests sub init() { $Test->description( 'Retrieve variables from the test harness and ' . "instantiate objects \n needed for test execution" ); $Node = NACL::C::Node->find(); # Create a Log object. # log_global() is a shortcut for doing # NATE::Log->new($::LOGSPEC, global => 1); $Log = log_global(); # Create a ParamSet object and retrieve name of VSERVER # Default it to vs0 if it is not passed in. # Note you can use Test Driver object as $Test->get_param # which is a wrapper around NATE::ParamSet my $p = NATE::ParamSet->new( global => 1 ); $VSERVER_NAME = $p->get('VSERVER', default => 'vs0'); # Get the mode and log it and name of the Vserver $Mode = $Node->mode(); #Combine both the calls into one for performance reasons $Log->comment('Mode is: ' . $Mode . "\nVserver name is: " . $VSERVER_NAME ); # For these tests we want to use the minimum amount of disks for # creation of the aggregate using raidtype of raid4 $Base_Diskcount = NACL::STask::Aggregate->get_min_diskcount( command_interface => $Node, raidtype => 'raid4', ); return $TCD::PASS; } ## end sub init ########## SETUP ################################################### # setup automatically called before executing tests sub setup() { $Test->description('Setting up the environment required'); $Aggr_Obj = NACL::STask::Aggregate->create( command_interface => $Node, raidtype => 'raid4', diskcount => $Base_Diskcount, nacltask_if_exists => 'purge', nacltask_to_cleanup => 1, nacltask_add_to_aggr_list_of_vserver => $VSERVER_NAME, ); $Aggr_Name = $Aggr_Obj->get_one_state_attribute('aggregate'); $Log->comment("Aggregate name is $Aggr_Name"); return $TCD::PASS; } ## end sub setup ########## CLEANUP################################################# # cleanup automatically called after each test sub cleanup { $Test->description('CLEANUP'); $Test->step('Delete the aggregate using cleanup object'); my $cleanup_obj = NACL::Cleanup->new(); $cleanup_obj->run(); return $TCD::PASS; } ## end sub cleanup ######## UNINIT ################################################### # uninit automatically called after executing tests sub uninit { return $TCD::PASS; } ########## TESTS ################################################### sub test1 { $Test->description("Test for disk add operation using stask object"); my $result = $TCD::PASS; $Test->step("Get the disk list from aggregate"); my $disk_count = $Aggr_Obj->get_one_state_attribute('diskcount'); $Log->comment("Disk count is - $disk_count"); $Test->step('Add 1 disk to aggregate'); $Aggr_Obj->add_disks( diskcount => 1 ); $Test->step('Get the number of disks aggregate has and confirm'); $disk_count = $Aggr_Obj->get_one_state_attribute('diskcount'); $Log->comment("Current disk count is - $disk_count"); if ( $disk_count != ($Base_Diskcount + 1) ) { $result = $TCD::FAIL; } return $result; } ## end sub test1 sub test2 { $Test->description('Test for snapmirror create operation'); $Test->step('Create a RW volume and a DP volume'); my ($child_proc_rw, $child_proc_dp, $src_obj, $dst_obj); my $vol_name; # Create a NATE process to create a source volume $child_proc_rw = NATE::Process->new( codespec => 'NACL/Examples/create_volume.thpl', runid => 'createvol_rw', params => { AGGR => $Aggr_Name, NODES => $Node->node(), VSERVER => $VSERVER_NAME, }, onexit => \&NATE::Process::on_exit_propagate_worst_result, ); $child_proc_rw->start(); # Send a message to the child to tell it what type of # volume to create. $child_proc_rw->message_put( type => 'create_vol', message => 'RW' ); # Create a NATE process to create a destination volume $child_proc_dp = NATE::Process->new( codespec => 'NACL/Examples/create_volume.thpl', runid => 'createvol_dp', params => { AGGR => $Aggr_Name, NODES => $Node->node(), VSERVER => $VSERVER_NAME, }, onexit => \&NATE::Process::on_exit_propagate_worst_result, ); $child_proc_dp->start(); # Send a message to the child to tell it what type of # volume to create. $child_proc_dp->message_put(type => 'create_vol', message => 'DP'); # Get the volume name from child creating source volume $vol_name = $child_proc_rw->message_get(type => 'create_done'); # Instantiate a source volume object $src_obj = NACL::STask::Volume->new( command_interface => $Node, vserver => $VSERVER_NAME, volume => $vol_name ); # Get the volume name from child creating destination volume $vol_name = $child_proc_dp->message_get(type => 'create_done'); # Instantiate a destination volume object $dst_obj = NACL::STask::Volume->new( command_interface => $Node, vserver => $VSERVER_NAME, volume => $vol_name ); $Test->step("Create DP type Snapmirror using above volumes"); my $sm_obj = NACL::STask::Snapmirror->create( command_interface => $Node, 'source-path' => $src_obj, 'destination-path' => $dst_obj, type => 'DP', do_initialize => 1, ); $Test->step('Delete snapmirror relationship using purge'); $sm_obj->purge( nacltask_release => 1, nacltask_verify => 1, ); $Test->step('Purge the RW and DP volumes'); $src_obj->purge(); $dst_obj->purge(); return $TCD::PASS; } ## end sub test2 sub test3 { $Test->description('Test for wafliron operations'); $Test->step('Run wafliron on the aggregate'); my $wafliron_object = NACL::MTask::Wafliron->new( command_interface => $Node, aggregate => $Aggr_Name ); $wafliron_object->start(); $Test->step('Wait for completion of wafliron'); $wafliron_object->wait_for_completion(); return $TCD::PASS; } ## end sub test3