public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override
@ 2023-06-16 11:33 Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH cluster 1/1] datacenter config: turn shutdown policy into a standard option Fiona Ebner
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

Make it possible to specify the HA shutdown policy for the
/nodes/{node}/status POST API enpoint for user flexibilty and
convenience.

The override is written to the LRM service's (new dedicated) runtime
directory. The LRM will check and honor the override when it receives
a shutdown/reboot request.


Still missing: UI part


(Build-)depedency bump pve-manager -> libpve-cluster-perl needed.

If patch ha-manager 5/7 is applied: (build-)depedency bump
pve-ha-manager -> libpve-cluster-perl needed.

Dependency bump pve-manager -> pve-ha-manager needed (to have the
runtime directory exist and LRM honor the new param).


cluster:

Fiona Ebner (1):
  datacenter config: turn shutdown policy into a standard option

 src/PVE/DataCenterConfig.pm | 50 +++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 24 deletions(-)


ha-manager:

Fiona Ebner (7):
  lrm service: add runtime directory
  lrm service: move PID file to service's runtime directory
  pve2 env: get shutdown policy override set by node's shutdown API
    endpoint
  lrm: honor shutdown policy override set by node's shutdown API
    endpoint
  pve2 env: validate shutdown policy from override file
  sim env: add support for datacenter config overrides
  tests: add test for shutdown policy override

 debian/pve-ha-lrm.service                     |  3 +-
 src/PVE/HA/Env/PVE2.pm                        | 19 +++++++
 src/PVE/HA/LRM.pm                             |  5 +-
 src/PVE/HA/Sim/Env.pm                         |  1 +
 src/PVE/Service/pve_ha_lrm.pm                 |  5 +-
 src/test/test-shutdown-policy-override/README |  3 +
 .../test-shutdown-policy-override/cmdlist     |  4 ++
 .../datacenter.cfg                            | 10 ++++
 .../hardware_status                           |  5 ++
 .../test-shutdown-policy-override/log.expect  | 57 +++++++++++++++++++
 .../manager_status                            |  1 +
 .../service_config                            |  6 ++
 12 files changed, 116 insertions(+), 3 deletions(-)
 create mode 100644 src/test/test-shutdown-policy-override/README
 create mode 100644 src/test/test-shutdown-policy-override/cmdlist
 create mode 100644 src/test/test-shutdown-policy-override/datacenter.cfg
 create mode 100644 src/test/test-shutdown-policy-override/hardware_status
 create mode 100644 src/test/test-shutdown-policy-override/log.expect
 create mode 100644 src/test/test-shutdown-policy-override/manager_status
 create mode 100644 src/test/test-shutdown-policy-override/service_config


manager:

Fiona Ebner (1):
  api: nodes: allow setting HA shutdown policy during shutdown/reboot

 PVE/API2/Nodes.pm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] [PATCH cluster 1/1] datacenter config: turn shutdown policy into a standard option
  2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
@ 2023-06-16 11:33 ` Fiona Ebner
  2023-06-16 12:47   ` [pve-devel] applied: " Thomas Lamprecht
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 1/7] lrm service: add runtime directory Fiona Ebner
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

to be re-used by the node/status API endpoint.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/DataCenterConfig.pm | 50 +++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/src/PVE/DataCenterConfig.pm b/src/PVE/DataCenterConfig.pm
index 5f12450..3d24e78 100644
--- a/src/PVE/DataCenterConfig.pm
+++ b/src/PVE/DataCenterConfig.pm
@@ -3,7 +3,7 @@ package PVE::DataCenterConfig;
 use strict;
 use warnings;
 
-use PVE::JSONSchema qw(parse_property_string);
+use PVE::JSONSchema qw(get_standard_option parse_property_string register_standard_option);
 use PVE::Tools;
 use PVE::Cluster;
 
@@ -59,30 +59,32 @@ my $notification_format = {
     },
 };
 
