[pve-devel] [RFC pve-ha-manager 4/8] TestHardware: implement 'restart' & 'shutdown' action

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Dec 11 20:01:41 CET 2015


Add two graceful actions to the TestHardware:
*) shutdown: this executes a shutdown_request() to the lrm and
   powers the node off 5 time slices later.
   The plan is to not freeze services during that period so fencing
   kicks in, if the node does not comes back up fast enough, this
   will be implemented in the next patches.

*) restart: this makes an transition from on to off to on, where
   the transition isn't instantly but delayed by 5 time
   slices each.
   Here the services should be freezed and thus not fenced, which
   is the default case now.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Sim/TestHardware.pm | 47 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/PVE/HA/Sim/TestHardware.pm b/src/PVE/HA/Sim/TestHardware.pm
index 1e1f20c..5c8a0cd 100644
--- a/src/PVE/HA/Sim/TestHardware.pm
+++ b/src/PVE/HA/Sim/TestHardware.pm
@@ -131,18 +131,40 @@ sub sim_hardware_cmd {
 	my ($cmd, $node, $action) = split(/\s+/, $cmdstr);
 
 	die "sim_hardware_cmd: no node specified" if !$node;
-	die "sim_hardware_cmd: unknown action '$action'" if $action !~ m/^(on|off)$/;
+	die "sim_hardware_cmd: unknown action '$action'"
+	    if $action !~ m/^(on|off|shutdown|restart)$/;
 
 	my $d = $self->{nodes}->{$node};
 	die "sim_hardware_cmd: no such node '$node'\n" if !$d;
 
 	$self->log('info', "execute $cmdstr", $logid);
-	
+
+	# write current action earlier so that the current state is known to
+	# the Env, does not violate anything as we're in a locked context
+	$cstatus->{$node}->{currentaction} = $action;
+	$self->write_hardware_status_nolock($cstatus);
+
 	if ($cmd eq 'power') {
 	    if ($cstatus->{$node}->{power} ne $action) {
 		if ($action eq 'on') {	      
 		    $d->{crm} = PVE::HA::CRM->new($d->{crm_env}) if !$d->{crm};
 		    $d->{lrm} = PVE::HA::LRM->new($d->{lrm_env}) if !$d->{lrm};
+		} elsif ($action eq 'restart') {
+		    if ($d->{lrm}) {
+			$d->{lrm_env}->log('info', "reboot node");
+			$d->{lrm}->shutdown_request();
+			&$add_helper_cmd($self, $self->{cur_time}+5, "power $node off");
+			&$add_helper_cmd($self, $self->{cur_time}+10, "power $node on");
+		    }
+		} elsif ($action eq 'shutdown') {
+		    if ($d->{lrm}) {
+			$d->{lrm}->shutdown_request();
+			$d->{lrm_env}->log('info', "graceful shutdown");
+			&$add_helper_cmd($self, $self->{cur_time}+5, "power $node off");
+		    }
+		    if ($d->{crm}) {
+			$d->{crm_env}->log('info', "graceful shutdown");
+		    }
 		} else {
 		    if ($d->{crm}) {
 			$d->{crm_env}->log('info', "killed by poweroff");
@@ -192,13 +214,22 @@ sub run {
 
 	foreach my $node (@nodes) {
 
+	    my $cstatus = $self->read_hardware_status_nolock();
+
 	    my $d = $self->{nodes}->{$node};
 	    
 	    if (my $crm = $d->{crm}) {
 
 		$d->{crm_env}->loop_start_hook($self->get_time());
 
-		die "implement me (CRM exit)" if !$crm->do_one_iteration();
+		if (!$crm->do_one_iteration()) {
+		    if($cstatus->{$node}->{power} ne 'on') {
+			$self->log('info', "stopped CRM on '$node'");
+			$d->{crm} = undef;
+		    } else {
+			die "implement me (CRM '$node' exit)";
+		    }
+		}
 
 		$d->{crm_env}->loop_end_hook();
 
@@ -210,8 +241,14 @@ sub run {
 
 		$d->{lrm_env}->loop_start_hook($self->get_time());
 
-		die "implement me (LRM exit)" if !$lrm->do_one_iteration();
-
+		if (!$lrm->do_one_iteration()) {
+		    if ($cstatus->{$node}->{power} ne 'on') {
+			$self->log('info', "stopped LRM on '$node'");
+			$d->{lrm} = undef;
+		    } else {
+			die "implement me (LRM '$node' exit)";
+		    }
+		}
 		$d->{lrm_env}->loop_end_hook();
 
 		my $nodetime = $d->{lrm_env}->get_time();
-- 
2.1.4





More information about the pve-devel mailing list