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

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