mirror of
git://git.proxmox.com/git/pve-ha-manager.git
synced 2025-02-11 21:57:34 +03:00
sim: allocate HA Env only once per service and node
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>
This commit is contained in:
parent
aa68337a8b
commit
d49a8daac8
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user