Author: arkurth
Date: Wed Sep 8 19:24:23 2010
New Revision: 995213
URL: http://svn.apache.org/viewvc?rev=995213&view=rev
Log:
VCL-221
Updated code which checks if the OS post-load tasks have run before reserving a
computer. The code in new.pm would attempt to call post_load regardless of the
provisioning module being used. The OS module's post_load subroutine should
only be called by the provisioning modules so they have the flexibility to call
it or not. Added 'POST_LOAD' return value option for provisioning modules'
node_status subroutines. Code in new.pm checks for this return string and
calls post_load if necessary.
Added check in OS.pm::get_vcld_post_load_status to make sure the OS module
implements a post_load subroutine. If not, it returns true indicating
post_load doesn't need to be called.
Updated OS.pm::set_vcld_post_load_status to check the OS type, and set the
correct line endings in currentimage.txt based on if the OS is Windows or not.
Other
Reworked utils.pm::nmap_port to call run_command.
Fixed bug in utils.pm::run_ssh_command where it was checking if the command was
a VMware command. It was checking the output rather than the command string.
Fixed typo in utils.pm::get_management_node_info.
Modified:
incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm
incubator/vcl/trunk/managementnode/lib/VCL/new.pm
incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm?rev=995213&r1=995212&r2=995213&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm Wed Sep 8 19:24:23
2010
@@ -698,13 +698,18 @@ sub get_vcld_post_load_status {
return;
}
+ # Make sure the OS module implements a post load subroutine
+ if (!$self->can('post_load')) {
+ notify($ERRORS{'DEBUG'}, 0, "OS module " . ref($self) . " does
not implement a post_load subroutine, returning 1");
+ return 1;
+ }
+
my $management_node_keys = $self->data->get_management_node_keys();
my $computer_node_name = $self->data->get_computer_node_name();
# Add a line to the end of currentimage.txt
my $command = "grep vcld_post_load= currentimage.txt";
-
my ($exit_status, $output) = run_ssh_command($computer_node_name,
$management_node_keys, $command, '', '', 0);
if (defined($output)) {
if (my ($status_line) = grep(/vcld_post_load=/, @$output)) {
@@ -749,7 +754,8 @@ sub set_vcld_post_load_status {
notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
return;
}
-
+
+ my $image_os_type = $self->data->get_image_os_type();
my $management_node_keys = $self->data->get_management_node_keys();
my $computer_node_name = $self->data->get_computer_node_name();
@@ -761,17 +767,28 @@ sub set_vcld_post_load_status {
my $command;
# Remove existing lines beginning with vcld_post_load
- $command .= "sed -i -e \"/^vcld_post_load.*/d\" currentimage.txt";
-
+ $command .= "sed -i -e \'/vcld_post_load.*/d\' currentimage.txt";
+
# Add a line to the end of currentimage.txt
- $command .= " && echo -E \"$post_load_line\" >> currentimage.txt";
+ $command .= " && echo >> currentimage.txt";
+ $command .= " && echo \"$post_load_line\" >> currentimage.txt";
+
+ # Remove blank lines
+ $command .= ' && sed -i -e \'/^[\\s\\r\\n]*$/d\' currentimage.txt';
+
+ if ($image_os_type =~ /windows/i) {
+ $command .= " && unix2dos currentimage.txt";
+ }
+ else {
+ $command .= " && dos2unix currentimage.txt";
+ }
my ($exit_status, $output) = run_ssh_command($computer_node_name,
$management_node_keys, $command, '', '', 1);
if (defined($exit_status) && $exit_status == 0) {
- notify($ERRORS{'DEBUG'}, 0, "added line to currentimage.txt on
$computer_node_name: $post_load_line");
+ notify($ERRORS{'DEBUG'}, 0, "added line to currentimage.txt on
$computer_node_name: '$post_load_line'");
}
elsif ($exit_status) {
- notify($ERRORS{'WARNING'}, 0, "failed to add line to
currentimage.txt on $computer_node_name: $post_load_line, exit status:
$exit_status, output:\n" . join("\n", @$output));
+ notify($ERRORS{'WARNING'}, 0, "failed to add line to
currentimage.txt on $computer_node_name: '$post_load_line', exit status:
$exit_status, output:\n" . join("\n", @$output));
return;
}
else {
Modified: incubator/vcl/trunk/managementnode/lib/VCL/new.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/new.pm?rev=995213&r1=995212&r2=995213&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/new.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/new.pm Wed Sep 8 19:24:23 2010
@@ -592,15 +592,35 @@ sub reload_image {
$node_status_string = 'reload';
}
- # Check the status string returned by node_status = 'ready'
+ # Check if the status string returned by node_status = 'ready'
if ($node_status_string =~ /^ready/i) {
# node_status returned 'ready'
notify($ERRORS{'OK'}, 0, "node_status returned
'$node_status_string', $computer_short_name will not be reloaded");
insertloadlog($reservation_id, $computer_id, "info", "node
status is $node_status_string, $computer_short_name will not be reloaded");
}
- # node_status did not return 'ready'
- else {
+ elsif ($node_status_string =~ /^post_load/i) {
+ notify($ERRORS{'OK'}, 0, "node_status returned
'$node_status_string', OS post_load tasks will be performed on
$computer_short_name");
+
+ # Check if the OS module implements a post_load subroutine and
that post_load has been run
+ if ($self->os->can('post_load')) {
+ if ($self->os->post_load()) {
+ # Add the vcld_post_load line to
currentimage.txt
+ $self->os->set_vcld_post_load_status();
+ $node_status_string = 'READY';
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "failed to
execute OS module's post_load() subroutine, $computer_short_name will be
reloaded");
+ $node_status_string = 'POST_LOAD_FAILED';
+ }
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "provisioning module's
node_status subroutine returned '$node_status' but OS module " . ref($self->os)
. " does not implement a post_load() subroutine, $computer_short_name will not
be reloaded");
+ }
+ }
+
+ # Provisioning module's node_status subroutine did not return 'ready'
+ if ($node_status_string !~ /^ready/i) {
notify($ERRORS{'OK'}, 0, "node status is $node_status_string,
$computer_short_name will be reloaded");
insertloadlog($reservation_id, $computer_id, "loadimageblade",
"$computer_short_name must be reloaded with $image_name");
@@ -694,9 +714,6 @@ sub reload_image {
notify($ERRORS{'WARNING'}, 0, "failed to update computer table
for $computer_short_name: currentimageid=$image_id");
}
- # Add the vcld_post_load line to currentimage.txt
- $self->os->set_vcld_post_load_status();
-
notify($ERRORS{'OK'}, 0, "returning 1");
return 1;
} ## end sub reload_image
@@ -1009,20 +1026,6 @@ sub reserve_computer {
if ($computer_type =~ /blade|virtualmachine/) {
- # Check if the OS module implements a post_load subroutine and
that post_load has been run
- if ($self->os->can('post_load') &&
!$self->os->get_vcld_post_load_status()) {
- # The OS module's post_load() tasks have not run
- notify($ERRORS{'DEBUG'}, 0, "calling OS module's
post_load() subroutine because currentimage.txt does not contain a
vcld_post_load= line");
-
- # Call OS::post_load()
- if ($self->os->post_load()) {
- # Add the vcld_post_load line to
currentimage.txt
- $self->os->set_vcld_post_load_status();}
- else {
- notify($ERRORS{'WARNING'}, 0, "failed to
execute OS module's post_load() subroutine");
- }
- }
-
if (!$self->os->update_public_ip_address()) {
$self->reservation_failed("failed to update private IP
address");
}
Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=995213&r1=995212&r2=995213&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Wed Sep 8 19:24:23 2010
@@ -2676,34 +2676,36 @@ sub _machine_os {
sub nmap_port {
my ($hostname, $port) = @_;
- my ($package, $filename, $line, $sub) = caller(0);
- notify($ERRORS{'WARNING'}, 0, "hostname is not defined") if
(!(defined($hostname)));
- notify($ERRORS{'WARNING'}, 0, "port is not defined") if
(!(defined($port)));
- my @file;
- my $l;
- if (open(NMAP, "/usr/bin/nmap $hostname -P0 -p $port -T Aggressive |"))
{
- @file = <NMAP>;
- close NMAP;
- foreach $l (@file) {
- if ($l =~ /open/) {
- return 1;
- }
- elsif ($l =~ /is: closed/) {
- return 0;
- }
- elsif ($l =~ /Host seems down/) {
- return 0;
- }
- elsif ($l =~ /filtered/) {
- return 0;
- }
- } ## end foreach $l (@file)
- } ## end if (open(NMAP, "/usr/bin/nmap $hostname -P0 -p $port -T
Aggressive |"...
+
+ if (!$hostname) {
+ notify($ERRORS{'WARNING'}, 0, "hostname argument was not
specified");
+ return;
+ }
+ if (!defined($port)) {
+ notify($ERRORS{'WARNING'}, 0, "port argument was not
specified");
+ return;
+ }
+
+ my $command = "/usr/bin/nmap $hostname -P0 -p $port -T Aggressive";
+ my ($exit_status, $output) = run_command($command, 1);
+
+ if (!defined($output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run nmap command on
management node: '$command'");
+ return;
+ }
+
+ if (grep(/open/i, @$output)) {
+ notify($ERRORS{'DEBUG'}, 0, "port $port is open on $hostname");
+ return 1;
+ }
+ elsif (grep(/(nmap:|warning)/i, @$output)) {
+ notify($ERRORS{'WARNING'}, 0, "error occurred running nmap
command: '$command', output:\n" . join("\n", @$output));
+ return;
+ }
else {
- notify($ERRORS{'WARNING'}, 0, "problems executing /usr/bin/nmap
$hostname -P0 -p $port $!");
+ notify($ERRORS{'DEBUG'}, 0, "port $port is closed on
$hostname");
return 0;
}
- return 0;
} ## end sub nmap_port
#/////////////////////////////////////////////////////////////////////////////
@@ -5508,7 +5510,7 @@ sub run_ssh_command {
# Check the exit status
# ssh exits with the exit status of the remote command or with
255 if an error occurred.
# Check for vmware-cmd usage message, it returns 255 if the
vmware-cmd usage output is returned
- if (($exit_status == 255 && $ssh_output_formatted !~
/(vmware-cmd|vim-cmd|vmkfstools)/i) ||
+ if (($exit_status == 255 && $ssh_command !~
/(vmware-cmd|vim-cmd|vmkfstools)/i) ||
$ssh_output_formatted =~ /(lost connection|reset by
peer|no route to host|connection refused|connection timed out|resource
temporarily unavailable)/i) {
notify($ERRORS{'WARNING'}, 0, "attempt
$attempts/$max_attempts: failed to execute SSH command on $node: $command, exit
status: $exit_status, SSH exits with the exit status of the remote command or
with 255 if an error occurred, output:\n$ssh_output_formatted") if
$output_level;
next;
@@ -6074,7 +6076,7 @@ AND managementnode.id != $management_nod
# Add the public IP address configuration variables
$management_node_info->{PUBLIC_IP_CONFIGURATION} =
$management_node_info->{publicIPconfiguration};
- $management_node_info->{PUBLIC_SUBNET_MASK} =
$management_node_info->{publicSubnetMmask};
+ $management_node_info->{PUBLIC_SUBNET_MASK} =
$management_node_info->{publicSubnetMask};
$management_node_info->{PUBLIC_DEFAULT_GATEWAY} =
$management_node_info->{publicDefaultGateway};
$management_node_info->{PUBLIC_DNS_SERVER} =
$management_node_info->{publicDNSserver};