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

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