Author: arkurth Date: Fri Jul 17 14:18:32 2009 New Revision: 795094 URL: http://svn.apache.org/viewvc?rev=795094&view=rev Log: VCL-23 Fixed bug that occurred during image capture if Sysprep is disabled. It wasn't configuring the image to automatically log in root and run post_load.cmd. Added prepare_post_load() subroutine to Windows.pm which does this. Added code to Version_5.pm to call prepare_post_load() if Sysprep is disabled, otherwise run_sysprep() is called. Removed pre_capture() subroutines from XP.pm and 2003.pm. This is now implemented by Version_5.pm since the code was the same for XP and 2003. Also moved defrag step to before the parent pre_capture() sub implemented by Windows.pm is called. This causes the hard drive to be defragmented before the pagefile is disabled. This causes the defrag to take less time.
Also fixed bug in Windows.pm::filesystem_entry_exists(). It was replacing forward or backslashes in the path to be checked with a single backslash. This needs to be a double backslash or else it's seen as an escape character. Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/2003.pm incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/XP.pm Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm?rev=795094&r1=795093&r2=795094&view=diff ============================================================================== --- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm (original) +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm Fri Jul 17 14:18:32 2009 @@ -361,7 +361,7 @@ notify($ERRORS{'WARNING'}, 0, "unable to set sshd service startup mode to manual"); return 0; } - + =back =cut @@ -1096,7 +1096,7 @@ } # Replace any backslashes or forward slashes with \\ - $path =~ s/[\\\/]+/\\/g; + $path =~ s/[\\\/]+/\\\\/g; # Assemble the dir command and execute it my $dir_command = "cmd.exe /c dir /a /b \"$path\""; @@ -2897,6 +2897,66 @@ #///////////////////////////////////////////////////////////////////////////// +=head2 prepare_post_load + + Parameters : None. + Returns : If successful: true + If failed: false + Description : This subroutine should be called as the last step before an image + is captured if neither Sysprep nor NewSID is used. It enables + autoadminlogon so that root automatically logs on the next time + the computer is booted and creates a registry key under + HKLM\Software\Microsoft\Windows\CurrentVersion\Run. + + This key causes the post_load.cmd script after the image is + loaded when root automatically logs on. This script needs to run + in order to configure networking and the Cygwin SSH service. + +=cut + +sub prepare_post_load { + my $self = shift; + if (ref($self) !~ /windows/i) { + notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called as a class method"); + return; + } + + my $management_node_keys = $self->data->get_management_node_keys(); + my $computer_node_name = $self->data->get_computer_node_name(); + my $end_state = $self->{end_state} || 'off'; + + # Get the node configuration directory + my $node_configuration_directory = $self->get_node_configuration_directory(); + unless ($node_configuration_directory) { + notify($ERRORS{'WARNING'}, 0, "node configuration directory could not be determined"); + return; + } + + # Add HKLM run key to call post_load.cmd after the image comes up + if (!$self->add_hklm_run_registry_key('post_load.cmd', $node_configuration_directory . '/Scripts/post_load.cmd >> ' . $node_configuration_directory . '/Logs/post_load.log')) { + notify($ERRORS{'WARNING'}, 0, "unable to create run key to call post_load.cmd"); + return; + } + + # Enable autoadminlogon + if (!$self->enable_autoadminlogon()) { + notify($ERRORS{'WARNING'}, 0, "unable to enable autoadminlogon"); + return 0; + } + + # Shut down computer unless end_state argument was passed with a value other than 'off' + if ($end_state eq 'off') { + if (!$self->shutdown()) { + notify($ERRORS{'WARNING'}, 0, "failed to shut down computer"); + return; + } + } + + return 1; +} + +#///////////////////////////////////////////////////////////////////////////// + =head2 prepare_newsid Parameters : None. @@ -2904,20 +2964,20 @@ If failed: false Description : This subroutine prepares a computer to automatically run newsid.exe the next time it is booted. Newsid.exe is a utility - which generates a new SID (security identifier) for the computer. - - This subroutine enables autoadminlogon so that root automatically - logs on the next time the computer is booted. - - A registry key is created under - HKLM\Software\Microsoft\Windows\CurrentVersion\Run. - This key calls the run_newsid.cmd script. This script will run - as root when it automatically logs on. - - The run_newsid.cmd script runs newsid.exe, removes the HKLM...Run - key which caused itself to be called, and configures another - HKLM...Run key to call post_load.cmd at next logon. The script - then reboots the computer. + which generates a new SID (security identifier) for the computer. + + This subroutine enables autoadminlogon so that root automatically + logs on the next time the computer is booted. + + A registry key is created under + HKLM\Software\Microsoft\Windows\CurrentVersion\Run. + This key calls the run_newsid.cmd script. This script will run + as root when it automatically logs on. + + The run_newsid.cmd script runs newsid.exe, removes the HKLM...Run + key which caused itself to be called, and configures another + HKLM...Run key to call post_load.cmd at next logon. The script + then reboots the computer. =cut Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm?rev=795094&r1=795093&r2=795094&view=diff ============================================================================== --- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm (original) +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm Fri Jul 17 14:18:32 2009 @@ -82,6 +82,13 @@ notify($ERRORS{'OK'}, 0, "beginning Windows version 5 image capture preparation tasks"); + # Defragment the hard drive + # Do this in Version_5.pm because defrag works well enough on XP and 2003 + # Version 6 OS's (Vista) take a very long time to run defrag + if (!$self->defragment_hard_drive()) { + notify($ERRORS{'WARNING'}, 0, "unable to defragment the hard drive"); + } + # Call parent class's pre_capture() subroutine notify($ERRORS{'OK'}, 0, "calling parent class pre_capture() subroutine"); if ($self->SUPER::pre_capture($args)) { @@ -92,11 +99,18 @@ return 0; } - # Defragment the hard drive - # Do this in Version_5.pm because defrag works well enough on XP and 2003 - # Version 6 OS's (Vista) take a very long time to run defrag - if (!$self->defragment_hard_drive()) { - notify($ERRORS{'WARNING'}, 0, "unable to defragment the hard drive"); + # Check if Sysprep should be used + if ($self->data->get_imagemeta_sysprep()) { + if (!$self->run_sysprep()) { + notify($ERRORS{'WARNING'}, 0, "capture preparation failed, failed to run Sysprep"); + return; + } + } + else { + if (!$self->prepare_post_load()) { + notify($ERRORS{'WARNING'}, 0, "capture preparation failed, failed to run prepare post_load"); + return; + } } notify($ERRORS{'OK'}, 0, "returning 1"); Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/2003.pm URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/2003.pm?rev=795094&r1=795093&r2=795094&view=diff ============================================================================== --- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/2003.pm (original) +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/2003.pm Fri Jul 17 14:18:32 2009 @@ -72,54 +72,6 @@ our $SOURCE_CONFIGURATION_DIRECTORY = "$TOOLS/Windows_Server_2003"; -############################################################################## - -=head1 OBJECT METHODS - -=cut - -#///////////////////////////////////////////////////////////////////////////// - -=head2 pre_capture - - Parameters : - Returns : - Description : - -=cut - -sub pre_capture { - my $self = shift; - my $args = shift; - if (ref($self) !~ /windows/i) { - notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called as a class method"); - return; - } - - notify($ERRORS{'OK'}, 0, "beginning Windows Server 2003 image capture preparation tasks"); - - # Call parent class's pre_capture() subroutine - notify($ERRORS{'OK'}, 0, "calling parent class pre_capture() subroutine"); - if ($self->SUPER::pre_capture($args)) { - notify($ERRORS{'OK'}, 0, "successfully executed parent class pre_capture() subroutine"); - } - else { - notify($ERRORS{'WARNING'}, 0, "failed to execute parent class pre_capture() subroutine"); - return; - } - - # Check if Sysprep should be used - if ($self->data->get_imagemeta_sysprep()) { - if (!$self->run_sysprep()) { - notify($ERRORS{'WARNING'}, 0, "capture preparation failed, failed to run Sysprep"); - return; - } - } - - notify($ERRORS{'OK'}, 0, "returning 1"); - return 1; -} ## end sub pre_capture - #///////////////////////////////////////////////////////////////////////////// 1; Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/XP.pm URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/XP.pm?rev=795094&r1=795093&r2=795094&view=diff ============================================================================== --- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/XP.pm (original) +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5/XP.pm Fri Jul 17 14:18:32 2009 @@ -72,54 +72,6 @@ our $SOURCE_CONFIGURATION_DIRECTORY = "$TOOLS/Windows_XP"; -############################################################################## - -=head1 OBJECT METHODS - -=cut - -#///////////////////////////////////////////////////////////////////////////// - -=head2 pre_capture - - Parameters : - Returns : - Description : - -=cut - -sub pre_capture { - my $self = shift; - my $args = shift; - if (ref($self) !~ /windows/i) { - notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called as a class method"); - return; - } - - notify($ERRORS{'OK'}, 0, "beginning Windows XP image capture preparation tasks"); - - # Call parent class's pre_capture() subroutine - notify($ERRORS{'OK'}, 0, "calling parent class pre_capture() subroutine"); - if ($self->SUPER::pre_capture($args)) { - notify($ERRORS{'OK'}, 0, "successfully executed parent class pre_capture() subroutine"); - } - else { - notify($ERRORS{'WARNING'}, 0, "failed to execute parent class pre_capture() subroutine"); - return; - } - - # Check if Sysprep should be used - if ($self->data->get_imagemeta_sysprep()) { - if (!$self->run_sysprep()) { - notify($ERRORS{'WARNING'}, 0, "capture preparation failed, failed to run Sysprep"); - return; - } - } - - notify($ERRORS{'OK'}, 0, "returning 1"); - return 1; -} ## end sub pre_capture - #///////////////////////////////////////////////////////////////////////////// 1;