summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2017-09-14 14:05:13 -0600
committerScott Moser <smoser@brickies.net>2017-09-15 14:42:35 -0400
commit024ecc1f758d36cc0aa5ebce65704eed6bd66d45 (patch)
tree870a26d70e4f4655a6e4512d73166ef1a49a89ef
parenta2f8ce9c80debdb788e7ab37401aa98c2c270f26 (diff)
downloadvyos-cloud-init-024ecc1f758d36cc0aa5ebce65704eed6bd66d45.tar.gz
vyos-cloud-init-024ecc1f758d36cc0aa5ebce65704eed6bd66d45.zip
resizefs: Drop check for read-only device file, do not warn on overlayroot.
As root user, os.access(<path>, os.W_OK) will always return True so that path will never get executed. Also avoid a warning if the root is overlayroot, which is the common case on a MAAS booted 'ephemeral' system.
-rw-r--r--cloudinit/config/cc_resizefs.py12
-rw-r--r--tests/unittests/test_handler/test_handler_resizefs.py72
2 files changed, 26 insertions, 58 deletions
diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py
index f42b6a63..f774baa3 100644
--- a/cloudinit/config/cc_resizefs.py
+++ b/cloudinit/config/cc_resizefs.py
@@ -192,6 +192,10 @@ def is_device_path_writable_block(devpath, info, log):
return False
log.debug("Converted /dev/root to '%s' per kernel cmdline", devpath)
+ if devpath == 'overlayroot':
+ log.debug("Not attempting to resize devpath '%s': %s", devpath, info)
+ return False
+
try:
statret = os.stat(devpath)
except OSError as exc:
@@ -205,14 +209,6 @@ def is_device_path_writable_block(devpath, info, log):
raise exc
return False
- if not os.access(devpath, os.W_OK):
- if container:
- log.debug("'%s' not writable in container. cannot resize: %s",
- devpath, info)
- else:
- log.warn("'%s' not writable. cannot resize: %s", devpath, info)
- return
-
if not stat.S_ISBLK(statret.st_mode) and not stat.S_ISCHR(statret.st_mode):
if container:
log.debug("device '%s' not a block device in container."
diff --git a/tests/unittests/test_handler/test_handler_resizefs.py b/tests/unittests/test_handler/test_handler_resizefs.py
index 76dddbf8..3e5d436c 100644
--- a/tests/unittests/test_handler/test_handler_resizefs.py
+++ b/tests/unittests/test_handler/test_handler_resizefs.py
@@ -166,6 +166,18 @@ class TestIsDevicePathWritableBlock(CiTestCase):
with_logs = True
+ def test_is_device_path_writable_block_false_on_overlayroot(self):
+ """When devpath is overlayroot (on MAAS), is_dev_writable is False."""
+ info = 'does not matter'
+ is_writable = wrap_and_call(
+ 'cloudinit.config.cc_resizefs.util',
+ {'is_container': {'return_value': False}},
+ is_device_path_writable_block, 'overlayroot', info, LOG)
+ self.assertFalse(is_writable)
+ self.assertIn(
+ "Not attempting to resize devpath 'overlayroot'",
+ self.logs.getvalue())
+
def test_is_device_path_writable_block_warns_missing_cmdline_root(self):
"""When root does not exist isn't in the cmdline, log warning."""
info = 'does not matter'
@@ -178,24 +190,24 @@ class TestIsDevicePathWritableBlock(CiTestCase):
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(
+ is_writable = wrap_and_call(
'cloudinit.config.cc_resizefs.util',
{'is_container': {'return_value': False},
'get_mount_info': {'side_effect': fake_mount_info},
'get_cmdline': {'return_value': 'BOOT_IMAGE=/vmlinuz.efi'}},
is_device_path_writable_block, '/dev/root', info, LOG)
- self.assertFalse(is_valid)
+ self.assertFalse(is_writable)
logs = self.logs.getvalue()
self.assertIn("WARNING: Unable to find device '/dev/root'", logs)
def test_is_device_path_writable_block_does_not_exist(self):
"""When devpath does not exist, a warning is logged."""
info = 'dev=/I/dont/exist mnt_point=/ path=/dev/none'
- is_valid = wrap_and_call(
+ is_writable = wrap_and_call(
'cloudinit.config.cc_resizefs.util',
{'is_container': {'return_value': False}},
is_device_path_writable_block, '/I/dont/exist', info, LOG)
- self.assertFalse(is_valid)
+ self.assertFalse(is_writable)
self.assertIn(
"WARNING: Device '/I/dont/exist' did not exist."
' cannot resize: %s' % info,
@@ -204,11 +216,11 @@ class TestIsDevicePathWritableBlock(CiTestCase):
def test_is_device_path_writable_block_does_not_exist_in_container(self):
"""When devpath does not exist in a container, log a debug message."""
info = 'dev=/I/dont/exist mnt_point=/ path=/dev/none'
- is_valid = wrap_and_call(
+ is_writable = wrap_and_call(
'cloudinit.config.cc_resizefs.util',
{'is_container': {'return_value': True}},
is_device_path_writable_block, '/I/dont/exist', info, LOG)
- self.assertFalse(is_valid)
+ self.assertFalse(is_writable)
self.assertIn(
"DEBUG: Device '/I/dont/exist' did not exist in container."
' cannot resize: %s' % info,
@@ -226,57 +238,17 @@ class TestIsDevicePathWritableBlock(CiTestCase):
self.assertEqual(
'Something unexpected', str(context_manager.exception))
- 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
- 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}},
- is_device_path_writable_block, '/dev/root', info, LOG)
- self.assertFalse(is_valid)
- logs = self.logs.getvalue()
- self.assertIn(
- "Converted /dev/root to '{0}' per kernel cmdline".format(
- fake_devpath),
- logs)
- self.assertIn(
- "WARNING: '{0}' not writable. cannot resize".format(fake_devpath),
- logs)
-
- 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
- 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}},
- is_device_path_writable_block, fake_devpath, info, LOG)
- self.assertFalse(is_valid)
- self.assertIn(
- "DEBUG: '{0}' not writable in container. cannot resize".format(
- fake_devpath),
- self.logs.getvalue())
-
def test_is_device_path_writable_block_non_block(self):
"""When device is not a block device, emit warning return False."""
fake_devpath = self.tmp_path('dev/readwrite')
util.write_file(fake_devpath, '', mode=0o600) # read-write
info = 'dev=/dev/root mnt_point=/ path={0}'.format(fake_devpath)
- is_valid = wrap_and_call(
+ is_writable = wrap_and_call(
'cloudinit.config.cc_resizefs.util',
{'is_container': {'return_value': False}},
is_device_path_writable_block, fake_devpath, info, LOG)
- self.assertFalse(is_valid)
+ self.assertFalse(is_writable)
self.assertIn(
"WARNING: device '{0}' not a block device. cannot resize".format(
fake_devpath),
@@ -288,11 +260,11 @@ class TestIsDevicePathWritableBlock(CiTestCase):
util.write_file(fake_devpath, '', mode=0o600) # read-write
info = 'dev=/dev/root mnt_point=/ path={0}'.format(fake_devpath)
- is_valid = wrap_and_call(
+ is_writable = wrap_and_call(
'cloudinit.config.cc_resizefs.util',
{'is_container': {'return_value': True}},
is_device_path_writable_block, fake_devpath, info, LOG)
- self.assertFalse(is_valid)
+ self.assertFalse(is_writable)
self.assertIn(
"DEBUG: device '{0}' not a block device in container."
' cannot resize'.format(fake_devpath),