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

Revision 1866, 30.5 kB (checked in by kindlund, 2 months ago)

More integration testing.

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
20 my $question = prompt("# Do you want to run basic tests?", "yes");
21 if ($question !~ /^y.*/i) { exit; }
22
23 # Make sure Log::Log4perl loads
24 BEGIN { use_ok('Log::Log4perl', qw(:nowarn))
25         or diag("Can't load Log::Log4perl package. Check to make sure the package library is correctly listed within the path.");
26        
27         # Suppress all logging messages, since we need clean output for unit testing.
28         Log::Log4perl->init({
29             "log4perl.rootLogger"                               => "DEBUG, Buffer",
30             "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer",
31             "log4perl.appender.Buffer.min_level"                => "fatal",
32             "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout",
33             "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n",
34         });
35 }
36 require_ok('Log::Log4perl');
37 use Log::Log4perl qw(:easy);
38
39 # Make sure HoneyClient::Util::Config loads.
40 BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar))
41         or diag("Can't load HoneyClient::Util::Config package.  Check to make sure the package library is correctly listed within the path.");
42
43         # Suppress all logging messages, since we need clean output for unit testing.
44         Log::Log4perl->init({
45             "log4perl.rootLogger"                               => "DEBUG, Buffer",
46             "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer",
47             "log4perl.appender.Buffer.min_level"                => "fatal",
48             "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout",
49             "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n",
50         });
51 }
52 require_ok('HoneyClient::Util::Config');
53 can_ok('HoneyClient::Util::Config', 'getVar');
54 use HoneyClient::Util::Config qw(getVar);
55
56 # Suppress all logging messages, since we need clean output for unit testing.
57 Log::Log4perl->init({
58     "log4perl.rootLogger"                               => "DEBUG, Buffer",
59     "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer",
60     "log4perl.appender.Buffer.min_level"                => "fatal",
61     "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout",
62     "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n",
63 });
64
65 # Make sure the module loads properly, with the exportable
66 # functions shared.
67 BEGIN { use_ok('HoneyClient::Manager::ESX') or diag("Can't load HoneyClient::Manager::ESX package.  Check to make sure the package library is correctly listed within the path."); }
68 require_ok('HoneyClient::Manager::ESX');
69 use HoneyClient::Manager::ESX;
70
71 # Make sure Data::Dumper loads.
72 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."); }
73 require_ok('Data::Dumper');
74 use Data::Dumper;
75
76 # Make sure File::Basename loads.
77 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."); }
78 require_ok('File::Basename');
79 can_ok('File::Basename', 'dirname');
80 can_ok('File::Basename', 'basename');
81 use File::Basename qw(dirname basename);
82
83 # Make sure Digest::MD5 loads.
84 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."); }
85 require_ok('Digest::MD5');
86 can_ok('Digest::MD5', 'md5_hex');
87 use Digest::MD5 qw(md5_hex);
88
89 # Make sure VMware::VIRuntime loads.
90 BEGIN { use_ok('VMware::VIRuntime') or diag("Can't load VMware::VIRuntime package.  Check to make sure the package library is correctly listed within the path."); }
91 require_ok('VMware::VIRuntime');
92 use VMware::VIRuntime;
93
94 diag("About to run extended tests.");
95 diag("Warning: These tests will take significant time to complete (10-20 minutes).");
96 diag("");
97 diag("Note: These tests expect VMware ESX Server to be accessible at the following location,");
98 diag("using the following credentials:");
99 diag("   service_url: " . getVar(name => "service_url", namespace => "HoneyClient::Manager::ESX"));
100 diag("   username:    " . getVar(name => "user_name", namespace => "HoneyClient::Manager::ESX"));
101 diag("   password:    " . getVar(name => "password", namespace => "HoneyClient::Manager::ESX"));
102 diag("");
103 diag("Also, these tests expect the following test VM to be registered and powered off on the VMware ESX");
104 diag("Server:");
105 diag("   test_vm_name: " . getVar(name => "test_vm_name", namespace => "HoneyClient::Manager::ESX::Test"));
106 diag("");
107
108 # TODO: Provide a URL where users can download, extract, and install the Test_VM.
109
110 $question = prompt("# Do you want to run extended tests?", "no");
111 if ($question !~ /^y.*/i) { exit; }
112 }
113
114
115
116 # =begin testing
117 {
118 my $testVM = getVar(name      => "test_vm_name",
119                     namespace => "HoneyClient::Manager::ESX::Test");
120
121 eval {
122     # Create a new session.
123     my $session = HoneyClient::Manager::ESX->login();
124
125     # Validate the session.
126     ok((ref($session) eq 'Vim'), "login()") or diag("The login() call failed.");
127
128     # Destroy the session.
129     HoneyClient::Manager::ESX->logout(session => $session);
130 };
131
132 # Report any failure found.
133 if ($@) {
134     fail($@);
135 }
136 }
137
138
139
140 # =begin testing
141 {
142 my $testVM = getVar(name      => "test_vm_name",
143                     namespace => "HoneyClient::Manager::ESX::Test");
144
145 eval {
146     # Create a new session.
147     my $session = HoneyClient::Manager::ESX->login();
148
149     # Destroy the session.
150     my $result = HoneyClient::Manager::ESX->logout(session => $session);
151     ok($result, "logout()") or diag("The logout() call failed.");
152 };
153
154 # Report any failure found.
155 if ($@) {
156     fail($@);
157 }
158 }
159
160
161
162 # =begin testing
163 {
164 my $testVM = getVar(name      => "test_vm_name",
165                     namespace => "HoneyClient::Manager::ESX::Test");
166
167 eval {
168     # Create a new session.
169     my $session = HoneyClient::Manager::ESX->login();
170    
171     # Start the test VM.
172     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
173
174     # Clone the test VM.
175     my $cloneVM = HoneyClient::Manager::ESX->fullCloneVM(session => $session, src_name => $testVM);
176     ok($cloneVM, "fullCloneVM(src_name => '$testVM')") or diag("The fullCloneVM() call failed.");
177
178     # Get the power state of the clone VM.
179     my $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $cloneVM);
180
181     # The clone VM should be powered on.
182     is($state, "poweredon", "fullCloneVM(name => '$testVM')") or diag("The fullCloneVM() call failed.");
183    
184     # Destroy the clone VM.
185     HoneyClient::Manager::ESX->destroyVM(session => $session, name => $cloneVM);
186    
187     # Start the test VM.
188     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
189    
190     # Stop the test VM.
191     HoneyClient::Manager::ESX->stopVM(session => $session, name => $testVM);
192
193     # Destroy the session.
194     HoneyClient::Manager::ESX->logout(session => $session);
195 };
196
197 # Report any failure found.
198 if ($@) {
199     fail($@);
200 }
201 }
202
203
204
205 # =begin testing
206 {
207 my $testVM = getVar(name      => "test_vm_name",
208                     namespace => "HoneyClient::Manager::ESX::Test");
209
210 eval {
211     # Create a new session.
212     my $session = HoneyClient::Manager::ESX->login();
213    
214     # Start the test VM.
215     my $result = HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
216     ok($result, "startVM(name => '$testVM')") or diag("The startVM() call failed.");
217
218     # Get the power state of the test VM.
219     my $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $testVM);
220
221     # The test VM should be on.
222     is($state, "poweredon", "startVM(name => '$testVM')") or diag("The startVM() call failed.");
223
224     # Stop the test VM.
225     HoneyClient::Manager::ESX->stopVM(session => $session, name => $testVM);
226
227     # Destroy the session.
228     HoneyClient::Manager::ESX->logout(session => $session);
229 };
230
231 # Report any failure found.
232 if ($@) {
233     fail($@);
234 }
235 }
236
237
238
239 # =begin testing
240 {
241 my $testVM = getVar(name      => "test_vm_name",
242                     namespace => "HoneyClient::Manager::ESX::Test");
243
244 eval {
245     # Create a new session.
246     my $session = HoneyClient::Manager::ESX->login();
247    
248     # Start the test VM.
249     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
250
251     # Stop the test VM.
252     my $result = HoneyClient::Manager::ESX->stopVM(session => $session, name => $testVM);
253     ok($result, "stopVM(name => '$testVM')") or diag("The stopVM() call failed.");
254
255     # Get the power state of the test VM.
256     my $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $testVM);
257
258     # The test VM should be off.
259     is($state, "poweredoff", "stopVM(name => '$testVM')") or diag("The stopVM() call failed.");
260
261     # Destroy the session.
262     HoneyClient::Manager::ESX->logout(session => $session);
263 };
264
265 # Report any failure found.
266 if ($@) {
267     fail($@);
268 }
269 }
270
271
272
273 # =begin testing
274 {
275 my $testVM = getVar(name      => "test_vm_name",
276                     namespace => "HoneyClient::Manager::ESX::Test");
277
278 eval {
279     # Create a new session.
280     my $session = HoneyClient::Manager::ESX->login();
281    
282     # Start the test VM.
283     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
284    
285     # Suspend the test VM.
286     my $result = HoneyClient::Manager::ESX->resetVM(session => $session, name => $testVM);
287     ok($result, "resetVM(name => '$testVM')") or diag("The resetVM() call failed.");
288
289     # Get the power state of the test VM.
290     my $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $testVM);
291
292     # The test VM should be powered on.
293     is($state, "poweredon", "resetVM(name => '$testVM')") or diag("The resetVM() call failed.");
294    
295     # Stop the test VM.
296     HoneyClient::Manager::ESX->stopVM(session => $session, name => $testVM);
297
298     # Destroy the session.
299     HoneyClient::Manager::ESX->logout(session => $session);
300 };
301
302 # Report any failure found.
303 if ($@) {
304     fail($@);
305 }
306 }
307
308
309
310 # =begin testing
311 {
312 my $testVM = getVar(name      => "test_vm_name",
313                     namespace => "HoneyClient::Manager::ESX::Test");
314
315 eval {
316     # Create a new session.
317     my $session = HoneyClient::Manager::ESX->login();
318    
319     # Start the test VM.
320     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
321    
322     # Suspend the test VM.
323     my $result = HoneyClient::Manager::ESX->suspendVM(session => $session, name => $testVM);
324     ok($result, "suspendVM(name => '$testVM')") or diag("The suspendVM() call failed.");
325
326     # Get the power state of the test VM.
327     my $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $testVM);
328
329     # The test VM should be suspended.
330     is($state, "suspended", "suspendVM(name => '$testVM')") or diag("The suspendVM() call failed.");
331    
332     # Start the test VM.
333     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
334
335     # Stop the test VM.
336     HoneyClient::Manager::ESX->stopVM(session => $session, name => $testVM);
337
338     # Destroy the session.
339     HoneyClient::Manager::ESX->logout(session => $session);
340 };
341
342 # Report any failure found.
343 if ($@) {
344     fail($@);
345 }
346 }
347
348
349
350 # =begin testing
351 {
352 my $testVM = getVar(name      => "test_vm_name",
353                     namespace => "HoneyClient::Manager::ESX::Test");
354
355 eval {
356     # Create a new session.
357     my $session = HoneyClient::Manager::ESX->login();
358    
359     # Clone the test VM.
360     my $cloneVM = HoneyClient::Manager::ESX->fullCloneVM(session => $session, src_name => $testVM);
361
362     # Destroy the clone VM.
363     my $result = HoneyClient::Manager::ESX->destroyVM(session => $session, name => $cloneVM);
364     ok($result, "destroyVM(name => '$cloneVM')") or diag("The destroyVM() call failed.");
365    
366     # The clone VM should no longer be registered.
367     ok(!HoneyClient::Manager::ESX->isRegisteredVM(session => $session, name => $cloneVM), "destroyVM(name => '$cloneVM')") or diag ("The destroyVM() call failed.");
368  
369     # Destroy the session.
370     HoneyClient::Manager::ESX->logout(session => $session);
371 };
372
373 # Report any failure found.
374 if ($@) {
375     fail($@);
376 }
377 }
378
379
380
381 # =begin testing
382 {
383 my $testVM = getVar(name      => "test_vm_name",
384                     namespace => "HoneyClient::Manager::ESX::Test");
385
386 eval {
387     # Create a new session.
388     my $session = HoneyClient::Manager::ESX->login();
389
390     # Get the power state of the test VM.
391     my $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $testVM);
392
393     # The test VM should be off.
394     is($state, "poweredoff", "getStateVM(name => '$testVM')") or diag("The getStateVM() call failed.");
395
396     # Destroy the session.
397     HoneyClient::Manager::ESX->logout(session => $session);
398 };
399
400 # Report any failure found.
401 if ($@) {
402     fail($@);
403 }
404 }
405
406
407
408 # =begin testing
409 {
410 my $testVM = getVar(name      => "test_vm_name",
411                     namespace => "HoneyClient::Manager::ESX::Test");
412
413 eval {
414     # Create a new session.
415     my $session = HoneyClient::Manager::ESX->login();
416    
417     # Start the test VM.
418     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
419
420     # Clone the test VM.
421     my $cloneVM = HoneyClient::Manager::ESX->quickCloneVM(session => $session, src_name => $testVM);
422
423     # Verify that the clone VM is a quick clone.
424     my $isQuickClone = HoneyClient::Manager::ESX->isQuickCloneVM(session => $session, name => $cloneVM);
425     ok($isQuickClone, "isQuickCloneVM(name => '$cloneVM')") or diag("The isQuickCloneVM() call failed.");
426
427     # Destroy the clone VM.
428     HoneyClient::Manager::ESX->destroyVM(session => $session, name => $cloneVM);
429    
430     # Start the test VM.
431     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
432    
433     # Stop the test VM.
434     HoneyClient::Manager::ESX->stopVM(session => $session, name => $testVM);
435
436     # Destroy the session.
437     HoneyClient::Manager::ESX->logout(session => $session);
438 };
439
440 # Report any failure found.
441 if ($@) {
442     fail($@);
443 }
444 }
445
446
447
448 # =begin testing
449 {
450 my $testVM = getVar(name      => "test_vm_name",
451                     namespace => "HoneyClient::Manager::ESX::Test");
452
453 eval {
454     # Create a new session.
455     my $session = HoneyClient::Manager::ESX->login();
456
457     # We assume the test VM is stopped and unregistered.
458
459     # The only consistent way to get a VM into a stuck state,
460     # is to manually copy a VM into a new directory, register it,
461     # and then proceed to start it.  VMware ESX Server will immediately
462     # ask if we'd like to create a new identifier before
463     # moving on.
464    
465     # Generate a new VM name.
466     my $newVM = HoneyClient::Manager::ESX->_generateVMID();
467
468     # Create the new VM.
469     my $new_config = HoneyClient::Manager::ESX::_fullCopyVM(
470         session => $session,
471         src_name => $testVM,
472         dst_name => $newVM,
473     );
474
475     # Register the new VM.
476     HoneyClient::Manager::ESX->registerVM(session => $session, name => $newVM, config => $new_config);
477
478     # Start the new VM and indirectly test the answerVM() method.
479     my $result = HoneyClient::Manager::ESX->startVM(session => $session, name => $newVM);
480     ok($result, "answerVM(name => '$newVM')") or diag("The answerVM() call failed.");
481
482     # Destroy the new VM.
483     HoneyClient::Manager::ESX->destroyVM(session => $session, name => $newVM);
484    
485     # Destroy the session.
486     HoneyClient::Manager::ESX->logout(session => $session);
487 };
488
489 # Report any failure found.
490 if ($@) {
491     fail($@);
492 }
493 }
494
495
496
497 # =begin testing
498 {
499 my $testVM = getVar(name      => "test_vm_name",
500                     namespace => "HoneyClient::Manager::ESX::Test");
501
502 eval {
503     # Create a new session.
504     my $session = HoneyClient::Manager::ESX->login();
505    
506     # Start the test VM.
507     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
508
509     # Get the power state of the test VM.
510     my $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $testVM);
511
512     # Wait until the test VM is on.
513     while ($state ne 'poweredon') {
514         sleep (1);
515         $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $testVM);
516     }
517    
518     # Get the MAC address of the test VM.
519     my $mac_address = undef;
520     for (my $counter = 0; $counter < 240; $counter++) {
521         $mac_address = HoneyClient::Manager::ESX->getMACaddrVM(session => $session, name => $testVM);
522         if (defined($mac_address)) {
523             last;
524         } else {
525             sleep (1);
526         }
527     }
528
529     # The exact MAC address of the VM will change from system to system,
530     # so we check to make sure the result looks like a valid MAC address.
531     like($mac_address, "/[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(name => '$testVM')") or diag("The getMACaddrVM() call failed.  Attempted to retrieve the MAC address of test VM ($testVM).");
532
533     # Stop the test VM.
534     HoneyClient::Manager::ESX->stopVM(session => $session, name => $testVM);
535
536     # Destroy the session.
537     HoneyClient::Manager::ESX->logout(session => $session);
538 };
539
540 # Report any failure found.
541 if ($@) {
542     fail($@);
543 }
544 }
545
546
547
548 # =begin testing
549 {
550 my $testVM = getVar(name      => "test_vm_name",
551                     namespace => "HoneyClient::Manager::ESX::Test");
552
553 eval {
554     # Create a new session.
555     my $session = HoneyClient::Manager::ESX->login();
556    
557     # Start the test VM.
558     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
559
560     # Get the power state of the test VM.
561     my $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $testVM);
562
563     # Wait until the test VM is on.
564     while ($state ne 'poweredon') {
565         sleep (1);
566         $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $testVM);
567     }
568    
569     # Get the IP address of the test VM.
570     my $ip_address = undef;
571     for (my $counter = 0; $counter < 240; $counter++) {
572         $ip_address = HoneyClient::Manager::ESX->getIPaddrVM(session => $session, name => $testVM);
573         if (defined($ip_address)) {
574             last;
575         } else {
576             sleep (1);
577         }
578     }
579
580     # The exact IP address of the VM will change from system to system,
581     # so we check to make sure the result looks like a valid IP address.
582     like($ip_address, "/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/", "getIPaddrVM(name => '$testVM')") or diag("The getIPaddrVM() call failed.  Attempted to retrieve the IP address of test VM ($testVM).");
583
584     # Stop the test VM.
585     HoneyClient::Manager::ESX->stopVM(session => $session, name => $testVM);
586
587     # Destroy the session.
588     HoneyClient::Manager::ESX->logout(session => $session);
589 };
590
591 # Report any failure found.
592 if ($@) {
593     fail($@);
594 }
595 }
596
597
598
599 # =begin testing
600 {
601 my $testVM = getVar(name      => "test_vm_name",
602                     namespace => "HoneyClient::Manager::ESX::Test");
603
604 eval {
605     # Create a new session.
606     my $session = HoneyClient::Manager::ESX->login();
607
608     # Get the VM's configuration file.   
609     my $config = HoneyClient::Manager::ESX->getConfigVM(session => $session, name => $testVM);
610     ok($config, "getConfigVM(name => '$testVM')") or diag("The getConfigVM() call failed.");
611
612     # Destroy the session.
613     HoneyClient::Manager::ESX->logout(session => $session);
614 };
615
616 # Report any failure found.
617 if ($@) {
618     fail($@);
619 }
620 }
621
622
623
624 # =begin testing
625 {
626 my $testVM = getVar(name      => "test_vm_name",
627                     namespace => "HoneyClient::Manager::ESX::Test");
628
629 eval {
630     # Create a new session.
631     my $session = HoneyClient::Manager::ESX->login();
632
633     # Check to see if the test VM is registered (should return true).
634     my $result = HoneyClient::Manager::ESX->isRegisteredVM(session => $session, name => $testVM);
635    
636     # The test VM should be registered.
637     ok($result, "isRegisteredVM(name => '$testVM')") or diag("The isRegisteredVM() call failed.");
638
639     # Unregister the test VM.
640     my $config = HoneyClient::Manager::ESX->unregisterVM(session => $session, name => $testVM);
641    
642     # Check to see if the test VM is registered (should return false).
643     $result = HoneyClient::Manager::ESX->isRegisteredVM(session => $session, name => $testVM);
644
645     # The test VM should not be registered.
646     ok(!$result, "isRegisteredVM(name => '$testVM')") or diag("The isRegisteredVM() call failed.");
647    
648     # Reregister the test VM.
649     HoneyClient::Manager::ESX->registerVM(session => $session, name => $testVM, config => $config);
650    
651     # Check to see if the test VM is registered (should return true).
652     $result = HoneyClient::Manager::ESX->isRegisteredVM(session => $session, name => $testVM);
653    
654     # The test VM should be registered.
655     ok($result, "isRegisteredVM(name => '$testVM')") or diag("The isRegisteredVM() call failed.");
656
657     # Destroy the session.
658     HoneyClient::Manager::ESX->logout(session => $session);
659 };
660
661 # Report any failure found.
662 if ($@) {
663     fail($@);
664 }
665 }
666
667
668
669 # =begin testing
670 {
671 my $testVM = getVar(name      => "test_vm_name",
672                     namespace => "HoneyClient::Manager::ESX::Test");
673
674 eval {
675     # Create a new session.
676     my $session = HoneyClient::Manager::ESX->login();
677
678     # Check the size of the backing datastore.
679     my $result = HoneyClient::Manager::ESX->getDatastoreSpaceAvailableESX(session => $session, name => $testVM);
680    
681     # The size returned should be a number.
682     like($result, "/[0-9]+/", "getDatastoreSpaceAvailableESX(name => '$testVM')") or diag("The getDatastoreSpaceAvailableESX() call failed.");
683
684     # Destroy the session.
685     HoneyClient::Manager::ESX->logout(session => $session);
686 };
687
688 # Report any failure found.
689 if ($@) {
690     fail($@);
691 }
692 }
693
694
695
696 # =begin testing
697 {
698 eval {
699     # Create a new session.
700     my $session = HoneyClient::Manager::ESX->login();
701
702     # Check the size of the backing datastore.
703     my $result = HoneyClient::Manager::ESX->getHostnameESX(session => $session);
704    
705     # The result should be a string.
706     ok($result, "getHostnameESX()") or diag("The getHostnameESX() call failed.");
707
708     # Destroy the session.
709     HoneyClient::Manager::ESX->logout(session => $session);
710 };
711
712 # Report any failure found.
713 if ($@) {
714     fail($@);
715 }
716 }
717
718
719
720 # =begin testing
721 {
722 eval {
723     # Create a new session.
724     my $session = HoneyClient::Manager::ESX->login();
725
726     # Check the size of the backing datastore.
727     my $result = HoneyClient::Manager::ESX->getIPaddrESX(session => $session);
728    
729     # The result should be a real IP address.
730     like($result, "/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/", "getIPaddrESX()") or diag("The getIPaddrESX() call failed.");
731
732     # Destroy the session.
733     HoneyClient::Manager::ESX->logout(session => $session);
734 };
735
736 # Report any failure found.
737 if ($@) {
738     fail($@);
739 }
740 }
741
742
743
744 # =begin testing
745 {
746 my $testVM = getVar(name      => "test_vm_name",
747                     namespace => "HoneyClient::Manager::ESX::Test");
748
749 eval {
750     # Create a new session.
751     my $session = HoneyClient::Manager::ESX->login();
752
753     # Unregister the test VM.
754     my $config = HoneyClient::Manager::ESX->unregisterVM(session => $session, name => $testVM);
755    
756     # Reregister the test VM.
757     my $result = HoneyClient::Manager::ESX->registerVM(session => $session, name => $testVM, config => $config);
758    
759     # The test VM should be registered.
760     ok($result, "registerVM(name => '$testVM', config => '$config')") or diag("The registerVM() call failed.");
761    
762     # Check to see if the test VM is registered (should return true).
763     $result = HoneyClient::Manager::ESX->isRegisteredVM(session => $session, name => $testVM);
764    
765     # The test VM should be registered.
766     ok($result, "registerVM(name => '$testVM', config => '$config')") or diag("The registerVM() call failed.");
767
768     # Destroy the session.
769     HoneyClient::Manager::ESX->logout(session => $session);
770 };
771
772 # Report any failure found.
773 if ($@) {
774     fail($@);
775 }
776 }
777
778
779
780 # =begin testing
781 {
782 my $testVM = getVar(name      => "test_vm_name",
783                     namespace => "HoneyClient::Manager::ESX::Test");
784
785 eval {
786     # Create a new session.
787     my $session = HoneyClient::Manager::ESX->login();
788
789     # Unregister the test VM.
790     my $config = HoneyClient::Manager::ESX->unregisterVM(session => $session, name => $testVM);
791    
792     # The test VM should not be registered.
793     ok($config, "unregisterVM(name => '$testVM')") or diag("The unregisterVM() call failed.");
794    
795     # Reregister the test VM.
796     HoneyClient::Manager::ESX->registerVM(session => $session, name => $testVM, config => $config);
797    
798     # Destroy the session.
799     HoneyClient::Manager::ESX->logout(session => $session);
800 };
801
802 # Report any failure found.
803 if ($@) {
804     fail($@);
805 }
806 }
807
808
809
810 # =begin testing
811 {
812 my $testVM = getVar(name      => "test_vm_name",
813                     namespace => "HoneyClient::Manager::ESX::Test");
814
815 eval {
816     # Create a new session.
817     my $session = HoneyClient::Manager::ESX->login();
818
819     # Clone the test VM.
820     my $cloneVM = HoneyClient::Manager::ESX->fullCloneVM(session => $session, src_name => $testVM);
821    
822     # Snapshot the clone VM.
823     my $snapshot_name = HoneyClient::Manager::ESX->snapshotVM(session => $session, name => $cloneVM);
824     ok($snapshot_name, "snapshotVM(name => '$cloneVM')") or diag("The snapshotVM() call failed.");
825
826     # Destroy the clone VM.
827     HoneyClient::Manager::ESX->destroyVM(session => $session, name => $cloneVM);
828    
829     # Destroy the session.
830     HoneyClient::Manager::ESX->logout(session => $session);
831 };
832
833 # Report any failure found.
834 if ($@) {
835     fail($@);
836 }
837 }
838
839
840
841 # =begin testing
842 {
843 my $testVM = getVar(name      => "test_vm_name",
844                     namespace => "HoneyClient::Manager::ESX::Test");
845
846 eval {
847     # Create a new session.
848     my $session = HoneyClient::Manager::ESX->login();
849
850     # Clone the test VM.
851     my $cloneVM = HoneyClient::Manager::ESX->fullCloneVM(session => $session, src_name => $testVM);
852    
853     # Snapshot the clone VM.
854     my $snapshot_name = HoneyClient::Manager::ESX->snapshotVM(session => $session, name => $cloneVM);
855
856     # Wait 2 seconds.
857     sleep (2);
858
859     # Revert the clone VM.
860     my $result = HoneyClient::Manager::ESX->revertVM(session => $session, name => $cloneVM, snapshot_name => $snapshot_name);
861     ok($result, "revertVM(name => '$cloneVM', snapshot_name => '$snapshot_name')") or diag("The revertVM() call failed.");
862
863     # Destroy the clone VM.
864     HoneyClient::Manager::ESX->destroyVM(session => $session, name => $cloneVM);
865    
866     # Destroy the session.
867     HoneyClient::Manager::ESX->logout(session => $session);
868 };
869
870 # Report any failure found.
871 if ($@) {
872     fail($@);
873 }
874 }
875
876
877
878 # =begin testing
879 {
880 my $testVM = getVar(name      => "test_vm_name",
881                     namespace => "HoneyClient::Manager::ESX::Test");
882
883 eval {
884     # Create a new session.
885     my $session = HoneyClient::Manager::ESX->login();
886
887     # Clone the test VM.
888     my $cloneVM = HoneyClient::Manager::ESX->quickCloneVM(session => $session, src_name => $testVM);
889    
890     # Snapshot the clone VM.
891     my $snapshot_name = HoneyClient::Manager::ESX->snapshotVM(session => $session, name => $cloneVM);
892
893     # Wait 2 seconds.
894     sleep (2);
895
896     # Rename this snapshot on the clone VM.
897     my $result = HoneyClient::Manager::ESX->renameSnapshotVM(session => $session, name => $cloneVM, old_snapshot_name => $snapshot_name);
898     ok($result, "renameSnapshotVM(name => '$cloneVM', old_snapshot_name => '$snapshot_name')") or diag("The renameSnapshotVM() call failed.");
899
900     # Destroy the clone VM.
901     HoneyClient::Manager::ESX->destroyVM(session => $session, name => $cloneVM);
902    
903     # Destroy the session.
904     HoneyClient::Manager::ESX->logout(session => $session);
905 };
906
907 # Report any failure found.
908 if ($@) {
909     fail($@);
910 }
911 }
912
913
914
915 # =begin testing
916 {
917 my $testVM = getVar(name      => "test_vm_name",
918                     namespace => "HoneyClient::Manager::ESX::Test");
919
920 eval {
921     # Create a new session.
922     my $session = HoneyClient::Manager::ESX->login();
923
924     # Clone the test VM.
925     my $cloneVM = HoneyClient::Manager::ESX->quickCloneVM(session => $session, src_name => $testVM);
926    
927     # Snapshot the clone VM.
928     my $snapshot_name = HoneyClient::Manager::ESX->snapshotVM(session => $session, name => $cloneVM);
929
930     # Wait 2 seconds.
931     sleep (2);
932
933     # Remove this snapshot on the clone VM.
934     my $result = HoneyClient::Manager::ESX->removeSnapshotVM(session => $session, name => $cloneVM, snapshot_name => $snapshot_name);
935     ok($result, "removeSnapshotVM(name => '$cloneVM', snapshot_name => '$snapshot_name')") or diag("The removeSnapshotVM() call failed.");
936
937     # Destroy the clone VM.
938     HoneyClient::Manager::ESX->destroyVM(session => $session, name => $cloneVM);
939    
940     # Destroy the session.
941     HoneyClient::Manager::ESX->logout(session => $session);
942 };
943
944 # Report any failure found.
945 if ($@) {
946     fail($@);
947 }
948 }
949
950
951
952 # =begin testing
953 {
954 my $testVM = getVar(name      => "test_vm_name",
955                     namespace => "HoneyClient::Manager::ESX::Test");
956
957 eval {
958     # Create a new session.
959     my $session = HoneyClient::Manager::ESX->login();
960    
961     # Start the test VM.
962     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
963
964     # Clone the test VM.
965     my $cloneVM = HoneyClient::Manager::ESX->quickCloneVM(session => $session, src_name => $testVM);
966     ok($cloneVM, "quickCloneVM(src_name => '$testVM')") or diag("The quickCloneVM() call failed.");
967
968     # Verify that the clone VM is a quick clone.
969     my $isQuickClone = HoneyClient::Manager::ESX->isQuickCloneVM(session => $session, name => $cloneVM);
970     ok($isQuickClone, "quickCloneVM(src_name => '$testVM')") or diag("The quickCloneVM() call failed.");
971
972     # Get the power state of the clone VM.
973     my $state = HoneyClient::Manager::ESX->getStateVM(session => $session, name => $cloneVM);
974
975     # The clone VM should be powered on.
976     is($state, "poweredon", "quickCloneVM(name => '$testVM')") or diag("The quickCloneVM() call failed.");
977    
978     # Destroy the clone VM.
979     HoneyClient::Manager::ESX->destroyVM(session => $session, name => $cloneVM);
980    
981     # Start the test VM.
982     HoneyClient::Manager::ESX->startVM(session => $session, name => $testVM);
983    
984     # Stop the test VM.
985     HoneyClient::Manager::ESX->stopVM(session => $session, name => $testVM);
986
987     # Destroy the session.
988     HoneyClient::Manager::ESX->logout(session => $session);
989 };
990
991 # Report any failure found.
992 if ($@) {
993     fail($@);
994 }
995 }
996
997
998
999
1000 1;
Note: See TracBrowser for help on using the browser.