mirror of
https://git.yoctoproject.org/poky
synced 2026-01-29 21:08:42 +01:00
oeqa/selftest: Add lower layer test for overlayfs-etc
Place a test file on the /etc by means of overlayfs-user recipe. Perform QA checks to make sure that: - When lower layer is exposed, that it's read-only to avoid undefined behavior - By default lower layer is not exposed (From OE-Core rev: 2fc742178675598208b400d9889a1681249d7eea) Signed-off-by: Vyacheslav Yurkov <v.yurkov@precitec.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
c3ec554ba5
commit
6cd5db1e62
@@ -12,6 +12,11 @@ OVERLAYFS_WRITABLE_PATHS[mnt-overlay] += "/usr/share/my-application"
|
||||
|
||||
do_install() {
|
||||
install -d ${D}/usr/share/my-application
|
||||
install -d ${D}${sysconfdir}
|
||||
echo "Original file in /etc" >> ${D}${sysconfdir}/lower-layer-test.txt
|
||||
}
|
||||
|
||||
FILES:${PN} += "/usr"
|
||||
FILES:${PN} += "\
|
||||
${exec_prefix} \
|
||||
${sysconfdir \
|
||||
"
|
||||
|
||||
@@ -381,7 +381,84 @@ OVERLAYFS_ETC_DEVICE = "/dev/sda3"
|
||||
Author: Vyacheslav Yurkov <uvv.mail@gmail.com>
|
||||
"""
|
||||
|
||||
config = """
|
||||
config = self.get_working_config()
|
||||
|
||||
args = {
|
||||
'OVERLAYFS_INIT_OPTION': "" if origInit else "init=/sbin/preinit",
|
||||
'OVERLAYFS_ETC_USE_ORIG_INIT_NAME': int(origInit == True)
|
||||
}
|
||||
|
||||
self.write_config(config.format(**args))
|
||||
|
||||
bitbake('core-image-minimal')
|
||||
testFile = "/etc/my-test-data"
|
||||
|
||||
with runqemu('core-image-minimal', image_fstype='wic', discard_writes=False) as qemu:
|
||||
status, output = qemu.run_serial("/bin/mount")
|
||||
|
||||
line = getline_qemu(output, "/dev/sda3")
|
||||
self.assertTrue("/data" in output, msg=output)
|
||||
|
||||
line = getline_qemu(output, "upperdir=/data/overlay-etc/upper")
|
||||
self.assertTrue(line and line.startswith("/data/overlay-etc/upper on /etc type overlay"), msg=output)
|
||||
|
||||
# check that lower layer is not available
|
||||
status, output = qemu.run_serial("ls -1 /data/overlay-etc/lower")
|
||||
line = getline_qemu(output, "No such file or directory")
|
||||
self.assertTrue(line, msg=output)
|
||||
|
||||
status, output = qemu.run_serial("touch " + testFile)
|
||||
status, output = qemu.run_serial("sync")
|
||||
status, output = qemu.run_serial("ls -1 " + testFile)
|
||||
line = getline_qemu(output, testFile)
|
||||
self.assertTrue(line and line.startswith(testFile), msg=output)
|
||||
|
||||
# Check that file exists in /etc after reboot
|
||||
with runqemu('core-image-minimal', image_fstype='wic') as qemu:
|
||||
status, output = qemu.run_serial("ls -1 " + testFile)
|
||||
line = getline_qemu(output, testFile)
|
||||
self.assertTrue(line and line.startswith(testFile), msg=output)
|
||||
|
||||
def test_lower_layer_access(self):
|
||||
"""
|
||||
Summary: Test that lower layer of /etc is available read-only when configured
|
||||
Expected: Can't write to lower layer. The files on lower and upper different after
|
||||
modification
|
||||
Author: Vyacheslav Yurkov <uvv.mail@gmail.com>
|
||||
"""
|
||||
|
||||
config = self.get_working_config()
|
||||
|
||||
configLower = """
|
||||
OVERLAYFS_ETC_EXPOSE_LOWER = "1"
|
||||
IMAGE_INSTALL:append = " overlayfs-user"
|
||||
"""
|
||||
testFile = "lower-layer-test.txt"
|
||||
|
||||
args = {
|
||||
'OVERLAYFS_INIT_OPTION': "",
|
||||
'OVERLAYFS_ETC_USE_ORIG_INIT_NAME': 1
|
||||
}
|
||||
|
||||
self.write_config(config.format(**args))
|
||||
|
||||
self.append_config(configLower)
|
||||
bitbake('core-image-minimal')
|
||||
|
||||
with runqemu('core-image-minimal', image_fstype='wic') as qemu:
|
||||
status, output = qemu.run_serial("echo \"Modified in upper\" > /etc/" + testFile)
|
||||
status, output = qemu.run_serial("diff /etc/" + testFile + " /data/overlay-etc/lower/" + testFile)
|
||||
line = getline_qemu(output, "Modified in upper")
|
||||
self.assertTrue(line, msg=output)
|
||||
line = getline_qemu(output, "Original file")
|
||||
self.assertTrue(line, msg=output)
|
||||
|
||||
status, output = qemu.run_serial("touch /data/overlay-etc/lower/ro-test.txt")
|
||||
line = getline_qemu(output, "Read-only file system")
|
||||
self.assertTrue(line, msg=output)
|
||||
|
||||
def get_working_config(self):
|
||||
return """
|
||||
DISTRO_FEATURES:append = " systemd"
|
||||
|
||||
# Use systemd as init manager
|
||||
@@ -403,34 +480,3 @@ OVERLAYFS_ETC_FSTYPE = "ext4"
|
||||
OVERLAYFS_ETC_DEVICE = "/dev/sda3"
|
||||
OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "{OVERLAYFS_ETC_USE_ORIG_INIT_NAME}"
|
||||
"""
|
||||
|
||||
args = {
|
||||
'OVERLAYFS_INIT_OPTION': "" if origInit else "init=/sbin/preinit",
|
||||
'OVERLAYFS_ETC_USE_ORIG_INIT_NAME': int(origInit == True)
|
||||
}
|
||||
|
||||
self.write_config(config.format(**args))
|
||||
|
||||
bitbake('core-image-minimal')
|
||||
testFile = "/etc/my-test-data"
|
||||
|
||||
with runqemu('core-image-minimal', image_fstype='wic', discard_writes=False) as qemu:
|
||||
status, output = qemu.run_serial("/bin/mount")
|
||||
|
||||
line = getline_qemu(output, "/dev/sda3")
|
||||
self.assertTrue("/data" in output, msg=output)
|
||||
|
||||
line = getline_qemu(output, "upperdir=/data/overlay-etc/upper")
|
||||
self.assertTrue(line and line.startswith("/data/overlay-etc/upper on /etc type overlay"), msg=output)
|
||||
|
||||
status, output = qemu.run_serial("touch " + testFile)
|
||||
status, output = qemu.run_serial("sync")
|
||||
status, output = qemu.run_serial("ls -1 " + testFile)
|
||||
line = getline_qemu(output, testFile)
|
||||
self.assertTrue(line and line.startswith(testFile), msg=output)
|
||||
|
||||
# Check that file exists in /etc after reboot
|
||||
with runqemu('core-image-minimal', image_fstype='wic') as qemu:
|
||||
status, output = qemu.run_serial("ls -1 " + testFile)
|
||||
line = getline_qemu(output, testFile)
|
||||
self.assertTrue(line and line.startswith(testFile), msg=output)
|
||||
|
||||
Reference in New Issue
Block a user