+register_standard_option('pve-ha-shutdown-policy', {
+    type => 'string',
+    enum => ['freeze', 'failover', 'conditional', 'migrate'],
+    description => "The policy for HA services on node shutdown. 'freeze' disables ".
+	"auto-recovery, 'failover' ensures recovery, 'conditional' recovers on ".
+	"poweroff and freezes on reboot. 'migrate' will migrate running services ".
+	"to other nodes, if possible. With 'freeze' or 'failover', HA Services will ".
+	"always get stopped first on shutdown.",
+    verbose_description => "Describes the policy for handling HA services on poweroff ".
+	"or reboot of a node. Freeze will always freeze services which are still located ".
+	"on the node on shutdown, those services won't be recovered by the HA manager. ".
+	"Failover will not mark the services as frozen and thus the services will get ".
+	"recovered to other nodes, if the shutdown node does not come up again quickly ".
+	"(< 1min). 'conditional' chooses automatically depending on the type of shutdown, ".
+	"i.e., on a reboot the service will be frozen but on a poweroff the service will ".
+	"stay as is, and thus get recovered after about 2 minutes. ".
+	"Migrate will try to move all running services to another node when a reboot or ".
+	"shutdown was triggered. The poweroff process will only continue once no running services ".
+	"are located on the node anymore. If the node comes up again, the service will ".
+	"be moved back to the previously powered-off node, at least if no other migration, ".
+	"reloaction or recovery took place.",
+    default => 'conditional',
+});
+
 my $ha_format = {
-    shutdown_policy => {
-	type => 'string',
-	enum => ['freeze', 'failover', 'conditional', 'migrate'],
-	description => "The policy for HA services on node shutdown. 'freeze' disables ".
-	    "auto-recovery, 'failover' ensures recovery, 'conditional' recovers on ".
-	    "poweroff and freezes on reboot. 'migrate' will migrate running services ".
-	    "to other nodes, if possible. With 'freeze' or 'failover', HA Services will ".
-	    "always get stopped first on shutdown.",
-	verbose_description => "Describes the policy for handling HA services on poweroff ".
-	    "or reboot of a node. Freeze will always freeze services which are still located ".
-	    "on the node on shutdown, those services won't be recovered by the HA manager. ".
-	    "Failover will not mark the services as frozen and thus the services will get ".
-	    "recovered to other nodes, if the shutdown node does not come up again quickly ".
-	    "(< 1min). 'conditional' chooses automatically depending on the type of shutdown, ".
-	    "i.e., on a reboot the service will be frozen but on a poweroff the service will ".
-	    "stay as is, and thus get recovered after about 2 minutes. ".
-	    "Migrate will try to move all running services to another node when a reboot or ".
-	    "shutdown was triggered. The poweroff process will only continue once no running services ".
-	    "are located on the node anymore. If the node comes up again, the service will ".
-	    "be moved back to the previously powered-off node, at least if no other migration, ".
-	    "reloaction or recovery took place.",
-	default => 'conditional',
-    }
+    shutdown_policy => get_standard_option('pve-ha-shutdown-policy'),
 };
 
 my $next_id_format = {
-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] [PATCH ha-manager 1/7] lrm service: add runtime directory
  2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH cluster 1/1] datacenter config: turn shutdown policy into a standard option Fiona Ebner
@ 2023-06-16 11:33 ` Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [RFC ha-manager 2/7] lrm service: move PID file to service's " Fiona Ebner
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

in preparation to allow overriding the shutdown policy with a file
there.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 debian/pve-ha-lrm.service | 1 +
 1 file changed, 1 insertion(+)

diff --git a/debian/pve-ha-lrm.service b/debian/pve-ha-lrm.service
index fb1b5db..9f3f73d 100644
--- a/debian/pve-ha-lrm.service
+++ b/debian/pve-ha-lrm.service
@@ -22,6 +22,7 @@ After=watchdog-mux.service
 ExecStart=/usr/sbin/pve-ha-lrm start
 ExecStop=/usr/sbin/pve-ha-lrm stop
 PIDFile=/run/pve-ha-lrm.pid
+RuntimeDirectory=pve-ha-lrm
 TimeoutStopSec=infinity
 KillMode=process
 Type=forking
-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] [RFC ha-manager 2/7] lrm service: move PID file to service's runtime directory
  2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH cluster 1/1] datacenter config: turn shutdown policy into a standard option Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 1/7] lrm service: add runtime directory Fiona Ebner
@ 2023-06-16 11:33 ` Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 3/7] pve2 env: get shutdown policy override set by node's shutdown API endpoint Fiona Ebner
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

it's arguably cleaner to put it there, now that there is one.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 debian/pve-ha-lrm.service     | 2 +-
 src/PVE/Service/pve_ha_lrm.pm | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/debian/pve-ha-lrm.service b/debian/pve-ha-lrm.service
