Blame SOURCES/bz2041933-bz2041935-2-fence_openstack-clouds-openrc.patch

cbc3ed
From 7d9572ec947d23fa18ac530f07fe33ba148c9634 Mon Sep 17 00:00:00 2001
cbc3ed
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
cbc3ed
Date: Mon, 17 Jan 2022 14:32:53 +0100
cbc3ed
Subject: [PATCH] fence_openstack: fix issues with new clouds.yaml/openrc
cbc3ed
 parameters - hardcoded clouds.yaml paths to work like the openstack cli
cbc3ed
 client   (used by the resource agents)
cbc3ed
cbc3ed
---
cbc3ed
 agents/openstack/fence_openstack.py     | 55 +++++++++++--------------
cbc3ed
 tests/data/metadata/fence_openstack.xml | 10 -----
cbc3ed
 2 files changed, 25 insertions(+), 40 deletions(-)
cbc3ed
cbc3ed
diff --git a/agents/openstack/fence_openstack.py b/agents/openstack/fence_openstack.py
cbc3ed
index d3a4be3aa..666016d78 100644
cbc3ed
--- a/agents/openstack/fence_openstack.py
cbc3ed
+++ b/agents/openstack/fence_openstack.py
cbc3ed
@@ -3,6 +3,7 @@
cbc3ed
 import atexit
cbc3ed
 import logging
cbc3ed
 import sys
cbc3ed
+import os
cbc3ed
 
cbc3ed
 import urllib3
cbc3ed
 
cbc3ed
@@ -27,9 +28,15 @@ def translate_status(instance_status):
cbc3ed
     return "unknown"
cbc3ed
 
cbc3ed
 def get_cloud(options):
cbc3ed
-    import os, yaml
cbc3ed
+    import yaml
cbc3ed
 
cbc3ed
-    clouds_yaml = os.path.expanduser("~/.config/openstack/clouds.yaml")
cbc3ed
+    clouds_yaml = "~/.config/openstack/clouds.yaml"
cbc3ed
+    if not os.path.exists(os.path.expanduser(clouds_yaml)):
cbc3ed
+        clouds_yaml = "/etc/openstack/clouds.yaml"
cbc3ed
+    if not os.path.exists(os.path.expanduser(clouds_yaml)):
cbc3ed
+        fail_usage("Failed: ~/.config/openstack/clouds.yaml and /etc/openstack/clouds.yaml does not exist")
cbc3ed
+
cbc3ed
+    clouds_yaml = os.path.expanduser(clouds_yaml)
cbc3ed
     if os.path.exists(clouds_yaml):
cbc3ed
         with open(clouds_yaml, "r") as yaml_stream:
cbc3ed
             try:
cbc3ed
@@ -201,22 +208,13 @@ def define_new_opts():
cbc3ed
         "default": "Default",
cbc3ed
         "order": 5,
cbc3ed
     }
cbc3ed
-    all_opt["clouds-yaml"] = {
cbc3ed
-        "getopt": ":",
cbc3ed
-        "longopt": "clouds-yaml",
cbc3ed
-        "help": "--clouds-yaml=[clouds-yaml]  Path to the clouds.yaml config file",
cbc3ed
-        "required": "0",
cbc3ed
-        "shortdesc": "clouds.yaml config file",
cbc3ed
-        "default": "~/.config/openstack/clouds.yaml",
cbc3ed
-        "order": 6,
cbc3ed
-    }
cbc3ed
     all_opt["cloud"] = {
cbc3ed
         "getopt": ":",
cbc3ed
         "longopt": "cloud",
cbc3ed
-        "help": "--cloud=[cloud]              Openstack cloud (from clouds.yaml).",
cbc3ed
+        "help": "--cloud=[cloud]              Openstack cloud (from ~/.config/openstack/clouds.yaml or /etc/openstack/clouds.yaml).",
cbc3ed
         "required": "0",
cbc3ed
         "shortdesc": "Cloud from clouds.yaml",
cbc3ed
-        "order": 7,
cbc3ed
+        "order": 6,
cbc3ed
     }
cbc3ed
     all_opt["openrc"] = {
cbc3ed
         "getopt": ":",
cbc3ed
@@ -224,7 +222,7 @@ def define_new_opts():
cbc3ed
         "help": "--openrc=[openrc]              Path to the openrc config file",
cbc3ed
         "required": "0",
cbc3ed
         "shortdesc": "openrc config file",
cbc3ed
-        "order": 8,
cbc3ed
+        "order": 7,
cbc3ed
     }
cbc3ed
     all_opt["uuid"] = {
cbc3ed
         "getopt": ":",
cbc3ed
@@ -232,7 +230,7 @@ def define_new_opts():
cbc3ed
         "help": "--uuid=[uuid]                  Replaced by -n, --plug",
cbc3ed
         "required": "0",
cbc3ed
         "shortdesc": "Replaced by port/-n/--plug",
cbc3ed
-        "order": 9,
cbc3ed
+        "order": 8,
cbc3ed
     }
