[pve-devel] [PATCH ha-manager 2/6] replace service_config_exists with has_services
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Feb 8 14:39:04 CET 2016
Remove the "service_config_exists" method from the Environment class
and replace it with a new method in PVE::HA::Tools.
First we do not need this method in the Environment class and second
this can be reused more for checking if a note has any service
configured.
This moves the regression test also a little closer to the real
world behaviour (while maintaining determinism).
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/HA/CRM.pm | 4 ++--
src/PVE/HA/Env.pm | 6 ------
src/PVE/HA/Env/PVE2.pm | 6 ------
src/PVE/HA/Sim/Env.pm | 6 ------
src/PVE/HA/Tools.pm | 17 +++++++++++++++++
src/test/test-service-command5/log.expect | 2 ++
src/test/test-service-command6/log.expect | 14 +++++++-------
7 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/src/PVE/HA/CRM.pm b/src/PVE/HA/CRM.pm
index e9c1783..3eec1ff 100644
--- a/src/PVE/HA/CRM.pm
+++ b/src/PVE/HA/CRM.pm
@@ -138,7 +138,7 @@ sub do_one_iteration {
if ($state eq 'wait_for_quorum') {
if (!$pending_fencing && $haenv->quorate() &&
- $haenv->service_config_exists()) {
+ PVE::HA::Tools::has_services($haenv)) {
if ($self->get_protected_ha_manager_lock()) {
$self->set_local_status({ state => 'master' });
} else {
@@ -149,7 +149,7 @@ sub do_one_iteration {
} elsif ($state eq 'slave') {
if (!$pending_fencing && $haenv->quorate() &&
- $haenv->service_config_exists()) {
+ PVE::HA::Tools::has_services($haenv)) {
if ($self->get_protected_ha_manager_lock()) {
$self->set_local_status({ state => 'master' });
}
diff --git a/src/PVE/HA/Env.pm b/src/PVE/HA/Env.pm
index f60c90b..b5aba32 100644
--- a/src/PVE/HA/Env.pm
+++ b/src/PVE/HA/Env.pm
@@ -81,12 +81,6 @@ sub read_crm_commands {
return $self->{plug}->read_crm_commands();
}
-sub service_config_exists {
- my ($self) = @_;
-
- return $self->{plug}->service_config_exists();
-}
-
sub read_service_config {
my ($self) = @_;
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 77e75ac..e4b0535 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -109,12 +109,6 @@ sub read_crm_commands {
return PVE::HA::Config::read_crm_commands();
}
-sub service_config_exists {
- my ($self) = @_;
-
- return PVE::HA::Config::resources_config_exists();
-}
-
sub read_service_config {
my ($self) = @_;
diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm
index 5760192..e154988 100644
--- a/src/PVE/HA/Sim/Env.pm
+++ b/src/PVE/HA/Sim/Env.pm
@@ -159,12 +159,6 @@ sub is_node_shutdown {
return 0; # default to freezing services if not overwritten by subclass
}
-sub service_config_exists {
- my ($self) = @_;
-
- return 1;
-}
-
sub read_service_config {
my ($self) = @_;
diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm
index 2814453..b9bf842 100644
--- a/src/PVE/HA/Tools.pm
+++ b/src/PVE/HA/Tools.pm
@@ -146,6 +146,23 @@ sub write_json_to_file {
PVE::Tools::file_set_contents($filename, $raw);
}
+sub has_services {
+ my ($haenv, $node) = @_;
+
+ return undef if !PVE::HA::Config::resources_config_exists();
+
+ my $conf = $haenv->read_service_config();
+
+ # if no node defined any service count is fine
+ return scalar(%{$conf}) if !$node;
+
+ foreach my $d (values %$conf) {
+ return 1 if $d->{node} eq $node;
+ }
+
+ return undef;
+}
+
sub count_fenced_services {
my ($ss, $node) = @_;
diff --git a/src/test/test-service-command5/log.expect b/src/test/test-service-command5/log.expect
index 1bf014e..32506f1 100644
--- a/src/test/test-service-command5/log.expect
+++ b/src/test/test-service-command5/log.expect
@@ -22,4 +22,6 @@ 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 122 node2/crm: status change slave => wait_for_quorum
+info 124 node3/crm: status change slave => wait_for_quorum
info 720 hardware: exit simulation - done
diff --git a/src/test/test-service-command6/log.expect b/src/test/test-service-command6/log.expect
index 947723a..3ce4895 100644
--- a/src/test/test-service-command6/log.expect
+++ b/src/test/test-service-command6/log.expect
@@ -8,17 +8,17 @@ 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: got lock 'ha_manager_lock'
+info 120 node1/crm: status change wait_for_quorum => master
+info 120 node1/crm: node 'node1': state changed from 'unknown' => 'online'
+info 120 node1/crm: node 'node2': state changed from 'unknown' => 'online'
+info 120 node1/crm: node 'node3': state changed from 'unknown' => 'online'
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 122 node2/crm: status change wait_for_quorum => slave
+info 124 node3/crm: status change wait_for_quorum => slave
info 720 hardware: exit simulation - done
--
2.1.4
More information about the pve-devel
mailing list