[pve-devel] [PATCH ha-manager 5/7] move start/end hooks to common code

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Nov 22 11:53:10 CET 2017


We called them at similar times anyways, and have them under the
regression test cover with this change.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/CRM.pm              | 14 ++++++++++++++
 src/PVE/HA/LRM.pm              | 14 ++++++++++++++
 src/PVE/HA/Sim/Env.pm          |  2 +-
 src/PVE/HA/Sim/RTHardware.pm   |  8 --------
 src/PVE/HA/Sim/TestEnv.pm      |  4 ++--
 src/PVE/HA/Sim/TestHardware.pm | 12 ++----------
 src/PVE/Service/pve_ha_crm.pm  |  8 +-------
 src/PVE/Service/pve_ha_lrm.pm  |  8 +-------
 8 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/src/PVE/HA/CRM.pm b/src/PVE/HA/CRM.pm
index 2d70570..21a0acc 100644
--- a/src/PVE/HA/CRM.pm
+++ b/src/PVE/HA/CRM.pm
@@ -144,6 +144,20 @@ sub do_one_iteration {
 
     my $haenv = $self->{haenv};
 
+    $haenv->loop_start_hook();
+
+    my $res = $self->work();
+
+    $haenv->loop_end_hook();
+
+    return $res;
+}
+
+sub work {
+    my ($self) = @_;
+
+    my $haenv = $self->{haenv};
+
     my $status = $self->get_local_status();
     my $state = $status->{state};
 
diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm
index f076735..0301fce 100644
--- a/src/PVE/HA/LRM.pm
+++ b/src/PVE/HA/LRM.pm
@@ -217,6 +217,20 @@ sub do_one_iteration {
 
     my $haenv = $self->{haenv};
 
+    $haenv->loop_start_hook();
+
+    my $res = $self->work();
+
+    $haenv->loop_end_hook();
+
+    return $res;
+}
+
+sub work {
+    my ($self) = @_;
+
+    my $haenv = $self->{haenv};
+
     if (!$wrote_lrm_status_at_startup) {
 	if ($self->update_lrm_status()) {
 	    $wrote_lrm_status_at_startup = 1;
diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm
index 92c9394..34848b1 100644
--- a/src/PVE/HA/Sim/Env.pm
+++ b/src/PVE/HA/Sim/Env.pm
@@ -355,7 +355,7 @@ sub get_node_info {
 }
 
 sub loop_start_hook {
-    my ($self, $starttime) = @_;
+    my ($self) = @_;
 
     # do nothing, overwrite in subclass
 }
diff --git a/src/PVE/HA/Sim/RTHardware.pm b/src/PVE/HA/Sim/RTHardware.pm
index ccac6ce..ee1b55f 100644
--- a/src/PVE/HA/Sim/RTHardware.pm
+++ b/src/PVE/HA/Sim/RTHardware.pm
@@ -128,14 +128,10 @@ sub fork_daemon {
 	    my $crm = PVE::HA::CRM->new($haenv);
 
 	    for (;;) {
-		$haenv->loop_start_hook();
-
 		if (!$crm->do_one_iteration()) {
 		    $haenv->log("info", "daemon stopped");
 		    exit (0);
 		}
-
-		$haenv->loop_end_hook();
 	    }
 
 	} else {
@@ -143,14 +139,10 @@ sub fork_daemon {
 	    my $lrm = PVE::HA::LRM->new($haenv);
 
 	    for (;;) {
-		$haenv->loop_start_hook();
-
 		if (!$lrm->do_one_iteration()) {
 		    $haenv->log("info", "daemon stopped");
 		    exit (0);
 		}
-
-		$haenv->loop_end_hook();
 	    }
 	}
 
diff --git a/src/PVE/HA/Sim/TestEnv.pm b/src/PVE/HA/Sim/TestEnv.pm
index 9414cff..c746c90 100644
--- a/src/PVE/HA/Sim/TestEnv.pm
+++ b/src/PVE/HA/Sim/TestEnv.pm
@@ -86,11 +86,11 @@ sub get_ha_agent_lock {
 }
 
 sub loop_start_hook {
-    my ($self, $starttime) = @_;
+    my ($self) = @_;
 
     $self->{loop_delay} = 0;
 
-    die "no starttime" if !defined($starttime);
+    my $starttime = $self->{hardware}->get_time();
     die "strange start time" if $starttime < $self->{cur_time};
 
     $self->{cur_time} = $starttime;
diff --git a/src/PVE/HA/Sim/TestHardware.pm b/src/PVE/HA/Sim/TestHardware.pm
index 37046b4..8b2ab71 100644
--- a/src/PVE/HA/Sim/TestHardware.pm
+++ b/src/PVE/HA/Sim/TestHardware.pm
@@ -136,12 +136,8 @@ sub run {
 	    
 	    if (my $crm = $d->{crm}) {
 
-		$d->{crm_env}->loop_start_hook($self->get_time());
-
 		my $exit_crm = !$crm->do_one_iteration();
 
-		$d->{crm_env}->loop_end_hook();
-
 		my $nodetime = $d->{crm_env}->get_time();
 		$self->{cur_time} = $nodetime if $nodetime > $self->{cur_time};
 
@@ -166,12 +162,8 @@ sub run {
 
 	    if (my $lrm = $d->{lrm}) {
 
-		$d->{lrm_env}->loop_start_hook($self->get_time());
-
 		my $exit_lrm = !$lrm->do_one_iteration();
 
-		$d->{lrm_env}->loop_end_hook();
-
 		my $nodetime = $d->{lrm_env}->get_time();
 		$self->{cur_time} = $nodetime if $nodetime > $self->{cur_time};
 
@@ -213,8 +205,8 @@ sub run {
 	foreach my $node (@nodes) {
 	    my $d = $self->{nodes}->{$node};
 	    # forced time update
-	    $d->{lrm_env}->loop_start_hook($self->get_time());
-	    $d->{crm_env}->loop_start_hook($self->get_time());
+	    $d->{lrm_env}->loop_start_hook();
+	    $d->{crm_env}->loop_start_hook();
 	}
 
 	next if $self->{cur_time} < $next_cmd_at;
diff --git a/src/PVE/Service/pve_ha_crm.pm b/src/PVE/Service/pve_ha_crm.pm
index 8b88dcb..98a7b13 100644
--- a/src/PVE/Service/pve_ha_crm.pm
+++ b/src/PVE/Service/pve_ha_crm.pm
@@ -25,13 +25,7 @@ sub run {
     $self->{crm} = PVE::HA::CRM->new($self->{haenv});
 
     for (;;) {
-	$self->{haenv}->loop_start_hook();
-
-	my $repeat = $self->{crm}->do_one_iteration();
-
-	$self->{haenv}->loop_end_hook();
-
-	last if !$repeat;
+	last if !$self->{crm}->do_one_iteration();
     }
 }
 
diff --git a/src/PVE/Service/pve_ha_lrm.pm b/src/PVE/Service/pve_ha_lrm.pm
index 1d7bf8e..400591d 100644
--- a/src/PVE/Service/pve_ha_lrm.pm
+++ b/src/PVE/Service/pve_ha_lrm.pm
@@ -25,13 +25,7 @@ sub run {
     $self->{lrm} = PVE::HA::LRM->new($self->{haenv});
 
     for (;;) {
-	$self->{haenv}->loop_start_hook();
-
-	my $repeat = $self->{lrm}->do_one_iteration();
-
-	$self->{haenv}->loop_end_hook();
-
-	last if !$repeat;
+	last if !$self->{lrm}->do_one_iteration();
     }
 }
 
-- 
2.11.0





More information about the pve-devel mailing list