cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #03372
[Merge] ~chad.smith/cloud-init:tests-fix-root-os-access-leak into cloud-init:master
Chad Smith has proposed merging ~chad.smith/cloud-init:tests-fix-root-os-access-leak into cloud-init:master.
Requested reviews:
cloud-init commiters (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/330774
tests: mock calls to os.access om resizefs unit tests
When os.access is unmocked, root user still sees read-only files as
writable so the unittests would fail. A mocked return value of False will
ensure both privileged and unprivileged users can run these unit tests.
--
Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:tests-fix-root-os-access-leak into cloud-init:master.
diff --git a/tests/unittests/test_handler/test_handler_resizefs.py b/tests/unittests/test_handler/test_handler_resizefs.py
index 76dddbf..eb7cb93 100644
--- a/tests/unittests/test_handler/test_handler_resizefs.py
+++ b/tests/unittests/test_handler/test_handler_resizefs.py
@@ -229,16 +229,17 @@ class TestIsDevicePathWritableBlock(CiTestCase):
def test_is_device_path_writable_block_readonly(self):
"""When root device is readonly, emit a warning and return False."""
fake_devpath = self.tmp_path('dev/readonly')
- util.write_file(fake_devpath, '', mode=0o400) # read-only
+ util.write_file(fake_devpath, '')
info = 'dev=/dev/root mnt_point=/ path={0}'.format(fake_devpath)
exists_mock_path = 'cloudinit.config.cc_resizefs.os.path.exists'
with mock.patch(exists_mock_path) as m_exists:
m_exists.return_value = False
is_valid = wrap_and_call(
- 'cloudinit.config.cc_resizefs.util',
- {'is_container': {'return_value': False},
- 'rootdev_from_cmdline': {'return_value': fake_devpath}},
+ 'cloudinit.config.cc_resizefs',
+ {'os.access': {'return_value': False}, # Fake it read-only
+ 'util.is_container': {'return_value': False},
+ 'util.rootdev_from_cmdline': {'return_value': fake_devpath}},
is_device_path_writable_block, '/dev/root', info, LOG)
self.assertFalse(is_valid)
logs = self.logs.getvalue()
@@ -253,12 +254,13 @@ class TestIsDevicePathWritableBlock(CiTestCase):
def test_is_device_path_writable_block_readonly_in_container(self):
"""When root device is readonly, emit debug log and return False."""
fake_devpath = self.tmp_path('dev/readonly')
- util.write_file(fake_devpath, '', mode=0o400) # read-only
+ util.write_file(fake_devpath, '')
info = 'dev=/dev/root mnt_point=/ path={0}'.format(fake_devpath)
is_valid = wrap_and_call(
- 'cloudinit.config.cc_resizefs.util',
- {'is_container': {'return_value': True}},
+ 'cloudinit.config.cc_resizefs',
+ {'os.access': {'return_value': False}, # Fake it read-only
+ 'util.is_container': {'return_value': True}},
is_device_path_writable_block, fake_devpath, info, LOG)
self.assertFalse(is_valid)
self.assertIn(
Follow ups