| 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 Log::Log4perl loads |
|---|
| 12 |
BEGIN { use_ok('Log::Log4perl', qw(:nowarn)) |
|---|
| 13 |
or diag("Can't load Log::Log4perl package. Check to make sure the package library is correctly listed within the path."); |
|---|
| 14 |
|
|---|
| 15 |
# Suppress all logging messages, since we need clean output for unit testing. |
|---|
| 16 |
Log::Log4perl->init({ |
|---|
| 17 |
"log4perl.rootLogger" => "DEBUG, Buffer", |
|---|
| 18 |
"log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", |
|---|
| 19 |
"log4perl.appender.Buffer.min_level" => "fatal", |
|---|
| 20 |
"log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", |
|---|
| 21 |
"log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", |
|---|
| 22 |
}); |
|---|
| 23 |
} |
|---|
| 24 |
require_ok('Log::Log4perl'); |
|---|
| 25 |
use Log::Log4perl qw(:easy); |
|---|
| 26 |
|
|---|
| 27 |
# Make sure HoneyClient::Util::Config loads. |
|---|
| 28 |
BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar)) |
|---|
| 29 |
or diag("Can't load HoneyClient::Util::Config 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 |
} |
|---|
| 41 |
require_ok('HoneyClient::Util::Config'); |
|---|
| 42 |
can_ok('HoneyClient::Util::Config', 'getVar'); |
|---|
| 43 |
use HoneyClient::Util::Config qw(getVar); |
|---|
| 44 |
|
|---|
| 45 |
# Make sure HoneyClient::Util::SOAP loads. |
|---|
| 46 |
BEGIN { use_ok('HoneyClient::Util::SOAP', qw(getClientHandle)) or diag("Can't load HoneyClient::Util::SOAP package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 47 |
require_ok('HoneyClient::Util::SOAP'); |
|---|
| 48 |
can_ok('HoneyClient::Util::SOAP', 'getClientHandle'); |
|---|
| 49 |
use HoneyClient::Util::SOAP qw(getClientHandle); |
|---|
| 50 |
|
|---|
| 51 |
# Make sure HoneyClient::Manager::VM loads. |
|---|
| 52 |
BEGIN { use_ok('HoneyClient::Manager::VM') or diag("Can't load HoneyClient::Manager:VM package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 53 |
require_ok('HoneyClient::Manager::VM'); |
|---|
| 54 |
use HoneyClient::Manager::VM; |
|---|
| 55 |
|
|---|
| 56 |
# Make sure VMware::VmPerl loads. |
|---|
| 57 |
BEGIN { use_ok('VMware::VmPerl', qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED)) or diag("Can't load VMware::VmPerl package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 58 |
require_ok('VMware::VmPerl'); |
|---|
| 59 |
use VMware::VmPerl qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED); |
|---|
| 60 |
|
|---|
| 61 |
# Make sure the module loads properly, with the exportable |
|---|
| 62 |
# functions shared. |
|---|
| 63 |
BEGIN { use_ok('HoneyClient::Manager::VM::Clone') or diag("Can't load HoneyClient::Manager::VM::Clone package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 64 |
require_ok('HoneyClient::Manager::VM::Clone'); |
|---|
| 65 |
use HoneyClient::Manager::VM::Clone; |
|---|
| 66 |
|
|---|
| 67 |
# Suppress all logging messages, since we need clean output for unit testing. |
|---|
| 68 |
Log::Log4perl->init({ |
|---|
| 69 |
"log4perl.rootLogger" => "DEBUG, Buffer", |
|---|
| 70 |
"log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", |
|---|
| 71 |
"log4perl.appender.Buffer.min_level" => "fatal", |
|---|
| 72 |
"log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", |
|---|
| 73 |
"log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", |
|---|
| 74 |
}); |
|---|
| 75 |
|
|---|
| 76 |
# Make sure Storable loads. |
|---|
| 77 |
BEGIN { use_ok('Storable', qw(dclone)) or diag("Can't load Storable package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 78 |
require_ok('Storable'); |
|---|
| 79 |
can_ok('Storable', 'dclone'); |
|---|
| 80 |
use Storable qw(dclone); |
|---|
| 81 |
|
|---|
| 82 |
# Make sure threads loads. |
|---|
| 83 |
BEGIN { use_ok('threads') or diag("Can't load threads package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 84 |
require_ok('threads'); |
|---|
| 85 |
use threads; |
|---|
| 86 |
|
|---|
| 87 |
# Make sure threads::shared loads. |
|---|
| 88 |
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."); } |
|---|
| 89 |
require_ok('threads::shared'); |
|---|
| 90 |
use threads::shared; |
|---|
| 91 |
|
|---|
| 92 |
# Make sure File::Basename loads. |
|---|
| 93 |
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."); } |
|---|
| 94 |
require_ok('File::Basename'); |
|---|
| 95 |
can_ok('File::Basename', 'dirname'); |
|---|
| 96 |
can_ok('File::Basename', 'basename'); |
|---|
| 97 |
use File::Basename qw(dirname basename); |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
# =begin testing |
|---|
| 103 |
{ |
|---|
| 104 |
# Shared test variables. |
|---|
| 105 |
my ($stub, $som, $URL); |
|---|
| 106 |
my $testVM = $ENV{PWD} . "/" . getVar(name => "test_vm_config", |
|---|
| 107 |
namespace => "HoneyClient::Manager::VM::Test"); |
|---|
| 108 |
|
|---|
| 109 |
# Catch all errors, in order to make sure child processes are |
|---|
| 110 |
# properly killed. |
|---|
| 111 |
eval { |
|---|
| 112 |
|
|---|
| 113 |
$URL = HoneyClient::Manager::VM->init(); |
|---|
| 114 |
|
|---|
| 115 |
# Connect to daemon as a client. |
|---|
| 116 |
$stub = getClientHandle(namespace => "HoneyClient::Manager::VM"); |
|---|
| 117 |
|
|---|
| 118 |
# In order to test setMasterVM(), we're going to fully clone |
|---|
| 119 |
# the testVM, then set the newly created clone as a master VM. |
|---|
| 120 |
|
|---|
| 121 |
# Get the test VM's parent directory, |
|---|
| 122 |
# in order to create a temporary master VM. |
|---|
| 123 |
my $testVMDir = dirname($testVM); |
|---|
| 124 |
my $masterVMDir = dirname($testVMDir) . "/test_vm_master"; |
|---|
| 125 |
my $masterVM = $masterVMDir . "/" . basename($testVM); |
|---|
| 126 |
|
|---|
| 127 |
# Create the master VM. |
|---|
| 128 |
$som = $stub->fullCloneVM(src_config => $testVM, dest_dir => $masterVMDir); |
|---|
| 129 |
|
|---|
| 130 |
# Wait a small amount of time for the asynchronous clone |
|---|
| 131 |
# to complete. |
|---|
| 132 |
sleep (60); |
|---|
| 133 |
|
|---|
| 134 |
# The master VM should be on. |
|---|
| 135 |
$som = $stub->getStateVM(config => $masterVM); |
|---|
| 136 |
|
|---|
| 137 |
# Since the master VM doesn't have an OS installed on it, |
|---|
| 138 |
# the VM may be considered stuck. Go ahead and answer |
|---|
| 139 |
# this question, if need be. |
|---|
| 140 |
if ($som->result == VM_EXECUTION_STATE_STUCK) { |
|---|
| 141 |
$som = $stub->answerVM(config => $masterVM); |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
HoneyClient::Manager::VM->destroy(); |
|---|
| 145 |
sleep (1); |
|---|
| 146 |
|
|---|
| 147 |
# Create a generic clone, with test state data. |
|---|
| 148 |
my $clone = HoneyClient::Manager::VM::Clone->new(test => 1, master_vm_config => $masterVM); |
|---|
| 149 |
is($clone->{test}, 1, "new(test => 1, master_vm_config => '$masterVM')") or diag("The new() call failed."); |
|---|
| 150 |
isa_ok($clone, 'HoneyClient::Manager::VM::Clone', "new(test => 1, master_vm_config => '$masterVM')") or diag("The new() call failed."); |
|---|
| 151 |
|
|---|
| 152 |
# Destroy the master VM. |
|---|
| 153 |
$som = $stub->destroyVM(config => $masterVM); |
|---|
| 154 |
}; |
|---|
| 155 |
|
|---|
| 156 |
# Kill the child daemon, if it still exists. |
|---|
| 157 |
HoneyClient::Manager::VM->destroy(); |
|---|
| 158 |
sleep (1); |
|---|
| 159 |
|
|---|
| 160 |
# Report any failure found. |
|---|
| 161 |
if ($@) { |
|---|
| 162 |
fail($@); |
|---|
| 163 |
} |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
1; |
|---|