mirror of
https://github.com/ceph/ceph
synced 2025-02-21 18:17:42 +00:00
ceph-volume: make it possible to skip needs_root()
Add the possibility to skip the `needs_root()` decorator. See linked tracker for details. Fixes: https://tracker.ceph.com/issues/53511 Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
This commit is contained in:
parent
347d7d0f26
commit
068a1d2a30
@ -11,7 +11,7 @@ def needs_root(func):
|
||||
"""
|
||||
@wraps(func)
|
||||
def is_root(*a, **kw):
|
||||
if not os.getuid() == 0:
|
||||
if not os.getuid() == 0 and not os.environ.get('CEPH_VOLUME_SKIP_NEEDS_ROOT', False):
|
||||
raise exceptions.SuperUserError()
|
||||
return func(*a, **kw)
|
||||
return is_root
|
||||
|
@ -11,6 +11,13 @@ class TestNeedsRoot(object):
|
||||
monkeypatch.setattr(decorators.os, 'getuid', lambda: 0)
|
||||
assert decorators.needs_root(func)() is True
|
||||
|
||||
def test_is_not_root_env_var_skip_needs_root(self, monkeypatch):
|
||||
def func():
|
||||
return True
|
||||
monkeypatch.setattr(decorators.os, 'getuid', lambda: 123)
|
||||
monkeypatch.setattr(decorators.os, 'environ', {'CEPH_VOLUME_SKIP_NEEDS_ROOT': '1'})
|
||||
assert decorators.needs_root(func)() is True
|
||||
|
||||
def test_is_not_root(self, monkeypatch):
|
||||
def func():
|
||||
return True # pragma: no cover
|
||||
|
Loading…
Reference in New Issue
Block a user