root/honeyclient/branches/exp/bhenderson-browser_automation/t/honeyclient_manager_vm.t

Revision 1649, 48.6 kB (checked in by kindlund, 6 months ago)

Fixing ticket #173. Had to add a new test_vm-livecd, since our unit tests for getIPaddrVM were failing otherwise.

Line 
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More 'no_plan';
5 $| = 1;
6
7
8
9 # =begin testing
10 {
11 # Make sure ExtUtils::MakeMaker loads.
12 BEGIN { use_ok('ExtUtils::MakeMaker', qw(prompt)) or diag("Can't load ExtUtils::MakeMaker package.  Check to make sure the package library is correctly listed within the path."); }
13 require_ok('ExtUtils::MakeMaker');
14 can_ok('ExtUtils::MakeMaker', 'prompt');
15 use ExtUtils::MakeMaker qw(prompt);
16
17 # Generate a notice, to clarify our assumptions.
18 diag("About to run basic unit tests.");
19 diag("Note: These tests *expect* VMware Server or VMware GSX to be installed and running on this system beforehand.");
20
21 my $question;
22 $question = prompt("# Do you want to run basic tests?", "yes");
23 if ($question !~ /^y.*/i) {
24     exit;
25 }
26
27 # Make sure Log::Log4perl loads
28 BEGIN { use_ok('Log::Log4perl', qw(:nowarn))
29         or diag("Can't load Log::Log4perl package. Check to make sure the package library is correctly listed within the path.");
30        
31         # Suppress all logging messages, since we need clean output for unit testing.
32         Log::Log4perl->init({
33             "log4perl.rootLogger"                               => "DEBUG, Buffer",
34             "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer",
35             "log4perl.appender.Buffer.min_level"                => "fatal",
36             "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout",
37             "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n",
38         });
39 }
40 require_ok('Log::Log4perl');
41 use Log::Log4perl qw(:easy);
42
43 # Make sure HoneyClient::Util::Config loads.
44 BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar))
45         or diag("Can't load HoneyClient::Util::Config package.  Check to make sure the package library is correctly listed within the path.");
46
47         # Suppress all logging messages, since we need clean output for unit testing.
48         Log::Log4perl->init({
49             "log4perl.rootLogger"                               => "DEBUG, Buffer",
50             "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer",
51             "log4perl.appender.Buffer.min_level"                => "fatal",
52             "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout",
53             "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n",
54         });
55 }
56 require_ok('HoneyClient::Util::Config');
57 can_ok('HoneyClient::Util::Config', 'getVar');
58 use HoneyClient::Util::Config qw(getVar);
59
60 # Suppress all logging messages, since we need clean output for unit testing.
61 Log::Log4perl->init({
62     "log4perl.rootLogger"                               => "DEBUG, Buffer",
63     "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer",
64     "log4perl.appender.Buffer.min_level"                => "fatal",
65     "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout",
66     "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n",
67 });
68
69 # Make sure the module loads properly, with the exportable
70 # functions shared.
71 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."); }
72 require_ok('HoneyClient::Manager::VM');
73 can_ok('HoneyClient::Manager::VM', 'init');
74 can_ok('HoneyClient::Manager::VM', 'destroy');
75 use HoneyClient::Manager::VM;
76
77 # Make sure HoneyClient::Util::SOAP loads.
78 BEGIN { use_ok('HoneyClient::Util::SOAP', qw(getServerHandle getClientHandle)) or diag("Can't load HoneyClient::Util::SOAP package.  Check to make sure the package library is correctly listed within the path."); }
79 require_ok('HoneyClient::Util::SOAP');
80 can_ok('HoneyClient::Util::SOAP', 'getServerHandle');
81 can_ok('HoneyClient::Util::SOAP', 'getClientHandle');
82 use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle);
83
84 # Make sure File::Basename loads.
85 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."); }
86 require_ok('File::Basename');
87 can_ok('File::Basename', 'dirname');
88 can_ok('File::Basename', 'basename');
89 use File::Basename qw(dirname basename);
90
91 # Make sure File::Copy::Recursive loads.
92 BEGIN { use_ok('File::Copy::Recursive', qw(dircopy pathrmdir)) or diag("Can't load File::Copy::Recursive package.  Check to make sure the package library is correctly listed within the path."); }
93 require_ok('File::Copy::Recursive');
94 can_ok('File::Copy::Recursive', 'dircopy');
95 can_ok('File::Copy::Recursive', 'pathrmdir');
96 use File::Copy::Recursive qw(dircopy pathrmdir);
97
98 # Make sure Data::Dumper loads.
99 BEGIN { use_ok('Data::Dumper') or diag("Can't load Data::Dumper package.  Check to make sure the package library is correctly listed within the path."); }
100 require_ok('Data::Dumper');
101 use Data::Dumper;
102
103 # Make sure File::stat loads.
104 BEGIN { use_ok('File::stat') or diag("Can't load File::stat package.  Check to make sure the package library is correctly listed within the path."); }
105 require_ok('File::stat');
106 use File::stat;
107
108 # Make sure Digest::MD5 loads.
109 BEGIN { use_ok('Digest::MD5', qw(md5_hex)) or diag("Can't load Digest::MD5 package.  Check to make sure the package library is correctly listed within the path."); }
110 require_ok('Digest::MD5');
111 can_ok('Digest::MD5', 'md5_hex');
112 use Digest::MD5 qw(md5_hex);
113
114 # Make sure DateTime::HiRes loads.
115 BEGIN { use_ok('DateTime::HiRes') or diag("Can't load DateTime::HiRes package.  Check to make sure the package library is correctly listed within the path."); }
116 require_ok('DateTime::HiRes');
117 use DateTime::HiRes;
118
119 # Make sure Text::DHCPLeases loads.
120 BEGIN { use_ok('Text::DHCPLeases') or diag("Can't load Text::DHCPLeases package.  Check to make sure the package library is correctly listed within the path."); }
121 require_ok('Text::DHCPLeases');
122 use Text::DHCPLeases;
123
124 # Make sure DateTime::Format::Natural loads.
125 BEGIN { use_ok('DateTime::Format::Natural') or diag("Can't load DateTime::Format::Natural package.  Check to make sure the package library is correctly listed within the path."); }
126 require_ok('DateTime::Format::Natural');
127 use DateTime::Format::Natural;
128
129 # Make sure Config::General loads.
130 BEGIN { use_ok('Config::General') or diag("Can't load Config::General package.  Check to make sure the package library is correctly listed within the path."); }
131 require_ok('Config::General');
132 use Config::General;
133
134 # Make sure VMware::VmPerl loads.
135 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."); }
136 require_ok('VMware::VmPerl');
137 use VMware::VmPerl qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED);
138
139 # Make sure VMware::VmPerl::Server loads.
140 BEGIN { use_ok('VMware::VmPerl::Server') or diag("Can't load VMware::VmPerl::Server package.  Check to make sure the package library is correctly listed within the path."); }
141 require_ok('VMware::VmPerl::Server');
142 use VMware::VmPerl::Server;
143
144 # Make sure VMware::VmPerl::ConnectParams loads.
145 BEGIN { use_ok('VMware::VmPerl::ConnectParams') or diag("Can't load VMware::VmPerl::ConnectParams package.  Check to make sure the package library is correctly listed within the path."); }
146 require_ok('VMware::VmPerl::ConnectParams');
147 use VMware::VmPerl::ConnectParams;
148
149 # Make sure VMware::VmPerl::VM loads.
150 BEGIN { use_ok('VMware::VmPerl::VM') or diag("Can't load VMware::VmPerl::VM package.  Check to make sure the package library is correctly listed within the path."); }
151 require_ok('VMware::VmPerl::VM');
152 use VMware::VmPerl::VM;
153
154 # Make sure VMware::VmPerl::VM loads.
155 BEGIN { use_ok('VMware::VmPerl::Question') or diag("Can't load VMware::VmPerl::Question package.  Check to make sure the package library is correctly listed within the path."); }
156 require_ok('VMware::VmPerl::Question');
157 use VMware::VmPerl::Question;
158
159 # Make sure threads loads.
160 BEGIN { use_ok('threads') or diag("Can't load threads package.  Check to make sure the package library is correctly listed within the path."); }
161 require_ok('threads');
162 use threads;
163
164 # Make sure threads::shared loads.
165 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."); }
166 require_ok('threads::shared');
167 use threads::shared;
168
169 # Make sure Thread::Queue loads.
170 BEGIN { use_ok('Thread::Queue') or diag("Can't load Thread::Queue package.  Check to make sure the package library is correctly listed within the path."); }
171 require_ok('Thread::Queue');
172 use Thread::Queue;
173
174 # Make sure Thread::Semaphore loads.
175 BEGIN { use_ok('Thread::Semaphore') or diag("Can't load Thread::Semaphore package.  Check to make sure the package library is correctly listed within the path."); }
176 require_ok('Thread::Semaphore');
177 use Thread::Semaphore;
178
179 diag("About to run extended tests.");
180 # Generate a notice, to inform the tester that these tests are not
181 # exactly quick.
182 diag("Note: These extended tests will take *significant* time to complete (10-30 minutes).");
183
184 $question = prompt("# Do you want to run extended tests?", "no");
185 if ($question !~ /^y.*/i) {
186     exit;
187 }
188 }
189
190
191
192 # =begin testing
193 {
194 # Shared test variables.
195 my $PORT = getVar(name      => "port",
196                   namespace => "HoneyClient::Manager::VM");
197 my ($stub, $som, $URL);
198 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
199                                       namespace => "HoneyClient::Manager::VM::Test");
200
201 # Test init() method.
202 $URL = HoneyClient::Manager::VM->init();
203 is($URL, "http://localhost:$PORT/HoneyClient/Manager/VM", "init()") or diag("Failed to start up the VM SOAP server.  Check to see if any other daemon is listening on TCP port $PORT.");
204 }
205
206
207
208 # =begin testing
209 {
210 # Shared test variables.
211 my $PORT = getVar(name      => "port",
212                   namespace => "HoneyClient::Manager::VM");
213 my ($stub, $som, $URL);
214 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
215                                       namespace => "HoneyClient::Manager::VM::Test");
216
217 # Test destroy() method.
218 is(HoneyClient::Manager::VM->destroy(), 1, "destroy()") or diag("Unable to terminate VM SOAP server.  Be sure to check for any stale or lingering processes.");
219 }
220
221
222
223 # =begin testing
224 {
225 # Shared test variables.
226 my $PORT = getVar(name      => "port",
227                   namespace => "HoneyClient::Manager::VM");
228 my ($stub, $som, $URL);
229 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
230                                       namespace => "HoneyClient::Manager::VM::Test");
231
232 # Catch all errors, in order to make sure child processes are
233 # properly killed.
234 eval {
235
236     $URL = HoneyClient::Manager::VM->init();
237    
238     # Connect to daemon as a client.
239     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
240
241     # Make sure the test VM is stopped.
242     $som = $stub->stopVM(config => $testVM);
243    
244     # Test isRegisteredVM() method.
245     $som = $stub->isRegisteredVM(config => $testVM);
246    
247     # The test VM should be registered.
248     ok($som->result, "isRegisteredVM(config => '$testVM')") or diag("The isRegisteredVM() call failed.  If ($testVM) is still registered, be sure to unregister it manually.");
249
250     # Make sure the test VM is unregistered.
251     $som = $stub->unregisterVM(config => $testVM);
252
253     # Test isRegisteredVM() method.
254     $som = $stub->isRegisteredVM(config => $testVM);
255
256     # The test VM should not be registered.
257     ok(!$som->result, "isRegisteredVM(config => '$testVM')") or diag("The isRegisteredVM() call failed.  If ($testVM) is still registered, be sure to unregister it manually.");
258 };
259
260 # Kill the child daemon, if it still exists.
261 HoneyClient::Manager::VM->destroy();
262
263 # Report any failure found.
264 if ($@) {
265     fail($@);
266 }
267 }
268
269
270
271 # =begin testing
272 {
273 # Shared test variables.
274 my $PORT = getVar(name      => "port",
275                   namespace => "HoneyClient::Manager::VM");
276 my ($stub, $som, $URL);
277 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
278                                       namespace => "HoneyClient::Manager::VM::Test");
279
280 # Catch all errors, in order to make sure child processes are
281 # properly killed.
282 eval {
283
284     $URL = HoneyClient::Manager::VM->init();
285    
286     # Connect to daemon as a client.
287     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
288
289     # Register the test VM.
290     $som = $stub->registerVM(config => $testVM);
291
292     # Test enumerate() method.
293     $som = $stub->enumerate();
294
295     # The test VM should be listed in the output.
296     my @list = $som->paramsall;
297     like(join(' ', @list), "/$testVM/", "enumerate()") or diag("The enumerate() call failed.  Attempted to register VM ($testVM), but the VM was not listed in the output of enumerate().");
298    
299     # Unregister the test VM.
300     $som = $stub->unregisterVM(config => $testVM);
301 };
302
303 # Kill the child daemon, if it still exists.
304 HoneyClient::Manager::VM->destroy();
305
306 # Report any failure found.
307 if ($@) {
308     fail($@);
309 }
310 }
311
312
313
314 # =begin testing
315 {
316 # Shared test variables.
317 my $PORT = getVar(name      => "port",
318                   namespace => "HoneyClient::Manager::VM");
319 my ($stub, $som, $URL);
320 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
321                                       namespace => "HoneyClient::Manager::VM::Test");
322
323 # Catch all errors, in order to make sure child processes are
324 # properly killed.
325 eval {
326
327     $URL = HoneyClient::Manager::VM->init();
328    
329     # Connect to daemon as a client.
330     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
331
332     # Register the test VM.
333     $som = $stub->registerVM(config => $testVM);
334
335     # Test getStateVM() method.
336     $som = $stub->getStateVM(config => $testVM);
337
338     # The test VM should be off.
339     is($som->result, VM_EXECUTION_STATE_OFF, "getStateVM(config => '$testVM')") or diag("The getStateVM() call failed.  Attempted to register VM ($testVM), but the VM state was not reported as OFF.");
340    
341     # Unregister the test VM.
342     $som = $stub->unregisterVM(config => $testVM);
343 };
344
345 # Kill the child daemon, if it still exists.
346 HoneyClient::Manager::VM->destroy();
347
348 # Report any failure found.
349 if ($@) {
350     fail($@);
351 }
352 }
353
354
355
356 # =begin testing
357 {
358 # Shared test variables.
359 my $PORT = getVar(name      => "port",
360                   namespace => "HoneyClient::Manager::VM");
361 my ($stub, $som, $URL);
362 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
363                                       namespace => "HoneyClient::Manager::VM::Test");
364
365 # Catch all errors, in order to make sure child processes are
366 # properly killed.
367 eval {
368
369     $URL = HoneyClient::Manager::VM->init();
370    
371     # Connect to daemon as a client.
372     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
373
374     # Register the test VM.
375     $som = $stub->registerVM(config => $testVM);
376
377     # Test startVM() method.
378     $som = $stub->startVM(config => $testVM);
379     ok($som->result, "startVM(config => '$testVM')");
380
381     # The test VM should be on.
382     $som = $stub->getStateVM(config => $testVM);
383
384     # Since the test VM doesn't have an OS installed on it,
385     # the VM may be considered stuck.  Go ahead and answer
386     # this question, if need be.
387     if ($som->result == VM_EXECUTION_STATE_STUCK) {
388         $som = $stub->answerVM(config => $testVM);
389         # Fetch the state again, to see if it's now ON.
390         $som = $stub->getStateVM(config => $testVM);
391     }
392     is($som->result, VM_EXECUTION_STATE_ON, "startVM(config => '$testVM')") or diag("The startVM() call failed.  Attempted to start VM ($testVM), but the VM state was not reported as ON.");
393    
394     # Stop and unregister the test VM.
395     $som = $stub->stopVM(config => $testVM);
396     $som = $stub->unregisterVM(config => $testVM);
397 };
398
399 # Kill the child daemon, if it still exists.
400 HoneyClient::Manager::VM->destroy();
401
402 # Report any failure found.
403 if ($@) {
404     fail($@);
405 }
406 }
407
408
409
410 # =begin testing
411 {
412 # Shared test variables.
413 my $PORT = getVar(name      => "port",
414                   namespace => "HoneyClient::Manager::VM");
415 my ($stub, $som, $URL);
416 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
417                                       namespace => "HoneyClient::Manager::VM::Test");
418
419 # Catch all errors, in order to make sure child processes are
420 # properly killed.
421 eval {
422
423     $URL = HoneyClient::Manager::VM->init();
424    
425     # Connect to daemon as a client.
426     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
427
428     # Register and start the test VM.
429     $som = $stub->registerVM(config => $testVM);
430     $som = $stub->startVM(config => $testVM);
431
432     # Test stopVM() method.
433     $som = $stub->stopVM(config => $testVM);
434     ok($som->result, "stopVM(config => '$testVM')");
435
436     # The test VM should be on.
437     $som = $stub->getStateVM(config => $testVM);
438     is($som->result, VM_EXECUTION_STATE_OFF, "stopVM(config => '$testVM')") or diag("The stopVM() call failed.  Attempted to stop VM ($testVM), but the VM state was not reported as OFF.");
439    
440     # Unregister the test VM.
441     $som = $stub->unregisterVM(config => $testVM);
442 };
443
444 # Kill the child daemon, if it still exists.
445 HoneyClient::Manager::VM->destroy();
446
447 # Report any failure found.
448 if ($@) {
449     fail($@);
450 }
451 }
452
453
454
455 # =begin testing
456 {
457 # Shared test variables.
458 my $PORT = getVar(name      => "port",
459                   namespace => "HoneyClient::Manager::VM");
460 my ($stub, $som, $URL);
461 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
462                                       namespace => "HoneyClient::Manager::VM::Test");
463
464 # Catch all errors, in order to make sure child processes are
465 # properly killed.
466 eval {
467
468     $URL = HoneyClient::Manager::VM->init();
469    
470     # Connect to daemon as a client.
471     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
472
473     # Register and start the test VM.
474     $som = $stub->registerVM(config => $testVM);
475     $som = $stub->startVM(config => $testVM);
476
477     # Test rebootVM() method.
478     $som = $stub->rebootVM(config => $testVM);
479     ok($som->result, "rebootVM(config => '$testVM')");
480
481     # The test VM should be on.
482     $som = $stub->getStateVM(config => $testVM);
483
484     # Since the test VM doesn't have an OS installed on it,
485     # the VM may be considered stuck.  Go ahead and answer
486     # this question, if need be.
487     if ($som->result == VM_EXECUTION_STATE_STUCK) {
488         $som = $stub->answerVM(config => $testVM);
489         # Fetch the state again, to see if it's now ON.
490         $som = $stub->getStateVM(config => $testVM);
491     }
492     is($som->result, VM_EXECUTION_STATE_ON, "rebootVM(config => '$testVM')") or diag("The rebootVM() call failed.  Attempted to reboot VM ($testVM), but the VM state was not reported as ON.");
493    
494     # Stop and unregister the test VM.
495     $som = $stub->stopVM(config => $testVM);
496     $som = $stub->unregisterVM(config => $testVM);
497 };
498
499 # Kill the child daemon, if it still exists.
500 HoneyClient::Manager::VM->destroy();
501
502 # Report any failure found.
503 if ($@) {
504     fail($@);
505 }
506 }
507
508
509
510 # =begin testing
511 {
512 # Shared test variables.
513 my $PORT = getVar(name      => "port",
514                   namespace => "HoneyClient::Manager::VM");
515 my ($stub, $som, $URL);
516 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
517                                       namespace => "HoneyClient::Manager::VM::Test");
518
519 # Catch all errors, in order to make sure child processes are
520 # properly killed.
521 eval {
522
523     $URL = HoneyClient::Manager::VM->init();
524    
525     # Connect to daemon as a client.
526     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
527
528     # Register and start the test VM.
529     $som = $stub->registerVM(config => $testVM);
530     $som = $stub->startVM(config => $testVM);
531
532     # Test suspendVM() method.
533     $som = $stub->suspendVM(config => $testVM);
534     ok($som->result, "suspendVM(config => '$testVM')");
535
536     # The test VM should be suspended.
537     $som = $stub->getStateVM(config => $testVM);
538     is($som->result, VM_EXECUTION_STATE_SUSPENDED, "suspendVM(config => '$testVM')") or diag("The suspendVM() call failed.  Attempted to suspend VM ($testVM), but the VM state was not reported as SUSPENDED.");
539
540     # Wake, stop, and unregister the test VM.
541     $som = $stub->startVM(config => $testVM);
542     $som = $stub->stopVM(config => $testVM);
543     $som = $stub->unregisterVM(config => $testVM);
544 };
545
546 # Kill the child daemon, if it still exists.
547 HoneyClient::Manager::VM->destroy();
548
549 # Report any failure found.
550 if ($@) {
551     fail($@);
552 }
553 }
554
555
556
557 # =begin testing
558 {
559 # Shared test variables.
560 my $PORT = getVar(name      => "port",
561                   namespace => "HoneyClient::Manager::VM");
562 my ($stub, $som, $URL);
563 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
564                                       namespace => "HoneyClient::Manager::VM::Test");
565
566 # Catch all errors, in order to make sure child processes are
567 # properly killed.
568 eval {
569
570     $URL = HoneyClient::Manager::VM->init();
571    
572     # Connect to daemon as a client.
573     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
574
575     # Register the test VM.
576     $som = $stub->registerVM(config => $testVM);
577
578     # Get the test VM's parent directory,
579     # in order to create a temporary clone VM.
580     my $testVMDir = dirname($testVM);
581     my $cloneVMDir = dirname($testVMDir) . "/test_vm_clone";
582     my $cloneVM = $cloneVMDir . "/" . basename($testVM);
583
584     # Test fullCloneVM() method.
585     $som = $stub->fullCloneVM(src_config => $testVM, dest_dir => $cloneVMDir);
586     # Check to see if the clone's absolute file path is returned.
587     is($som->result, $cloneVM, "fullCloneVM(src_config => '$testVM', dest_dir => '$cloneVMDir')");
588
589     # Wait a small amount of time for the asynchronous clone
590     # to complete.
591     sleep (15);
592
593     # The clone VM should be on.
594     $som = $stub->getStateVM(config => $cloneVM);
595
596     # Since the clone VM doesn't have an OS installed on it,
597     # the VM may be considered stuck.  Go ahead and answer
598     # this question, if need be.
599     if ($som->result == VM_EXECUTION_STATE_STUCK) {
600         $som = $stub->answerVM(config => $cloneVM);
601         # Fetch the state again, to see if it's now ON.
602         $som = $stub->getStateVM(config => $cloneVM);
603     }
604     is($som->result, VM_EXECUTION_STATE_ON, "fullCloneVM(src_config => '$testVM', dest_dir => '$cloneVMDir')") or diag("The fullCloneVM() call failed.  Attempted to fully clone VM ($testVM) at ($cloneVM), but the cloned VM state was not reported as ON.");
605  
606     # Destroy the clone VM.
607     $som = $stub->destroyVM(config => $cloneVM);
608
609     # Stop and unregister the test VM.
610     $som = $stub->stopVM(config => $testVM);
611     $som = $stub->unregisterVM(config => $testVM);
612 };
613
614 # Kill the child daemon, if it still exists.
615 HoneyClient::Manager::VM->destroy();
616
617 # Report any failure found.
618 if ($@) {
619     fail($@);
620 }
621 }
622
623
624
625 # =begin testing
626 {
627 # Shared test variables.
628 my $PORT = getVar(name      => "port",
629                   namespace => "HoneyClient::Manager::VM");
630 my ($stub, $som, $URL);
631 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
632                                       namespace => "HoneyClient::Manager::VM::Test");
633
634 # Catch all errors, in order to make sure child processes are
635 # properly killed.
636 eval {
637
638     $URL = HoneyClient::Manager::VM->init();
639    
640     # Connect to daemon as a client.
641     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
642
643     # Make sure the test VM is registered.
644     $som = $stub->registerVM(config => $testVM);
645
646     # Test getNameVM() method.
647     $som = $stub->getNameVM(config => $testVM);
648
649     # The test VM should not be registered.
650     is($som->result, "testVM", "getNameVM(config => '$testVM')") or diag("The getNameVM() call failed.  Expected VM ($testVM) to have the name \"testVM\".");
651    
652     # Unregister the test VM.
653     $som = $stub->unregisterVM(config => $testVM);
654 };
655
656 # Kill the child daemon, if it still exists.
657 HoneyClient::Manager::VM->destroy();
658
659 # Report any failure found.
660 if ($@) {
661     fail($@);
662 }
663 }
664
665
666
667 # =begin testing
668 {
669 # Shared test variables.
670 my $PORT = getVar(name      => "port",
671                   namespace => "HoneyClient::Manager::VM");
672 my ($stub, $som, $URL);
673 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
674                                       namespace => "HoneyClient::Manager::VM::Test");
675
676 # Catch all errors, in order to make sure child processes are
677 # properly killed.
678 eval {
679
680     $URL = HoneyClient::Manager::VM->init();
681    
682     # Connect to daemon as a client.
683     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
684
685     # Register the test VM.
686     $som = $stub->registerVM(config => $testVM);
687
688     # Get the current name of the test VM.
689     $som = $stub->getNameVM(config => $testVM);
690     my $oldName = $som->result;
691
692     # Set the new name of the test VM.
693     my $newName = "newVM";
694     # Test setNameVM() method.
695     $som = $stub->setNameVM(config => $testVM, name => $newName);
696     is($som->result, $newName, "setNameVM(config => '$testVM', name => '$newName')") or diag("The setNameVM() call failed.  Attempted to change the test VM ($testVM) name of \"$oldName\" to \"$newName\".");
697
698     # Check to make sure the new name is set.
699     $som = $stub->getNameVM(config => $testVM);
700     is($som->result, $newName, "setNameVM(config => '$testVM', name => '$newName')") or diag("The setNameVM() call failed.  Attempted to change the test VM ($testVM) name of \"$oldName\" to \"$newName\".");
701
702     # Restore the old test VM name and unregister the test VM.
703     $som = $stub->setNameVM(config => $testVM, name => $oldName);
704     $som = $stub->unregisterVM(config => $testVM);
705 };
706
707 # Kill the child daemon, if it still exists.
708 HoneyClient::Manager::VM->destroy();
709
710 # Report any failure found.
711 if ($@) {
712     fail($@);
713 }
714 }
715
716
717
718 # =begin testing
719 {
720 # Shared test variables.
721 my $PORT = getVar(name      => "port",
722                   namespace => "HoneyClient::Manager::VM");
723 my ($stub, $som, $URL);
724 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
725                                       namespace => "HoneyClient::Manager::VM::Test");
726
727 # Catch all errors, in order to make sure child processes are
728 # properly killed.
729 eval {
730
731     $URL = HoneyClient::Manager::VM->init();
732    
733     # Connect to daemon as a client.
734     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
735
736     # Register the test VM.
737     $som = $stub->registerVM(config => $testVM);
738
739     # Get the MAC address of the test VM.
740     # Test getMACaddrVM() method.
741     $som = $stub->getMACaddrVM(config => $testVM);
742
743     # The exact MAC address of the VM will change from system to system,
744     # so we check to make sure the result looks like a valid MAC address.
745     like($som->result, "/[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]/", "getMACaddrVM(config => '$testVM')") or diag("The getMACaddrVM() call failed.  Attempted to retrieve the MAC address of test VM ($testVM).");
746
747     # Unregister the test VM.
748     $som = $stub->unregisterVM(config => $testVM);
749 };
750
751 # Kill the child daemon, if it still exists.
752 HoneyClient::Manager::VM->destroy();
753
754 # Report any failure found.
755 if ($@) {
756     fail($@);
757 }
758 }
759
760
761
762 # =begin testing
763 {
764 # Shared test variables.
765 my $PORT = getVar(name      => "port",
766                   namespace => "HoneyClient::Manager::VM");
767 my ($stub, $som, $URL);
768 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config_livecd",
769                                       namespace => "HoneyClient::Manager::VM::Test");
770
771 # Catch all errors, in order to make sure child processes are
772 # properly killed.
773 eval {
774
775     $URL = HoneyClient::Manager::VM->init();
776    
777     # Connect to daemon as a client.
778     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
779
780     # Register and start the test VM.
781     $som = $stub->registerVM(config => $testVM);
782     $som = $stub->startVM(config => $testVM);
783
784     # Wait 240 seconds, for the DHCP server to give the testVM
785     # a DHCP lease.
786     sleep (240);
787
788     # Get the IP address of the test VM.
789     # Test getIPaddrVM() method.
790     $som = $stub->getIPaddrVM(config => $testVM);
791
792     # The exact IP address of the VM will change from system to system,
793     # so we check to make sure the result looks like a valid IP address.
794     like($som->result, "/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/", "getIPaddrVM(config => '$testVM')") or diag("The getIPaddrVM() call failed.  Attempted to retrieve the IP address of test VM ($testVM).");
795
796     # Stop and unregister the test VM.
797     $som = $stub->stopVM(config => $testVM);
798     $som = $stub->unregisterVM(config => $testVM);
799 };
800
801 # Kill the child daemon, if it still exists.
802 HoneyClient::Manager::VM->destroy();
803
804 # Report any failure found.
805 if ($@) {
806     fail($@);
807 }
808 }
809
810
811
812 # =begin testing
813 {
814 # Shared test variables.
815 my $PORT = getVar(name      => "port",
816                   namespace => "HoneyClient::Manager::VM");
817 my ($stub, $som, $URL);
818 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
819                                       namespace => "HoneyClient::Manager::VM::Test");
820
821 # Catch all errors, in order to make sure child processes are
822 # properly killed.
823 eval {
824
825     $URL = HoneyClient::Manager::VM->init();
826    
827     # Connect to daemon as a client.
828     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
829
830     # Make sure the test VM is stopped and unregistered.
831     $som = $stub->stopVM(config => $testVM);
832     $som = $stub->unregisterVM(config => $testVM);
833
834     # Test registerVM() method.
835     $som = $stub->registerVM(config => $testVM);
836     ok($som->result, "registerVM(config => '$testVM')") or diag("The registerVM() call failed.");
837
838     # The test VM should be registered.
839     $som = $stub->isRegisteredVM(config => $testVM);
840     ok($som->result, "registerVM(config => '$testVM')") or diag("The registerVM() call failed.  If ($testVM) is still registered, be sure to unregister it manually.");
841
842     # Unregister the test VM.
843     $som = $stub->unregisterVM(config => $testVM);
844 };
845
846 # Kill the child daemon, if it still exists.
847 HoneyClient::Manager::VM->destroy();
848
849 # Report any failure found.
850 if ($@) {
851     fail($@);
852 }
853 }
854
855
856
857 # =begin testing
858 {
859 # Shared test variables.
860 my $PORT = getVar(name      => "port",
861                   namespace => "HoneyClient::Manager::VM");
862 my ($stub, $som, $URL);
863 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
864                                       namespace => "HoneyClient::Manager::VM::Test");
865
866 # Catch all errors, in order to make sure child processes are
867 # properly killed.
868 eval {
869
870     $URL = HoneyClient::Manager::VM->init();
871    
872     # Connect to daemon as a client.
873     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
874
875     # Make sure the test VM is stopped and registered.
876     $som = $stub->stopVM(config => $testVM);
877     $som = $stub->registerVM(config => $testVM);
878
879     # Test unregisterVM() method.
880     $som = $stub->unregisterVM(config => $testVM);
881     ok($som->result, "unregisterVM(config => '$testVM')") or diag("The unregisterVM() call failed.");
882
883     # The test VM should be registered.
884     $som = $stub->isRegisteredVM(config => $testVM);
885     ok(!$som->result, "unregisterVM(config => '$testVM')") or diag("The unregisterVM() call failed.  If ($testVM) is still registered, be sure to unregister it manually.");
886 };
887
888 # Kill the child daemon, if it still exists.
889 HoneyClient::Manager::VM->destroy();
890
891 # Report any failure found.
892 if ($@) {
893     fail($@);
894 }
895 }
896
897
898
899 # =begin testing
900 {
901 # Shared test variables.
902 my $PORT = getVar(name      => "port",
903                   namespace => "HoneyClient::Manager::VM");
904 my ($stub, $som, $URL);
905 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
906                                       namespace => "HoneyClient::Manager::VM::Test");
907
908 # Catch all errors, in order to make sure child processes are
909 # properly killed.
910 eval {
911
912     $URL = HoneyClient::Manager::VM->init();
913    
914     # Connect to daemon as a client.
915     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
916
917     # Make sure the test VM is stopped and unregistered.
918     $som = $stub->stopVM(config => $testVM);
919     $som = $stub->unregisterVM(config => $testVM);
920
921     # The only consistent way to get a VM into a stuck state,
922     # is to manually copy a VM into a new directory, register it,
923     # and then proceed to start it.  VMware Server / GSX will immediately
924     # ask if we'd like to create a new identifier before
925     # moving on.
926
927     # Get the test VM's parent directory,
928     # in order to create a temporary clone VM.
929     my $testVMDir = dirname($testVM);
930     my $cloneVMDir = dirname($testVMDir) . "/test_vm_clone";
931     my $cloneVM = $cloneVMDir . "/" . basename($testVM);
932
933     # Make the destDir.
934     if (!dircopy($testVMDir, $cloneVMDir)) {
935         fail("answerVM()");
936         diag("Could not copy test VM directory ($testVMDir) for testing answerVM() method.");
937     } else {
938         # Update clone VM data permissions...
939         chmod(oct(700), $cloneVM);
940         chmod(oct(700), glob($cloneVMDir . "/*.nvram"));
941         chmod(oct(600), glob($cloneVMDir . "/*.vms*"));
942         chmod(oct(600), glob($cloneVMDir . "/*REDO*"));
943     }
944
945     # Register the clone VM.
946     $som = $stub->registerVM(config => $cloneVM);
947
948     # Start the clone VM.
949     # Test answerVM() method.
950     $som = $stub->startVM(config => $cloneVM);
951     ok($som->result, "answerVM(config => '$cloneVM')") or diag("The answerVM() call failed.");
952
953     # Destroy the clone VM.
954     $som = $stub->destroyVM(config => $cloneVM);
955 };
956
957 # Kill the child daemon, if it still exists.
958 HoneyClient::Manager::VM->destroy();
959
960 # Report any failure found.
961 if ($@) {
962     fail($@);
963 }
964 }
965
966
967
968 # =begin testing
969 {
970 # Shared test variables.
971 my $PORT = getVar(name      => "port",
972                   namespace => "HoneyClient::Manager::VM");
973 my ($stub, $som, $URL);
974 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
975                                       namespace => "HoneyClient::Manager::VM::Test");
976
977 # Catch all errors, in order to make sure child processes are
978 # properly killed.
979 eval {
980
981     $URL = HoneyClient::Manager::VM->init();
982    
983     # Connect to daemon as a client.
984     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
985
986     # Register the test VM.
987     $som = $stub->registerVM(config => $testVM);
988
989     # Get the test VM's parent directory,
990     # in order to create a temporary clone VM.
991     my $testVMDir = dirname($testVM);
992     my $cloneVMDir = dirname($testVMDir) . "/test_vm_clone";
993     my $cloneVM = $cloneVMDir . "/" . basename($testVM);
994
995     # Clone the test VM.
996     $som = $stub->fullCloneVM(src_config => $testVM, dest_dir => $cloneVMDir);
997
998     # Wait a small amount of time for the asynchronous clone
999     # to complete.
1000     sleep (15);
1001
1002     # The clone VM should be on.
1003     $som = $stub->getStateVM(config => $cloneVM);
1004
1005     # Since the clone VM doesn't have an OS installed on it,
1006     # the VM may be considered stuck.  Go ahead and answer
1007     # this question, if need be.
1008     if ($som->result == VM_EXECUTION_STATE_STUCK) {
1009         $som = $stub->answerVM(config => $cloneVM);
1010     }
1011
1012     # Destroy the clone VM.
1013     $som = $stub->destroyVM(config => $cloneVM);
1014
1015     # Test destroyVM() method.
1016     ok($som->result, "destroyVM(config => '$cloneVM')") or diag("The destroyVM() call failed.");
1017
1018     # Check to make sure the clone VM is unregistered.
1019     $som = $stub->isRegisteredVM(config => $cloneVM);
1020     ok(!$som->result, "destroyVM(config => '$cloneVM')") or diag("The destroyVM() call failed.  If ($cloneVM) is still registered, be sure to unregister it manually.");
1021
1022     # Stop and unregister the test VM.
1023     $som = $stub->stopVM(config => $testVM);
1024     $som = $stub->unregisterVM(config => $testVM);
1025 };
1026
1027 # Kill the child daemon, if it still exists.
1028 HoneyClient::Manager::VM->destroy();
1029
1030 # Report any failure found.
1031 if ($@) {
1032     fail($@);
1033 }
1034 }
1035
1036
1037
1038 # =begin testing
1039 {
1040 # Shared test variables.
1041 my $PORT = getVar(name      => "port",
1042                   namespace => "HoneyClient::Manager::VM");
1043 my ($stub, $som, $URL);
1044 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
1045                                       namespace => "HoneyClient::Manager::VM::Test");
1046
1047 # Catch all errors, in order to make sure child processes are
1048 # properly killed.
1049 eval {
1050
1051     $URL = HoneyClient::Manager::VM->init();
1052    
1053     # Connect to daemon as a client.
1054     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
1055
1056     # Register the test VM.
1057     $som = $stub->registerVM(config => $testVM);
1058
1059     # In order to test the setMasterVM() method,
1060     # we're going to clone the test VM, then set the clone
1061     # as a master VM, and finally, check to make sure
1062     # the corresponding permissions were set in the
1063     # clone, as per master VM specification.
1064
1065     # Get the test VM's parent directory,
1066     # in order to create a temporary clone VM.
1067     my $testVMDir = dirname($testVM);
1068     my $cloneVMDir = dirname($testVMDir) . "/test_vm_clone";
1069     my $cloneVM = $cloneVMDir . "/" . basename($testVM);
1070
1071     # Create the clone VM.
1072     $som = $stub->fullCloneVM(src_config => $testVM, dest_dir => $cloneVMDir);
1073
1074     # Wait a small amount of time for the asynchronous clone
1075     # to complete.
1076     sleep (15);
1077
1078     # The clone VM should be on.
1079     $som = $stub->getStateVM(config => $cloneVM);
1080
1081     # Since the clone VM doesn't have an OS installed on it,
1082     # the VM may be considered stuck.  Go ahead and answer
1083     # this question, if need be.
1084     if ($som->result == VM_EXECUTION_STATE_STUCK) {
1085         $som = $stub->answerVM(config => $cloneVM);
1086     }
1087
1088     # Set the clone as a master VM.
1089     $som = $stub->setMasterVM(config => $cloneVM);
1090
1091     # Test setMasterVM() method.
1092     ok($som->result, "setMasterVM(config => '$cloneVM')") or diag("The setMasterVM() call failed.");
1093
1094     my $mode = undef;
1095     foreach (glob($cloneVMDir . "/*.vmdk*"),
1096              glob($cloneVMDir . "/*.vms*"),
1097              glob($cloneVMDir . "/*.vme*")) {
1098         $mode = sprintf("%04o", stat($_)->mode & 07777);
1099         is($mode, "0440", "setMasterVM(config => '$cloneVM')") or diag("The setMasterVM() call failed.  Expected file ($_) to be mode 0440, but it was mode $mode instead.");
1100     }
1101
1102     # Destroy the clone VM.
1103     $som = $stub->destroyVM(config => $cloneVM);
1104
1105     # Stop and unregister the test VM.
1106     $som = $stub->stopVM(config => $testVM);
1107     $som = $stub->unregisterVM(config => $testVM);
1108 };
1109
1110 # Kill the child daemon, if it still exists.
1111 HoneyClient::Manager::VM->destroy();
1112
1113 # Report any failure found.
1114 if ($@) {
1115     fail($@);
1116 }
1117 }
1118
1119
1120
1121 # =begin testing
1122 {
1123 # Shared test variables.
1124 my $PORT = getVar(name      => "port",
1125                   namespace => "HoneyClient::Manager::VM");
1126 my ($stub, $som, $URL);
1127 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config",
1128                                       namespace => "HoneyClient::Manager::VM::Test");
1129
1130 # Catch all errors, in order to make sure child processes are
1131 # properly killed.
1132 eval {
1133
1134     $URL = HoneyClient::Manager::VM->init();
1135    
1136     # Connect to daemon as a client.
1137     $stub = getClientHandle(namespace => "HoneyClient::Manager::VM");
1138
1139     # Register the test VM.
1140     $som = $stub->registerVM(config => $testVM);
1141
1142     # In order to test the quickCloneVM() method,
1143     # we're going to fully clone the test VM, then set the
1144     # newly created clone as a master VM, and finally,
1145     # create a secondary quick clone from the master VM.
1146
1147     # Get the test VM's parent directory,
1148     # in order to create a temporary master and clone VM.
1149     my $testVMDir = dirname($testVM);
1150     my $masterVMDir = dirname($testVMDir) . "/test_vm_master";
1151     my $cloneVMDir = dirname($testVMDir) . "/test_vm_clone";
1152     my $masterVM = $masterVMDir . "/" . basename($testVM);
1153     my $cloneVM = $cloneVMDir . "/" . basename($testVM);
1154
1155     # Create the master VM.
1156     $som = $stub->fullCloneVM(src_config => $testVM, dest_dir => $masterVMDir);
1157
1158     # Wait a small amount of time for the asynchronous clone
1159     # to complete.
1160     sleep (60);
1161
1162     # The master VM should be on.
1163     $som = $stub->getStateVM(config => $masterVM);
1164
1165     # Since the master VM doesn't have an OS installed on it,
1166     # the VM may be considered stuck.  Go ahead and answer
1167 &n