[pve-devel] [PATCH pve-ha-manager 4/4] add service disable/enable/migrate to regression tests

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Dec 21 12:52:56 CET 2015


Allow execution of some service commands like enable, disable,
migrate and relocate.

Use variable 'victim' (as the victim of the command) which gets
parsed to a service ID (sid) or node name respective to the command.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Sim/TestHardware.pm                 | 35 +++++++++++++++++++++++---
 src/test/test-service-command1/README          |  2 ++
 src/test/test-service-command1/cmdlist         |  5 ++++
 src/test/test-service-command1/hardware_status |  5 ++++
 src/test/test-service-command1/log.expect      | 32 +++++++++++++++++++++++
 src/test/test-service-command1/manager_status  |  1 +
 src/test/test-service-command1/service_config  |  3 +++
 src/test/test-service-command2/README          |  1 +
 src/test/test-service-command2/cmdlist         |  4 +++
 src/test/test-service-command2/hardware_status |  5 ++++
 src/test/test-service-command2/log.expect      | 34 +++++++++++++++++++++++++
 src/test/test-service-command2/manager_status  |  1 +
 src/test/test-service-command2/service_config  |  3 +++
 13 files changed, 127 insertions(+), 4 deletions(-)
 create mode 100644 src/test/test-service-command1/README
 create mode 100644 src/test/test-service-command1/cmdlist
 create mode 100644 src/test/test-service-command1/hardware_status
 create mode 100644 src/test/test-service-command1/log.expect
 create mode 100644 src/test/test-service-command1/manager_status
 create mode 100644 src/test/test-service-command1/service_config
 create mode 100644 src/test/test-service-command2/README
 create mode 100644 src/test/test-service-command2/cmdlist
 create mode 100644 src/test/test-service-command2/hardware_status
 create mode 100644 src/test/test-service-command2/log.expect
 create mode 100644 src/test/test-service-command2/manager_status
 create mode 100644 src/test/test-service-command2/service_config

diff --git a/src/PVE/HA/Sim/TestHardware.pm b/src/PVE/HA/Sim/TestHardware.pm
index d666f7f..d791222 100644
--- a/src/PVE/HA/Sim/TestHardware.pm
+++ b/src/PVE/HA/Sim/TestHardware.pm
@@ -95,12 +95,23 @@ sub sim_hardware_cmd {
 
 	my $cstatus = $self->read_hardware_status_nolock();
 
-	my ($cmd, $node, $action) = split(/\s+/, $cmdstr);
+	my ($cmd, $victim, $action, $target) = split(/\s+/, $cmdstr);
 
-	die "sim_hardware_cmd: no node specified" if !$node;
+	die "sim_hardware_cmd: no node or service for command specified"
+	    if !$victim;
 
-	my $d = $self->{nodes}->{$node};
-	die "sim_hardware_cmd: no such node '$node'\n" if !$d;
+	my ($node, $sid, $d, $conf);
+
+	if ($cmd eq 'service') {
+	    $sid = PVE::HA::Tools::pve_verify_ha_resource_id($victim);
+	    $conf = $self->read_service_config();
+	    die "sim_hardware_cmd: no such service '$sid'\n"
+		if !($conf->{$sid});
+	} else {
+	    $node = $victim;
+	    $d = $self->{nodes}->{$node} ||
+		die "sim_hardware_cmd: no such node '$node'\n";
+	}
 
 	$self->log('info', "execute $cmdstr", $logid);
 	
@@ -150,6 +161,22 @@ sub sim_hardware_cmd {
 		$d->{lrm_restart} = 1;
 		$d->{lrm}->shutdown_request();
 	    }
+	} elsif ($cmd eq 'service') {
+	    if ($action eq 'enabled' || $action eq 'disabled') {
+
+		$conf->{$sid}->{state} = $action;
+		$self->write_service_config($conf);
+
+	    } elsif ($action eq 'migrate' || $action eq 'relocate') {
+
+		die "sim_hardware_cmd: no such $action target node '$target'\n"
+		    if !$self->{nodes}->{$target};
+		$self->queue_crm_commands("$action $sid $target", 1);
+
+	    } else {
+		die "sim_hardware_cmd: unknown service action '$action' " .
+		    " - not implemented\n" if !$d;
+	    }
 	} else {
 	    die "sim_hardware_cmd: unknown command '$cmdstr'\n";
 	}
