From 6eeaf503305570897d0a21fa1d335a0567e1a1e1 Mon Sep 17 00:00:00 2001
From: Alex Barchiesi <alex.barchiesi@garr.it>
Date: Tue, 7 Nov 2017 12:58:50 +0100
Subject: [PATCH] Fix to missing directory /etc/keystone, when leader-changed.

---
 charmhelpers/contrib/openstack/templating.py | 2 ++
 hooks/keystone_hooks.py                      | 2 +-
 hooks/keystone_utils.py                      | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/charmhelpers/contrib/openstack/templating.py b/charmhelpers/contrib/openstack/templating.py
index d8c1fc7f..ee95bfbf 100644
--- a/charmhelpers/contrib/openstack/templating.py
+++ b/charmhelpers/contrib/openstack/templating.py
@@ -273,6 +273,8 @@ class OSConfigRenderer(object):
 
         _out = self.render(config_file)
 
+        from charmhelpers.core.host import (mkdir) # Attardi
+        mkdir(os.path.dirname(config_file)) # Attardi
         with open(config_file, 'wb') as out:
             out.write(_out)
 
diff --git a/hooks/keystone_hooks.py b/hooks/keystone_hooks.py
index a035ee8f..92b440bb 100755
--- a/hooks/keystone_hooks.py
+++ b/hooks/keystone_hooks.py
@@ -18,7 +18,6 @@ import hashlib
 import json
 import os
 import sys
-import requests
 
 from subprocess import check_call
 
@@ -846,6 +845,7 @@ def configure_idp(idp, remote_ids, mappings_file, mapping_id, protocol):
         get_local_endpoint,
         get_admin_token
     )
+    import requests
 
     log("Configuring provider: %s" % idp, level=DEBUG)
 
diff --git a/hooks/keystone_utils.py b/hooks/keystone_utils.py
index 91de93ef..1ea356dc 100644
--- a/hooks/keystone_utils.py
+++ b/hooks/keystone_utils.py
@@ -155,11 +155,11 @@ BASE_PACKAGES = [
     'python-keystoneclient',
     'python-mysqldb',
     'python-psycopg2',
+    'python-requests',
     'python-six',
     'pwgen',
     'unison',
     'uuid',
-    'python-requests',
 ]
 
 VERSION_PACKAGE = 'keystone'
-- 
GitLab