[pve-devel] [PATCH pve-ha-manager 2/2] add service addition and deletion regression tests

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Jan 7 11:34:50 CET 2016


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Sim/Hardware.pm                     | 27 ++++++++++++++++++++++++++
 src/PVE/HA/Sim/TestHardware.pm                 |  8 ++++++++
 src/test/test-service-command5/README          |  1 +
 src/test/test-service-command5/cmdlist         |  4 ++++
 src/test/test-service-command5/hardware_status |  5 +++++
 src/test/test-service-command5/log.expect      | 25 ++++++++++++++++++++++++
 src/test/test-service-command5/manager_status  |  1 +
 src/test/test-service-command5/service_config  |  3 +++
 src/test/test-service-command6/README          |  1 +
 src/test/test-service-command6/cmdlist         |  4 ++++
 src/test/test-service-command6/hardware_status |  5 +++++
 src/test/test-service-command6/log.expect      | 24 +++++++++++++++++++++++
 src/test/test-service-command6/manager_status  |  1 +
 src/test/test-service-command6/service_config  |  1 +
 14 files changed, 110 insertions(+)
 create mode 100644 src/test/test-service-command5/README
 create mode 100644 src/test/test-service-command5/cmdlist
 create mode 100644 src/test/test-service-command5/hardware_status
 create mode 100644 src/test/test-service-command5/log.expect
 create mode 100644 src/test/test-service-command5/manager_status
 create mode 100644 src/test/test-service-command5/service_config
 create mode 100644 src/test/test-service-command6/README
 create mode 100644 src/test/test-service-command6/cmdlist
 create mode 100644 src/test/test-service-command6/hardware_status
 create mode 100644 src/test/test-service-command6/log.expect
 create mode 100644 src/test/test-service-command6/manager_status
 create mode 100644 src/test/test-service-command6/service_config

diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index adccf25..cfeba7e 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -127,6 +127,33 @@ sub set_service_state {
     return $conf;
 }
 
+sub add_service {
+    my ($self, $sid, $opts) = @_;
+
+    my $conf = $self->read_service_config();
+    die "resource ID '$sid' already defined\n" if $conf->{$sid};
+
+    $conf->{$sid} = $opts;
+
+    $self->write_service_config($conf);
+
+    return $conf;
+}
+
+sub delete_service {
+    my ($self, $sid) = @_;
+
+    my $conf = $self->read_service_config();
+
+    die "no such service '$sid'" if !$conf->{$sid};
+
+    delete $conf->{$sid};
+
+    $self->write_service_config($conf);
+
+    return $conf;
+}
+
 sub change_service_location {
     my ($self, $sid, $current_node, $new_node) = @_;
 
diff --git a/src/PVE/HA/Sim/TestHardware.pm b/src/PVE/HA/Sim/TestHardware.pm
index 6ba9404..d7f4efb 100644
--- a/src/PVE/HA/Sim/TestHardware.pm
+++ b/src/PVE/HA/Sim/TestHardware.pm
@@ -172,6 +172,14 @@ sub sim_hardware_cmd {
 
 		$self->queue_crm_commands_nolock("$action $sid $target");
 
+	    } elsif ($action eq 'add') {
+
+		$self->add_service($sid, {state => 'enabled', node => $target});
+
+	    } elsif ($action eq 'delete') {
+
+		$self->delete_service($sid);
+
 	    } else {
 		die "sim_hardware_cmd: unknown service action '$action' " .
 		    "- not implemented\n"
diff --git a/src/test/test-service-command5/README b/src/test/test-service-command5/README
new file mode 100644
index 0000000..e446ede
--- /dev/null
+++ b/src/test/test-service-command5/README
@@ -0,0 +1 @@
+Test user triggered service deletion.
diff --git a/src/test/test-service-command5/cmdlist b/src/test/test-service-command5/cmdlist
new file mode 100644
index 0000000..8ecc4db
--- /dev/null
+++ b/src/test/test-service-command5/cmdlist
@@ -0,0 +1,4 @@
+[
+    [ "power node1 on", "power node2 on", "power node3 on"],
+    [ "service vm:103 delete" ]
+]
diff --git a/src/test/test-service-command5/hardware_status b/src/test/test-service-command5/hardware_status
new file mode 100644
index 0000000..451beb1
--- /dev/null
+++ b/src/test/test-service-command5/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-command5/log.expect b/src/test/test-service-command5/log.expect
new file mode 100644
index 0000000..1bf014e
--- /dev/null
+++ b/src/test/test-service-command5/log.expect
@@ -0,0 +1,25 @@
+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 delete
+info    120    node1/crm: removing stale service 'vm:103' (no config)
+info    720     hardware: exit simulation - done
diff --git a/src/test/test-service-command5/manager_status b/src/test/test-service-command5/manager_status
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/src/test/test-service-command5/manager_status
@@ -0,0 +1 @@
+{}
diff --git a/src/test/test-service-command5/service_config b/src/test/test-service-command5/service_config
new file mode 100644
index 0000000..c6860e7
--- /dev/null
+++ b/src/test/test-service-command5/service_config
@@ -0,0 +1,3 @@
+{
+    "vm:103": { "node": "node3", "state": "enabled" }
+}
diff --git a/src/test/test-service-command6/README b/src/test/test-service-command6/README
new file mode 100644
index 0000000..bdf319e
--- /dev/null
+++ b/src/test/test-service-command6/README
@@ -0,0 +1 @@
+Test user triggered service addition.
diff --git a/src/test/test-service-command6/cmdlist b/src/test/test-service-command6/cmdlist
new file mode 100644
index 0000000..86840cc
--- /dev/null
+++ b/src/test/test-service-command6/cmdlist
@@ -0,0 +1,4 @@
+[
+    [ "power node1 on", "power node2 on", "power node3 on"],
+    [ "service vm:103 add node1" ]
+]
diff --git a/src/test/test-service-command6/hardware_status b/src/test/test-service-command6/hardware_status
new file mode 100644
index 0000000..451beb1
--- /dev/null
+++ b/src/test/test-service-command6/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-command6/log.expect b/src/test/test-service-command6/log.expect
new file mode 100644
index 0000000..947723a
--- /dev/null
+++ b/src/test/test-service-command6/log.expect
@@ -0,0 +1,24 @@
+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     22    node2/crm: status change wait_for_quorum => slave
+info     24    node3/crm: status change wait_for_quorum => slave
+info    120      cmdlist: execute service vm:103 add node1
+info    120    node1/crm: adding new service 'vm:103' on node 'node1'
+info    121    node1/lrm: got lock 'ha_agent_node1_lock'
+info    121    node1/lrm: status change wait_for_agent_lock => active
+info    121    node1/lrm: starting service vm:103
+info    121    node1/lrm: service status vm:103 started
+info    720     hardware: exit simulation - done
diff --git a/src/test/test-service-command6/manager_status b/src/test/test-service-command6/manager_status
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/src/test/test-service-command6/manager_status
@@ -0,0 +1 @@
+{}
diff --git a/src/test/test-service-command6/service_config b/src/test/test-service-command6/service_config
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/src/test/test-service-command6/service_config
@@ -0,0 +1 @@
+{}
-- 
2.1.4





More information about the pve-devel mailing list