Blame SOURCES/bz1781357-fence_aws-improve-logging-and-metadata-usage-text.patch

21d5fd
From 7ac16fb281fa8cfc51a31f672014c614c81aec82 Mon Sep 17 00:00:00 2001
21d5fd
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
21d5fd
Date: Fri, 31 Jan 2020 15:53:47 +0100
21d5fd
Subject: [PATCH] fence_aws: improve logging and metadata/usage text
21d5fd
21d5fd
---
21d5fd
 agents/aws/fence_aws.py           | 36 +++++++++++++++++++------------
21d5fd
 tests/data/metadata/fence_aws.xml |  6 +++---
21d5fd
 2 files changed, 25 insertions(+), 17 deletions(-)
21d5fd
21d5fd
diff --git a/agents/aws/fence_aws.py b/agents/aws/fence_aws.py
21d5fd
index 647b66fc..74321e8e 100644
21d5fd
--- a/agents/aws/fence_aws.py
21d5fd
+++ b/agents/aws/fence_aws.py
21d5fd
@@ -5,7 +5,7 @@
21d5fd
 import atexit
21d5fd
 sys.path.append("@FENCEAGENTSLIBDIR@")
21d5fd
 from fencing import *
21d5fd
-from fencing import fail, fail_usage, EC_TIMED_OUT, run_delay
21d5fd
+from fencing import fail, fail_usage, run_delay, EC_STATUS
21d5fd
 
21d5fd
 import boto3
21d5fd
 from botocore.exceptions import ClientError, EndpointConnectionError, NoRegionError
21d5fd
@@ -19,6 +19,8 @@ def get_nodes_list(conn, options):
21d5fd
 		fail_usage("Failed: Incorrect Access Key or Secret Key.")
21d5fd
 	except EndpointConnectionError:
21d5fd
 		fail_usage("Failed: Incorrect Region.")
21d5fd
+	except Exception as e:
21d5fd
+		logging.error("Failed to get node list: %s", e)
21d5fd
 
21d5fd
 	return result
21d5fd
 
21d5fd
@@ -38,20 +40,26 @@ def get_power_status(conn, options):
21d5fd
 	except EndpointConnectionError:
21d5fd
 		fail_usage("Failed: Incorrect Region.")
21d5fd
 	except IndexError:
21d5fd
-		return "fail"
21d5fd
+		fail(EC_STATUS)
21d5fd
+	except Exception as e:
21d5fd
+		logging.error("Failed to get power status: %s", e)
21d5fd
+		fail(EC_STATUS)
21d5fd
 
21d5fd
 def set_power_status(conn, options):
21d5fd
-	if (options["--action"]=="off"):
21d5fd
-		conn.instances.filter(InstanceIds=[options["--plug"]]).stop(Force=True)
21d5fd
-	elif (options["--action"]=="on"):
21d5fd
-		conn.instances.filter(InstanceIds=[options["--plug"]]).start()
21d5fd
-
21d5fd
+	try:
21d5fd
+		if (options["--action"]=="off"):
21d5fd
+			conn.instances.filter(InstanceIds=[options["--plug"]]).stop(Force=True)
21d5fd
+		elif (options["--action"]=="on"):
21d5fd
+			conn.instances.filter(InstanceIds=[options["--plug"]]).start()
21d5fd
+	except Exception as e:
21d5fd
+		logging.error("Failed to power %s %s: %s", \
21d5fd
+				options["--action"], options["--plug"], e)
21d5fd
 
21d5fd
 def define_new_opts():