index 9f3f73d..d9fcf87 100644
--- a/debian/pve-ha-lrm.service
+++ b/debian/pve-ha-lrm.service
@@ -21,7 +21,7 @@ After=watchdog-mux.service
 [Service]
 ExecStart=/usr/sbin/pve-ha-lrm start
 ExecStop=/usr/sbin/pve-ha-lrm stop
-PIDFile=/run/pve-ha-lrm.pid
+PIDFile=/run/pve-ha-lrm/pve-ha-lrm.pid
 RuntimeDirectory=pve-ha-lrm
 TimeoutStopSec=infinity
 KillMode=process
diff --git a/src/PVE/Service/pve_ha_lrm.pm b/src/PVE/Service/pve_ha_lrm.pm
index 91a9409..0790215 100644
--- a/src/PVE/Service/pve_ha_lrm.pm
+++ b/src/PVE/Service/pve_ha_lrm.pm
@@ -13,7 +13,10 @@ use base qw(PVE::Daemon);
 
 my $cmdline = [$0, @ARGV];
 
-my %daemon_options = (stop_wait_time => 60*60);
+my %daemon_options = (
+    stop_wait_time => 60*60,
+    pidfile => '/run/pve-ha-lrm/pve-ha-lrm.pid',
+);
 
 my $daemon = __PACKAGE__->new('pve-ha-lrm', $cmdline, %daemon_options);
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] [PATCH ha-manager 3/7] pve2 env: get shutdown policy override set by node's shutdown API endpoint
  2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
                   ` (2 preceding siblings ...)
  2023-06-16 11:33 ` [pve-devel] [RFC ha-manager 2/7] lrm service: move PID file to service's " Fiona Ebner
@ 2023-06-16 11:33 ` Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 4/7] lrm: honor " Fiona Ebner
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/HA/Env/PVE2.pm | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index f6ebfeb..6a75bd4 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -458,9 +458,17 @@ sub get_datacenter_settings {
     my $datacenterconfig = eval { cfs_read_file('datacenter.cfg') };
     $self->log('err', "unable to get HA settings from datacenter.cfg - $@") if $@;
 
+    my $sp_override_fn = '/run/pve-ha-lrm/shutdown-policy.local-override';
+    my $shutdown_policy_override = eval { PVE::Tools::file_read_firstline($sp_override_fn); };
+    $self->log('warning', "error reading shutdown policy override from $sp_override_fn - $@") if $@;
+
+    my $overrides = {};
+    $overrides->{ha}->{shutdown_policy} = $shutdown_policy_override if $shutdown_policy_override;
+
     return {
 	ha => $datacenterconfig->{ha} // {},
 	crs => $datacenterconfig->{crs} // {},
+	'local-overrides' => $overrides,
     };
 }
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] [PATCH ha-manager 4/7] lrm: honor shutdown policy override set by node's shutdown API endpoint
  2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
                   ` (3 preceding siblings ...)
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 3/7] pve2 env: get shutdown policy override set by node's shutdown API endpoint Fiona Ebner
@ 2023-06-16 11:33 ` Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [RFC ha-manager 5/7] pve2 env: validate shutdown policy from override file Fiona Ebner
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

The /nodes/<node>/status API endpoint in pve-manager allows to specify
the shutdown policy now. This change is required for it to have any
effect of course.

Being able to choose the shutdown policy on a per-node/per-shutdown
is more flexible and user-friendly.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/HA/LRM.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm
index b6ac0fe..b8b842f 100644
--- a/src/PVE/HA/LRM.pm
+++ b/src/PVE/HA/LRM.pm
@@ -60,7 +60,10 @@ sub shutdown_request {
     my ($shutdown, $reboot) = $haenv->is_node_shutdown();
 
     my $dc_cfg = $haenv->get_datacenter_settings();
-    my $shutdown_policy = $dc_cfg->{ha}->{shutdown_policy} // 'conditional';
+    my $dc_ha_overrides = $dc_cfg->{'local-overrides'}->{ha} // {};
+
+    my $shutdown_policy =
+	$dc_ha_overrides->{shutdown_policy} // $dc_cfg->{ha}->{shutdown_policy} // 'conditional';
 
     if ($shutdown) { # don't log this on service restart, only on node shutdown
 	$haenv->log('info', "got shutdown request with shutdown policy '$shutdown_policy'");
-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] [RFC ha-manager 5/7] pve2 env: validate shutdown policy from override file
  2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
                   ` (4 preceding siblings ...)
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 4/7] lrm: honor " Fiona Ebner
@ 2023-06-16 11:33 ` Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 6/7] sim env: add support for datacenter config overrides Fiona Ebner
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

for future-proofing.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

Not sure if this is worth it.

(Build-)dependency bump for libpve-cluster-perl needed

 src/PVE/HA/Env/PVE2.pm | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 6a75bd4..6eb4aa7 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -12,6 +12,7 @@ use PVE::Tools;
 use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_write_file cfs_lock_file);
 use PVE::DataCenterConfig;
 use PVE::INotify;
+use PVE::JSONSchema;
 use PVE::RPCEnvironment;
 
 use PVE::HA::Tools ':exit_codes';
@@ -463,7 +464,17 @@ sub get_datacenter_settings {
     $self->log('warning', "error reading shutdown policy override from $sp_override_fn - $@") if $@;
 
     my $overrides = {};
-    $overrides->{ha}->{shutdown_policy} = $shutdown_policy_override if $shutdown_policy_override;
+
+    if ($shutdown_policy_override) {
+	eval {
+	    PVE::JSONSchema::validate(
+		$shutdown_policy_override,
+		PVE::JSONSchema::get_standard_option('pve-ha-shutdown-policy'),
+	    );
+	    $overrides->{ha}->{shutdown_policy} = $shutdown_policy_override;
+	};
+	$self->log('warning', "error validating shutdown policy override - $@") if $@;
+    }
 
     return {
 	ha => $datacenterconfig->{ha} // {},
-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] [PATCH ha-manager 6/7] sim env: add support for datacenter config overrides
  2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
                   ` (5 preceding siblings ...)
  2023-06-16 11:33 ` [pve-devel] [RFC ha-manager 5/7] pve2 env: validate shutdown policy from override file Fiona Ebner
@ 2023-06-16 11:33 ` Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 7/7] tests: add test for shutdown policy override Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH manager 1/1] api: nodes: allow setting HA shutdown policy during shutdown/reboot Fiona Ebner
  8 siblings, 0 replies; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

