Browse Source

charmhelpers-sync

Pull in fix for call to ceph-authtool when updating keys.

Change-Id: I472cfa91e682d662cae9db4006bdc8b25174a24b
Closes-Bug: #1810917
changes/73/631673/1
Pete Vander Giessen 4 months ago
parent
commit
98a5f35b1d
1 changed files with 21 additions and 6 deletions
  1. 21
    6
      hooks/charmhelpers/contrib/storage/linux/ceph.py

+ 21
- 6
hooks/charmhelpers/contrib/storage/linux/ceph.py View File

@@ -856,12 +856,22 @@ def _keyring_path(service):
856 856
     return KEYRING.format(service)
857 857
 
858 858
 
859
-def create_keyring(service, key):
860
-    """Create a new Ceph keyring containing key."""
859
+def add_key(service, key):
860
+    """
861
+    Add a key to a keyring.
862
+
863
+    Creates the keyring if it doesn't already exist.
864
+
865
+    Logs and returns if the key is already in the keyring.
866
+    """
861 867
     keyring = _keyring_path(service)
862 868
     if os.path.exists(keyring):
863
-        log('Ceph keyring exists at %s.' % keyring, level=WARNING)
864
-        return
869
+        with open(keyring, 'r') as ring:
870
+            if key in ring.read():
871
+                log('Ceph keyring exists at %s and has not changed.' % keyring,
872
+                    level=DEBUG)
873
+                return
874
+            log('Updating existing keyring %s.' % keyring, level=DEBUG)
865 875
 
866 876
     cmd = ['ceph-authtool', keyring, '--create-keyring',
867 877
            '--name=client.{}'.format(service), '--add-key={}'.format(key)]
@@ -869,6 +879,11 @@ def create_keyring(service, key):
869 879
     log('Created new ceph keyring at %s.' % keyring, level=DEBUG)
870 880
 
871 881
 
882
+def create_keyring(service, key):
883
+    """Deprecated. Please use the more accurately named 'add_key'"""
884
+    return add_key(service, key)
885
+
886
+
872 887
 def delete_keyring(service):
873 888
     """Delete an existing Ceph keyring."""
874 889
     keyring = _keyring_path(service)
@@ -905,7 +920,7 @@ def get_ceph_nodes(relation='ceph'):
905 920
 
906 921
 def configure(service, key, auth, use_syslog):
907 922
     """Perform basic configuration of Ceph."""
908
-    create_keyring(service, key)
923
+    add_key(service, key)
909 924
     create_key_file(service, key)
910 925
     hosts = get_ceph_nodes()
911 926
     with open('/etc/ceph/ceph.conf', 'w') as ceph_conf:
@@ -1068,7 +1083,7 @@ def ensure_ceph_keyring(service, user=None, group=None,
1068 1083
     if not key:
1069 1084
         return False
1070 1085
 
1071
-    create_keyring(service=service, key=key)
1086
+    add_key(service=service, key=key)
1072 1087
     keyring = _keyring_path(service)
1073 1088
     if user and group:
1074 1089
         check_call(['chown', '%s.%s' % (user, group), keyring])

Loading…
Cancel
Save