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

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