to model the recent change in the pve2 environment.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/HA/Sim/Env.pm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm
index c6ea73c..1b8399a 100644
--- a/src/PVE/HA/Sim/Env.pm
+++ b/src/PVE/HA/Sim/Env.pm
@@ -433,6 +433,7 @@ sub get_datacenter_settings {
     return {
 	ha => $datacenterconfig->{ha} // {},
 	crs => $datacenterconfig->{crs} // {},
+	'local-overrides' => $datacenterconfig->{'local-overrides'} // {},
     };
 }
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] [PATCH ha-manager 7/7] tests: add test for shutdown policy override
  2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
                   ` (6 preceding siblings ...)
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 6/7] sim env: add support for datacenter config overrides Fiona Ebner
@ 2023-06-16 11:33 ` Fiona Ebner
  2023-06-16 11:33 ` [pve-devel] [PATCH manager 1/1] api: nodes: allow setting HA shutdown policy during shutdown/reboot Fiona Ebner
  8 siblings, 0 replies; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/test/test-shutdown-policy-override/README |  3 +
 .../test-shutdown-policy-override/cmdlist     |  4 ++
 .../datacenter.cfg                            | 10 ++++
 .../hardware_status                           |  5 ++
 .../test-shutdown-policy-override/log.expect  | 57 +++++++++++++++++++
 .../manager_status                            |  1 +
 .../service_config                            |  6 ++
 7 files changed, 86 insertions(+)
 create mode 100644 src/test/test-shutdown-policy-override/README
 create mode 100644 src/test/test-shutdown-policy-override/cmdlist
 create mode 100644 src/test/test-shutdown-policy-override/datacenter.cfg
 create mode 100644 src/test/test-shutdown-policy-override/hardware_status
 create mode 100644 src/test/test-shutdown-policy-override/log.expect
 create mode 100644 src/test/test-shutdown-policy-override/manager_status
 create mode 100644 src/test/test-shutdown-policy-override/service_config

diff --git a/src/test/test-shutdown-policy-override/README b/src/test/test-shutdown-policy-override/README
new file mode 100644
index 0000000..b9c71ce
--- /dev/null
+++ b/src/test/test-shutdown-policy-override/README
@@ -0,0 +1,3 @@
+Test shutdown policy override.
+
+Expect that the policy from the override is used.
diff --git a/src/test/test-shutdown-policy-override/cmdlist b/src/test/test-shutdown-policy-override/cmdlist
new file mode 100644
index 0000000..a86b9e2
--- /dev/null
+++ b/src/test/test-shutdown-policy-override/cmdlist
@@ -0,0 +1,4 @@
+[
+    [ "power node1 on", "power node2 on", "power node3 on"],
+    [ "shutdown node3" ]
+]
diff --git a/src/test/test-shutdown-policy-override/datacenter.cfg b/src/test/test-shutdown-policy-override/datacenter.cfg
new file mode 100644
index 0000000..0a188bd
--- /dev/null
+++ b/src/test/test-shutdown-policy-override/datacenter.cfg
@@ -0,0 +1,10 @@
+{
+    "ha": {
+        "shutdown_policy": "migrate"
+    },
+    "local-overrides": {
+        "ha": {
+            "shutdown_policy": "freeze"
+        }
+    }
+}
diff --git a/src/test/test-shutdown-policy-override/hardware_status b/src/test/test-shutdown-policy-override/hardware_status
new file mode 100644
index 0000000..451beb1
--- /dev/null
+++ b/src/test/test-shutdown-policy-override/hardware_status
@@ -0,0 +1,5 @@
+{
+  "node1": { "power": "off", "network": "off" },
+  "node2": { "power": "off", "network": "off" },
+  "node3": { "power": "off", "network": "off" }
+}
diff --git a/src/test/test-shutdown-policy-override/log.expect b/src/test/test-shutdown-policy-override/log.expect
new file mode 100644
index 0000000..4aecc4f
--- /dev/null
+++ b/src/test/test-shutdown-policy-override/log.expect
@@ -0,0 +1,57 @@
+info      0     hardware: starting simulation
+info     20      cmdlist: execute power node1 on
+info     20    node1/crm: status change startup => wait_for_quorum
+info     20    node1/lrm: status change startup => wait_for_agent_lock
+info     20      cmdlist: execute power node2 on
+info     20    node2/crm: status change startup => wait_for_quorum
+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     20    node1/crm: adding new service 'vm:103' on node 'node3'
+info     20    node1/crm: adding new service 'vm:104' on node 'node3'
+info     20    node1/crm: adding new service 'vm:105' on node 'node3'
+info     20    node1/crm: adding new service 'vm:106' on node 'node3'
+info     20    node1/crm: service 'vm:103': state changed from 'request_start' to 'started'  (node = node3)
+info     20    node1/crm: service 'vm:104': state changed from 'request_start' to 'started'  (node = node3)
+info     20    node1/crm: service 'vm:105': state changed from 'request_start' to 'started'  (node = node3)
+info     20    node1/crm: service 'vm:106': state changed from 'request_start' to 'started'  (node = node3)
+info     22    node2/crm: status change wait_for_quorum => slave
+info     24    node3/crm: status change wait_for_quorum => slave
+info     25    node3/lrm: got lock 'ha_agent_node3_lock'
+info     25    node3/lrm: status change wait_for_agent_lock => active
+info     25    node3/lrm: starting service vm:103
+info     25    node3/lrm: service status vm:103 started
+info     25    node3/lrm: starting service vm:104
+info     25    node3/lrm: service status vm:104 started
+info     25    node3/lrm: starting service vm:105
+info     25    node3/lrm: service status vm:105 started
+info     25    node3/lrm: starting service vm:106
+info     25    node3/lrm: service status vm:106 started
+info    120      cmdlist: execute shutdown node3
+info    120    node3/lrm: got shutdown request with shutdown policy 'freeze'
+info    120    node3/lrm: shutdown LRM, stop and freeze all services
+info    120    node1/crm: service 'vm:103': state changed from 'started' to 'freeze'
+info    120    node1/crm: service 'vm:104': state changed from 'started' to 'freeze'
+info    120    node1/crm: service 'vm:105': state changed from 'started' to 'freeze'
+info    120    node1/crm: service 'vm:106': state changed from 'started' to 'freeze'
+info    125    node3/lrm: stopping service vm:103
+info    125    node3/lrm: service status vm:103 stopped
+info    125    node3/lrm: stopping service vm:104
+info    125    node3/lrm: service status vm:104 stopped
+info    125    node3/lrm: stopping service vm:105
+info    125    node3/lrm: service status vm:105 stopped
+info    125    node3/lrm: stopping service vm:106
+info    125    node3/lrm: service status vm:106 stopped
+info    126    node3/lrm: exit (loop end)
+info    126     shutdown: execute crm node3 stop
+info    125    node3/crm: server received shutdown request
+info    145    node3/crm: exit (loop end)
+info    145     shutdown: execute power node3 off
+info    160    node1/crm: node 'node3': state changed from 'online' => 'unknown'
+info    720     hardware: exit simulation - done
diff --git a/src/test/test-shutdown-policy-override/manager_status b/src/test/test-shutdown-policy-override/manager_status
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/src/test/test-shutdown-policy-override/manager_status
@@ -0,0 +1 @@
+{}
diff --git a/src/test/test-shutdown-policy-override/service_config b/src/test/test-shutdown-policy-override/service_config
new file mode 100644
index 0000000..d6f4fd9
--- /dev/null
+++ b/src/test/test-shutdown-policy-override/service_config
@@ -0,0 +1,6 @@
+{
+    "vm:103": { "node": "node3", "state": "enabled" },
+    "vm:104": { "node": "node3", "state": "enabled" },
+    "vm:105": { "node": "node3", "state": "enabled" },
+    "vm:106": { "node": "node3", "state": "enabled" }
+}
-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] [PATCH manager 1/1] api: nodes: allow setting HA shutdown policy during shutdown/reboot
  2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
                   ` (7 preceding siblings ...)
  2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 7/7] tests: add test for shutdown policy override Fiona Ebner
