]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
sim: allocate HA Env only once per service and node
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 19 Jan 2017 12:32:45 +0000 (13:32 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 24 Jan 2017 08:45:44 +0000 (09:45 +0100)
Do not allocate the HA Environment every time we fork a new CRM or
LRM, but once at the start of the Simulator for all nodes.
This can be done as the Env does not saves any state and thus can be
reused, we use this also in the TestHardware class.
Making the behavior of both Hardware classes more similar allows us
to refactor out some common code in following commits.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/HA/Sim/RTHardware.pm

index 0b29340d2b7360f80f94214bd222a58dc96a6f44..145d73b9bc78d4f3312852bda139f97846f5cf40 100644 (file)
@@ -39,7 +39,10 @@ sub new {
        my $d = $self->{nodes}->{$node};
 
        $d->{crm} = undef; # create on power on
+       $d->{crm_env} = PVE::HA::Env->new('PVE::HA::Sim::RTEnv', $node, $self, 'crm');
+
        $d->{lrm} = undef; # create on power on
+       $d->{lrm_env} = PVE::HA::Env->new('PVE::HA::Sim::RTEnv', $node, $self, 'lrm');
     }
 
     $self->create_main_window();
@@ -78,7 +81,7 @@ sub read_manager_status {
 }
 
 sub fork_daemon {
-    my ($self, $lockfh, $type, $node) = @_;
+    my ($self, $lockfh, $type, $haenv) = @_;
 
     my @psync = POSIX::pipe();
 
@@ -122,8 +125,6 @@ sub fork_daemon {
 
        if ($type eq 'crm') {
 
-           my $haenv = PVE::HA::Env->new('PVE::HA::Sim::RTEnv', $node, $self, 'crm');
-
            my $crm = PVE::HA::CRM->new($haenv);
 
            for (;;) {
@@ -139,8 +140,6 @@ sub fork_daemon {
 
        } else {
 
-           my $haenv = PVE::HA::Env->new('PVE::HA::Sim::RTEnv', $node, $self, 'lrm');
-
            my $lrm = PVE::HA::LRM->new($haenv);
 
            for (;;) {
@@ -207,8 +206,8 @@ sub sim_hardware_cmd {
        if ($cmd eq 'power') {
            if ($cstatus->{$node}->{power} ne $action) {
                if ($action eq 'on') {
-                   $d->{crm} = $self->fork_daemon($lockfh, 'crm', $node) if !$d->{crm};
-                   $d->{lrm} = $self->fork_daemon($lockfh, 'lrm', $node) if !$d->{lrm};
+                   $d->{crm} = $self->fork_daemon($lockfh, 'crm', $d->{crm_env}) if !$d->{crm};
+                   $d->{lrm} = $self->fork_daemon($lockfh, 'lrm', $d->{lrm_env}) if !$d->{lrm};
                } else {
                    if ($d->{crm}) {
                        $self->log('info', "crm on node '$node' killed by poweroff");