Blame SOURCES/bz1830776-fence_compute-fence_evacuate-fix-insecure-parameter.patch

bf99d3
From 8920d2fc7993453e7ad05f807f6ec51745b408a5 Mon Sep 17 00:00:00 2001
bf99d3
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
bf99d3
Date: Mon, 4 May 2020 16:53:55 +0200
bf99d3
Subject: [PATCH] fence_compute/fence_evacuate: fix --insecure parameter
bf99d3
bf99d3
---
bf99d3
 agents/compute/fence_compute.py        | 10 +++++++---
bf99d3
 agents/evacuate/fence_evacuate.py      | 10 +++++++---
bf99d3
 tests/data/metadata/fence_compute.xml  |  2 +-
bf99d3
 tests/data/metadata/fence_evacuate.xml |  2 +-
bf99d3
 4 files changed, 16 insertions(+), 8 deletions(-)
bf99d3
bf99d3
diff --git a/agents/compute/fence_compute.py b/agents/compute/fence_compute.py
bf99d3
index d0e012e6..f53b97da 100644
bf99d3
--- a/agents/compute/fence_compute.py
bf99d3
+++ b/agents/compute/fence_compute.py
bf99d3
@@ -281,7 +281,7 @@ def create_nova_connection(options):
bf99d3
 
bf99d3
 	loader = loading.get_plugin_loader('password')
bf99d3
 	keystone_auth = loader.load_from_options(**kwargs)
bf99d3
-	keystone_session = session.Session(auth=keystone_auth, verify=(not options["--insecure"]))
bf99d3
+	keystone_session = session.Session(auth=keystone_auth, verify=not "--insecure" in options)
bf99d3
 
bf99d3
 	nova_versions = [ "2.11", "2" ]
bf99d3
 	for version in nova_versions:
bf99d3
@@ -307,7 +307,7 @@ def create_nova_connection(options):
bf99d3
 					     None, # Password
bf99d3
 					     None, # Tenant
bf99d3
 					     None, # Auth URL
bf99d3
-					     insecure=options["--insecure"],
bf99d3
+					     insecure="--insecure" in options,
bf99d3
 					     region_name=options["--region-name"],
bf99d3
 					     endpoint_type=options["--endpoint-type"],
bf99d3
 					     session=keystone_session, auth=keystone_auth,
bf99d3
@@ -395,7 +395,6 @@ def define_new_opts():
bf99d3
 		"help" : "--insecure                     Explicitly allow agent to perform \"insecure\" TLS (https) requests",
bf99d3
 		"required" : "0",
bf99d3
 		"shortdesc" : "Allow Insecure TLS Requests",
bf99d3
-		"default" : "False",
bf99d3
 		"order": 2,
bf99d3
 	}
bf99d3
 	all_opt["domain"] = {
bf99d3
@@ -484,6 +483,11 @@ def main():
bf99d3
 		options["--domain"] = options["--compute-domain"]
bf99d3
 		del options["--domain"]
bf99d3
 
bf99d3
+	# Disable insecure-certificate-warning message
bf99d3
+	if "--insecure" in options:
bf99d3
+		import urllib3
bf99d3
+		urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
bf99d3
+
bf99d3
 	logging.debug("Running "+options["--action"])
bf99d3
 	connection = create_nova_connection(options)
bf99d3
 
bf99d3
diff --git a/agents/evacuate/fence_evacuate.py b/agents/evacuate/fence_evacuate.py
bf99d3
index 60bb130e..88837dd8 100644
bf99d3
--- a/agents/evacuate/fence_evacuate.py
bf99d3
+++ b/agents/evacuate/fence_evacuate.py
bf99d3
@@ -217,7 +217,7 @@ def create_nova_connection(options):
bf99d3
 
bf99d3
 	loader = loading.get_plugin_loader('password')
bf99d3
 	keystone_auth = loader.load_from_options(**kwargs)
bf99d3
-	keystone_session = session.Session(auth=keystone_auth, verify=(not options["--insecure"]))
bf99d3
+	keystone_session = session.Session(auth=keystone_auth, verify=not "--insecure" in options)
bf99d3
 
bf99d3
 	versions = [ "2.11", "2" ]
bf99d3
 	for version in versions:
bf99d3
@@ -244,7 +244,7 @@ def create_nova_connection(options):
bf99d3
 					     None, # Password
bf99d3
 					     None, # Tenant
bf99d3
 					     None, # Auth URL
bf99d3
-					     insecure=options["--insecure"],
bf99d3
+					     insecure="--insecure" in options,
bf99d3
 					     region_name=options["--region-name"],
bf99d3
 					     endpoint_type=options["--endpoint-type"],
bf99d3
 					     session=keystone_session, auth=keystone_auth,
bf99d3
@@ -332,7 +332,6 @@ def define_new_opts():
bf99d3
 		"help" : "--insecure                                     Explicitly allow agent to perform \"insecure\" TLS (https) requests",
bf99d3
 		"required" : "0",
bf99d3
 		"shortdesc" : "Allow Insecure TLS Requests",
bf99d3
-		"default" : "False",
bf99d3
 		"order": 2,
bf99d3
 	}
bf99d3
 	all_opt["domain"] = {
bf99d3
@@ -397,6 +396,11 @@ def main():
bf99d3
 		del options["--domain"]
bf99d3
 
bf99d3
 
bf99d3
+	# Disable insecure-certificate-warning message
bf99d3
+	if "--insecure" in options:
bf99d3
+		import urllib3
bf99d3
+		urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
bf99d3
+
bf99d3
 	connection = create_nova_connection(options)
bf99d3
 
bf99d3
 	# Un-evacuating a server doesn't make sense
bf99d3
diff --git a/tests/data/metadata/fence_compute.xml b/tests/data/metadata/fence_compute.xml
bf99d3
index 99d56af0..2f183268 100644
bf99d3
--- a/tests/data/metadata/fence_compute.xml
bf99d3
+++ b/tests/data/metadata/fence_compute.xml
bf99d3
@@ -70,7 +70,7 @@
bf99d3
 	</parameter>
bf99d3
 	<parameter name="insecure" unique="0" required="0">
bf99d3
 		<getopt mixed="--insecure" />
bf99d3
-		<content type="boolean" default="False"  />
bf99d3
+		<content type="boolean"  />
bf99d3
 		<shortdesc lang="en">Allow Insecure TLS Requests</shortdesc>
bf99d3
 	</parameter>
bf99d3
 	<parameter name="project-domain" unique="0" required="0" deprecated="1">
bf99d3
diff --git a/tests/data/metadata/fence_evacuate.xml b/tests/data/metadata/fence_evacuate.xml
bf99d3
index 8c720b80..95da0e1b 100644
bf99d3
--- a/tests/data/metadata/fence_evacuate.xml
bf99d3
+++ b/tests/data/metadata/fence_evacuate.xml
bf99d3
@@ -70,7 +70,7 @@
bf99d3
 	</parameter>
bf99d3
 	<parameter name="insecure" unique="0" required="0">
bf99d3
 		<getopt mixed="--insecure" />
bf99d3
-		<content type="boolean" default="False"  />
bf99d3
+		<content type="boolean"  />
bf99d3
 		<shortdesc lang="en">Allow Insecure TLS Requests</shortdesc>
bf99d3
 	</parameter>
bf99d3
 	<parameter name="project-domain" unique="0" required="0" deprecated="1">