Changeset 589
- Timestamp:
- 06/20/07 15:50:00 (1 year ago)
- Files:
-
- honeyclient/trunk/lib/HoneyClient/Manager/VM/Clone.pm (modified) (8 diffs)
- honeyclient/trunk/t/honeyclient_manager_vm.t (modified) (1 diff)
- honeyclient/trunk/t/honeyclient_manager_vm_clone.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/trunk/lib/HoneyClient/Manager/VM/Clone.pm
r585 r589 202 202 use HoneyClient::Util::Config qw(getVar); 203 203 204 # Make sure HoneyClient::Util::SOAP loads. 205 BEGIN { 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."); } 206 require_ok('HoneyClient::Util::SOAP'); 207 can_ok('HoneyClient::Util::SOAP', 'getClientHandle'); 208 use HoneyClient::Util::SOAP qw(getClientHandle); 209 210 # Make sure HoneyClient::Manager::VM loads. 211 BEGIN { 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."); } 212 require_ok('HoneyClient::Manager::VM'); 213 use HoneyClient::Manager::VM; 214 215 # Make sure VMware::VmPerl loads. 216 BEGIN { 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."); } 217 require_ok('VMware::VmPerl'); 218 use VMware::VmPerl qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED); 219 204 220 # XXX: FIX THIS 205 221 # Make sure the module loads properly, with the exportable … … 229 245 use Storable qw(dclone); 230 246 247 # Make sure threads loads. 248 BEGIN { use_ok('threads') or diag("Can't load threads package. Check to make sure the package library is correctly listed within the path."); } 249 require_ok('threads'); 250 use threads; 251 252 # Make sure threads::shared loads. 253 BEGIN { 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."); } 254 require_ok('threads::shared'); 255 use threads::shared; 256 257 # Make sure File::Basename loads. 258 BEGIN { 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."); } 259 require_ok('File::Basename'); 260 can_ok('File::Basename', 'dirname'); 261 can_ok('File::Basename', 'basename'); 262 use File::Basename qw(dirname basename); 263 231 264 =end testing 232 265 … … 236 269 237 270 # Include Threading Library 238 # TODO: Include unit tests.239 271 use threads; 240 272 use threads::shared; … … 244 276 245 277 # Include SOAP Library 246 # TODO: Include unit tests.247 278 use HoneyClient::Util::SOAP qw(getClientHandle); 248 279 249 # Include VM Library 250 # TODO: Include unit tests. 280 # Include VM Libraries 281 use VMware::VmPerl qw(VM_EXECUTION_STATE_ON 282 VM_EXECUTION_STATE_OFF 283 VM_EXECUTION_STATE_STUCK 284 VM_EXECUTION_STATE_SUSPENDED); 251 285 use HoneyClient::Manager::VM; 252 286 … … 282 316 $object->{key} = $value; # Sets key's value. 283 317 284 =head2 bypass_clone285 286 =over 4287 288 When set to 1, the object will forgo any type of initial cloning289 operation, upon initialization. Otherwise, cloning will occur290 as normal, upon initialization.291 292 =back293 294 318 =head2 master_vm_config 295 319 … … 304 328 305 329 my %PARAMS = ( 306 # When set to 1, the object will forgo any type of initial cloning307 # operation, upon initialization. Otherwise, cloning will occur308 # as normal, upon initialization.309 bypass_clone => 0,310 311 330 # The full absolute path to the master VM's configuration file, whose 312 331 # contents will be the basis for each subsequently cloned VM. … … 420 439 =begin testing 421 440 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. 442 my ($stub, $som, $URL); 443 my $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. 448 eval { 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. 494 HoneyClient::Manager::VM->destroy(); 495 sleep (1); 496 497 # Report any failure found. 498 if ($@) { 499 fail($@); 500 } 428 501 429 502 =end testing … … 475 548 $self->{'_vm_handle'} = getClientHandle(namespace => "HoneyClient::Manager::VM"); 476 549 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."; 483 555 } 484 556 honeyclient/trunk/t/honeyclient_manager_vm.t
r328 r589 1159 1159 # this question, if need be. 1160 1160 if ($som->result == VM_EXECUTION_STATE_STUCK) { 1161 $som = $stub->answerVM(config => $ cloneVM);1161 $som = $stub->answerVM(config => $masterVM); 1162 1162 } 1163 1163 honeyclient/trunk/t/honeyclient_manager_vm_clone.t
r558 r589 43 43 use HoneyClient::Util::Config qw(getVar); 44 44 45 # Make sure HoneyClient::Util::SOAP loads. 46 BEGIN { 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."); } 47 require_ok('HoneyClient::Util::SOAP'); 48 can_ok('HoneyClient::Util::SOAP', 'getClientHandle'); 49 use HoneyClient::Util::SOAP qw(getClientHandle); 50 51 # Make sure HoneyClient::Manager::VM loads. 52 BEGIN { 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."); } 53 require_ok('HoneyClient::Manager::VM'); 54 use HoneyClient::Manager::VM; 55 56 # Make sure VMware::VmPerl loads. 57 BEGIN { 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."); } 58 require_ok('VMware::VmPerl'); 59 use VMware::VmPerl qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED); 60 45 61 # XXX: FIX THIS 46 62 # Make sure the module loads properly, with the exportable 47 63 # functions shared. 48 BEGIN { use_ok('HoneyClient:: Agent::Driver') or diag("Can't load HoneyClient::Agent::Driverpackage. 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;64 BEGIN { 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."); } 65 require_ok('HoneyClient::Manager::VM::Clone'); 66 can_ok('HoneyClient::Manager::VM::Clone', 'new'); 67 can_ok('HoneyClient::Manager::VM::Clone', 'drive'); 68 can_ok('HoneyClient::Manager::VM::Clone', 'isFinished'); 69 can_ok('HoneyClient::Manager::VM::Clone', 'next'); 70 can_ok('HoneyClient::Manager::VM::Clone', 'status'); 71 use HoneyClient::Manager::VM::Clone; 56 72 57 73 # Suppress all logging messages, since we need clean output for unit testing. … … 69 85 can_ok('Storable', 'dclone'); 70 86 use Storable qw(dclone); 87 88 # Make sure threads loads. 89 BEGIN { use_ok('threads') or diag("Can't load threads package. Check to make sure the package library is correctly listed within the path."); } 90 require_ok('threads'); 91 use threads; 92 93 # Make sure threads::shared loads. 94 BEGIN { 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."); } 95 require_ok('threads::shared'); 96 use threads::shared; 97 98 # Make sure File::Basename loads. 99 BEGIN { 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."); } 100 require_ok('File::Basename'); 101 can_ok('File::Basename', 'dirname'); 102 can_ok('File::Basename', 'basename'); 103 use File::Basename qw(dirname basename); 71 104 } 72 105 … … 75 108 # =begin testing 76 109 { 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. 111 my ($stub, $som, $URL); 112 my $testVM = $ENV{PWD} . "/" . getVar(name => "test_vm_config", 113 namespace => "HoneyClient::Manager::VM::Test"); 81 114 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. 117 eval { 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. 163 HoneyClient::Manager::VM->destroy(); 164 sleep (1); 165 166 # Report any failure found. 167 if ($@) { 168 fail($@); 83 169 } 84 85 86 87 # =begin testing88 {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 testing97 {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 testing106 {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 testing115 {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.");119 170 } 120 171