diff --git a/src/test/test-service-command1/README b/src/test/test-service-command1/README
new file mode 100644
index 0000000..6e21415
--- /dev/null
+++ b/src/test/test-service-command1/README
@@ -0,0 +1,2 @@
+Test an user triggered service disable and enable cycle. The services should
+succesfully stop and then start again.
diff --git a/src/test/test-service-command1/cmdlist b/src/test/test-service-command1/cmdlist
new file mode 100644
index 0000000..815901d
--- /dev/null
+++ b/src/test/test-service-command1/cmdlist
@@ -0,0 +1,5 @@
+[
+    [ "power node1 on", "power node2 on", "power node3 on"],
+    [ "service vm:103 disabled" ],
+    [ "service vm:103 enabled" ]
+]
diff --git a/src/test/test-service-command1/hardware_status b/src/test/test-service-command1/hardware_status
new file mode 100644
index 0000000..451beb1
--- /dev/null
+++ b/src/test/test-service-command1/hardware_status
@@ -0,0 +1,5 @@
+{
+  "node1": { "power": "off", "network": "off" },
+  "node2": { "power": "off", "network": "off" },
+  "node3": { "power": "off", "network": "off" }
+}
diff --git a/src/test/test-service-command1/log.expect b/src/test/test-service-command1/log.expect
new file mode 100644
index 0000000..8e2d1f1
--- /dev/null
+++ b/src/test/test-service-command1/log.expect
@@ -0,0 +1,32 @@
+info      0     hardware: starting simulation
+info     20      cmdlist: execute power node1 on
+info     20    node1/crm: status change startup => wait_for_quorum
+info     20    node1/lrm: status change startup => wait_for_agent_lock
+info     20      cmdlist: execute power node2 on
+info     20    node2/crm: status change startup => wait_for_quorum
+info     20    node2/lrm: status change startup => wait_for_agent_lock
+info     20      cmdlist: execute power node3 on
+info     20    node3/crm: status change startup => wait_for_quorum
+info     20    node3/lrm: status change startup => wait_for_agent_lock
+info     20    node1/crm: got lock 'ha_manager_lock'
+info     20    node1/crm: status change wait_for_quorum => master
+info     20    node1/crm: node 'node1': state changed from 'unknown' => 'online'
+info     20    node1/crm: node 'node2': state changed from 'unknown' => 'online'
+info     20    node1/crm: node 'node3': state changed from 'unknown' => 'online'
+info     20    node1/crm: adding new service 'vm:103' on node 'node3'
+info     22    node2/crm: status change wait_for_quorum => slave
+info     24    node3/crm: status change wait_for_quorum => slave
+info     25    node3/lrm: got lock 'ha_agent_node3_lock'
+info     25    node3/lrm: status change wait_for_agent_lock => active
+info     25    node3/lrm: starting service vm:103
+info     25    node3/lrm: service status vm:103 started
+info    120      cmdlist: execute service vm:103 disabled
+info    120    node1/crm: service 'vm:103': state changed from 'started' to 'request_stop' 
+info    125    node3/lrm: stopping service vm:103
+info    125    node3/lrm: service status vm:103 stopped
+info    140    node1/crm: service 'vm:103': state changed from 'request_stop' to 'stopped' 
+info    220      cmdlist: execute service vm:103 enabled
+info    220    node1/crm: service 'vm:103': state changed from 'stopped' to 'started'  (node = node3)
+info    225    node3/lrm: starting service vm:103
+info    225    node3/lrm: service status vm:103 started
+info    820     hardware: exit simulation - done
diff --git a/src/test/test-service-command1/manager_status b/src/test/test-service-command1/manager_status
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/src/test/test-service-command1/manager_status
@@ -0,0 +1 @@
+{}
diff --git a/src/test/test-service-command1/service_config b/src/test/test-service-command1/service_config
new file mode 100644
index 0000000..c6860e7
--- /dev/null
+++ b/src/test/test-service-command1/service_config
@@ -0,0 +1,3 @@
+{
+    "vm:103": { "node": "node3", "state": "enabled" }
+}
diff --git a/src/test/test-service-command2/README b/src/test/test-service-command2/README
new file mode 100644
index 0000000..f8bffe3
--- /dev/null
+++ b/src/test/test-service-command2/README
@@ -0,0 +1 @@
+Test user triggered service migration.
diff --git a/src/test/test-service-command2/cmdlist b/src/test/test-service-command2/cmdlist
new file mode 100644
index 0000000..8c5a8ea
--- /dev/null
+++ b/src/test/test-service-command2/cmdlist
@@ -0,0 +1,4 @@
+[
+    [ "power node1 on", "power node2 on", "power node3 on"],
+    [ "service vm:103 migrate node1" ]
+]
diff --git a/src/test/test-service-command2/hardware_status b/src/test/test-service-command2/hardware_status
new file mode 100644
index 0000000..451beb1
--- /dev/null
+++ b/src/test/test-service-command2/hardware_status
@@ -0,0 +1,5 @@
+{
+  "node1": { "power": "off", "network": "off" },
+  "node2": { "power": "off", "network": "off" },
+  "node3": { "power": "off", "network": "off" }
+}
diff --git a/src/test/test-service-command2/log.expect b/src/test/test-service-command2/log.expect
new file mode 100644
index 0000000..397ccee
--- /dev/null
+++ b/src/test/test-service-command2/log.expect
@@ -0,0 +1,34 @@
+info      0     hardware: starting simulation
+info     20      cmdlist: execute power node1 on
+info     20    node1/crm: status change startup => wait_for_quorum
+info     20    node1/lrm: status change startup => wait_for_agent_lock
+info     20      cmdlist: execute power node2 on
+info     20    node2/crm: status change startup => wait_for_quorum
+info     20    node2/lrm: status change startup => wait_for_agent_lock
+info     20      cmdlist: execute power node3 on
+info     20    node3/crm: status change startup => wait_for_quorum
+info     20    node3/lrm: status change startup => wait_for_agent_lock
+info     20    node1/crm: got lock 'ha_manager_lock'
+info     20    node1/crm: status change wait_for_quorum => master
+info     20    node1/crm: node 'node1': state changed from 'unknown' => 'online'
+info     20    node1/crm: node 'node2': state changed from 'unknown' => 'online'
+info     20    node1/crm: node 'node3': state changed from 'unknown' => 'online'
+info     20    node1/crm: adding new service 'vm:103' on node 'node3'
+info     22    node2/crm: status change wait_for_quorum => slave
+info     24    node3/crm: status change wait_for_quorum => slave
+info     25    node3/lrm: got lock 'ha_agent_node3_lock'
+info     25    node3/lrm: status change wait_for_agent_lock => active
+info     25    node3/lrm: starting service vm:103
+info     25    node3/lrm: service status vm:103 started
+info    120      cmdlist: execute service vm:103 migrate node1
+info    120    node1/crm: got crm command: migrate vm:103 node1
+info    120    node1/crm: migrate service 'vm:103' to node 'node1' (running)
+info    120    node1/crm: service 'vm:103': state changed from 'started' to 'migrate'  (node = node3, target = node1)
+info    125    node3/lrm: service vm:103 - start migrate to node 'node1'
+info    125    node3/lrm: service vm:103 - end migrate to node 'node1'
+info    140    node1/crm: service 'vm:103': state changed from 'migrate' to 'started'  (node = node1)
+info    141    node1/lrm: got lock 'ha_agent_node1_lock'
+info    141    node1/lrm: status change wait_for_agent_lock => active
+info    141    node1/lrm: starting service vm:103
+info    141    node1/lrm: service status vm:103 started
+info    720     hardware: exit simulation - done
diff --git a/src/test/test-service-command2/manager_status b/src/test/test-service-command2/manager_status
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/src/test/test-service-command2/manager_status
@@ -0,0 +1 @@
+{}
diff --git a/src/test/test-service-command2/service_config b/src/test/test-service-command2/service_config
new file mode 100644
index 0000000..c6860e7
--- /dev/null
+++ b/src/test/test-service-command2/service_config
@@ -0,0 +1,3 @@
+{
+    "vm:103": { "node": "node3", "state": "enabled" }
+}
-- 
2.1.4





More information about the pve-devel mailing list