public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Jakob-Tobias Winter <tobias@stuttgart.de>
To: pve-devel@lists.proxmox.com
Cc: Jakob-Tobias Winter <tobias@stuttgart.de>
Subject: [RFC PATCH ha-manager 04/11] sim: hardware: add poweroff command for services
Date: Sat, 28 Nov 2026 16:11:11 +0100	[thread overview]
Message-ID: <20261128151118.892037-5-tobias@stuttgart.de> (raw)
In-Reply-To: <20261128151118.892037-1-tobias@stuttgart.de>

Allow test cases to let the guest of a service get powered off from
within. The service is not running anymore afterwards, and the stopped
state gets requested for it if stop-on-poweroff applies, like the
cleanup after a real guest does.

Signed-off-by: Jakob-Tobias Winter <tobias@stuttgart.de>
---
 src/PVE/HA/Sim/Hardware.pm | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index 9367449..147cfb6 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -798,6 +798,7 @@ sub get_cfs_state {
 #   service <sid> migrate <target> [<key>=<value>[,<key>=<value>...]]
 #   service <sid> relocate <target>
 #   service <sid> stop <timeout>
+#   service <sid> poweroff
 #   service <sid> lock/unlock [lockname]
 #   service <sid> add <node> [<request-state=started>] [<running=0>]
 #   service <sid> set-static-stats  [maxcpu <cores>] [maxmem <MiB>]
@@ -972,6 +973,28 @@ sub sim_hardware_cmd {
 
                 $self->queue_crm_commands_nolock("$action $sid $param");
 
+            } elsif ($action eq 'poweroff') {
+
+                my $cd = $self->read_service_config()->{$sid}
+                    || die "sim_hardware_cmd: service '$sid' not configured\n";
+
+                my $ss = $self->read_service_status($cd->{node});
+                $ss->{$sid} = 0;
+                $self->write_service_status($cd->{node}, $ss);
+
+                # the cleanup after the guest reports that it got powered off from within
+                my $ms = PVE::HA::Tools::read_json_from_file(
+                    "$self->{statusdir}/manager_status", {},
+                );
+                my $sd = $ms->{service_status}->{$sid};
+                my $lrm_mode = $sd ? $self->read_lrm_status($sd->{node})->{mode} : undef;
+                my $ha_settings = $self->read_datacenter_conf()->{ha};
+
+                my $applies = PVE::HA::Tools::stop_on_poweroff_applies(
+                    $cd, $sd, $ms->{disarm}, $lrm_mode, $ha_settings,
+                );
+                $self->set_service_state($sid, 'stopped') if $applies;
+
             } elsif ($action eq 'add') {
                 $self->add_service(
                     $sid,
-- 
2.53.0




  parent reply	other threads:[~2026-11-28 15:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 15:11 [RFC PATCH cluster/ha-manager/qemu-server/manager/docs 00/11] fix #6314: ha: keep guests stopped that got powered off from within Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH cluster 01/11] datacenter config: add stop-on-poweroff to the HA settings Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH ha-manager 02/11] fix #6314: config: request stopped state for powered off guests Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH ha-manager 03/11] lrm: do not start a service again that is about to be stopped Jakob-Tobias Winter
2026-11-28 15:11 ` Jakob-Tobias Winter [this message]
2026-11-28 15:11 ` [RFC PATCH ha-manager 05/11] test: add test cases for stop-on-poweroff Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH ha-manager 06/11] resources: add stop-on-poweroff property for virtual machines Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH qemu-server 07/11] fix #6314: qm cleanup: report a guest poweroff to the HA stack Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH manager 08/11] ui: dc options: add stop-on-poweroff to the HA settings Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH manager 09/11] ui: ha: add stop-on-poweroff selector to the resource edit window Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH docs 10/11] ha-manager: document the stop-on-poweroff setting Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH docs 11/11] ha-manager: document the stop-on-poweroff property of resources Jakob-Tobias Winter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128151118.892037-5-tobias@stuttgart.de \
    --to=tobias@stuttgart.de \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal