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

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