"""
@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
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