From 7359b981d6cc1d44a1b9b28ce9e61dc250a3705e Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Fri, 4 Sep 2020 16:58:11 +0200 Subject: [PATCH] Ensure that the actions use the configured admin user Change-Id: I357b26fb585d68d2fbe9bbf21bbf9bfc52ac5050 Closes-Bug: #1893790 --- actions/create-cache-tier | 10 +++++----- actions/create-cache-tier.py | 9 +++++---- actions/create-erasure-profile | 12 ++++++------ actions/create-pool | 7 ++++--- actions/delete-erasure-profile | 4 ++-- actions/get-erasure-profile | 4 ++-- actions/list-erasure-profiles | 4 ++-- actions/list-pools | 4 ++-- actions/pool-get | 4 ++-- actions/pool-set | 4 ++-- actions/pool-statistics | 4 ++-- actions/remove-cache-tier | 9 +++++---- actions/remove-cache-tier.py | 10 +++++----- actions/remove-pool-snapshot | 4 ++-- actions/rename-pool | 4 ++-- actions/set-pool-max-bytes | 4 ++-- actions/snapshot-pool | 4 ++-- 17 files changed, 52 insertions(+), 49 deletions(-) diff --git a/actions/create-cache-tier b/actions/create-cache-tier index e8170cf..51a6518 100755 --- a/actions/create-cache-tier +++ b/actions/create-cache-tier @@ -6,28 +6,28 @@ import sys sys.path.append('hooks') from charmhelpers.contrib.storage.linux.ceph import Pool, pool_exists -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail def make_cache_tier(): backer_pool = action_get("backer-pool") cache_pool = action_get("cache-pool") cache_mode = action_get("cache-mode") - + user = config('admin-user') # Pre flight checks - if not pool_exists('admin', backer_pool): + if not pool_exists(user, backer_pool): log("Please create {} pool before calling create-cache-tier".format( backer_pool)) action_fail("create-cache-tier failed. Backer pool {} must exist " "before calling this".format(backer_pool)) - if not pool_exists('admin', cache_pool): + if not pool_exists(user, cache_pool): log("Please create {} pool before calling create-cache-tier".format( cache_pool)) action_fail("create-cache-tier failed. Cache pool {} must exist " "before calling this".format(cache_pool)) - pool = Pool(service='admin', name=backer_pool) + pool = Pool(service=user, name=backer_pool) try: pool.add_cache_tier(cache_pool=cache_pool, mode=cache_mode) except CalledProcessError as err: diff --git a/actions/create-cache-tier.py b/actions/create-cache-tier.py index 928e941..97a1d1e 100755 --- a/actions/create-cache-tier.py +++ b/actions/create-cache-tier.py @@ -18,28 +18,29 @@ _add_path(_root) from charmhelpers.contrib.storage.linux.ceph import Pool, pool_exists -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail def make_cache_tier(): backer_pool = action_get("backer-pool") cache_pool = action_get("cache-pool") cache_mode = action_get("cache-mode") + user = config('admin-user') # Pre flight checks - if not pool_exists('admin', backer_pool): + if not pool_exists(user, backer_pool): log("Please create {} pool before calling create-cache-tier".format( backer_pool)) action_fail("create-cache-tier failed. Backer pool {} must exist " "before calling this".format(backer_pool)) - if not pool_exists('admin', cache_pool): + if not pool_exists(user, cache_pool): log("Please create {} pool before calling create-cache-tier".format( cache_pool)) action_fail("create-cache-tier failed. Cache pool {} must exist " "before calling this".format(cache_pool)) - pool = Pool(service='admin', name=backer_pool) + pool = Pool(service=user, name=backer_pool) try: pool.add_cache_tier(cache_pool=cache_pool, mode=cache_mode) except CalledProcessError as err: diff --git a/actions/create-erasure-profile b/actions/create-erasure-profile index 7400ccd..016862c 100755 --- a/actions/create-erasure-profile +++ b/actions/create-erasure-profile @@ -17,14 +17,14 @@ _add_path(_root) from charmhelpers.contrib.storage.linux.ceph import create_erasure_profile -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail def make_erasure_profile(): name = action_get("name") plugin = action_get("plugin") failure_domain = action_get("failure-domain") - + user = config('admin-user') # jerasure requires k+m # isa requires k+m # local requires k+m+l @@ -34,7 +34,7 @@ def make_erasure_profile(): k = action_get("data-chunks") m = action_get("coding-chunks") try: - create_erasure_profile(service='admin', + create_erasure_profile(service=user, erasure_plugin_name=plugin, profile_name=name, data_chunks=k, @@ -48,7 +48,7 @@ def make_erasure_profile(): k = action_get("data-chunks") m = action_get("coding-chunks") try: - create_erasure_profile(service='admin', + create_erasure_profile(service=user, erasure_plugin_name=plugin, profile_name=name, data_chunks=k, @@ -63,7 +63,7 @@ def make_erasure_profile(): m = action_get("coding-chunks") l = action_get("locality-chunks") try: - create_erasure_profile(service='admin', + create_erasure_profile(service=user, erasure_plugin_name=plugin, profile_name=name, data_chunks=k, @@ -79,7 +79,7 @@ def make_erasure_profile(): m = action_get("coding-chunks") c = action_get("durability-estimator") try: - create_erasure_profile(service='admin', + create_erasure_profile(service=user, erasure_plugin_name=plugin, profile_name=name, data_chunks=k, diff --git a/actions/create-pool b/actions/create-pool index 0dd0be3..ee6a779 100755 --- a/actions/create-pool +++ b/actions/create-pool @@ -15,18 +15,19 @@ _add_path(_hooks) _add_path(_root) from subprocess import CalledProcessError -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail from charmhelpers.contrib.storage.linux.ceph import ErasurePool, ReplicatedPool def create_pool(): pool_name = action_get("name") pool_type = action_get("pool-type") + user = config('admin-user') try: if pool_type == "replicated": replicas = action_get("replicas") replicated_pool = ReplicatedPool(name=pool_name, - service='admin', + service=user, replicas=replicas) replicated_pool.create() @@ -34,7 +35,7 @@ def create_pool(): crush_profile_name = action_get("erasure-profile-name") erasure_pool = ErasurePool(name=pool_name, erasure_code_profile=crush_profile_name, - service='admin') + service=user) erasure_pool.create() else: log("Unknown pool type of {}. Only erasure or replicated is " diff --git a/actions/delete-erasure-profile b/actions/delete-erasure-profile index 8651d07..7df8c44 100755 --- a/actions/delete-erasure-profile +++ b/actions/delete-erasure-profile @@ -18,14 +18,14 @@ _add_path(_hooks) _add_path(_root) from charmhelpers.contrib.storage.linux.ceph import remove_erasure_profile -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail def delete_erasure_profile(): name = action_get("name") try: - remove_erasure_profile(service='admin', profile_name=name) + remove_erasure_profile(service=config('admin-user'), profile_name=name) except CalledProcessError as e: action_fail("Remove erasure profile failed with error: {}".format( e.message)) diff --git a/actions/get-erasure-profile b/actions/get-erasure-profile index 39947bb..1f6b311 100755 --- a/actions/get-erasure-profile +++ b/actions/get-erasure-profile @@ -16,12 +16,12 @@ _add_path(_hooks) _add_path(_root) from charmhelpers.contrib.storage.linux.ceph import get_erasure_profile -from charmhelpers.core.hookenv import action_get, action_set +from charmhelpers.core.hookenv import action_get, action_set, config def make_erasure_profile(): name = action_get("name") - out = get_erasure_profile(service='admin', name=name) + out = get_erasure_profile(service=config('admin-user'), name=name) action_set({'message': out}) diff --git a/actions/list-erasure-profiles b/actions/list-erasure-profiles index fd0586f..caaa68c 100755 --- a/actions/list-erasure-profiles +++ b/actions/list-erasure-profiles @@ -16,13 +16,13 @@ def _add_path(path): _add_path(_hooks) _add_path(_root) -from charmhelpers.core.hookenv import action_get, log, action_set, action_fail +from charmhelpers.core.hookenv import action_get, log, config, action_set, action_fail if __name__ == '__main__': name = action_get("name") try: out = check_output(['ceph', - '--id', 'admin', + '--id', config('admin-user'), 'osd', 'erasure-code-profile', 'ls']).decode('UTF-8') diff --git a/actions/list-pools b/actions/list-pools index 67c1aed..401619c 100755 --- a/actions/list-pools +++ b/actions/list-pools @@ -16,11 +16,11 @@ def _add_path(path): _add_path(_hooks) _add_path(_root) -from charmhelpers.core.hookenv import log, action_set, action_fail +from charmhelpers.core.hookenv import log, config, action_set, action_fail if __name__ == '__main__': try: - out = check_output(['ceph', '--id', 'admin', + out = check_output(['ceph', '--id', config('admin-user'), 'osd', 'lspools']).decode('UTF-8') action_set({'message': out}) except CalledProcessError as e: diff --git a/actions/pool-get b/actions/pool-get index 3a42ab4..f1a5077 100755 --- a/actions/pool-get +++ b/actions/pool-get @@ -16,13 +16,13 @@ def _add_path(path): _add_path(_hooks) _add_path(_root) -from charmhelpers.core.hookenv import log, action_set, action_get, action_fail +from charmhelpers.core.hookenv import log, config, action_set, action_get, action_fail if __name__ == '__main__': name = action_get('pool-name') key = action_get('key') try: - out = check_output(['ceph', '--id', 'admin', + out = check_output(['ceph', '--id', config('admin-user'), 'osd', 'pool', 'get', name, key]).decode('UTF-8') action_set({'message': out}) except CalledProcessError as e: diff --git a/actions/pool-set b/actions/pool-set index 8963c90..44874eb 100755 --- a/actions/pool-set +++ b/actions/pool-set @@ -15,7 +15,7 @@ def _add_path(path): _add_path(_hooks) _add_path(_root) -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail from ceph_broker import handle_set_pool_value if __name__ == '__main__': @@ -27,7 +27,7 @@ if __name__ == '__main__': 'value': value} try: - handle_set_pool_value(service='admin', request=request) + handle_set_pool_value(service=config('admin-user'), request=request) except CalledProcessError as e: log(str(e)) action_fail("Setting pool key: {} and value: {} failed with " diff --git a/actions/pool-statistics b/actions/pool-statistics index 403267f..56e56a7 100755 --- a/actions/pool-statistics +++ b/actions/pool-statistics @@ -15,11 +15,11 @@ _add_path(_hooks) _add_path(_root) from subprocess import check_output, CalledProcessError -from charmhelpers.core.hookenv import log, action_set, action_fail +from charmhelpers.core.hookenv import log, config, action_set, action_fail if __name__ == '__main__': try: - out = check_output(['ceph', '--id', 'admin', + out = check_output(['ceph', '--id', config('admin-user'), 'df']).decode('UTF-8') action_set({'message': out}) except CalledProcessError as e: diff --git a/actions/remove-cache-tier b/actions/remove-cache-tier index 79db9cf..215704d 100755 --- a/actions/remove-cache-tier +++ b/actions/remove-cache-tier @@ -5,7 +5,7 @@ import sys sys.path.append('hooks') from charmhelpers.contrib.storage.linux.ceph import Pool, pool_exists -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail __author__ = 'chris' @@ -13,21 +13,22 @@ __author__ = 'chris' def delete_cache_tier(): backer_pool = action_get("backer-pool") cache_pool = action_get("cache-pool") + user = config('admin-user') # Pre flight checks - if not pool_exists('admin', backer_pool): + if not pool_exists(user, backer_pool): log("Backer pool {} must exist before calling this".format( backer_pool)) action_fail("remove-cache-tier failed. Backer pool {} must exist " "before calling this".format(backer_pool)) - if not pool_exists('admin', cache_pool): + if not pool_exists(user, cache_pool): log("Cache pool {} must exist before calling this".format( cache_pool)) action_fail("remove-cache-tier failed. Cache pool {} must exist " "before calling this".format(cache_pool)) - pool = Pool(service='admin', name=backer_pool) + pool = Pool(service=user, name=backer_pool) try: pool.remove_cache_tier(cache_pool=cache_pool) except CalledProcessError as err: diff --git a/actions/remove-cache-tier.py b/actions/remove-cache-tier.py index 8c9b937..a6f8f2b 100755 --- a/actions/remove-cache-tier.py +++ b/actions/remove-cache-tier.py @@ -16,7 +16,7 @@ _add_path(_hooks) _add_path(_root) from charmhelpers.contrib.storage.linux.ceph import Pool, pool_exists -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail __author__ = 'chris' @@ -24,21 +24,21 @@ __author__ = 'chris' def delete_cache_tier(): backer_pool = action_get("backer-pool") cache_pool = action_get("cache-pool") - + user = config('admin-user') # Pre flight checks - if not pool_exists('admin', backer_pool): + if not pool_exists(user, backer_pool): log("Backer pool {} must exist before calling this".format( backer_pool)) action_fail("remove-cache-tier failed. Backer pool {} must exist " "before calling this".format(backer_pool)) - if not pool_exists('admin', cache_pool): + if not pool_exists(user, cache_pool): log("Cache pool {} must exist before calling this".format( cache_pool)) action_fail("remove-cache-tier failed. Cache pool {} must exist " "before calling this".format(cache_pool)) - pool = Pool(service='admin', name=backer_pool) + pool = Pool(service=user, name=backer_pool) try: pool.remove_cache_tier(cache_pool=cache_pool) except CalledProcessError as err: diff --git a/actions/remove-pool-snapshot b/actions/remove-pool-snapshot index 645ff07..7569db5 100755 --- a/actions/remove-pool-snapshot +++ b/actions/remove-pool-snapshot @@ -15,14 +15,14 @@ _add_path(_hooks) _add_path(_root) from subprocess import CalledProcessError -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail from charmhelpers.contrib.storage.linux.ceph import remove_pool_snapshot if __name__ == '__main__': name = action_get("pool-name") snapname = action_get("snapshot-name") try: - remove_pool_snapshot(service='admin', + remove_pool_snapshot(service=config('admin-user'), pool_name=name, snapshot_name=snapname) except CalledProcessError as e: diff --git a/actions/rename-pool b/actions/rename-pool index 3301830..c8508b7 100755 --- a/actions/rename-pool +++ b/actions/rename-pool @@ -15,14 +15,14 @@ _add_path(_hooks) _add_path(_root) from subprocess import CalledProcessError -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail from charmhelpers.contrib.storage.linux.ceph import rename_pool if __name__ == '__main__': name = action_get("pool-name") new_name = action_get("new-name") try: - rename_pool(service='admin', old_name=name, new_name=new_name) + rename_pool(service=config('admin-user'), old_name=name, new_name=new_name) except CalledProcessError as e: log(str(e)) action_fail("Renaming pool failed with message: {}".format(str(e))) diff --git a/actions/set-pool-max-bytes b/actions/set-pool-max-bytes index c1550d4..91196b3 100755 --- a/actions/set-pool-max-bytes +++ b/actions/set-pool-max-bytes @@ -15,14 +15,14 @@ _add_path(_hooks) _add_path(_root) from subprocess import CalledProcessError -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail from charmhelpers.contrib.storage.linux.ceph import set_pool_quota if __name__ == '__main__': max_bytes = action_get("max") name = action_get("pool-name") try: - set_pool_quota(service='admin', pool_name=name, max_bytes=max_bytes) + set_pool_quota(service=config('admin-user'), pool_name=name, max_bytes=max_bytes) except CalledProcessError as e: log(str(e)) action_fail("Set pool quota failed with message: {}".format(str(e))) diff --git a/actions/snapshot-pool b/actions/snapshot-pool index 0191bcc..3eb6926 100755 --- a/actions/snapshot-pool +++ b/actions/snapshot-pool @@ -15,14 +15,14 @@ _add_path(_hooks) _add_path(_root) from subprocess import CalledProcessError -from charmhelpers.core.hookenv import action_get, log, action_fail +from charmhelpers.core.hookenv import action_get, config, log, action_fail from charmhelpers.contrib.storage.linux.ceph import snapshot_pool if __name__ == '__main__': name = action_get("pool-name") snapname = action_get("snapshot-name") try: - snapshot_pool(service='admin', + snapshot_pool(service=config('admin-user'), pool_name=name, snapshot_name=snapname) except CalledProcessError as e: