Author: arkurth
Date: Thu May 18 20:17:29 2017
New Revision: 1795558

URL: http://svn.apache.org/viewvc?rev=1795558&view=rev
Log:
VCL-1048
Replaced calls in image.pm from legacy utils.pm::switch_state to state_exit and 
removed explicit calls to exit.

Renamed iptables.pm::sanitize_nat_reservation to nat_sanitize_reservation to 
match format of other NAT subroutines.

Added code to State.pm::state_exit to call nat_sanitize_reservation if NAT is 
used and (argument was passed to set log.ending or the next request state is 
(timeout|deleted|complete|image|checkpoint).

Removed call to sanitize_nat_reservation from reclaim.pm::process.

Modified:
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm
    vcl/trunk/managementnode/lib/VCL/Module/State.pm
    vcl/trunk/managementnode/lib/VCL/image.pm
    vcl/trunk/managementnode/lib/VCL/reclaim.pm

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm?rev=1795558&r1=1795557&r2=1795558&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm 
(original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm Thu 
May 18 20:17:29 2017
@@ -1380,7 +1380,7 @@ sub chain_exists {
 
 #//////////////////////////////////////////////////////////////////////////////
 
-=head2 sanitize_nat_reservation
+=head2 nat_sanitize_reservation
 
  Parameters  : $reservation_id (optional)
  Returns     : boolean
@@ -1389,7 +1389,7 @@ sub chain_exists {
 
 =cut
 
-sub sanitize_nat_reservation {
+sub nat_sanitize_reservation {
        my $self = shift;
        if (ref($self) !~ /VCL::Module/i) {
                notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");

Modified: vcl/trunk/managementnode/lib/VCL/Module/State.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/State.pm?rev=1795558&r1=1795557&r2=1795558&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/State.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/State.pm Thu May 18 20:17:29 2017
@@ -1004,6 +1004,24 @@ sub state_exit {
                }
        }
        
+       # If $request_log_ending was passed this should be the end of the 
reservation
+       # If NAT is used, rules added to the NAT host should be removed
+       if ($self->nathost_os(0) && $self->nathost_os->firewall() && 
$self->nathost_os->firewall->can('nat_sanitize_reservation')) {
+               my $nathost_hostname = $self->data->get_nathost_hostname();
+               my $nat_sanitize_needed = 0;
+               if ($request_log_ending) {
+                       notify($ERRORS{'DEBUG'}, 0, "attempting to sanitize 
firewall rules created for reservation $reservation_id on NAT host 
$nathost_hostname, \$request_log_ending argument was specified");
+                       $nat_sanitize_needed = 1;
+               }
+               elsif ($request_state_name_new && $request_state_name_new =~ 
/(timeout|deleted|complete|image|checkpoint)/) {
+                       notify($ERRORS{'DEBUG'}, 0, "attempting to sanitize 
firewall rules created for reservation $reservation_id on NAT host 
$nathost_hostname, next request state is '$request_state_name_new'");
+                       $nat_sanitize_needed = 1;
+               }
+               if ($nat_sanitize_needed) {
+                       $self->nathost_os->firewall->nat_sanitize_reservation();
+               }
+       }
+       
        # Update the computer state if argument was supplied
        if ($computer_state_name_new) {
                my $computer_state_name_old = 
$self->data->get_computer_state_name();

Modified: vcl/trunk/managementnode/lib/VCL/image.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/image.pm?rev=1795558&r1=1795557&r2=1795558&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/image.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/image.pm Thu May 18 20:17:29 2017
@@ -282,7 +282,7 @@ sub reservation_successful {
        }
        
        if ($request_state_name eq 'checkpoint') {
-               switch_state($request_data, 'reserved', 'checkpoint');
+               $self->state_exit('reserved', 'checkpoint');
        }
        else {
                # Insert reload request data into the datbase
@@ -291,10 +291,8 @@ sub reservation_successful {
                }
                
                # Switch the request state to complete, leave the computer 
state as is, update log ending to EOR, exit
-               switch_state($request_data, 'complete', '', 'EOR', '1');
+               $self->state_exit('complete', undef, 'EOR');
        }
-       
-       exit;
 } ## end sub reservation_successful
 
 #//////////////////////////////////////////////////////////////////////////////
@@ -349,25 +347,8 @@ sub reservation_failed {
                        mail($sysadmin_mail_address, $admin_subject, 
$admin_message, $affiliation_helpaddress);
                }
        }
-
-       # Update the request state to maintenance, laststate to image
-       if (update_request_state($request_id, "maintenance", 
$request_state_name)) {
-               notify($ERRORS{'OK'}, 0, "request state set to maintenance, 
laststate to $request_state_name");
-       }
-       else {
-               notify($ERRORS{'CRITICAL'}, 0, "unable to set request state to 
maintenance, laststate to image");
-       }
-
-       # Update the computer state to maintenance
-       if (update_computer_state($computer_id, "maintenance")) {
-               notify($ERRORS{'OK'}, 0, "$computer_shortname state set to 
maintenance");
-       }
-       else {
-               notify($ERRORS{'CRITICAL'}, 0, "unable to set 
$computer_shortname state to maintenance");
-       }
-
-       notify($ERRORS{'OK'}, 0, "exiting");
-       exit;
+       
+       $self->state_exit('maintenance', 'maintenance');
 } ## end sub reservation_failed
 
 #//////////////////////////////////////////////////////////////////////////////

Modified: vcl/trunk/managementnode/lib/VCL/reclaim.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/reclaim.pm?rev=1795558&r1=1795557&r2=1795558&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/reclaim.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/reclaim.pm Thu May 18 20:17:29 2017
@@ -127,25 +127,6 @@ sub process {
                }
        }
        
-       # Clean up rules on the NAT host if NAT is used
-       if ($self->nathost_os(0)) {
-               my $nathost_hostname = $self->data->get_nathost_hostname();
-               if ($self->nathost_os->firewall()) {
-                       if 
($self->nathost_os->firewall->can('sanitize_nat_reservation')) {
-                               if 
(!$self->nathost_os->firewall->sanitize_nat_reservation()) {
-                                       notify($ERRORS{'CRITICAL'}, 0, "failed 
to sanitize firewall for reservation on NAT host $nathost_hostname");
-                               }
-                       }
-                       else {
-                               notify($ERRORS{'WARNING'}, 0, "unable to 
sanitize firewall for reservation on NAT host $nathost_hostname, " . 
ref($self->nathost_os->firewall) . " does not implement a 
'sanitize_nat_reservation' subroutine");
-                       }
-                       
-               }
-               else {
-                       notify($ERRORS{'WARNING'}, 0, "unable to sanitize 
firewall for reservation on NAT host $nathost_hostname, NAT host OS firewall 
object is not available");
-               }
-       }
-       
        # Insert into computerloadlog if request state = timeout
        if ($request_state_name =~ /timeout|deleted/) {
                insertloadlog($reservation_id, $computer_id, 
$request_state_name, "reclaim: starting $request_state_name process");


Reply via email to