[pve-devel] [PATCH ha-manager 08/13] Add stop command to simulation

Fabian Ebner f.ebner at proxmox.com
Thu Sep 26 13:38:54 CEST 2019


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

The name 'target' doesn't fit with the 'stop' command,
so I wanted to change it.
I went with 'param', but suggestions are welcome.

 src/PVE/HA/Sim/Hardware.pm | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index d2c0ec0..7e1a8bc 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -543,6 +543,7 @@ sub get_cfs_state {
 # restart-lrm <node>
 # service <sid> <started|disabled|stopped|ignored>
 # service <sid> <migrate|relocate> <target>
+# service <sid> stop <timeout>
 # service <sid> lock/unlock [lockname]
 
 sub sim_hardware_cmd {
@@ -553,7 +554,7 @@ sub sim_hardware_cmd {
 
 	my $cstatus = $self->read_hardware_status_nolock();
 
-	my ($cmd, $objid, $action, $target) = split(/\s+/, $cmdstr);
+	my ($cmd, $objid, $action, $param) = split(/\s+/, $cmdstr);
 
 	die "sim_hardware_cmd: no node or service for command specified"
 	    if !$objid;
@@ -617,10 +618,10 @@ sub sim_hardware_cmd {
 	} elsif ($cmd eq 'cfs') {
 	    die "sim_hardware_cmd: unknown cfs action '$action' for node '$node'"
 		if $action !~ m/^(rw|update)$/;
-	    die "sim_hardware_cmd: unknown cfs command '$target' for '$action' on node '$node'"
-		if $target !~ m/^(work|fail)$/;
+	    die "sim_hardware_cmd: unknown cfs command '$param' for '$action' on node '$node'"
+		if $param !~ m/^(work|fail)$/;
 
-	    $cstatus->{$node}->{cfs}->{$action} = $target eq 'work';
+	    $cstatus->{$node}->{cfs}->{$action} = $param eq 'work';
 	    $self->write_hardware_status_nolock($cstatus);
 
 	} elsif ($cmd eq 'reboot' || $cmd eq 'shutdown') {
@@ -656,13 +657,20 @@ sub sim_hardware_cmd {
 	    } elsif ($action eq 'migrate' || $action eq 'relocate') {
 
 		die "sim_hardware_cmd: missing target node for '$action' command"
-		    if !$target;
+		    if !$param;
 
-		$self->queue_crm_commands_nolock("$action $sid $target");
+		$self->queue_crm_commands_nolock("$action $sid $param");
+
+	    } elsif ($action eq 'stop') {
+
+		die "sim_hardware_cmd: missing timeout for '$action' command"
+		    if !defined($param);
+
+		$self->queue_crm_commands_nolock("$action $sid $param");
 
 	    } elsif ($action eq 'add') {
 
-		$self->add_service($sid, {state => 'started', node => $target});
+		$self->add_service($sid, {state => 'started', node => $param});
 
 	    } elsif ($action eq 'delete') {
 
@@ -670,11 +678,11 @@ sub sim_hardware_cmd {
 
 	    } elsif ($action eq 'lock') {
 
-		$self->lock_service($sid, $target);
+		$self->lock_service($sid, $param);
 
 	    } elsif ($action eq 'unlock') {
 
-		$self->unlock_service($sid, $target);
+		$self->unlock_service($sid, $param);
 
 	    } else {
 		die "sim_hardware_cmd: unknown service action '$action' " .
-- 
2.20.1





More information about the pve-devel mailing list