fence-agents/SOURCES/bz1839776-fence_aws-catch-connectionerror.patch

96 lines
3.2 KiB
Diff
Raw Normal View History

2021-05-14 04:12:18 +00:00
From be20615859c518b3161b08ee63f5da5213eba91d Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Mon, 25 May 2020 14:03:53 +0200
Subject: [PATCH 1/2] fence_aws: catch ConnectionError and suppress traceback
for caught exceptions
---
agents/aws/fence_aws.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/agents/aws/fence_aws.py b/agents/aws/fence_aws.py
index 17c2fedb..191f5de1 100644
--- a/agents/aws/fence_aws.py
+++ b/agents/aws/fence_aws.py
@@ -9,14 +9,14 @@
from fencing import fail, fail_usage, run_delay, EC_STATUS, SyslogLibHandler
import boto3
-from botocore.exceptions import ClientError, EndpointConnectionError, NoRegionError
+from botocore.exceptions import ConnectionError, ClientError, EndpointConnectionError, NoRegionError
logger = logging.getLogger("fence_aws")
logger.propagate = False
logger.setLevel(logging.INFO)
logger.addHandler(SyslogLibHandler())
logging.getLogger('botocore.vendored').propagate = False
-
+
def get_instance_id():
try:
r = requests.get('http://169.254.169.254/latest/meta-data/instance-id')
@@ -38,6 +38,8 @@ def get_nodes_list(conn, options):
fail_usage("Failed: Incorrect Access Key or Secret Key.")
except EndpointConnectionError:
fail_usage("Failed: Incorrect Region.")
+ except ConnectionError as e:
+ fail_usage("Failed: Unable to connect to AWS: " + str(e))
except Exception as e:
logger.error("Failed to get node list: %s", e)
logger.debug("Monitor operation OK: %s",result)
@@ -169,7 +171,7 @@ def main():
if options["--boto3_debug"] != "on":
boto3.set_stream_logger('boto3',logging.INFO)
- boto3.set_stream_logger('botocore',logging.INFO)
+ boto3.set_stream_logger('botocore',logging.CRITICAL)
logging.getLogger('botocore').propagate = False
logging.getLogger('boto3').propagate = False
else:
@@ -197,4 +199,4 @@ def main():
sys.exit(result)
if __name__ == "__main__":
- main()
\ No newline at end of file
+ main()
From 50772024cffa60d05938d328bbd5cffd930f6b42 Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Mon, 25 May 2020 14:07:14 +0200
Subject: [PATCH 2/2] fence_aws: improve boto3_debug boolean handling
---
agents/aws/fence_aws.py | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/agents/aws/fence_aws.py b/agents/aws/fence_aws.py
index 191f5de1..483a2991 100644
--- a/agents/aws/fence_aws.py
+++ b/agents/aws/fence_aws.py
@@ -132,6 +132,7 @@ def define_new_opts():
"help" : "-b, --boto3_debug=[option] Boto3 and Botocore library debug logging",
"shortdesc": "Boto Lib debug",
"required": "0",
+ "default": "False",
"order": 5
}
@@ -146,7 +147,6 @@ def main():
define_new_opts()
all_opt["power_timeout"]["default"] = "60"
- all_opt["boto3_debug"]["default"] = "off"
options = check_input(device_opt, process_input(device_opt))
@@ -169,7 +169,7 @@ def main():
lh.setFormatter(lhf)
logger.setLevel(logging.DEBUG)
- if options["--boto3_debug"] != "on":
+ if options["--boto3_debug"].lower() not in ["1", "yes", "on", "true"]:
boto3.set_stream_logger('boto3',logging.INFO)
boto3.set_stream_logger('botocore',logging.CRITICAL)
logging.getLogger('botocore').propagate = False