Changeset 816

Show
Ignore:
Timestamp:
09/05/07 10:47:29 (1 year ago)
Author:
kindlund
Message:

Updated unit testing and Clone integration with VM daemon.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/branches/exp/kindlund-dynamic_updates/lib/HoneyClient/Manager.pm

    r814 r816  
    239239use HoneyClient::Util::Config qw(getVar); 
    240240 
     241# Check if HoneyClient::DB support is enabled.  
     242my $DB_ENABLE = getVar(name      => "enable", 
     243                       namespace => "HoneyClient::DB"); 
     244 
     245if ($DB_ENABLE) { 
     246    # Make sure HoneyClient::DB::Fingerprint loads.  
     247    require_ok('HoneyClient::DB::Fingerprint'); 
     248    require HoneyClient::DB::Fingerprint; 
     249} 
     250 
    241251# Make sure Storable loads. 
    242252BEGIN { use_ok('Storable', qw(nfreeze thaw)) or diag("Can't load Storable package.  Check to make sure the package library is correctly listed within the path."); } 
     
    275285use HoneyClient::Manager::VM qw(); 
    276286 
    277 # Check if DB support is enabled.  
     287# Check if HoneyClient::DB support is enabled.  
    278288our $DB_ENABLE = getVar(name      => "enable", 
    279289                        namespace => "HoneyClient::DB"); 
    280290 
    281291if ($DB_ENABLE) { 
    282     # Include DB Utility Library 
    283     # TODO: Include unit tests. 
     292    # Include HoneyClient::DB Utility Libraries 
    284293    require HoneyClient::DB::Fingerprint; 
    285294} 
     
    325334 
    326335# XXX: These will be migrated somewhere else, eventually. 
    327 our $vmStateTable = { }; 
    328336our $vmCloneConfig      = undef; 
    329 our $stubVM             = undef; 
    330 our $stubAgent          = undef; 
    331 our $stubFW             = undef; 
    332337 
    333338# This is a temporary, shared variable, used to print out the 
     
    336341# eventually. 
    337342our $globalAgentState   = undef; 
    338  
    339 # This static variable may contain a filename that the Manager 
    340 # would use to dump its entire state information, upon termination. 
    341 # XXX: May want to change this format/usage, eventually. 
    342 our $STATE_FILE = getVar(name => "manager_state"); 
    343343 
    344344# Temporary variable, used to indicate to the fault handler whether 
     
    493493        # Hence, rather than fight the VM daemon's natural self termination, 
    494494        # we let the daemon die, but the create a new one, for the sole purpose 
    495         # of cleanup up the clones. 
     495        # of cleaning up the clones. 
    496496        HoneyClient::Manager::VM->init(); 
    497497        $LOG->info("Calling suspendVM(config => " . $vmCloneConfig . ")."); 
     
    502502    } 
    503503 
     504    # This variable may contain a filename that the Manager 
     505    # would use to dump its entire state information, upon termination. 
    504506    # XXX: May want to change this format/usage, eventually. 
     507    my $STATE_FILE = getVar(name => "manager_state"); 
     508 
    505509    if (length($STATE_FILE) > 0 && 
    506510        defined($globalAgentState)) { 
     
    600604    my ($class, %args) = @_; 
    601605 
     606    my $stubVM    = undef; 
     607    my $stubFW    = undef; 
     608    my $stubAgent = undef; 
    602609    my $som       = undef; 
    603610    my $ret       = undef; 
     
    608615    my $vmState   = undef; 
    609616    my $vmCompromised = 0; 
     617    my $vmStateTable = { }; 
    610618 
    611619    # Get a stub connection to the firewall. 
  • honeyclient/branches/exp/kindlund-dynamic_updates/lib/HoneyClient/Manager/VM.pm

    r814 r816  
    307307use Carp (); 
    308308 
     309# XXX: Check this. 
    309310# Traps signals, allowing END: blocks to perform cleanup. 
    310 use sigtrap qw(die untrapped normal-signals error-signals); 
     311#use sigtrap qw(die untrapped normal-signals error-signals); 
    311312 
    312313####################################################################### 
     
    767768        } 
    768769 
     770        # XXX: Check this. 
    769771        # Do not attempt to rejoin parent process tree, 
    770772        # if any type of termination signal is received. 
    771         local $SIG{HUP} = sub { exit; }; 
    772         local $SIG{INT} = sub { exit; }; 
    773         local $SIG{QUIT} = sub { exit; }; 
    774         local $SIG{ABRT} = sub { exit; }; 
    775         local $SIG{PIPE} = sub { exit; }; 
    776         local $SIG{TERM} = sub { exit; }; 
     773        # local $SIG{HUP} = sub { exit; }; 
     774        # local $SIG{INT} = sub { exit; }; 
     775        # local $SIG{QUIT} = sub { exit; }; 
     776        # local $SIG{ABRT} = sub { exit; }; 
     777        # local $SIG{PIPE} = sub { exit; }; 
     778        # local $SIG{TERM} = sub { exit; }; 
    777779 
    778780        my $daemon = getServerHandle(address => $args{'address'}, 
     
    47764778    # Disconnect from the VMware Server / GSX host. 
    47774779    _disconnect(); 
     4780 
    47784781} 
    47794782 
  • honeyclient/branches/exp/kindlund-dynamic_updates/lib/HoneyClient/Manager/VM/Clone.pm

    r814 r816  
    127127use Config; 
    128128use Carp (); 
     129 
     130# XXX: Verify this. 
     131# Traps signals, allowing END: blocks to perform cleanup. 
     132#use sigtrap qw(die untrapped normal-signals error-signals); 
     133use sigtrap qw(die untrapped normal-signals); 
    129134 
    130135####################################################################### 
     
    438443 
    439444    if (($OBJECT_COUNT >= 0) && defined($self->{'config'})) { 
     445        
     446        # Initialize a new handler, but suppress any initial connection errors. 
     447        $self->{'_vm_handle'} = getClientHandle(namespace => "HoneyClient::Manager::VM", 
     448                                                fault_handler => sub { die "ERROR"; }); 
     449 
    440450        $LOG->info("Suspending clone VM (" . $self->{'config'} . ")."); 
    441         my $som = $self->{'_vm_handle'}->suspendVM(config => $self->{'config'}); 
    442         if (!$som->result()) { 
     451        my $som = undef; 
     452        eval { 
     453            $som = $self->{'_vm_handle'}->suspendVM(config => $self->{'config'}); 
     454        }; 
     455 
     456        # Reinitialize the VM daemon, in case it died from 
     457        # a CTRL-C or other forced termination. 
     458        unless(defined($som)) { 
     459            # Make sure the VM daemon was properly destroyed. 
     460            HoneyClient::Manager::VM->destroy(); 
     461             
     462            # Sleep a bit, in order for the terminated VM daemon to release 
     463            # its network bindings. 
     464            sleep(10); 
     465 
     466            # Reinitialize VM daemon. 
     467            HoneyClient::Manager::VM->init(); 
     468 
     469            # Reinitialize handler, with errors not suppressed. 
     470            $self->{'_vm_handle'} = getClientHandle(namespace => "HoneyClient::Manager::VM"); 
     471 
     472            # Call suspendVM one more time... 
     473            $som = $self->{'_vm_handle'}->suspendVM(config => $self->{'config'}); 
     474        } 
     475 
     476        if (!defined($som)) { 
    443477            $LOG->error("Unable to suspend VM (" . $self->{'config'} . ")."); 
    444478        } 
     479 
    445480    } 
    446481 
     
    670705    # Now, kill the VM daemon. 
    671706    HoneyClient::Manager::VM->destroy(); 
    672     sleep (1); 
     707    sleep (10); 
    673708 
    674709    # Create a generic empty clone, with test state data. 
  • honeyclient/branches/exp/kindlund-dynamic_updates/t/honeyclient_manager.t

    r814 r816  
    8383use HoneyClient::Util::Config qw(getVar); 
    8484 
     85# Check if HoneyClient::DB support is enabled.  
     86my $DB_ENABLE = getVar(name      => "enable", 
     87                       namespace => "HoneyClient::DB"); 
     88 
     89if ($DB_ENABLE) { 
     90    # Make sure HoneyClient::DB::Fingerprint loads.  
     91    require_ok('HoneyClient::DB::Fingerprint'); 
     92    require HoneyClient::DB::Fingerprint; 
     93} 
     94 
    8595# Make sure Storable loads. 
    8696BEGIN { use_ok('Storable', qw(nfreeze thaw)) or diag("Can't load Storable package.  Check to make sure the package library is correctly listed within the path."); } 
  • honeyclient/branches/exp/kindlund-dynamic_updates/t/honeyclient_manager_vm_clone.t

    r814 r816  
    157157    # Now, kill the VM daemon. 
    158158    HoneyClient::Manager::VM->destroy(); 
    159     sleep (1); 
     159    sleep (10); 
    160160 
    161161    # Create a generic empty clone, with test state data.