]> 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)
committerKefu Chai <tchaikov@gmail.com>
Mon, 10 Oct 2022 14:42:57 +0000 (22:42 +0800)
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>
src/cephadm/tests/fixtures.py
src/cephadm/tests/test_cephadm.py

index ef61e68474b1c074b41e060fda151b81493f88c4..1274a89bd75ddd0ef3c304349c9512570a3adb4a 100644 (file)
@@ -77,6 +77,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(_cephadm.DATA_DIR)
             fs.create_dir(_cephadm.LOG_DIR)
             fs.create_dir(_cephadm.LOCK_DIR)
index ab87a42665cda31a90f139e8bee4ea212def0777..87e700b535cefa264047e85441cb9cbb10ef5e00 100644 (file)
@@ -18,6 +18,7 @@ from .fixtures import (
     import_cephadm,
 )
 
+from pyfakefs import fake_filesystem
 from pyfakefs import fake_filesystem_unittest
 
 _cephadm = import_cephadm()
@@ -2565,6 +2566,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 = _cephadm.CephadmContext()
         self.ctx.func = _cephadm.command_rescan_disks