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