Author: arkurth Date: Fri Sep 23 18:21:12 2011 New Revision: 1174939 URL: http://svn.apache.org/viewvc?rev=1174939&view=rev Log: VCL-512 Fixed bug in Linux.pm's get_available_space and get_total_space subroutines. It now attempts to determine the block size by checking for either the 'Block size:' or 'Size:' value in the 'stat -f' output. Some versions only display 'Size:'.
Added error checking to VMware.pm in locations where it calls get_available_space. It wasn't checking to make sure a value was returned. As a result, divide by 0 errors occurred if available space couldn't be determined. Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm?rev=1174939&r1=1174938&r2=1174939&view=diff ============================================================================== --- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original) +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Fri Sep 23 18:21:12 2011 @@ -1607,9 +1607,11 @@ sub get_available_space { # Extract the block size value # Search case sensitive for 'Block size:' because the line may also contain "Fundamental block size:" - my ($block_size) = $output_string =~ /Block size: (\d+)/; + # Some versions of Linux may not display a "Size:" value instead of "Block size:" + # Blocks: Total: 8720776 Free: 8288943 Available: 7845951 Size: 4096 + my ($block_size) = $output_string =~ /(?:Block size|Size): (\d+)/; if (!$block_size) { - notify($ERRORS{'WARNING'}, 0, "unable to locate 'Block size:' value in stat output:\ncommand: $command\noutput:\n" . join("\n", @$output)); + notify($ERRORS{'WARNING'}, 0, "unable to locate 'Block size:' or 'Size:' value in stat output:\ncommand: $command\noutput:\n" . join("\n", @$output)); return; } @@ -1676,9 +1678,11 @@ sub get_total_space { # Extract the block size value # Search case sensitive for 'Block size:' because the line may also contain "Fundamental block size:" - my ($block_size) = $output_string =~ /Block size: (\d+)/; + # Some versions of Linux may not display a "Size:" value instead of "Block size:" + # Blocks: Total: 8720776 Free: 8288943 Available: 7845951 Size: 4096 + my ($block_size) = $output_string =~ /(?:Block size|Size): (\d+)/; if (!$block_size) { - notify($ERRORS{'WARNING'}, 0, "unable to locate 'Block size:' value in stat output:\ncommand: $command\noutput:\n" . join("\n", @$output)); + notify($ERRORS{'WARNING'}, 0, "unable to locate 'Block size:' or 'Size:' value in stat output:\ncommand: $command\noutput:\n" . join("\n", @$output)); return; } Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm?rev=1174939&r1=1174938&r2=1174939&view=diff ============================================================================== --- incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm (original) +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm Fri Sep 23 18:21:12 2011 @@ -2208,6 +2208,10 @@ sub check_vmhost_disk_space { my $vmdk_base_directory_path = $self->get_vmdk_base_directory_path(); my $vmx_volume_available_space = $self->vmhost_os->get_available_space($vmx_base_directory_path); + if (!defined($vmx_volume_available_space)) { + notify($ERRORS{'WARNING'}, 0, "failed to determine available space for the vmx directory on VM host $vmhost_name"); + return; + } # Figure out how much additional space is required for the vmx and vmdk directories my $vmx_additional_bytes_required = $self->get_vm_additional_vmx_bytes_required(); @@ -2241,6 +2245,10 @@ sub check_vmhost_disk_space { } else { my $vmdk_volume_available_space = $self->vmhost_os->get_available_space($vmdk_base_directory_path); + if (!defined($vmdk_volume_available_space)) { + notify($ERRORS{'WARNING'}, 0, "failed to determine available space for the vmdk directory on VM host $vmhost_name"); + return; + } $space_message .= "vmx additional space required: " . get_file_size_info_string($vmx_additional_bytes_required) . "\n"; $space_message .= "vmx volume available space: " . get_file_size_info_string($vmx_volume_available_space) . "\n"; @@ -4524,16 +4532,13 @@ sub get_vm_virtual_hardware_version { } - if (!$hardware_version && $self->api->can("get_virtual_disk_hardware_version")) { - $hardware_version = $self->api->get_virtual_disk_hardware_version($self->get_vmdk_file_path()); + if (!$hardware_version && $self->api->can("get_virtual_disk_hardware_version") && ($hardware_version = $self->api->get_virtual_disk_hardware_version($self->get_vmdk_file_path()))) { notify($ERRORS{'DEBUG'}, 0, "retrieved hardware version from api object: $hardware_version"); } - elsif (!$hardware_version) { - $hardware_version = $self->get_vmdk_parameter_value('virtualHWVersion'); - notify($ERRORS{'DEBUG'}, 0, "retrieved hardware version stored in the vmdk file: $hardware_version"); + elsif (!$hardware_version && ($hardware_version = $self->get_vmdk_parameter_value('virtualHWVersion'))) { + notify($ERRORS{'DEBUG'}, 0, "retrieved hardware version stored in the vmdk file: $hardware_version") if $hardware_version; } - - if (!$hardware_version) { + elsif (!$hardware_version) { notify($ERRORS{'WARNING'}, 0, "unable to determine hardware version of vmdk file, returning 7"); return 7; } @@ -5064,7 +5069,7 @@ sub delete_vm { delete $self->{vmx_info}{$vmx_file_path}; # Unregister the VM - if (!$self->api->vm_unregister($vmx_file_path)) { + if ($self->is_vm_registered($vmx_file_path) && !$self->api->vm_unregister($vmx_file_path)) { notify($ERRORS{'WARNING'}, 0, "failed to unregister VM: $vmx_file_path, VM not deleted"); return; }