diff options
author | Vyacheslav Yurkov <v.yurkov@precitec.de> | 2022-09-07 21:51:39 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-09-09 12:24:43 +0100 |
commit | 6cd5db1e626c36c11dd22322daeaaec307c68d07 (patch) | |
tree | 438e465cf6f34a3d402410f26c2671b806ff990a | |
parent | c3ec554ba5dbe5abcba35724f039baba8a4c27eb (diff) | |
download | poky-6cd5db1e626c36c11dd22322daeaaec307c68d07.tar.gz |
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>
-rw-r--r-- | meta-selftest/recipes-test/overlayfs-user/overlayfs-user.bb | 7 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/overlayfs.py | 90 |
2 files changed, 74 insertions, 23 deletions
diff --git a/meta-selftest/recipes-test/overlayfs-user/overlayfs-user.bb b/meta-selftest/recipes-test/overlayfs-user/overlayfs-user.bb index 913a4d1fdb..50cba9514b 100644 --- a/meta-selftest/recipes-test/overlayfs-user/overlayfs-user.bb +++ b/meta-selftest/recipes-test/overlayfs-user/overlayfs-user.bb | |||
@@ -12,6 +12,11 @@ OVERLAYFS_WRITABLE_PATHS[mnt-overlay] += "/usr/share/my-application" | |||
12 | 12 | ||
13 | do_install() { | 13 | do_install() { |
14 | install -d ${D}/usr/share/my-application | 14 | install -d ${D}/usr/share/my-application |
15 | install -d ${D}${sysconfdir} | ||
16 | echo "Original file in /etc" >> ${D}${sysconfdir}/lower-layer-test.txt | ||
15 | } | 17 | } |
16 | 18 | ||
17 | FILES:${PN} += "/usr" | 19 | FILES:${PN} += "\ |
20 | ${exec_prefix} \ | ||
21 | ${sysconfdir \ | ||
22 | " | ||
diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py index f550015b4b..57a8c8bdb6 100644 --- a/meta/lib/oeqa/selftest/cases/overlayfs.py +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py | |||
@@ -381,28 +381,7 @@ OVERLAYFS_ETC_DEVICE = "/dev/sda3" | |||
381 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> | 381 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> |
382 | """ | 382 | """ |
383 | 383 | ||
384 | config = """ | 384 | config = self.get_working_config() |
385 | DISTRO_FEATURES:append = " systemd" | ||
386 | |||
387 | # Use systemd as init manager | ||
388 | VIRTUAL-RUNTIME_init_manager = "systemd" | ||
389 | |||
390 | # enable overlayfs in the kernel | ||
391 | KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc" | ||
392 | |||
393 | IMAGE_FSTYPES += "wic" | ||
394 | OVERLAYFS_INIT_OPTION = "{OVERLAYFS_INIT_OPTION}" | ||
395 | WKS_FILE = "overlayfs_etc.wks.in" | ||
396 | |||
397 | EXTRA_IMAGE_FEATURES += "read-only-rootfs" | ||
398 | # Image configuration for overlayfs-etc | ||
399 | EXTRA_IMAGE_FEATURES += "overlayfs-etc" | ||
400 | IMAGE_FEATURES:remove = "package-management" | ||
401 | OVERLAYFS_ETC_MOUNT_POINT = "/data" | ||
402 | OVERLAYFS_ETC_FSTYPE = "ext4" | ||
403 | OVERLAYFS_ETC_DEVICE = "/dev/sda3" | ||
404 | OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "{OVERLAYFS_ETC_USE_ORIG_INIT_NAME}" | ||
405 | """ | ||
406 | 385 | ||
407 | args = { | 386 | args = { |
408 | 'OVERLAYFS_INIT_OPTION': "" if origInit else "init=/sbin/preinit", | 387 | 'OVERLAYFS_INIT_OPTION': "" if origInit else "init=/sbin/preinit", |
@@ -423,6 +402,11 @@ OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "{OVERLAYFS_ETC_USE_ORIG_INIT_NAME}" | |||
423 | line = getline_qemu(output, "upperdir=/data/overlay-etc/upper") | 402 | line = getline_qemu(output, "upperdir=/data/overlay-etc/upper") |
424 | self.assertTrue(line and line.startswith("/data/overlay-etc/upper on /etc type overlay"), msg=output) | 403 | self.assertTrue(line and line.startswith("/data/overlay-etc/upper on /etc type overlay"), msg=output) |
425 | 404 | ||
405 | # check that lower layer is not available | ||
406 | status, output = qemu.run_serial("ls -1 /data/overlay-etc/lower") | ||
407 | line = getline_qemu(output, "No such file or directory") | ||
408 | self.assertTrue(line, msg=output) | ||
409 | |||
426 | status, output = qemu.run_serial("touch " + testFile) | 410 | status, output = qemu.run_serial("touch " + testFile) |
427 | status, output = qemu.run_serial("sync") | 411 | status, output = qemu.run_serial("sync") |
428 | status, output = qemu.run_serial("ls -1 " + testFile) | 412 | status, output = qemu.run_serial("ls -1 " + testFile) |
@@ -434,3 +418,65 @@ OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "{OVERLAYFS_ETC_USE_ORIG_INIT_NAME}" | |||
434 | status, output = qemu.run_serial("ls -1 " + testFile) | 418 | status, output = qemu.run_serial("ls -1 " + testFile) |
435 | line = getline_qemu(output, testFile) | 419 | line = getline_qemu(output, testFile) |
436 | self.assertTrue(line and line.startswith(testFile), msg=output) | 420 | self.assertTrue(line and line.startswith(testFile), msg=output) |
421 | |||
422 | def test_lower_layer_access(self): | ||
423 | """ | ||
424 | Summary: Test that lower layer of /etc is available read-only when configured | ||
425 | Expected: Can't write to lower layer. The files on lower and upper different after | ||
426 | modification | ||
427 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> | ||
428 | """ | ||
429 | |||
430 | config = self.get_working_config() | ||
431 | |||
432 | configLower = """ | ||
433 | OVERLAYFS_ETC_EXPOSE_LOWER = "1" | ||
434 | IMAGE_INSTALL:append = " overlayfs-user" | ||
435 | """ | ||
436 | testFile = "lower-layer-test.txt" | ||
437 | |||
438 | args = { | ||
439 | 'OVERLAYFS_INIT_OPTION': "", | ||
440 | 'OVERLAYFS_ETC_USE_ORIG_INIT_NAME': 1 | ||
441 | } | ||
442 | |||
443 | self.write_config(config.format(**args)) | ||
444 | |||
445 | self.append_config(configLower) | ||
446 | bitbake('core-image-minimal') | ||
447 | |||
448 | with runqemu('core-image-minimal', image_fstype='wic') as qemu: | ||
449 | status, output = qemu.run_serial("echo \"Modified in upper\" > /etc/" + testFile) | ||
450 | status, output = qemu.run_serial("diff /etc/" + testFile + " /data/overlay-etc/lower/" + testFile) | ||
451 | line = getline_qemu(output, "Modified in upper") | ||
452 | self.assertTrue(line, msg=output) | ||
453 | line = getline_qemu(output, "Original file") | ||
454 | self.assertTrue(line, msg=output) | ||
455 | |||
456 | status, output = qemu.run_serial("touch /data/overlay-etc/lower/ro-test.txt") | ||
457 | line = getline_qemu(output, "Read-only file system") | ||
458 | self.assertTrue(line, msg=output) | ||
459 | |||
460 | def get_working_config(self): | ||
461 | return """ | ||
462 | DISTRO_FEATURES:append = " systemd" | ||
463 | |||
464 | # Use systemd as init manager | ||
465 | VIRTUAL-RUNTIME_init_manager = "systemd" | ||
466 | |||
467 | # enable overlayfs in the kernel | ||
468 | KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc" | ||
469 | |||
470 | IMAGE_FSTYPES += "wic" | ||
471 | OVERLAYFS_INIT_OPTION = "{OVERLAYFS_INIT_OPTION}" | ||
472 | WKS_FILE = "overlayfs_etc.wks.in" | ||
473 | |||
474 | EXTRA_IMAGE_FEATURES += "read-only-rootfs" | ||
475 | # Image configuration for overlayfs-etc | ||
476 | EXTRA_IMAGE_FEATURES += "overlayfs-etc" | ||
477 | IMAGE_FEATURES:remove = "package-management" | ||
478 | OVERLAYFS_ETC_MOUNT_POINT = "/data" | ||
479 | OVERLAYFS_ETC_FSTYPE = "ext4" | ||
480 | OVERLAYFS_ETC_DEVICE = "/dev/sda3" | ||
481 | OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "{OVERLAYFS_ETC_USE_ORIG_INIT_NAME}" | ||
482 | """ | ||