Changeset 1649

Show
Ignore:
Timestamp:
07/01/08 23:42:30 (3 months ago)
Author:
kindlund
Message:

Fixing ticket #173. Had to add a new test_vm-livecd, since our unit tests for getIPaddrVM were failing otherwise.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/etc/honeyclient.xml

    r1643 r1649  
    319319        <VM> 
    320320            <master_vm_config description="The full absolute path to the VM configuration file on the host system that will be used by all subsequent cloned VMs."> 
    321                 /vm/masters/Agent.Master-41-IE6/winXPPro.cfg 
     321                /vm/masters/Agent.Master-42-IE6/winXPPro.cfg 
    322322            </master_vm_config> 
    323323            <port description="The TCP port number that the SOAP server of the VM daemon will listen on for requests.  Note: This port should be unique and not already be used by other modules, services, or daemons running on the host system." default="7627"> 
     
    342342                26 
    343343            </vm_id_length> 
    344             <dhcp_log description="The absolute path to the file that contains the DHCP logs, when a new VM gets a DHCP lease from the VMware Server." default="/var/log/messages"> 
    345                 /var/log/messages 
    346             </dhcp_log
     344            <dhcp_leases description="The absolute path to the file that contains the DHCP leases, when a new VM gets a DHCP lease from the VMware Server." default="/etc/vmware/vmnet1/dhcpd/dhcpd.leases"> 
     345                /etc/vmware/vmnet1/dhcpd/dhcpd.leases 
     346            </dhcp_leases
    347347            <max_connect_retries description="When the VMware Server attempts to connect to any VM, it will repeatedly attempt to connect to the VM if the first attempt fails, for a maximum number of times specified by this value.  Generally, this value should not be changed, unless the host system has an exceptionally slow disk - in which case, increasing this value may help." default="5"> 
    348348                5 
     
    367367                    t/test_vm/winXPPro.vmx 
    368368                </test_vm_config> 
     369                <test_vm_config_livecd description="The relative path to the (livecd) test VM, that's used during unit testing." default="t/test_vm-livecd/winXPPro.vmx"> 
     370                    t/test_vm-livecd/winXPPro.vmx 
     371                </test_vm_config_livecd> 
    369372            </Test> 
    370373        </VM> 
  • honeyclient/trunk/lib/HoneyClient/Manager/VM.pm

    r1590 r1649  
    460460use DateTime::HiRes; 
    461461 
    462 # Make sure Fcntl loads. 
    463 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."); } 
    464 require_ok('Fcntl'); 
    465 use Fcntl qw(O_RDONLY); 
     462# Make sure Text::DHCPLeases loads. 
     463BEGIN { use_ok('Text::DHCPLeases') or diag("Can't load Text::DHCPLeases package.  Check to make sure the package library is correctly listed within the path."); } 
     464require_ok('Text::DHCPLeases'); 
     465use Text::DHCPLeases; 
     466 
     467# Make sure DateTime::Format::Natural loads. 
     468BEGIN { use_ok('DateTime::Format::Natural') or diag("Can't load DateTime::Format::Natural package.  Check to make sure the package library is correctly listed within the path."); } 
     469require_ok('DateTime::Format::Natural'); 
     470use DateTime::Format::Natural; 
    466471 
    467472# Make sure Config::General loads. 
     
    585590use File::Copy::Recursive qw(dircopy pathrmdir); 
    586591use File::Basename qw(dirname basename); 
    587 use Tie::File; 
    588 use Fcntl qw(O_RDONLY); 
    589592use Config::General; 
     593 
     594# Include DHCP Lease Analysis Libraries 
     595use Text::DHCPLeases; 
     596use DateTime::Format::Natural; 
    590597 
    591598# Include Thread Libraries 
     
    668675our $VM_ID_LENGTH   : shared = getVar(name => "vm_id_length"); 
    669676 
    670 # The log file that contains DHCP lease log entries. 
    671 our $DHCP_LOGFILE   : shared = getVar(name => "dhcp_log"); 
     677# The file that contains DHCP leases. 
     678our $DHCP_LEASES    : shared = getVar(name => "dhcp_leases"); 
    672679 
    673680####################################################################### 
     
    28492856                  namespace => "HoneyClient::Manager::VM"); 
    28502857my ($stub, $som, $URL); 
    2851 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config", 
     2858my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config_livecd", 
    28522859                                      namespace => "HoneyClient::Manager::VM::Test"); 
    28532860 
     
    28652872    $som = $stub->startVM(config => $testVM); 
    28662873 
    2867     # Wait 10 seconds, for the DHCP server to give the testVM 
     2874    # Wait 240 seconds, for the DHCP server to give the testVM 
    28682875    # a DHCP lease. 
    2869     sleep (10); 
     2876    sleep (240); 
    28702877 
    28712878    # Get the IP address of the test VM. 
     
    29442951    } 
    29452952 
    2946     my @logArray = undef; 
    2947     my $match = undef; 
     2953    # Now, let's determine the IP address from the DHCP leases file. 
    29482954    my $IP = undef; 
    29492955 
    2950     if (!tie(@logArray, 'Tie::File', $DHCP_LOGFILE, mode => O_RDONLY)) { 
    2951         $LOG->warn("Could not open DHCP log file ($DHCP_LOGFILE)."); 
    2952         die SOAP::Fault->faultcode(__PACKAGE__ . "->getIPaddrVM()") 
    2953                        ->faultstring("Could not open DHCP log file ($DHCP_LOGFILE)."); 
    2954     } 
    2955  
    2956     for (@logArray) { 
    2957         # Look for all lines that have the VM's MAC address and the keyword 
    2958         # DHCPACK or DHCPOFFER on it. 
    2959         if ((/DHCPACK/ || /DHCPOFFER/) && /$args{'mac_address'}/) { 
    2960             $match = $_; 
    2961             $match =~ s/^.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*$/$1/; 
    2962             if (defined($match) and ($match ne "")) { 
    2963                 $IP = $match; 
    2964             } 
    2965         } 
    2966     } 
    2967     untie @logArray; 
     2956    # Create a new DHCP leases parser. 
     2957    my $leases = Text::DHCPLeases->new(file => $DHCP_LEASES); 
     2958 
     2959    # Create a new DateTime parser. 
     2960    my $parser = DateTime::Format::Natural->new( 
     2961        lang => 'en', 
     2962        format => 'yyyy/mm/dd', 
     2963        prefer_future => 0, 
     2964        time_zone => 'UTC', 
     2965    ); 
     2966 
     2967    # Current date/time. 
     2968    my $dt_now = $parser->parse_datetime("now"); 
     2969 
     2970    # Helper function designed to parse DHCP lease datetime objects. 
     2971    sub parse_datetime { 
     2972        my ($parser,$string) = @_; 
     2973        # Remove the beginning weekday number. 
     2974        $string =~ s/\d (.*)/$1/; 
     2975        # Return a parsed DateTime object. 
     2976        return $parser->parse_datetime($string); 
     2977    } 
     2978 
     2979    # Iterate through the lease objects. 
     2980    foreach my $obj ($leases->get_objects()) { 
     2981        # Only look for leases. 
     2982        next if ($obj->type() ne 'lease'); 
     2983 
     2984        # Only look for leases that haven't expired. 
     2985        next if (($dt_now < parse_datetime($parser,$obj->starts)) || 
     2986                 ($dt_now > parse_datetime($parser,$obj->ends))); 
     2987 
     2988        if ($obj->mac_address eq $args{'mac_address'}) { 
     2989            $IP = $obj->name(); 
     2990            last; 
     2991        } 
     2992    } 
    29682993 
    29692994    return ($IP); 
     
    44334458 
    44344459    # Perform the snapshot operation... 
    4435    # XXX: Do this synchronously instead of asynchronously, since we've had problems running 
    4436    # this code in multi-threaded environments. 
     4460    # XXX: Do this synchronously instead of asynchronously, since we've had problems running 
     4461    # this code in multi-threaded environments. 
    44374462#    # Since this may take awhile, we perform the remaining operations in a child thread. 
    44384463#    my $thread = async { 
     
    49394964threads, threads::shared, Thread::Queue, Thread::Semaphore, perlthrtut 
    49404965 
    4941 POSIX, File::Copy, File::Copy::Recursive, File::Basename, Tie::File 
     4966POSIX, File::Copy, File::Copy::Recursive, File::Basename, Text::DHCPLeases 
    49424967 
    49434968Apache::SessionX::General::MD5 
  • honeyclient/trunk/t/honeyclient_manager_vm.t

    r1590 r1649  
    117117use DateTime::HiRes; 
    118118 
    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); 
     119# Make sure Text::DHCPLeases loads. 
     120BEGIN { use_ok('Text::DHCPLeases') or diag("Can't load Text::DHCPLeases package.  Check to make sure the package library is correctly listed within the path."); } 
     121require_ok('Text::DHCPLeases'); 
     122use Text::DHCPLeases; 
     123 
     124# Make sure DateTime::Format::Natural loads. 
     125BEGIN { use_ok('DateTime::Format::Natural') or diag("Can't load DateTime::Format::Natural package.  Check to make sure the package library is correctly listed within the path."); } 
     126require_ok('DateTime::Format::Natural'); 
     127use DateTime::Format::Natural; 
    123128 
    124129# Make sure Config::General loads. 
     
    761766                  namespace => "HoneyClient::Manager::VM"); 
    762767my ($stub, $som, $URL); 
    763 my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config", 
     768my $testVM = $ENV{PWD} . "/" . getVar(name      => "test_vm_config_livecd", 
    764769                                      namespace => "HoneyClient::Manager::VM::Test"); 
    765770 
     
    777782    $som = $stub->startVM(config => $testVM); 
    778783 
    779     # Wait 10 seconds, for the DHCP server to give the testVM 
     784    # Wait 240 seconds, for the DHCP server to give the testVM 
    780785    # a DHCP lease. 
    781     sleep (10); 
     786    sleep (240); 
    782787 
    783788    # Get the IP address of the test VM. 
  • honeyclient/trunk/t/test_vm-livecd/winXPPro.vmx

    r1008 r1649  
    88ide0:0.mode = "persistent" 
    99ide1:0.present = "TRUE" 
    10 ide1:0.fileName = "auto detect
    11 ide1:0.deviceType = "atapi-cdrom
     10ide1:0.fileName = "install-x86-minimal-2007.0-r1.iso
     11ide1:0.deviceType = "cdrom-image
    1212floppy0.fileName = "/dev/fd0" 
    1313usb.present = "FALSE" 
     
    2121powerType.reset = "soft" 
    2222 
    23 ide1:0.startConnected = "FALSE" 
     23ide1:0.startConnected = "TRUE" 
    2424floppy0.startConnected = "FALSE" 
    2525redoLogDir = "." 
    2626 
    27 uuid.location = "56 4d a4 e9 36 ce 79 71-8e bc 38 d2 b8 3e ed ea
    28 uuid.bios = "56 4d a4 e9 36 ce 79 71-8e bc 38 d2 b8 3e ed ea
     27uuid.location = "56 4d 67 c7 da f3 e5 cd-5a dc c8 79 9d 00 35 81
     28uuid.bios = "56 4d 67 c7 da f3 e5 cd-5a dc c8 79 9d 00 35 81
    2929 
    3030Ethernet0.present = "TRUE" 
    3131 
    3232Ethernet0.addressType = "generated" 
    33 ethernet0.generatedAddress = "00:0c:29:3e:ed:ea
     33ethernet0.generatedAddress = "00:0c:29:00:35:81
    3434ethernet0.generatedAddressOffset = "0" 
    3535 
     
    4040 
    4141Ethernet0.connectionType = "hostonly" 
     42 
     43uuid.action = "create" 
  • honeyclient/trunk/t/test_vm/winXPPro.vmx

    r1008 r1649  
    11#!/usr/bin/vmware 
     2 
     3Ethernet0.addressType = "generated" 
     4Ethernet0.connectionType = "hostonly" 
     5Ethernet0.present = "TRUE" 
     6Ethernet0.startConnected = "TRUE" 
    27config.version = "7" 
    3 virtualHW.version = "3" 
    4 scsi0.present = "TRUE" 
    5 memsize = "256" 
    6 ide0:0.present = "TRUE" 
     8displayName = "testVM" 
     9ethernet0.generatedAddress = "00:0c:29:e2:08:e8" 
     10ethernet0.generatedAddressOffset = "0" 
     11floppy0.fileName = "/dev/fd0" 
     12floppy0.startConnected = "FALSE" 
     13guestOS = "winxppro" 
     14ide0:0.deviceType = "ata-hardDisk" 
    715ide0:0.fileName = "winXPPro.vmdk" 
    816ide0:0.mode = "persistent" 
     17ide0:0.present = "TRUE" 
     18ide0:0.redo = "" 
     19ide1:0.deviceType = "atapi-cdrom" 
     20ide1:0.fileName = "auto detect" 
    921ide1:0.present = "TRUE" 
    10 ide1:0.fileName = "auto detect
    11 ide1:0.deviceType = "atapi-cdrom
    12 floppy0.fileName = "/dev/fd0
    13 usb.present = "FALSE
    14 displayName = "testVM
    15 guestOS = "winxppro
     22ide1:0.startConnected = "FALSE
     23memsize = "256
     24powerType.powerOff = "soft
     25powerType.powerOn = "soft
     26powerType.reset = "soft
     27powerType.suspend = "soft
    1628priority.grabbed = "normal" 
    1729priority.ungrabbed = "normal" 
    18 powerType.powerOff = "soft" 
    19 powerType.powerOn = "soft" 
    20 powerType.suspend = "soft" 
    21 powerType.reset = "soft" 
    22  
    23 ide1:0.startConnected = "FALSE" 
    24 floppy0.startConnected = "FALSE" 
    2530redoLogDir = "." 
    26  
    27 uuid.location = "56 4d a4 e9 36 ce 79 71-8e bc 38 d2 b8 3e ed ea" 
    28 uuid.bios = "56 4d a4 e9 36 ce 79 71-8e bc 38 d2 b8 3e ed ea" 
    29  
    30 Ethernet0.present = "TRUE" 
    31  
    32 Ethernet0.addressType = "generated" 
    33 ethernet0.generatedAddress = "00:0c:29:3e:ed:ea" 
    34 ethernet0.generatedAddressOffset = "0" 
    35  
    36 Ethernet0.startConnected = "TRUE" 
    37  
    38 ide0:0.redo = "" 
    39 ide0:0.deviceType = "ata-hardDisk" 
    40  
    41 Ethernet0.connectionType = "hostonly" 
     31scsi0.present = "TRUE" 
     32usb.present = "FALSE" 
     33uuid.bios = "56 4d 32 85 a0 59 c7 f7-64 37 b9 78 9f e2 08 e8" 
     34uuid.location = "56 4d 32 85 a0 59 c7 f7-64 37 b9 78 9f e2 08 e8" 
     35virtualHW.version = "3"