Blame SOURCES/bz1763674-fence_rhevm-add-cookie-support.patch

66332a
From b885e0f65af626154096a49554e9765e18bfbbd9 Mon Sep 17 00:00:00 2001
66332a
From: Frank Toth <ftoth1@bloomberg.net>
66332a
Date: Wed, 16 Oct 2019 13:58:50 +0800
66332a
Subject: [PATCH 1/3] Added cookie file management to properly reuse session
66332a
 and do not create new one every time.
66332a
66332a
---
66332a
 agents/rhevm/fence_rhevm.py | 15 ++++++++++++++-
66332a
 1 file changed, 14 insertions(+), 1 deletion(-)
66332a
66332a
diff --git a/agents/rhevm/fence_rhevm.py b/agents/rhevm/fence_rhevm.py
66332a
index 9e4650cd..defa35e6 100644
66332a
--- a/agents/rhevm/fence_rhevm.py
66332a
+++ b/agents/rhevm/fence_rhevm.py
66332a
@@ -117,7 +117,12 @@ def send_command(opt, command, method="GET"):
66332a
 		conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
66332a
 		conn.setopt(pycurl.USERPWD, opt["--username"] + ":" + opt["--password"])
66332a
 		if "--use-cookies" in opt:
66332a
-			conn.setopt(pycurl.COOKIEFILE, "")
66332a
+			if "--cookie-file" in opt:
66332a
+				cookie_file = opt["--cookie-file"]
66332a
+			else:
66332a
+				cookie_file = "/tmp/fence_rhevm_" + opt["--ip"] + "_" + opt["--username"] + "_cookie.dat"
66332a
+			conn.setopt(pycurl.COOKIEFILE, cookie_file)
66332a
+			conn.setopt(pycurl.COOKIEJAR, cookie_file)
66332a
 
66332a
 	conn.setopt(pycurl.TIMEOUT, int(opt["--shell-timeout"]))
66332a
 	if "--ssl" in opt or "--ssl-secure" in opt:
66332a
@@ -166,6 +171,14 @@ def define_new_opts():
66332a
 		"required" : "0",
66332a
 		"shortdesc" : "Reuse cookies for authentication",
66332a
 		"order" : 1}
66332a
+	all_opt["cookie_file"] = {
66332a
+		"getopt" : ":",
66332a
+		"longopt" : "cookie-file",
66332a
+		"help" : "--cookie-file                  Path to cookie file for authentication\n"
66332a
+                        "\t\t\t\t  (Default: /tmp/fence_rhevm_ip_username_cookie.dat)",
66332a
+		"required" : "0",
66332a
+		"shortdesc" : "Path to cookie file for authentication",
66332a
+		"order" : 2}
66332a
 	all_opt["api_version"] = {
66332a
 		"getopt" : ":",
66332a
 		"longopt" : "api-version",
66332a
66332a
From 874344acbfee5f774b320e384a46e1ce953a34ce Mon Sep 17 00:00:00 2001
66332a
From: Frank Toth <ftoth1@bloomberg.net>
66332a
Date: Wed, 16 Oct 2019 23:41:50 +0800
66332a
Subject: [PATCH 2/3] Added cookie_file to device_opt array. Use
66332a
 tempfile.gettempdir() to get the TMP dir instead of hardcoded /tmp
66332a
66332a
---
66332a
 agents/rhevm/fence_rhevm.py | 4 +++-
66332a
 1 file changed, 3 insertions(+), 1 deletion(-)
66332a
66332a
diff --git a/agents/rhevm/fence_rhevm.py b/agents/rhevm/fence_rhevm.py
66332a
index defa35e6..25aecbe5 100644
66332a
--- a/agents/rhevm/fence_rhevm.py
66332a
+++ b/agents/rhevm/fence_rhevm.py
66332a
@@ -4,6 +4,7 @@
66332a
 import pycurl, io
66332a
 import logging
66332a
 import atexit
66332a
+import tempfile
66332a
 sys.path.append("@FENCEAGENTSLIBDIR@")
66332a
 from fencing import *
66332a
 from fencing import fail, EC_FETCH_VM_UUID, run_delay
66332a
@@ -120,7 +121,7 @@ def send_command(opt, command, method="GET"):
66332a
 			if "--cookie-file" in opt:
66332a
 				cookie_file = opt["--cookie-file"]
66332a
 			else:
66332a
-				cookie_file = "/tmp/fence_rhevm_" + opt["--ip"] + "_" + opt["--username"] + "_cookie.dat"
66332a
+				cookie_file = tempfile.gettempdir() + "/fence_rhevm_" + opt["--ip"] + "_" + opt["--username"] + "_cookie.dat"
66332a
 			conn.setopt(pycurl.COOKIEFILE, cookie_file)
66332a
 			conn.setopt(pycurl.COOKIEJAR, cookie_file)
66332a
 
66332a
@@ -215,6 +216,7 @@ def main():
66332a
 		"web",
66332a
 		"port",
66332a
 		"use_cookies",
66332a
+		"cookie_file",
66332a
 		"api_version",
66332a
 		"api_path",
66332a
 		"disable_http_filter",
66332a
66332a
From 196513cfc0edfd28f483a00b4adfa230b666a47d Mon Sep 17 00:00:00 2001
66332a
From: Frank Toth <ftoth1@bloomberg.net>
66332a
Date: Fri, 18 Oct 2019 05:16:18 +0200
66332a
Subject: [PATCH 3/3] After 'make xml-upload'
66332a
66332a
---
66332a
 tests/data/metadata/fence_rhevm.xml | 5 +++++
66332a
 1 file changed, 5 insertions(+)
66332a
66332a
diff --git a/tests/data/metadata/fence_rhevm.xml b/tests/data/metadata/fence_rhevm.xml
66332a
index c56cf64b..2b6b02b2 100644
66332a
--- a/tests/data/metadata/fence_rhevm.xml
66332a
+++ b/tests/data/metadata/fence_rhevm.xml
66332a
@@ -103,6 +103,11 @@
66332a
 		<content type="string" default="auto"  />
66332a
 		<shortdesc lang="en">Version of RHEV API (default: auto)</shortdesc>
66332a
 	</parameter>
66332a
+	<parameter name="cookie_file" unique="0" required="0">
66332a
+		<getopt mixed="--cookie-file" />
66332a
+		<content type="string"  />
66332a
+		<shortdesc lang="en">Path to cookie file for authentication</shortdesc>
66332a
+	</parameter>
66332a
 	<parameter name="api_path" unique="0" required="0">
66332a
 		<getopt mixed="--api-path=[path]" />
66332a
 		<shortdesc lang="en">The path part of the API URL</shortdesc>