21d5fd
 	all_opt["region"] = {
21d5fd
 		"getopt" : "r:",
21d5fd
 		"longopt" : "region",
21d5fd
-		"help" : "-r, --region=[name]            Region, e.g. us-east-1",
21d5fd
+		"help" : "-r, --region=[region]           Region, e.g. us-east-1",
21d5fd
 		"shortdesc" : "Region.",
21d5fd
 		"required" : "0",
21d5fd
 		"order" : 2
21d5fd
@@ -59,7 +67,7 @@ def define_new_opts():
21d5fd
 	all_opt["access_key"] = {
21d5fd
 		"getopt" : "a:",
21d5fd
 		"longopt" : "access-key",
21d5fd
-		"help" : "-a, --access-key=[name]         Access Key",
21d5fd
+		"help" : "-a, --access-key=[key]         Access Key",
21d5fd
 		"shortdesc" : "Access Key.",
21d5fd
 		"required" : "0",
21d5fd
 		"order" : 3
21d5fd
@@ -67,7 +75,7 @@ def define_new_opts():
21d5fd
 	all_opt["secret_key"] = {
21d5fd
 		"getopt" : "s:",
21d5fd
 		"longopt" : "secret-key",
21d5fd
-		"help" : "-s, --secret-key=[name]         Secret Key",
21d5fd
+		"help" : "-s, --secret-key=[key]         Secret Key",
21d5fd
 		"shortdesc" : "Secret Key.",
21d5fd
 		"required" : "0",
21d5fd
 		"order" : 4
21d5fd
@@ -107,16 +115,16 @@ def main():
21d5fd
 			conn = boto3.resource('ec2', region_name=region,
21d5fd
 					      aws_access_key_id=access_key,
21d5fd
 					      aws_secret_access_key=secret_key)
21d5fd
-		except:
21d5fd
-			fail_usage("Failed: Unable to connect to AWS. Check your configuration.")
21d5fd
+		except Exception as e:
21d5fd
+			fail_usage("Failed: Unable to connect to AWS: " + str(e))
21d5fd
 	else:
21d5fd
 		# If setup with "aws configure" or manually in
21d5fd
 		# ~/.aws/credentials
21d5fd
 		try:
21d5fd
 			conn = boto3.resource('ec2')
21d5fd
-		except:
21d5fd
+		except Exception as e:
21d5fd
 			# If any of region/access/secret are missing
21d5fd
-			fail_usage("Failed: Unable to connect to AWS. Check your configuration.")
21d5fd
+			fail_usage("Failed: Unable to connect to AWS: " + str(e))
21d5fd
 
21d5fd
 	# Operate the fencing device
21d5fd
 	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)
21d5fd
diff --git a/tests/data/metadata/fence_aws.xml b/tests/data/metadata/fence_aws.xml
21d5fd
index 4dea4418..5e5d5d99 100644
21d5fd
--- a/tests/data/metadata/fence_aws.xml
21d5fd
+++ b/tests/data/metadata/fence_aws.xml
21d5fd
@@ -22,17 +22,17 @@ For instructions see: https://boto3.readthedocs.io/en/latest/guide/quickstart.ht
21d5fd
 		<shortdesc lang="en">Physical plug number on device, UUID or identification of machine</shortdesc>
21d5fd
 	</parameter>
21d5fd
 	<parameter name="region" unique="0" required="0">
21d5fd
-		<getopt mixed="-r, --region=[name]" />
21d5fd
+		<getopt mixed="-r, --region=[region]" />
21d5fd
 		<content type="string"  />
21d5fd
 		<shortdesc lang="en">Region.</shortdesc>
21d5fd
 	</parameter>
21d5fd
 	<parameter name="access_key" unique="0" required="0">
21d5fd
-		<getopt mixed="-a, --access-key=[name]" />
21d5fd
+		<getopt mixed="-a, --access-key=[key]" />
21d5fd
 		<content type="string"  />
21d5fd
 		<shortdesc lang="en">Access Key.</shortdesc>
21d5fd
 	</parameter>
21d5fd
 	<parameter name="secret_key" unique="0" required="0">
21d5fd
-		<getopt mixed="-s, --secret-key=[name]" />
21d5fd
+		<getopt mixed="-s, --secret-key=[key]" />
21d5fd
 		<content type="string"  />
21d5fd
 		<shortdesc lang="en">Secret Key.</shortdesc>
21d5fd
 	</parameter>