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