]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: make it possible to skip needs_root() 44319/head
authorGuillaume Abrioux <gabrioux@redhat.com>
Tue, 7 Dec 2021 14:18:10 +0000 (15:18 +0100)
committerGuillaume Abrioux <gabrioux@redhat.com>
Wed, 15 Dec 2021 14:35:13 +0000 (15:35 +0100)
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>
(cherry picked from commit 068a1d2a300bc21e9aa08142c4195970ef480e41)

src/ceph-volume/ceph_volume/decorators.py
src/ceph-volume/ceph_volume/tests/test_decorators.py

index 95acce064fe184172440971074e0fe7e97a378b1..3c003ad77c417a737f449f172d36fc82f09947ff 100644 (file)
@@ -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
index 8df891456e607afc2960b60128449b3eb067bcec..5bdf6b3d27bf98261d26d402471de975fe2a0286 100644 (file)
@@ -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