Changeset 589

Show
Ignore:
Timestamp:
06/20/07 15:50:00 (1 year ago)
Author:
kindlund
Message:

Updated VM unit testing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/lib/HoneyClient/Manager/VM/Clone.pm

    r585 r589  
    202202use HoneyClient::Util::Config qw(getVar); 
    203203 
     204# Make sure HoneyClient::Util::SOAP loads. 
     205BEGIN { use_ok('HoneyClient::Util::SOAP', qw(getClientHandle)) or diag("Can't load HoneyClient::Util::SOAP package.  Check to make sure the package library is correctly listed within the path."); } 
     206require_ok('HoneyClient::Util::SOAP'); 
     207can_ok('HoneyClient::Util::SOAP', 'getClientHandle'); 
     208use HoneyClient::Util::SOAP qw(getClientHandle); 
     209 
     210# Make sure HoneyClient::Manager::VM loads. 
     211BEGIN { use_ok('HoneyClient::Manager::VM') or diag("Can't load HoneyClient::Manager:VM package.  Check to make sure the package library is correctly listed within the path."); } 
     212require_ok('HoneyClient::Manager::VM'); 
     213use HoneyClient::Manager::VM; 
     214 
     215# Make sure VMware::VmPerl loads. 
     216BEGIN { use_ok('VMware::VmPerl', qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED)) or diag("Can't load VMware::VmPerl package.  Check to make sure the package library is correctly listed within the path."); } 
     217require_ok('VMware::VmPerl'); 
     218use VMware::VmPerl qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED); 
     219 
    204220# XXX: FIX THIS 
    205221# Make sure the module loads properly, with the exportable 
     
    229245use Storable qw(dclone); 
    230246 
     247# Make sure threads loads. 
     248BEGIN { use_ok('threads') or diag("Can't load threads package.  Check to make sure the package library is correctly listed within the path."); } 
     249require_ok('threads'); 
     250use threads; 
     251 
     252# Make sure threads::shared loads. 
     253BEGIN { use_ok('threads::shared') or diag("Can't load threads::shared package.  Check to make sure the package library is correctly listed within the path."); } 
     254require_ok('threads::shared'); 
     255use threads::shared; 
     256 
     257# Make sure File::Basename loads. 
     258BEGIN { use_ok('File::Basename', qw(dirname basename)) or diag("Can't load File::Basename package.  Check to make sure the package library is correctly listed within the path."); } 
     259require_ok('File::Basename'); 
     260can_ok('File::Basename', 'dirname'); 
     261can_ok('File::Basename', 'basename'); 
     262use File::Basename qw(dirname basename); 
     263 
    231264=end testing 
    232265 
     
    236269 
    237270# Include Threading Library 
    238 # TODO: Include unit tests. 
    239271use threads; 
    240272use threads::shared; 
     
    244276 
    245277# Include SOAP Library 
    246 # TODO: Include unit tests. 
    247278use HoneyClient::Util::SOAP qw(getClientHandle); 
    248279 
    249 # Include VM Library 
    250 # TODO: Include unit tests. 
     280# Include VM Libraries 
     281use VMware::VmPerl qw(VM_EXECUTION_STATE_ON 
     282                      VM_EXECUTION_STATE_OFF 
     283                      VM_EXECUTION_STATE_STUCK 
     284                      VM_EXECUTION_STATE_SUSPENDED); 
    251285use HoneyClient::Manager::VM; 
    252286 
     
    282316  $object->{key} = $value;    # Sets key's value. 
    283317 
    284 =head2 bypass_clone 
    285  
    286 =over 4 
    287  
    288 When set to 1, the object will forgo any type of initial cloning 
    289 operation, upon initialization.  Otherwise, cloning will occur 
    290 as normal, upon initialization. 
    291  
    292 =back 
    293  
    294318=head2 master_vm_config 
    295319 
     
    304328 
    305329my %PARAMS = ( 
    306     # When set to 1, the object will forgo any type of initial cloning 
    307     # operation, upon initialization.  Otherwise, cloning will occur 
    308     # as normal, upon initialization. 
    309     bypass_clone => 0, 
    310  
    311330    # The full absolute path to the master VM's configuration file, whose 
    312331    # contents will be the basis for each subsequently cloned VM. 
     
    420439=begin testing 
    421440 
    422 # Create a generic clone, with test state data. 
    423 my $clone = HoneyClient::Manager::VM::Clone->new(test => 1, bypass_clone => 1); 
    424 is($clone->{test}, 1, "new(test => 1, bypass_clone => 1)") or diag("The new() call failed."); 
    425 isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "new(test => 1, bypass_clone => 1)") or diag("The new() call failed."); 
    426  
    427 # TODO: Need more comprehensive test, where the clone actually gets created. 
     441# Shared test variables. 
     442my ($stub, $som, $URL); 
     443my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config", 
     444                                      namespace => "HoneyClient::Manager::VM::Test"); 
     445 
     446# Catch all errors, in order to make sure child processes are 
     447# properly killed. 
     448eval { 
     449 
     450    $URL = HoneyClient::Manager::VM->init(); 
     451 
     452    # Connect to daemon as a client. 
     453    $stub = getClientHandle(namespace => "HoneyClient::Manager::VM"); 
     454 
     455    # In order to test setMasterVM(), we're going to fully clone 
     456    # the testVM, then set the newly created clone as a master VM. 
     457 
     458    # Get the test VM's parent directory, 
     459    # in order to create a temporary master VM. 
     460    my $testVMDir = dirname($testVM); 
     461    my $masterVMDir = dirname($testVMDir) . "/test_vm_master"; 
     462    my $masterVM = $masterVMDir . "/" . basename($testVM); 
     463 
     464    # Create the master VM. 
     465    $som = $stub->fullCloneVM(src_config => $testVM, dest_dir => $masterVMDir); 
     466 
     467    # Wait a small amount of time for the asynchronous clone 
     468    # to complete. 
     469    sleep (60); 
     470 
     471    # The master VM should be on. 
     472    $som = $stub->getStateVM(config => $masterVM); 
     473 
     474    # Since the master VM doesn't have an OS installed on it, 
     475    # the VM may be considered stuck.  Go ahead and answer 
     476    # this question, if need be. 
     477    if ($som->result == VM_EXECUTION_STATE_STUCK) { 
     478        $som = $stub->answerVM(config => $masterVM); 
     479    } 
     480 
     481    HoneyClient::Manager::VM->destroy(); 
     482    sleep (1); 
     483 
     484    # Create a generic clone, with test state data. 
     485    my $clone = HoneyClient::Manager::VM::Clone->new(test => 1, master_vm_config => $masterVM); 
     486    is($clone->{test}, 1, "new(test => 1, master_vm_config => '$masterVM')") or diag("The new() call failed."); 
     487    isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "new(test => 1, master_vm_config => '$masterVM')") or diag("The new() call failed."); 
     488 
     489    # Destroy the master VM. 
     490    $som = $stub->destroyVM(config => $masterVM); 
     491}; 
     492 
     493# Kill the child daemon, if it still exists. 
     494HoneyClient::Manager::VM->destroy(); 
     495sleep (1); 
     496 
     497# Report any failure found. 
     498if ($@) { 
     499    fail($@); 
     500
    428501 
    429502=end testing 
     
    475548    $self->{'_vm_handle'} = getClientHandle(namespace => "HoneyClient::Manager::VM"); 
    476549 
    477     # Perform baselining, if not bypassed. 
    478     # TODO: Finish this. 
    479     if (!$self->{'bypass_clone'}) { 
    480  
    481         $LOG->info("Cloning Master VM."); 
    482         #$self->_baseline(); 
     550    # Set the master VM. 
     551    my $som = $self->{'_vm_handle'}->setMasterVM(config => $self->{'master_vm_config'}); 
     552    if (!$som->result()) { 
     553        $LOG->fatal("Unable to set VM (" . $self->{'master_vm_config'} . ") as a master VM."); 
     554        Carp::croak "Unable to set VM (" . $self->{'master_vm_config'} . ") as a master VM."; 
    483555    } 
    484556 
  • honeyclient/trunk/t/honeyclient_manager_vm.t

    r328 r589  
    11591159    # this question, if need be. 
    11601160    if ($som->result == VM_EXECUTION_STATE_STUCK) { 
    1161         $som = $stub->answerVM(config => $cloneVM); 
     1161        $som = $stub->answerVM(config => $masterVM); 
    11621162    } 
    11631163 
  • honeyclient/trunk/t/honeyclient_manager_vm_clone.t

    r558 r589  
    4343use HoneyClient::Util::Config qw(getVar); 
    4444 
     45# Make sure HoneyClient::Util::SOAP loads. 
     46BEGIN { use_ok('HoneyClient::Util::SOAP', qw(getClientHandle)) or diag("Can't load HoneyClient::Util::SOAP package.  Check to make sure the package library is correctly listed within the path."); } 
     47require_ok('HoneyClient::Util::SOAP'); 
     48can_ok('HoneyClient::Util::SOAP', 'getClientHandle'); 
     49use HoneyClient::Util::SOAP qw(getClientHandle); 
     50 
     51# Make sure HoneyClient::Manager::VM loads. 
     52BEGIN { use_ok('HoneyClient::Manager::VM') or diag("Can't load HoneyClient::Manager:VM package.  Check to make sure the package library is correctly listed within the path."); } 
     53require_ok('HoneyClient::Manager::VM'); 
     54use HoneyClient::Manager::VM; 
     55 
     56# Make sure VMware::VmPerl loads. 
     57BEGIN { use_ok('VMware::VmPerl', qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED)) or diag("Can't load VMware::VmPerl package.  Check to make sure the package library is correctly listed within the path."); } 
     58require_ok('VMware::VmPerl'); 
     59use VMware::VmPerl qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED); 
     60 
    4561# XXX: FIX THIS 
    4662# Make sure the module loads properly, with the exportable 
    4763# functions shared. 
    48 BEGIN { use_ok('HoneyClient::Agent::Driver') or diag("Can't load HoneyClient::Agent::Driver package.  Check to make sure the package library is correctly listed within the path."); } 
    49 require_ok('HoneyClient::Agent::Driver'); 
    50 can_ok('HoneyClient::Agent::Driver', 'new'); 
    51 can_ok('HoneyClient::Agent::Driver', 'drive'); 
    52 can_ok('HoneyClient::Agent::Driver', 'isFinished'); 
    53 can_ok('HoneyClient::Agent::Driver', 'next'); 
    54 can_ok('HoneyClient::Agent::Driver', 'status'); 
    55 use HoneyClient::Agent::Driver
     64BEGIN { use_ok('HoneyClient::Manager::VM::Clone') or diag("Can't load HoneyClient::Manager::VM::Clone package.  Check to make sure the package library is correctly listed within the path."); } 
     65require_ok('HoneyClient::Manager::VM::Clone'); 
     66can_ok('HoneyClient::Manager::VM::Clone', 'new'); 
     67can_ok('HoneyClient::Manager::VM::Clone', 'drive'); 
     68can_ok('HoneyClient::Manager::VM::Clone', 'isFinished'); 
     69can_ok('HoneyClient::Manager::VM::Clone', 'next'); 
     70can_ok('HoneyClient::Manager::VM::Clone', 'status'); 
     71use HoneyClient::Manager::VM::Clone
    5672 
    5773# Suppress all logging messages, since we need clean output for unit testing. 
     
    6985can_ok('Storable', 'dclone'); 
    7086use Storable qw(dclone); 
     87 
     88# Make sure threads loads. 
     89BEGIN { use_ok('threads') or diag("Can't load threads package.  Check to make sure the package library is correctly listed within the path."); } 
     90require_ok('threads'); 
     91use threads; 
     92 
     93# Make sure threads::shared loads. 
     94BEGIN { use_ok('threads::shared') or diag("Can't load threads::shared package.  Check to make sure the package library is correctly listed within the path."); } 
     95require_ok('threads::shared'); 
     96use threads::shared; 
     97 
     98# Make sure File::Basename loads. 
     99BEGIN { use_ok('File::Basename', qw(dirname basename)) or diag("Can't load File::Basename package.  Check to make sure the package library is correctly listed within the path."); } 
     100require_ok('File::Basename'); 
     101can_ok('File::Basename', 'dirname'); 
     102can_ok('File::Basename', 'basename'); 
     103use File::Basename qw(dirname basename); 
    71104} 
    72105 
     
    75108# =begin testing 
    76109{ 
    77 # Create a generic clone, with test state data
    78 my $clone = HoneyClient::Manager::VM::Clone->new(test => 1, bypass_clone => 1); 
    79 is($clone->{test}, 1, "new(test => 1, bypass_clone => 1)") or diag("The new() call failed."); 
    80 isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "new(test => 1, bypass_clone => 1)") or diag("The new() call failed."); 
     110# Shared test variables
     111my ($stub, $som, $URL); 
     112my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config", 
     113                                      namespace => "HoneyClient::Manager::VM::Test"); 
    81114 
    82 # TODO: Need more comprehensive test, where the clone actually gets created. 
     115# Catch all errors, in order to make sure child processes are 
     116# properly killed. 
     117eval { 
     118 
     119    $URL = HoneyClient::Manager::VM->init(); 
     120 
     121    # Connect to daemon as a client. 
     122    $stub = getClientHandle(namespace => "HoneyClient::Manager::VM"); 
     123 
     124    # In order to test setMasterVM(), we're going to fully clone 
     125    # the testVM, then set the newly created clone as a master VM. 
     126 
     127    # Get the test VM's parent directory, 
     128    # in order to create a temporary master VM. 
     129    my $testVMDir = dirname($testVM); 
     130    my $masterVMDir = dirname($testVMDir) . "/test_vm_master"; 
     131    my $masterVM = $masterVMDir . "/" . basename($testVM); 
     132 
     133    # Create the master VM. 
     134    $som = $stub->fullCloneVM(src_config => $testVM, dest_dir => $masterVMDir); 
     135 
     136    # Wait a small amount of time for the asynchronous clone 
     137    # to complete. 
     138    sleep (60); 
     139 
     140    # The master VM should be on. 
     141    $som = $stub->getStateVM(config => $masterVM); 
     142 
     143    # Since the master VM doesn't have an OS installed on it, 
     144    # the VM may be considered stuck.  Go ahead and answer 
     145    # this question, if need be. 
     146    if ($som->result == VM_EXECUTION_STATE_STUCK) { 
     147        $som = $stub->answerVM(config => $masterVM); 
     148    } 
     149 
     150    HoneyClient::Manager::VM->destroy(); 
     151    sleep (1); 
     152 
     153    # Create a generic clone, with test state data. 
     154    my $clone = HoneyClient::Manager::VM::Clone->new(test => 1, master_vm_config => $masterVM); 
     155    is($clone->{test}, 1, "new(test => 1, master_vm_config => '$masterVM')") or diag("The new() call failed."); 
     156    isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "new(test => 1, master_vm_config => '$masterVM')") or diag("The new() call failed."); 
     157 
     158    # Destroy the master VM. 
     159    $som = $stub->destroyVM(config => $masterVM); 
     160}; 
     161 
     162# Kill the child daemon, if it still exists. 
     163HoneyClient::Manager::VM->destroy(); 
     164sleep (1); 
     165 
     166# Report any failure found. 
     167if ($@) { 
     168    fail($@); 
    83169} 
    84  
    85  
    86  
    87 # =begin testing 
    88 { 
    89 # Create a generic driver, with test state data. 
    90 #my $driver = HoneyClient::Agent::Driver->new(test => 1); 
    91 #dies_ok {$driver->drive()} 'drive()' or diag("The drive() call failed.  Expected drive() to throw an exception."); 
    92 } 
    93  
    94  
    95  
    96 # =begin testing 
    97 { 
    98 # Create a generic driver, with test state data. 
    99 #my $driver = HoneyClient::Agent::Driver->new(test => 1); 
    100 #dies_ok {$driver->isFinished()} 'isFinished()' or diag("The isFinished() call failed.  Expected isFinished() to throw an exception."); 
    101 } 
    102  
    103  
    104  
    105 # =begin testing 
    106 { 
    107 # Create a generic driver, with test state data. 
    108 #my $driver = HoneyClient::Agent::Driver->new(test => 1); 
    109 #dies_ok {$driver->next()} 'next()' or diag("The next() call failed.  Expected next() to throw an exception."); 
    110 } 
    111  
    112  
    113  
    114 # =begin testing 
    115 { 
    116 # Create a generic driver, with test state data. 
    117 #my $driver = HoneyClient::Agent::Driver->new(test => 1); 
    118 #dies_ok {$driver->status()} 'status()' or diag("The status() call failed.  Expected status() to throw an exception."); 
    119170} 
    120171