]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: run tests as root
authorKefu Chai <tchaikov@gmail.com>
Mon, 10 Oct 2022 13:57:57 +0000 (21:57 +0800)
committerAdam King <adking@redhat.com>
Wed, 12 Oct 2022 21:15:34 +0000 (17:15 -0400)
as we will be create/access directories which are only accessible by
root with pyfakefs, and pyfake respects the uid of current effective
user, so if we run the test using non-root user, these tests would fail
after the fix for https://github.com/pytest-dev/pyfakefs/issues/489
is addressed in the pyfakefs we are using.

in this change, we will run the test on behalf of root, so we can
create and access the directories as we did before.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
(cherry picked from commit ed19416067a7ef3b69310d22bf4e3b573e3011f0)

Conflicts:
src/cephadm/tests/fixtures.py

src/cephadm/tests/fixtures.py
src/cephadm/tests/test_cephadm.py

index 66d49cf17a2acb9933554807cef86c36e8ed973d..2cd41be85de98fd776c3c4e83d7643da9f5ad17e 100644 (file)
@@ -81,6 +81,9 @@ def cephadm_fs(
          mock.patch('platform.processor', return_value='x86_64'), \
          mock.patch('cephadm.extract_uid_gid', return_value=(uid, gid)):
 
+            if not fake_filesystem.is_root():
+                fake_filesystem.set_uid(0)
+
             fs.create_dir(cd.DATA_DIR)
             fs.create_dir(cd.LOG_DIR)
             fs.create_dir(cd.LOCK_DIR)
index c57963d4dc9ad67a6c1bc45b6076a97e7ed6abb4..7383ac0ee1861cd5faae797016cd1535d0594d1c 100644 (file)
@@ -27,6 +27,7 @@ from .fixtures import (
     mock_bad_firewalld,
 )
 
+from pyfakefs import fake_filesystem
 from pyfakefs import fake_filesystem_unittest
 
 with mock.patch('builtins.open', create=True):
@@ -2380,6 +2381,9 @@ class TestRescan(fake_filesystem_unittest.TestCase):
 
     def setUp(self):
         self.setUpPyfakefs()
+        if not fake_filesystem.is_root():
+            fake_filesystem.set_uid(0)
+
         self.fs.create_dir('/sys/class')
         self.ctx = cd.CephadmContext()
         self.ctx.func = cd.command_rescan_disks