root/honeyclient/branches/exp/jpuchalski-esx/t/honeyclient_manager_vm.t

Revision 1590, 48.3 kB (checked in by kindlund, 8 months ago)

Added finer-grain .vmx/.cfg configuration editing, as suggested in ticket #148. By using Config::General to handle low-level .vmx/.cfg parsing, we no longer need to worry about how well each VM configuration is formatted, in order for the system properly run.

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