cbc3ed
     all_opt["cacert"] = {
cbc3ed
         "getopt": ":",
cbc3ed
@@ -241,7 +239,7 @@ def define_new_opts():
cbc3ed
         "required": "0",
cbc3ed
         "shortdesc": "SSL X.509 certificates file",
cbc3ed
         "default": "",
cbc3ed
-        "order": 10,
cbc3ed
+        "order": 9,
cbc3ed
     }
cbc3ed
     all_opt["apitimeout"] = {
cbc3ed
         "getopt": ":",
cbc3ed
@@ -251,7 +249,7 @@ def define_new_opts():
cbc3ed
         "shortdesc": "Timeout in seconds to use for API calls, default is 60.",
cbc3ed
         "required": "0",
cbc3ed
         "default": 60,
cbc3ed
-        "order": 11,
cbc3ed
+        "order": 10,
cbc3ed
     }
cbc3ed
 
cbc3ed
 
cbc3ed
@@ -267,7 +265,6 @@ def main():
cbc3ed
         "project-name",
cbc3ed
         "user-domain-name",
cbc3ed
         "project-domain-name",
cbc3ed
-        "clouds-yaml",
cbc3ed
         "cloud",
cbc3ed
         "openrc",
cbc3ed
         "port",
cbc3ed
@@ -312,28 +309,26 @@ def main():
cbc3ed
 
cbc3ed
     run_delay(options)
cbc3ed
 
cbc3ed
-    if options.get("--clouds-yaml"):
cbc3ed
-        if not os.path.exists(os.path.expanduser(options["--clouds-yaml"])):
cbc3ed
-            fail_usage("Failed: {} does not exist".format(options.get("--clouds-yaml")))
cbc3ed
-        if not options.get("--cloud"):
cbc3ed
-            fail_usage("Failed: \"cloud\" not specified")
cbc3ed
+    if options.get("--cloud"):
cbc3ed
         cloud = get_cloud(options)
cbc3ed
-        username = cloud.get("username")
cbc3ed
-        password = cloud.get("password")
cbc3ed
-        projectname = cloud.get("project_name")
cbc3ed
+        username = cloud.get("auth").get("username")
cbc3ed
+        password = cloud.get("auth").get("password")
cbc3ed
+        projectname = cloud.get("auth").get("project_name")
cbc3ed
         auth_url = None
cbc3ed
         try:
cbc3ed
-            auth_url = cloud.get("auth_url")
cbc3ed
+            auth_url = cloud.get("auth").get("auth_url")
cbc3ed
         except KeyError:
cbc3ed
             fail_usage("Failed: You have to set the Keystone service endpoint for authorization")
cbc3ed
-        user_domain_name = cloud.get("user_domain_name")
cbc3ed
-        project_domain_name = cloud.get("project_domain_name")
cbc3ed
+        user_domain_name = cloud.get("auth").get("user_domain_name")
cbc3ed
+        project_domain_name = cloud.get("auth").get("project_domain_name")
cbc3ed
         caverify = cloud.get("verify")
cbc3ed
         if caverify in [True, False]:
cbc3ed
                 options["--ssl-insecure"] = caverify
cbc3ed
         else:
cbc3ed
                 options["--cacert"] = caverify
cbc3ed
-    if options.get("--openrc") and os.path.exists(os.path.expanduser(options["--openrc"])):
cbc3ed
+    elif options.get("--openrc"):
cbc3ed
+        if not os.path.exists(os.path.expanduser(options["--openrc"])):
cbc3ed
+            fail_usage("Failed: {} does not exist".format(options.get("--openrc")))
cbc3ed
         source_env(options["--openrc"])
cbc3ed
         env = os.environ
cbc3ed
         username = env.get("OS_USERNAME")
cbc3ed
diff --git a/tests/data/metadata/fence_openstack.xml b/tests/data/metadata/fence_openstack.xml
cbc3ed
index 55a57b4d7..67b2191b7 100644
cbc3ed
--- a/tests/data/metadata/fence_openstack.xml
cbc3ed
+++ b/tests/data/metadata/fence_openstack.xml
cbc3ed
@@ -93,16 +93,6 @@
cbc3ed
 		<content type="string" default="Default"  />
cbc3ed
 		<shortdesc lang="en">Keystone Project Domain Name</shortdesc>
cbc3ed
 	</parameter>
cbc3ed
-	<parameter name="clouds-yaml" unique="0" required="0" deprecated="1">
cbc3ed
-		<getopt mixed="--clouds-yaml=[clouds-yaml]" />
cbc3ed
-		<content type="string" default="~/.config/openstack/clouds.yaml"  />
cbc3ed
-		<shortdesc lang="en">clouds.yaml config file</shortdesc>
cbc3ed
-	</parameter>
cbc3ed
-	<parameter name="clouds_yaml" unique="0" required="0" obsoletes="clouds-yaml">
cbc3ed
-		<getopt mixed="--clouds-yaml=[clouds-yaml]" />
cbc3ed
-		<content type="string" default="~/.config/openstack/clouds.yaml"  />
cbc3ed
-		<shortdesc lang="en">clouds.yaml config file</shortdesc>
cbc3ed
-	</parameter>
cbc3ed
 	<parameter name="cloud" unique="0" required="0">
cbc3ed
 		<getopt mixed="--cloud=[cloud]" />
cbc3ed
 		<content type="string"  />