@ 2023-06-16 11:33 ` Fiona Ebner
  2023-06-20  8:35   ` Fabian Grünbichler
  8 siblings, 1 reply; 12+ messages in thread
From: Fiona Ebner @ 2023-06-16 11:33 UTC (permalink / raw)
  To: pve-devel

Increases flexibility/user-friendliness.

Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

(Build-)dependency bump for libpve-cluster-perl needed.

Dependency bump for ha-manager needed (to have the runtime dir exist
and LRM honor the new param).

 PVE/API2/Nodes.pm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 9269694d..1cb83af5 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -8,7 +8,7 @@ use Digest::SHA;
 use Filesys::Df;
 use HTTP::Status qw(:constants);
 use JSON;
-use POSIX qw(LONG_MAX);
+use POSIX qw(ENOENT LONG_MAX);
 use Time::Local qw(timegm_nocheck);
 use Socket;
 use IO::Socket::SSL;
@@ -557,12 +557,21 @@ __PACKAGE__->register_method({
 		type => 'string',
 		enum => [qw(reboot shutdown)],
 	    },
+	    'shutdown-policy' => get_standard_option('pve-ha-shutdown-policy', { optional => 1 }),
 	},
     },
     returns => { type => "null" },
     code => sub {
 	my ($param) = @_;
 
+	my $sp_override_fn = '/run/pve-ha-lrm/shutdown-policy.local-override';
+	if ($param->{'shutdown-policy'}) {
+	    eval { PVE::Tools::file_set_contents($sp_override_fn, $param->{'shutdown-policy'}); };
+	    die "could not write shutdown policy override to $sp_override_fn - $@" if $@;
+	} else {
+	    unlink $sp_override_fn or $! == ENOENT or die "unable to remove $sp_override_fn - $!";
+	}
+
 	if ($param->{command} eq 'reboot') {
 	    system ("(sleep 2;/sbin/reboot)&");
 	} elsif ($param->{command} eq 'shutdown') {
-- 
2.39.2





^ permalink raw reply	[flat|nested] 12+ messages in thread

* [pve-devel] applied: [PATCH cluster 1/1] datacenter config: turn shutdown policy into a standard option
  2023-06-16 11:33 ` [pve-devel] [PATCH cluster 1/1] datacenter config: turn shutdown policy into a standard option Fiona Ebner
@ 2023-06-16 12:47   ` Thomas Lamprecht
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Lamprecht @ 2023-06-16 12:47 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fiona Ebner

Am 16/06/2023 um 13:33 schrieb Fiona Ebner:
> to be re-used by the node/status API endpoint.
> 
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
>  src/PVE/DataCenterConfig.pm | 50 +++++++++++++++++++------------------
>  1 file changed, 26 insertions(+), 24 deletions(-)
> 
>

this doesn't hurt in any case, so: applied, thanks!




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [pve-devel] [PATCH manager 1/1] api: nodes: allow setting HA shutdown policy during shutdown/reboot
  2023-06-16 11:33 ` [pve-devel] [PATCH manager 1/1] api: nodes: allow setting HA shutdown policy during shutdown/reboot Fiona Ebner
@ 2023-06-20  8:35   ` Fabian Grünbichler
  0 siblings, 0 replies; 12+ messages in thread
From: Fabian Grünbichler @ 2023-06-20  8:35 UTC (permalink / raw)
  To: Proxmox VE development discussion

On June 16, 2023 1:33 pm, Fiona Ebner wrote:
> Increases flexibility/user-friendliness.
> 
> Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
> 
> (Build-)dependency bump for libpve-cluster-perl needed.
> 
> Dependency bump for ha-manager needed (to have the runtime dir exist
> and LRM honor the new param).
> 
>  PVE/API2/Nodes.pm | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
> index 9269694d..1cb83af5 100644
> --- a/PVE/API2/Nodes.pm
> +++ b/PVE/API2/Nodes.pm
> @@ -8,7 +8,7 @@ use Digest::SHA;
>  use Filesys::Df;
>  use HTTP::Status qw(:constants);
>  use JSON;
> -use POSIX qw(LONG_MAX);
> +use POSIX qw(ENOENT LONG_MAX);
>  use Time::Local qw(timegm_nocheck);
>  use Socket;
>  use IO::Socket::SSL;
> @@ -557,12 +557,21 @@ __PACKAGE__->register_method({
>  		type => 'string',
>  		enum => [qw(reboot shutdown)],
>  	    },
> +	    'shutdown-policy' => get_standard_option('pve-ha-shutdown-policy', { optional => 1 }),
>  	},
>      },
>      returns => { type => "null" },
>      code => sub {
>  	my ($param) = @_;
>  
> +	my $sp_override_fn = '/run/pve-ha-lrm/shutdown-policy.local-override';
> +	if ($param->{'shutdown-policy'}) {
> +	    eval { PVE::Tools::file_set_contents($sp_override_fn, $param->{'shutdown-policy'}); };
> +	    die "could not write shutdown policy override to $sp_override_fn - $@" if $@;
> +	} else {
> +	    unlink $sp_override_fn or $! == ENOENT or die "unable to remove $sp_override_fn - $!";
> +	}

should this part (setting or removing the override if one is set)
require `Sys.Modify` (like setting the policy via datacenter.cfg would)
in addition to `Sys.PowerMgmt` that the endpoint itself requires?

> +
>  	if ($param->{command} eq 'reboot') {
>  	    system ("(sleep 2;/sbin/reboot)&");
>  	} elsif ($param->{command} eq 'shutdown') {
> -- 
> 2.39.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-06-20  8:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 11:33 [pve-devel] [PATCH-SERIES cluster/(ha-)manager] allow node HA shutdown policy override Fiona Ebner
2023-06-16 11:33 ` [pve-devel] [PATCH cluster 1/1] datacenter config: turn shutdown policy into a standard option Fiona Ebner
2023-06-16 12:47   ` [pve-devel] applied: " Thomas Lamprecht
2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 1/7] lrm service: add runtime directory Fiona Ebner
2023-06-16 11:33 ` [pve-devel] [RFC ha-manager 2/7] lrm service: move PID file to service's " Fiona Ebner
2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 3/7] pve2 env: get shutdown policy override set by node's shutdown API endpoint Fiona Ebner
2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 4/7] lrm: honor " Fiona Ebner
2023-06-16 11:33 ` [pve-devel] [RFC ha-manager 5/7] pve2 env: validate shutdown policy from override file Fiona Ebner
2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 6/7] sim env: add support for datacenter config overrides Fiona Ebner
2023-06-16 11:33 ` [pve-devel] [PATCH ha-manager 7/7] tests: add test for shutdown policy override Fiona Ebner
2023-06-16 11:33 ` [pve-devel] [PATCH manager 1/1] api: nodes: allow setting HA shutdown policy during shutdown/reboot Fiona Ebner
2023-06-20  8:35   ` Fabian Grünbichler

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