Blame SOURCES/bz1827652-fence_vmware_rest-2-fix-1000-VM-monitor-error.patch

91f48e
From 0296bc8512e37b8b935bc342b6493ed4fa8aa001 Mon Sep 17 00:00:00 2001
91f48e
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
91f48e
Date: Thu, 14 May 2020 13:17:04 +0200
91f48e
Subject: [PATCH 1/2] fence_vmware_rest: fix exception and remove default value
91f48e
 for filter parameter (which was shown in the manpage)
91f48e
91f48e
---
91f48e
 agents/vmware_rest/fence_vmware_rest.py   | 3 +--
91f48e
 tests/data/metadata/fence_vmware_rest.xml | 2 +-
91f48e
 2 files changed, 2 insertions(+), 3 deletions(-)
91f48e
91f48e
diff --git a/agents/vmware_rest/fence_vmware_rest.py b/agents/vmware_rest/fence_vmware_rest.py
91f48e
index 6daff121..2635ae07 100644
91f48e
--- a/agents/vmware_rest/fence_vmware_rest.py
91f48e
+++ b/agents/vmware_rest/fence_vmware_rest.py
91f48e
@@ -46,7 +46,7 @@ def get_list(conn, options):
91f48e
 		if "--filter" in options:
91f48e
 			command = command + "?" + options["--filter"]
91f48e
 		res = send_command(conn, command)
91f48e
-	except:
91f48e
+	except Exception as e:
91f48e
 		logging.debug("Failed: {}".format(e))
91f48e
 		fail(EC_STATUS)
91f48e
 
91f48e
@@ -165,7 +165,6 @@ def define_new_opts():
91f48e
 		"longopt" : "filter",
91f48e
 		"help" : "--filter=[filter]              Filter to only return relevant VMs"
91f48e
 			 " (e.g. \"filter.names=node1&filter.names=node2\").",
91f48e
-		"default" : "",
91f48e
 		"required" : "0",
91f48e
 		"shortdesc" : "Filter to only return relevant VMs. It can be used to avoid "
91f48e
 			      "the agent failing when more than 1000 VMs should be returned.",
91f48e
diff --git a/tests/data/metadata/fence_vmware_rest.xml b/tests/data/metadata/fence_vmware_rest.xml
91f48e
index d60c8775..830b6a21 100644
91f48e
--- a/tests/data/metadata/fence_vmware_rest.xml
91f48e
+++ b/tests/data/metadata/fence_vmware_rest.xml
91f48e
@@ -91,7 +91,7 @@ NOTE: If there's more than 1000 VMs there is a filter parameter to work around t
91f48e
 	</parameter>
91f48e
 	<parameter name="filter" unique="0" required="0">
91f48e
 		<getopt mixed="--filter=[filter]" />
91f48e
-		<content type="string" default=""  />
91f48e
+		<content type="string"  />
91f48e
 		<shortdesc lang="en">Filter to only return relevant VMs. It can be used to avoid the agent failing when more than 1000 VMs should be returned.</shortdesc>
91f48e
 	</parameter>
91f48e
 	<parameter name="quiet" unique="0" required="0">
91f48e
91f48e
From 7420cf9f11568be7239956bed4631cdbaa6fb87c Mon Sep 17 00:00:00 2001
91f48e
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
91f48e
Date: Thu, 14 May 2020 14:17:03 +0200
91f48e
Subject: [PATCH 2/2] fence_vmware_rest: dont fail when receiving more than
91f48e
 1000 VM error during monitor-action
91f48e
91f48e
---
91f48e
 agents/vmware_rest/fence_vmware_rest.py | 9 ++++++++-
91f48e
 1 file changed, 8 insertions(+), 1 deletion(-)
91f48e
91f48e
diff --git a/agents/vmware_rest/fence_vmware_rest.py b/agents/vmware_rest/fence_vmware_rest.py
91f48e
index 2635ae07..675de246 100644
91f48e
--- a/agents/vmware_rest/fence_vmware_rest.py
91f48e
+++ b/agents/vmware_rest/fence_vmware_rest.py
91f48e
@@ -48,7 +48,14 @@ def get_list(conn, options):
91f48e
 		res = send_command(conn, command)
91f48e
 	except Exception as e:
91f48e
 		logging.debug("Failed: {}".format(e))
91f48e
-		fail(EC_STATUS)
91f48e
+		if str(e).startswith("400"):
91f48e
+			if options.get("--original-action") == "monitor":
91f48e
+				return outlets
91f48e
+			else:
91f48e
+				logging.error("More than 1000 VMs returned. Use --filter parameter to limit which VMs to list.")
91f48e
+				fail(EC_STATUS)
91f48e
+		else:
91f48e
+			fail(EC_STATUS)
91f48e
 
91f48e
 	for r in res["value"]:
91f48e
 		outlets[r["name"]] = ("", state[r["power_state"]])