summaryrefslogtreecommitdiff
path: root/tests/unittests/test_handler
diff options
context:
space:
mode:
authorEduardo Otubo <otubo@redhat.com>2021-03-30 18:08:25 +0200
committerGitHub <noreply@github.com>2021-03-30 10:08:25 -0600
commit74fa008bfcd3263eb691cc0b3f7a055b17569f8b (patch)
tree35e37aefdcbd563189dca70bd3ac357b320a993c /tests/unittests/test_handler
parent3b7e2e82310d417c0d59b268a6f47bc8f7996cab (diff)
downloadvyos-cloud-init-74fa008bfcd3263eb691cc0b3f7a055b17569f8b.tar.gz
vyos-cloud-init-74fa008bfcd3263eb691cc0b3f7a055b17569f8b.zip
Add support to resize rootfs if using LVM (#721)
This patch adds support to resize a single partition of a VM if it's using an LVM underneath. The patch detects if it's LVM if the given block device is a device mapper by its name (e.g. `/dev/dm-1`) and if it has slave devices under it on sysfs. After that syspath is updated to the real block device and growpart will be called to resize it (and automatically its Physical Volume). The Volume Group will be updated automatically and a final call to extend the rootfs to the remaining space available will be made. Using the same growpart configuration, the user can specify only one device to be resized when using LVM and growpart, otherwise cloud-init won't know which one should be resized and will fail. rhbz: #1810878 LP: #1799953 Signed-off-by: Eduardo Otubo <otubo@redhat.com> Signed-off-by: Scott Moser <smoser@brickies.net>
Diffstat (limited to 'tests/unittests/test_handler')
-rw-r--r--tests/unittests/test_handler/test_handler_growpart.py56
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/unittests/test_handler/test_handler_growpart.py b/tests/unittests/test_handler/test_handler_growpart.py
index 7f039b79..cc0a9248 100644
--- a/tests/unittests/test_handler/test_handler_growpart.py
+++ b/tests/unittests/test_handler/test_handler_growpart.py
@@ -172,6 +172,53 @@ class TestResize(unittest.TestCase):
self.name = "growpart"
self.log = logging.getLogger("TestResize")
+ def test_lvm_resize(self):
+ # LVM resize should work only if a single device is configured. More
+ # than one device should fail.
+ lvm_pass = ["/dev/XXdm-0"]
+ lvm_fail = ["/dev/XXdm-1", "/dev/YYdm-1"]
+ devstat_ret = Bunch(st_mode=25008, st_ino=6078, st_dev=5,
+ st_nlink=1, st_uid=0, st_gid=6, st_size=0,
+ st_atime=0, st_mtime=0, st_ctime=0)
+ real_stat = os.stat
+ resize_calls = []
+
+ class myresizer(object):
+ def resize(self, diskdev, partnum, partdev):
+ resize_calls.append((diskdev, partnum, partdev))
+ if partdev == "/dev/XXdm-0":
+ return (1024, 2048)
+ return (1024, 1024) # old size, new size
+
+ def mystat(path):
+ if path in lvm_pass or path in lvm_fail:
+ return devstat_ret
+ return real_stat(path)
+
+ try:
+ opinfo = cc_growpart.device_part_info
+ cc_growpart.device_part_info = simple_device_part_info_lvm
+ os.stat = mystat
+
+ resized = cc_growpart.resize_devices(myresizer(), lvm_pass)
+ not_resized = cc_growpart.resize_devices(myresizer(), lvm_fail)
+
+ def find(name, res):
+ for f in res:
+ if f[0] == name:
+ return f
+ return None
+
+ self.assertEqual(cc_growpart.RESIZE.CHANGED,
+ find("/dev/XXdm-0", resized)[1])
+ self.assertEqual(cc_growpart.RESIZE.NOCHANGE,
+ find("/dev/XXdm-1", not_resized)[1])
+ self.assertEqual(cc_growpart.RESIZE.NOCHANGE,
+ find("/dev/YYdm-1", not_resized)[1])
+ finally:
+ cc_growpart.device_part_info = opinfo
+ os.stat = real_stat
+
def test_simple_devices(self):
# test simple device list
# this patches out devent2dev, os.stat, and device_part_info
@@ -227,7 +274,14 @@ class TestResize(unittest.TestCase):
os.stat = real_stat
-def simple_device_part_info(devpath):
+def simple_device_part_info_lvm(devpath, is_lvm):
+ # simple stupid return (/dev/vda, 1) for /dev/vda
+ ret = re.search("([^0-9]*)([0-9]*)$", devpath)
+ x = (ret.group(1), ret.group(2))
+ return x
+
+
+def simple_device_part_info(devpath, is_lvm):
# simple stupid return (/dev/vda, 1) for /dev/vda
ret = re.search("([^0-9]*)([0-9]*)$", devpath)
x = (ret.group(1), ret.group(2))