Merge pull request #44905 from mgfritch/cephadm-prom-chown

cephadm: chown the prometheus data dir during redeploy

Reviewed-by: Adam King <adking@redhat.com>
Reviewed-by: Patrick Seidensal <pseidensal@suse.com>
This commit is contained in:
Adam King 2022-02-21 10:19:40 -05:00 committed by GitHub
commit a3ed8ddb4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -2098,6 +2098,13 @@ def move_files(ctx, src, dst, uid=None, gid=None):
os.chown(dst_file, uid, gid)
def recursive_chown(path: str, uid: int, gid: int) -> None:
for dirpath, dirnames, filenames in os.walk(path):
os.chown(dirpath, uid, gid)
for filename in filenames:
os.chown(os.path.join(dirpath, filename), uid, gid)
# copied from distutils
def find_executable(executable: str, path: Optional[str] = None) -> Optional[str]:
"""Tries to find 'executable' in the directories listed in 'path'.
@ -2403,6 +2410,8 @@ def create_daemon_dirs(ctx, fsid, daemon_type, daemon_id, uid, gid,
makedirs(os.path.join(data_dir_root, config_dir), uid, gid, 0o755)
makedirs(os.path.join(data_dir_root, config_dir, 'alerting'), uid, gid, 0o755)
makedirs(os.path.join(data_dir_root, 'data'), uid, gid, 0o755)
recursive_chown(os.path.join(data_dir_root, 'etc'), uid, gid)
recursive_chown(os.path.join(data_dir_root, 'data'), uid, gid)
elif daemon_type == 'grafana':
data_dir_root = get_data_dir(fsid, ctx.data_dir,
daemon_type, daemon_id)

View File

@ -812,6 +812,22 @@ class TestMonitoring(object):
with open(file) as f:
assert f.read() == content
# assert uid/gid after redeploy
new_uid = uid+1
new_gid = gid+1
cd.create_daemon_dirs(ctx,
fsid,
daemon_type,
daemon_id,
new_uid,
new_gid,
config=None,
keyring=None)
for file,content in expected.items():
file = os.path.join(prefix, file)
assert os.stat(file).st_uid == new_uid
assert os.stat(file).st_gid == new_gid
class TestBootstrap(object):