Skip to content

Commit 8f6bc33

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add exclude for permissions in kolla config.json file"
2 parents fe1aefd + 07d0b12 commit 8f6bc33

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

doc/source/admin/kolla_api.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ The `kolla_set_configs`_ script understands the following attributes:
6565
Must be passed in the numeric octal form.
6666
* **recurse**: whether to apply the change recursively over the target
6767
directory. Boolean, defaults to ``false``.
68+
* **exclude**: array of names of the directories or files to be excluded when
69+
``recurse`` is set to ``true``. Supports Python regular expressions.
70+
Defaults to empty array.
6871

6972
Here is an example configuration file:
7073

@@ -85,7 +88,8 @@ Here is an example configuration file:
8588
{
8689
"path": "/var/log/kolla/trove",
8790
"owner": "trove:trove",
88-
"recurse": true
91+
"recurse": true,
92+
"exclude": ["/var/log/^snapshot.*"]
8993
}
9094
]
9195
}

docker/base/set_configs.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import logging
2020
import os
2121
import pwd
22+
import re
2223
import shutil
2324
import stat
2425
import sys
@@ -334,6 +335,7 @@ def handle_permissions(config):
334335
owner = permission.get('owner')
335336
recurse = permission.get('recurse', False)
336337
perm = permission.get('perm')
338+
exclude = permission.get('exclude', [])
337339

338340
desired_user, desired_group = user_group(owner)
339341
uid = pwd.getpwnam(desired_user).pw_uid
@@ -373,14 +375,24 @@ def set_perms(path, uid, gid, perm):
373375
LOG.exception('Failed to set permission of %s to %s',
374376
path, perm)
375377

378+
def handle_exclusion(root, path_suffix):
379+
full_path = os.path.join(root, path_suffix)
380+
LOG.debug("Checking for exclusion: %s" % full_path)
381+
if exclude:
382+
for exclude_ in exclude:
383+
if not re.search(exclude_, full_path):
384+
set_perms(full_path, uid, gid, perm)
385+
else:
386+
set_perms(full_path, uid, gid, perm)
387+
376388
for dest in glob.glob(path):
377389
set_perms(dest, uid, gid, perm)
378390
if recurse and os.path.isdir(dest):
379391
for root, dirs, files in os.walk(dest):
380392
for dir_ in dirs:
381-
set_perms(os.path.join(root, dir_), uid, gid, perm)
393+
handle_exclusion(root, dir_)
382394
for file_ in files:
383-
set_perms(os.path.join(root, file_), uid, gid, perm)
395+
handle_exclusion(root, file_)
384396

385397

386398
def execute_config_strategy(config):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Adds option to exclude files and directories when setting permissions
5+
defined in kolla config.json using regular expression.

0 commit comments

Comments
 (0)