You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by ar...@apache.org on 2013/08/29 16:15:08 UTC

svn commit: r1518659 - in /vcl/trunk/managementnode/lib/VCL/Module: Provisioning/xCAT.pm State.pm

Author: arkurth
Date: Thu Aug 29 14:15:07 2013
New Revision: 1518659

URL: http://svn.apache.org/r1518659
Log:
VCL-711
Moved _check_image_os from State.pm to xCAT.pm. Moved call from State.pm::initialize to xCAT.pm::capture.

VCL-682
Added check to xCAT.pm::node_status to determine if currentimage.txt contains a vcld_post_load line. This was missing when the module was reworked.

Modified:
    vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT.pm
    vcl/trunk/managementnode/lib/VCL/Module/State.pm

Modified: vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT.pm?rev=1518659&r1=1518658&r2=1518659&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT.pm Thu Aug 29 14:15:07 2013
@@ -432,6 +432,11 @@ sub capture {
 	my $capture_done_file_path = "$image_repository_path/$image_name.img.capturedone";
 	my $capture_failed_file_path = "$image_repository_path/$image_name.img.capturefailed";
 	
+	# Check if image OS needs to be updated
+	if (!$self->_check_image_os()) {
+		return;
+	}
+	
 	# Print some preliminary information
 	notify($ERRORS{'OK'}, 0, "attempting to capture image '$image_name' on $computer_node_name");
 
@@ -747,6 +752,17 @@ sub node_status {
 		return $return_value;
 	}
 	
+	# Check if currentimage.txt contains a 'vcld_post_load' line
+	my $vcld_post_load_status = $self->data->get_computer_currentimage_vcld_post_load(0);
+	if ($vcld_post_load_status) {
+		notify($ERRORS{'DEBUG'}, 0, "OS module post_load tasks have been completed on VM $computer_node_name");
+	}
+	else {
+		my $return_value = 'POST_LOAD';
+		notify($ERRORS{'OK'}, 0, "OS module post_load tasks have not been completed on VM $computer_node_name, returning '$return_value'");
+		return $return_value;
+	}
+	
 	my $return_value = 'READY';
 	notify($ERRORS{'DEBUG'}, 0, "$computer_node_name is loaded with the correct image: $current_image_name, returning '$return_value'"); 
 	return $return_value;
@@ -2296,6 +2312,96 @@ sub _get_install_status {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 _check_image_os
+
+ Parameters  : none
+ Returns     : boolean
+ Description : For image captures, checks the OS in the VCL database of the
+               image to be captured. If capturing a Kickstart-based image, the
+               image OS needs to be changed to from the Kickstart OS entry to
+               the corresponding image OS entry.
+
+=cut
+
+sub _check_image_os {
+	my $self = shift;
+	if (ref($self) !~ /xCAT/i) {
+		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called as a class method");
+		return;
+	}
+	
+	my $request_state_name = $self->data->get_request_state_name();
+	my $image_id           = $self->data->get_image_id();
+	my $image_name         = $self->data->get_image_name();
+	my $image_os_name      = $self->data->get_image_os_name();
+	my $imagerevision_id   = $self->data->get_imagerevision_id();
+	my $image_architecture = $self->data->get_image_architecture();
+	
+	my $image_os_name_new;
+	if ($image_os_name =~ /^(rh)el[s]?([0-9])/ || $image_os_name =~ /^rh(fc)([0-9])/) {
+		# Change rhelX --> rhXimage, rhfcX --> fcXimage
+		$image_os_name_new = "$1$2image";
+	}
+	elsif($image_os_name =~ /^(centos)([0-9])/) {
+		# Change rhelX --> rhXimage, rhfcX --> fcXimage
+		$image_os_name_new = "$1$2image";
+	}
+	elsif ($image_os_name =~ /^(fedora)([0-9])/) {
+		# Change fedoraX --> fcXimage
+		$image_os_name_new = "fc$1image"
+	}
+	else {
+		notify($ERRORS{'DEBUG'}, 0, "no corrections need to be made to image OS: $image_os_name");
+		return 1;
+	}
+	
+	# Change the image name
+	$image_name =~ /^[^-]+-(.*)/;
+	my $image_name_new = "$image_os_name_new-$1";
+	
+	my $new_architecture = $image_architecture;
+	if ($image_architecture eq "x86_64" ) {
+		$new_architecture = "x86";
+	}
+	
+	notify($ERRORS{'OK'}, 0, "Kickstart image OS needs to be changed: $image_os_name -> $image_os_name_new, image name: $image_name -> $image_name_new");
+	
+	# Update the image table, change the OS for this image
+	my $sql_statement = <<EOF;
+UPDATE
+OS,
+image,
+imagerevision
+SET
+image.OSid = OS.id,
+image.architecture = '$new_architecture',
+image.name = '$image_name_new',
+imagerevision.imagename = '$image_name_new'
+WHERE
+image.id = $image_id
+AND imagerevision.id = $imagerevision_id
+AND OS.name = '$image_os_name_new'
+EOF
+	
+	# Update the image and imagerevision tables
+	if (database_execute($sql_statement)) {
+		notify($ERRORS{'OK'}, 0, "image ($image_id) and imagerevision ($imagerevision_id) tables updated: $image_name -> $image_name_new");
+	}
+	else {
+		notify($ERRORS{'WARNING'}, 0, "failed to update image and imagerevision tables: $image_name -> $image_name_new, returning 0");
+		return 0;
+	}
+	
+	if (!$self->data->refresh()) {
+		notify($ERRORS{'WARNING'}, 0, "failed to update DataStructure updated correcting image OS");
+		return 0;
+	}
+	
+	return 1;
+} ## end sub check_image_os
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 DESTROY
 
  Parameters  : none

Modified: vcl/trunk/managementnode/lib/VCL/Module/State.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/State.pm?rev=1518659&r1=1518658&r2=1518659&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/State.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/State.pm Thu Aug 29 14:15:07 2013
@@ -115,13 +115,6 @@ sub initialize {
 		$self->data->set_reservation_lastcheck_time($reservation_lastcheck);
 	}
 	
-	# TODO: Move this (VCL-711)
-	# Check the image OS before creating OS object
-	if (!$self->check_image_os()) {
-		notify($ERRORS{'WARNING'}, 0, "failed to check if image OS is correct");
-		return;
-	}
-	
 	# Set the PARENTIMAGE and SUBIMAGE keys in the request data hash
 	# These are deprecated, DataStructure's is_parent_reservation function should be used
 	$self->data->get_request_data->{PARENTIMAGE} = ($self->data->is_parent_reservation() + 0);
@@ -335,100 +328,6 @@ sub reservation_failed {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 check_image_os
-
- Parameters  :
- Returns     :
- Description :
-
-=cut
-
-
-sub check_image_os {
-	my $self               = shift;
-	my $request_state_name = $self->data->get_request_state_name();
-	my $image_id           = $self->data->get_image_id();
-	my $image_name         = $self->data->get_image_name();
-	my $image_os_name      = $self->data->get_image_os_name();
-	my $imagerevision_id   = $self->data->get_imagerevision_id();
-	my $image_architecture    = $self->data->get_image_architecture();
-
-	# Only make corrections if state is image
-	if ($request_state_name ne 'image') {
-		notify($ERRORS{'DEBUG'}, 0, "no corrections need to be made, not an imaging request, returning 1");
-		return 1;
-	}
-
-	my $image_os_name_new;
-	if ($image_os_name =~ /^(rh)el[s]?([0-9])/ || $image_os_name =~ /^rh(fc)([0-9])/) {
-		# Change rhelX --> rhXimage, rhfcX --> fcXimage
-		$image_os_name_new = "$1$2image";
-	}
-	elsif($image_os_name =~ /^(centos)([0-9])/) {
-		# Change rhelX --> rhXimage, rhfcX --> fcXimage
-		$image_os_name_new = "$1$2image";
-	}
-	elsif ($image_os_name =~ /^(fedora)([0-9])/) {
-		# Change fedoraX --> fcXimage
-		$image_os_name_new = "fc$1image"
-   }
-
-	else {
-		notify($ERRORS{'DEBUG'}, 0, "no corrections need to be made to image OS: $image_os_name");
-		return 1;
-	}
-
-	# Change the image name
-	$image_name =~ /^[^-]+-(.*)/;
-	my $image_name_new = "$image_os_name_new-$1";
-	
-	my $new_architecture = $image_architecture;
-	if ($image_architecture eq "x86_64" ) {
-		$new_architecture = "x86";
-	}
-
-	notify($ERRORS{'OK'}, 0, "Kickstart image OS needs to be changed: $image_os_name -> $image_os_name_new, image name: $image_name -> $image_name_new");
-
-	# Update the image table, change the OS for this image
-	my $sql_statement = "
-	UPDATE
-	OS,
-	image,
-	imagerevision
-	SET
-	image.OSid = OS.id,
-	image.architecture = \'$new_architecture'\,
-	image.name = \'$image_name_new\',
-	imagerevision.imagename = \'$image_name_new\'
-	WHERE
-	image.id = $image_id
-	AND imagerevision.id = $imagerevision_id
-	AND OS.name = \'$image_os_name_new\'
-	";
-
-	# Update the image and imagerevision tables
-	if (database_execute($sql_statement)) {
-		notify($ERRORS{'OK'}, 0, "image($image_id) and imagerevision($imagerevision_id) tables updated: $image_name -> $image_name_new");
-	}
-	else {
-		notify($ERRORS{'WARNING'}, 0, "failed to update image and imagerevision tables: $image_name -> $image_name_new, returning 0");
-		return 0;
-	}
-
-	if ($self->data->refresh()) {
-		notify($ERRORS{'DEBUG'}, 0, "DataStructure refreshed after correcting image OS");
-	}
-	else {
-		notify($ERRORS{'WARNING'}, 0, "failed to update DataStructure updated correcting image OS, returning 0");
-		return 0;
-	}
-	
-	notify($ERRORS{'DEBUG'}, 0, "returning 1");
-	return 1;
-} ## end sub check_image_os
-
-#/////////////////////////////////////////////////////////////////////////////
-
 =head2 does_loadstate_entry_exist
 
  Parameters  : $loadstate_name, $ignore_current_reservation (optional)