File 632.patch of Package fence-agents.42831

From f2d93300f6a3d0718fb4c30bac2c0543a80c9fdc Mon Sep 17 00:00:00 2001
From: Guilherme Felix <fguilher@amazon.com>
Date: Wed, 23 Jul 2025 20:03:27 -0700
Subject: [PATCH 1/2] fence_aws: Add new skip_os_shutdown flag

---
 agents/aws/fence_aws.py           | 23 +++++++++++++++++++++--
 tests/data/metadata/fence_aws.xml |  5 +++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/agents/aws/fence_aws.py b/agents/aws/fence_aws.py
index 5459a06c4..dcec008fe 100644
--- a/agents/aws/fence_aws.py
+++ b/agents/aws/fence_aws.py
@@ -120,9 +120,19 @@ def get_self_power_status(conn, instance_id):
 def set_power_status(conn, options):
 	my_instance = get_instance_id(options)
 	try:
+		if "--skip-os-shutdown" in options and options["--skip-os-shutdown"] == "on":
+			shutdown_option = {
+				"SkipOsShutdown": True,
+				"Force": True
+			}
+		else:
+			shutdown_option = {
+				"SkipOsShutdown": False,
+				"Force": True
+			}
 		if (options["--action"]=="off"):
 			if "--skip-race-check" in options or get_self_power_status(conn,my_instance) == "ok":
-				conn.instances.filter(InstanceIds=[options["--plug"]]).stop(Force=True)
+				conn.instances.filter(InstanceIds=[options["--plug"]]).stop(**shutdown_option)
 				logger.debug("Called StopInstance API call for %s", options["--plug"])
 			else:
 				logger.debug("Skipping fencing as instance is not in running status")
@@ -183,12 +193,21 @@ def define_new_opts():
 		"required": "0",
 		"order": 7
 	}
+	all_opt["skip_os_shutdown"] = {
+		"getopt": "k:",
+		"longopt": "skip-os-shutdown",
+		"help": "-k, --skip-os-shutdown=[on|off]    Uses SkipOsShutdown flag",
+		"shortdesc": "Use SkipOsShutdown flag to stop the EC2 instance",
+		"required": "0",
+		"default": "off",
+		"order": 8
+	}
 
 # Main agent method
 def main():
 	conn = None
 
-	device_opt = ["port", "no_password", "region", "access_key", "secret_key", "filter", "boto3_debug", "skip_race_check"]
+	device_opt = ["port", "no_password", "region", "access_key", "secret_key", "filter", "boto3_debug", "skip_race_check", "skip_os_shutdown"]
 
 	atexit.register(atexit_handler)
 
diff --git a/tests/data/metadata/fence_aws.xml b/tests/data/metadata/fence_aws.xml
index ad471c797..4c803a61a 100644
--- a/tests/data/metadata/fence_aws.xml
+++ b/tests/data/metadata/fence_aws.xml
@@ -51,6 +51,11 @@ For instructions see: https://boto3.readthedocs.io/en/latest/guide/quickstart.ht
 		<content type="boolean"  />
 		<shortdesc lang="en">Skip race condition check</shortdesc>
 	</parameter>
+	<parameter name="skip_os_shutdown" unique="0" required="0">
+		<getopt mixed="-k, --skip-os-shutdown=[on|off]" />
+		<content type="string" default="off"  />
+		<shortdesc lang="en">Use SkipOsShutdown flag to stop the EC2 instance</shortdesc>
+	</parameter>
 	<parameter name="quiet" unique="0" required="0">
 		<getopt mixed="-q, --quiet" />
 		<content type="boolean"  />

From 45c7ec985d775153e733719ef743901800d009d8 Mon Sep 17 00:00:00 2001
From: Guilherme Felix <fguilher@amazon.com>
Date: Mon, 11 Aug 2025 13:28:45 -0700
Subject: [PATCH 2/2] fence_aws: improvements for the SkipOsShutdown logic

---
 agents/aws/fence_aws.py           | 22 +++++++++++++---------
 tests/data/metadata/fence_aws.xml |  4 ++--
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/agents/aws/fence_aws.py b/agents/aws/fence_aws.py
index dcec008fe..cddca4580 100644
--- a/agents/aws/fence_aws.py
+++ b/agents/aws/fence_aws.py
@@ -12,7 +12,7 @@
 
 try:
 	import boto3
-	from botocore.exceptions import ConnectionError, ClientError, EndpointConnectionError, NoRegionError
+	from botocore.exceptions import ConnectionError, ClientError, EndpointConnectionError, NoRegionError, ParamValidationError
 except ImportError:
 	pass
 
@@ -120,7 +120,7 @@ def get_self_power_status(conn, instance_id):
 def set_power_status(conn, options):
 	my_instance = get_instance_id(options)
 	try:
-		if "--skip-os-shutdown" in options and options["--skip-os-shutdown"] == "on":
+		if options.get("--skip-os-shutdown", "false").lower() in ["1", "yes", "on", "true"]:
 			shutdown_option = {
 				"SkipOsShutdown": True,
 				"Force": True
@@ -138,6 +138,10 @@ def set_power_status(conn, options):
 				logger.debug("Skipping fencing as instance is not in running status")
 		elif (options["--action"]=="on"):
 			conn.instances.filter(InstanceIds=[options["--plug"]]).start()
+	except ParamValidationError:
+		if (options["--action"] == "off"):
+			logger.warning(f"SkipOsShutdown not supported with the current boto3 version {boto3.__version__} - falling back to graceful shutdown")
+			conn.instances.filter(InstanceIds=[options["--plug"]]).stop(Force=True)
 	except Exception as e:
 		logger.debug("Failed to power %s %s: %s", \
 				options["--action"], options["--plug"], e)
@@ -194,13 +198,13 @@ def define_new_opts():
 		"order": 7
 	}
 	all_opt["skip_os_shutdown"] = {
-		"getopt": "k:",
-		"longopt": "skip-os-shutdown",
-		"help": "-k, --skip-os-shutdown=[on|off]    Uses SkipOsShutdown flag",
-		"shortdesc": "Use SkipOsShutdown flag to stop the EC2 instance",
-		"required": "0",
-		"default": "off",
-		"order": 8
+		"getopt" : ":",
+		"longopt" : "skip-os-shutdown",
+		"help" : "--skip-os-shutdown=[true|false]    Uses SkipOsShutdown flag",
+		"shortdesc" : "Use SkipOsShutdown flag to stop the EC2 instance",
+		"required" : "0",
+		"default" : "true",
+		"order" : 8
 	}
 
 # Main agent method
diff --git a/tests/data/metadata/fence_aws.xml b/tests/data/metadata/fence_aws.xml
index 4c803a61a..c53873bbe 100644
--- a/tests/data/metadata/fence_aws.xml
+++ b/tests/data/metadata/fence_aws.xml
@@ -52,8 +52,8 @@ For instructions see: https://boto3.readthedocs.io/en/latest/guide/quickstart.ht
 		<shortdesc lang="en">Skip race condition check</shortdesc>
 	</parameter>
 	<parameter name="skip_os_shutdown" unique="0" required="0">
-		<getopt mixed="-k, --skip-os-shutdown=[on|off]" />
-		<content type="string" default="off"  />
+		<getopt mixed="--skip-os-shutdown=[true|false]" />
+		<content type="string" default="true"  />
 		<shortdesc lang="en">Use SkipOsShutdown flag to stop the EC2 instance</shortdesc>
 	</parameter>
 	<parameter name="quiet" unique="0" required="0">
openSUSE Build Service is sponsored by