All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/8] overlayfs-qa: common functions for overlayfs
@ 2021-07-09 11:31 Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 2/8] overlayfs.bbclass: generate overlayfs mount units Vyacheslav Yurkov
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-09 11:31 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Vyacheslav Yurkov

This class provides commom functions for overlayfs and its QA check,
which is performed in ROOTFS_POSTPROCESS_COMMAND

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 meta/classes/overlayfs-qa.bbclass | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 meta/classes/overlayfs-qa.bbclass

diff --git a/meta/classes/overlayfs-qa.bbclass b/meta/classes/overlayfs-qa.bbclass
new file mode 100644
index 0000000000..54fa8316a2
--- /dev/null
+++ b/meta/classes/overlayfs-qa.bbclass
@@ -0,0 +1,14 @@
+# This class contains common functions for overlayfs and its QA check,
+# which is performed in ROOTFS_POSTPROCESS_COMMAND
+
+# this function is based on https://github.com/systemd/systemd/blob/main/src/basic/unit-name.c
+def escapeSystemdUnitName(path):
+    escapeMap = {
+        '/': '-',
+        '-': "\\x2d",
+        '\\': "\\x5d"
+    }
+    return "".join([escapeMap.get(c, c) for c in path.strip('/')])
+
+def mountUnitName(unit):
+    return escapeSystemdUnitName(unit) + '.mount'
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 2/8] overlayfs.bbclass: generate overlayfs mount units
  2021-07-09 11:31 [PATCH v2 1/8] overlayfs-qa: common functions for overlayfs Vyacheslav Yurkov
@ 2021-07-09 11:31 ` Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 3/8] maintainers.inc: overlayfs bbclass maintainer Vyacheslav Yurkov
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-09 11:31 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Vyacheslav Yurkov

It's often desired in Embedded System design to have a read-only rootfs.
But a lot of different applications might want to have a read-write access
to some parts of a filesystem. It can be especially useful when your update
mechanism overwrites the whole rootfs, but you want your application data
to be preserved between updates. This class provides a way to achieve that
by means of overlayfs and at the same time keeping the base rootfs read-only.

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 meta/classes/overlayfs.bbclass | 133 +++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)
 create mode 100644 meta/classes/overlayfs.bbclass

diff --git a/meta/classes/overlayfs.bbclass b/meta/classes/overlayfs.bbclass
new file mode 100644
index 0000000000..40e6107f0d
--- /dev/null
+++ b/meta/classes/overlayfs.bbclass
@@ -0,0 +1,133 @@
+# Class for generation of overlayfs mount units
+#
+# It's often desired in Embedded System design to have a read-only rootfs.
+# But a lot of different applications might want to have a read-write access to
+# some parts of a filesystem. It can be especially useful when your update mechanism
+# overwrites the whole rootfs, but you want your application data to be preserved
+# between updates. This class provides a way to achieve that by means
+# of overlayfs and at the same time keeping the base rootfs read-only.
+#
+# Usage example.
+#
+# Set a mount point for a partition overlayfs is going to use as upper layer
+# in your machine configuration. Underlying file system can be anything that
+# is supported by overlayfs. This has to be done in your machine configuration.
+# QA check fails to catch file existence if you redefine this variable in your recipe!
+#
+#   OVERLAYFS_MOUNT_POINT[data] ?= "/data"
+#
+# The class assumes you have a data.mount systemd unit defined in your
+# systemd-machine-units recipe and installed to the image.
+#
+# Then you can specify writable directories on a recipe base
+#
+#   OVERLAYFS_WRITABLE_PATHS[data] = "/usr/share/my-custom-application"
+#
+# To support several mount points you can use a different variable flag. Assume we
+# want to have a writable location on the file system, but not interested where the data
+# survive a reboot. Then we could have a mnt-overlay.mount unit for a tmpfs file system:
+#
+#   OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
+#   OVERLAYFS_WRITABLE_PATHS[mnt-overlay] = "/usr/share/another-application"
+#
+# Note: the class does not support /etc directory itself, because systemd depends on it
+
+REQUIRED_DISTRO_FEATURES += "systemd overlayfs"
+
+inherit systemd features_check overlayfs-qa
+
+def strForBash(s):
+    return s.replace('\\', '\\\\')
+
+def unitFileList(d):
+    fileList = []
+    overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
+
+    if not overlayMountPoints:
+        bb.fatal("A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
+
+    # check that we have required mount points set first
+    requiredMountPoints = d.getVarFlags('OVERLAYFS_WRITABLE_PATHS')
+    for mountPoint in requiredMountPoints:
+        if mountPoint not in overlayMountPoints:
+            bb.fatal("Missing required mount point for OVERLAYFS_MOUNT_POINT[%s] in your MACHINE configuration" % mountPoint)
+
+    for mountPoint in overlayMountPoints:
+        for path in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split():
+            fileList.append(mountUnitName(path))
+            fileList.append(helperUnitName(path))
+
+    return fileList
+
+def helperUnitName(unit):
+    return escapeSystemdUnitName(unit) + '-create-upper-dir.service'
+
+python do_create_overlayfs_units() {
+    CreateDirsUnitTemplate = """[Unit]
+Description=Overlayfs directories setup
+Requires={DATA_MOUNT_UNIT}
+After={DATA_MOUNT_UNIT}
+DefaultDependencies=no
+
+[Service]
+Type=oneshot
+ExecStart=mkdir -p {DATA_MOUNT_POINT}/workdir{LOWERDIR} && mkdir -p {DATA_MOUNT_POINT}/upper{LOWERDIR}
+RemainAfterExit=true
+StandardOutput=journal
+
+[Install]
+WantedBy=multi-user.target
+"""
+    MountUnitTemplate = """[Unit]
+Description=Overlayfs mount unit
+Requires={CREATE_DIRS_SERVICE}
+After={CREATE_DIRS_SERVICE}
+
+[Mount]
+What=overlay
+Where={LOWERDIR}
+Type=overlay
+Options=lowerdir={LOWERDIR},upperdir={DATA_MOUNT_POINT}/upper{LOWERDIR},workdir={DATA_MOUNT_POINT}/workdir{LOWERDIR}
+
+[Install]
+WantedBy=multi-user.target
+"""
+
+    def prepareUnits(data, lower):
+        args = {
+            'DATA_MOUNT_POINT': data,
+            'DATA_MOUNT_UNIT': mountUnitName(data),
+            'CREATE_DIRS_SERVICE': helperUnitName(lower),
+            'LOWERDIR': lower,
+        }
+
+        with open(os.path.join(d.getVar('WORKDIR'), mountUnitName(lower)), 'w') as f:
+            f.write(MountUnitTemplate.format(**args))
+
+        with open(os.path.join(d.getVar('WORKDIR'), helperUnitName(lower)), 'w') as f:
+            f.write(CreateDirsUnitTemplate.format(**args))
+
+    overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
+    for mountPoint in overlayMountPoints:
+        for lower in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split():
+            prepareUnits(d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint), lower)
+}
+
+# we need to generate file names early during parsing stage
+python () {
+    unitList = unitFileList(d)
+    for unit in unitList:
+        d.appendVar('SYSTEMD_SERVICE_' + d.getVar('PN'), ' ' + unit);
+        d.appendVar('FILES_' + d.getVar('PN'), ' ' + strForBash(unit))
+
+    d.setVar('OVERLAYFS_UNIT_LIST', ' '.join([strForBash(s) for s in unitList]))
+}
+
+do_install_append() {
+    install -d ${D}${systemd_system_unitdir}
+    for unit in ${OVERLAYFS_UNIT_LIST}; do
+        install -m 0444 ${WORKDIR}/${unit} ${D}${systemd_system_unitdir}
+    done
+}
+
+addtask create_overlayfs_units before do_install
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 3/8] maintainers.inc: overlayfs bbclass maintainer
  2021-07-09 11:31 [PATCH v2 1/8] overlayfs-qa: common functions for overlayfs Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 2/8] overlayfs.bbclass: generate overlayfs mount units Vyacheslav Yurkov
@ 2021-07-09 11:31 ` Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 4/8] rootfs-postcommands: add QA check for overlayfs Vyacheslav Yurkov
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-09 11:31 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Vyacheslav Yurkov

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 meta/conf/distro/include/maintainers.inc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/meta/conf/distro/include/maintainers.inc b/meta/conf/distro/include/maintainers.inc
index e59f01d66a..90b20c9223 100644
--- a/meta/conf/distro/include/maintainers.inc
+++ b/meta/conf/distro/include/maintainers.inc
@@ -808,3 +808,5 @@ RECIPE_MAINTAINER_pn-xz = "Denys Dmytriyenko <denis@denix.org>"
 RECIPE_MAINTAINER_pn-zip = "Denys Dmytriyenko <denis@denix.org>"
 RECIPE_MAINTAINER_pn-zlib = "Denys Dmytriyenko <denis@denix.org>"
 RECIPE_MAINTAINER_pn-zstd = "Alexander Kanavin <alex.kanavin@gmail.com>"
+BBCLASS_MAINTAINER_overlayfs = "Vyacheslav Yurkov <uvv.mail@gmail.com>"
+BBCLASS_MAINTAINER_overlayfs-qa = "Vyacheslav Yurkov <uvv.mail@gmail.com>"
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 4/8] rootfs-postcommands: add QA check for overlayfs
  2021-07-09 11:31 [PATCH v2 1/8] overlayfs-qa: common functions for overlayfs Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 2/8] overlayfs.bbclass: generate overlayfs mount units Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 3/8] maintainers.inc: overlayfs bbclass maintainer Vyacheslav Yurkov
@ 2021-07-09 11:31 ` Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 5/8] systemd-machine-units: add bbappend for meta-selftest Vyacheslav Yurkov
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-09 11:31 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Vyacheslav Yurkov

The check is conditional and only enabled when overlayfs is set in
DISTRO_FEATURES

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 meta/classes/rootfs-postcommands.bbclass | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/meta/classes/rootfs-postcommands.bbclass b/meta/classes/rootfs-postcommands.bbclass
index e66ed5938b..b6ddf5475c 100644
--- a/meta/classes/rootfs-postcommands.bbclass
+++ b/meta/classes/rootfs-postcommands.bbclass
@@ -39,7 +39,10 @@ ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd"
 
 ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile;'
 
+ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "overlayfs", "overlayfs_qa_check;", "", d)}'
+
 inherit image-artifact-names
+inherit ${@bb.utils.contains("DISTRO_FEATURES", "overlayfs", "overlayfs-qa", "", d)}
 
 # Sort the user and group entries in /etc by ID in order to make the content
 # deterministic. Package installs are not deterministic, causing the ordering
@@ -373,3 +376,24 @@ rootfs_reproducible () {
 		fi
 	fi
 }
+
+python overlayfs_qa_check() {
+    # this is a dumb check for unit existence, not its validity
+    overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
+    imagepath = d.getVar("IMAGE_ROOTFS")
+    searchpaths = [oe.path.join(imagepath, d.getVar("sysconfdir"), "systemd", "system"),
+                   oe.path.join(imagepath, d.getVar("systemd_system_unitdir"))]
+
+    allUnitExist = True;
+    for mountPoint in overlayMountPoints:
+        path = d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint)
+        unit = mountUnitName(path)
+
+        if not any(os.path.isfile(oe.path.join(dirpath, unit))
+                   for dirpath in searchpaths):
+            bb.warn('Unit name %s not found in systemd unit directories' % unit)
+            allUnitExist = False;
+
+    if not allUnitExist:
+        bb.fatal('Not all mount units are installed by the BSP')
+}
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 5/8] systemd-machine-units: add bbappend for meta-selftest
  2021-07-09 11:31 [PATCH v2 1/8] overlayfs-qa: common functions for overlayfs Vyacheslav Yurkov
                   ` (2 preceding siblings ...)
  2021-07-09 11:31 ` [PATCH v2 4/8] rootfs-postcommands: add QA check for overlayfs Vyacheslav Yurkov
@ 2021-07-09 11:31 ` Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 6/8] overlayfs: meta-selftest recipe Vyacheslav Yurkov
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-09 11:31 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Vyacheslav Yurkov

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 .../systemd-machine-units/systemd-machine-units_%.bbappend      | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 meta-selftest/recipes-test/systemd-machine-units/systemd-machine-units_%.bbappend

diff --git a/meta-selftest/recipes-test/systemd-machine-units/systemd-machine-units_%.bbappend b/meta-selftest/recipes-test/systemd-machine-units/systemd-machine-units_%.bbappend
new file mode 100644
index 0000000000..205720982c
--- /dev/null
+++ b/meta-selftest/recipes-test/systemd-machine-units/systemd-machine-units_%.bbappend
@@ -0,0 +1,2 @@
+# This bbappend is used to alter the recipe using the test_recipe.inc file created by tests.
+include test_recipe.inc
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 6/8] overlayfs: meta-selftest recipe
  2021-07-09 11:31 [PATCH v2 1/8] overlayfs-qa: common functions for overlayfs Vyacheslav Yurkov
                   ` (3 preceding siblings ...)
  2021-07-09 11:31 ` [PATCH v2 5/8] systemd-machine-units: add bbappend for meta-selftest Vyacheslav Yurkov
@ 2021-07-09 11:31 ` Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests Vyacheslav Yurkov
  2021-07-09 11:31 ` [PATCH v2 8/8] docs: add overlayfs class Vyacheslav Yurkov
  6 siblings, 0 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-09 11:31 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Vyacheslav Yurkov

The recipe demonstrates example usage of overlayfs bbclass

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 .../recipes-test/overlayfs/overlayfs-user.bb     | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 meta-selftest/recipes-test/overlayfs/overlayfs-user.bb

diff --git a/meta-selftest/recipes-test/overlayfs/overlayfs-user.bb b/meta-selftest/recipes-test/overlayfs/overlayfs-user.bb
new file mode 100644
index 0000000000..5b0d9a2f3e
--- /dev/null
+++ b/meta-selftest/recipes-test/overlayfs/overlayfs-user.bb
@@ -0,0 +1,16 @@
+SUMMARY = "Overlayfs class unit test"
+DESCRIPTION = "Contains an overlayfs configuration"
+LICENSE = "MIT"
+
+INHIBIT_DEFAULT_DEPS = "1"
+EXCLUDE_FROM_WORLD = "1"
+
+inherit overlayfs
+
+OVERLAYFS_WRITABLE_PATHS[mnt-overlay] = "/usr/share/my-application"
+
+do_install() {
+    install -d ${D}/usr/share/my-application
+}
+
+FILES_${PN} += "/usr"
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests
  2021-07-09 11:31 [PATCH v2 1/8] overlayfs-qa: common functions for overlayfs Vyacheslav Yurkov
                   ` (4 preceding siblings ...)
  2021-07-09 11:31 ` [PATCH v2 6/8] overlayfs: meta-selftest recipe Vyacheslav Yurkov
@ 2021-07-09 11:31 ` Vyacheslav Yurkov
  2021-07-10  9:01   ` [OE-core] " Alexander Kanavin
  2021-07-10  9:41   ` Alexandre Belloni
  2021-07-09 11:31 ` [PATCH v2 8/8] docs: add overlayfs class Vyacheslav Yurkov
  6 siblings, 2 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-09 11:31 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Vyacheslav Yurkov

Unit tests for overlayfs.bbclass

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 meta/lib/oeqa/selftest/cases/overlayfs.py | 126 ++++++++++++++++++++++
 1 file changed, 126 insertions(+)
 create mode 100644 meta/lib/oeqa/selftest/cases/overlayfs.py

diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
new file mode 100644
index 0000000000..74bf1c4167
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
@@ -0,0 +1,126 @@
+#
+# SPDX-License-Identifier: MIT
+#
+
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
+
+class OverlayFSTests(OESelftestTestCase):
+    """Overlayfs class usage tests"""
+
+    def getline(self, res, line):
+        for l in res.output.split('\n'):
+            if line in l:
+                return l
+
+    def test_distro_features_missing(self):
+        """
+        Summary:   Check that required DISTRO_FEATURES are set
+        Expected:  Fail when either systemd or overlayfs are not in DISTRO_FEATURES
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
+IMAGE_INSTALL_append = "overlayfs-user"
+"""
+        self.write_config(config)
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "overlayfs-user was skipped: missing required distro features")
+        self.assertTrue("overlayfs" in res.output, msg=res.output)
+        self.assertTrue("systemd" in res.output, msg=res.output)
+        self.assertTrue("ERROR: Required build target 'core-image-minimal' has no buildable providers." in res.output, msg=res.output)
+
+    def test_not_all_units_installed(self):
+        """
+        Summary:   Test QA check that we have required mount units in the image
+        Expected:  Fail because mount unit for overlay partition is not installed
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
+IMAGE_INSTALL_append = "overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+        self.write_config(config)
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "Unit name mnt-overlay.mount not found in systemd unit directories")
+        self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
+        line = self.getline(res, "Not all mount units are installed by the BSP")
+        self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
+
+    def test_mount_unit_not_set(self):
+        """
+        Summary:   Test whether mount unit was set properly
+        Expected:  Fail because mount unit was not set
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = "overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+        self.write_config(config)
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
+        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
+
+    def test_wrong_mount_unit_set(self):
+        """
+        Summary:   Test whether mount unit was set properly
+        Expected:  Fail because not the correct flag used for mount unit
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay"
+IMAGE_INSTALL_append = "overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+        self.write_config(config)
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "Missing required mount point for OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration")
+        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
+
+    def test_correct_image(self):
+        """
+        Summary:   Check that we can create an image when all parameters are
+                   set correctly
+        Expected:  Image is created successfully
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
+IMAGE_INSTALL_append = "overlayfs-user systemd-machine-units"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+
+        systemd_machine_unit_append = """
+SYSTEMD_SERVICE_${PN} += " \
+    mnt-overlay.mount \
+"
+
+do_install() {
+    install -d ${D}${systemd_unitdir}/system
+    cat <<EOT > ${D}${systemd_unitdir}/system/mnt-overlay.mount
+[Unit]
+Description=Tmpfs directory
+DefaultDependencies=no
+
+[Mount]
+What=tmpfs
+Where=/mnt/overlay
+Type=tmpfs
+Options=mode=1777,strictatime,nosuid,nodev
+
+[Install]
+WantedBy=multi-user.target
+EOT
+}
+
+"""
+        self.write_config(config)
+        self.write_recipeinc('systemd-machine-units', systemd_machine_unit_append)
+        bitbake('core-image-minimal')
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 8/8] docs: add overlayfs class
  2021-07-09 11:31 [PATCH v2 1/8] overlayfs-qa: common functions for overlayfs Vyacheslav Yurkov
                   ` (5 preceding siblings ...)
  2021-07-09 11:31 ` [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests Vyacheslav Yurkov
@ 2021-07-09 11:31 ` Vyacheslav Yurkov
  6 siblings, 0 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-09 11:31 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Vyacheslav Yurkov

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 documentation/ref-manual/classes.rst | 46 ++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/documentation/ref-manual/classes.rst b/documentation/ref-manual/classes.rst
index 09878c480f..6d80e7dc4f 100644
--- a/documentation/ref-manual/classes.rst
+++ b/documentation/ref-manual/classes.rst
@@ -1708,6 +1708,52 @@ one such example. However, being aware of this class can reduce the
 proliferation of different versions of similar classes across multiple
 layers.
 
+.. _ref-classes-overlayfs:
+
+``overlayfs.bbclass``
+=======================
+
+
+It's often desired in Embedded System design to have a read-only rootfs.
+But a lot of different applications might want to have a read-write access to
+some parts of a filesystem. It can be especially useful when your update mechanism
+overwrites the whole rootfs, but you want your application data to be preserved
+between updates. The ``overlayfs`` class provides a way to achieve that by means
+of overlayfs and at the same time keeping the base rootfs read-only.
+
+To use this class, set a mount point for a partition overlayfs is going to use as upper
+layer in your machine configuration. Underlying file system can be anything that
+is supported by overlayfs. This has to be done in your machine configuration::
+
+  OVERLAYFS_MOUNT_POINT[data] = "/data"
+
+.. note::
+
+  QA check fails to catch file existence if you redefine this variable in your recipe!
+
+The class assumes you have a data.mount systemd unit defined elsewhere in your BSP
+(e.g. in systemd-machine-units recipe) and it's installed to the image.
+
+Then you can specify writable directories on a recipe basis::
+
+  OVERLAYFS_WRITABLE_PATHS[data] = "/usr/share/my-custom-application"
+
+To support several mount points you can use a different variable flag. Assume we
+want to have a writable location on the file system, but not interested where the data
+survive a reboot. Then we could have a mnt-overlay.mount unit for a tmpfs file system.
+
+In your machine configuration::
+
+  OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
+
+and then in your recipe::
+
+  OVERLAYFS_WRITABLE_PATHS[mnt-overlay] = "/usr/share/another-application"
+
+.. note::
+
+   The class does not support /etc directory itself, because systemd depends on it
+
 .. _ref-classes-own-mirrors:
 
 ``own-mirrors.bbclass``
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [OE-core] [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests
  2021-07-09 11:31 ` [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests Vyacheslav Yurkov
@ 2021-07-10  9:01   ` Alexander Kanavin
  2021-07-10  9:41   ` Alexandre Belloni
  1 sibling, 0 replies; 16+ messages in thread
From: Alexander Kanavin @ 2021-07-10  9:01 UTC (permalink / raw)
  To: Vyacheslav Yurkov; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 5991 bytes --]

Thank you for the patchset! These tests do not perform runtime testing of
the feature (by starting the built images with qemu), can this be added?
There is plenty of examples of how to do this in selftests (grep for
runqemu).

Alex

On Fri, 9 Jul 2021 at 13:33, Vyacheslav Yurkov <uvv.mail@gmail.com> wrote:

> Unit tests for overlayfs.bbclass
>
> Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
> ---
>  meta/lib/oeqa/selftest/cases/overlayfs.py | 126 ++++++++++++++++++++++
>  1 file changed, 126 insertions(+)
>  create mode 100644 meta/lib/oeqa/selftest/cases/overlayfs.py
>
> diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py
> b/meta/lib/oeqa/selftest/cases/overlayfs.py
> new file mode 100644
> index 0000000000..74bf1c4167
> --- /dev/null
> +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
> @@ -0,0 +1,126 @@
> +#
> +# SPDX-License-Identifier: MIT
> +#
> +
> +from oeqa.selftest.case import OESelftestTestCase
> +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
> +
> +class OverlayFSTests(OESelftestTestCase):
> +    """Overlayfs class usage tests"""
> +
> +    def getline(self, res, line):
> +        for l in res.output.split('\n'):
> +            if line in l:
> +                return l
> +
> +    def test_distro_features_missing(self):
> +        """
> +        Summary:   Check that required DISTRO_FEATURES are set
> +        Expected:  Fail when either systemd or overlayfs are not in
> DISTRO_FEATURES
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> +IMAGE_INSTALL_append = "overlayfs-user"
> +"""
> +        self.write_config(config)
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "overlayfs-user was skipped: missing
> required distro features")
> +        self.assertTrue("overlayfs" in res.output, msg=res.output)
> +        self.assertTrue("systemd" in res.output, msg=res.output)
> +        self.assertTrue("ERROR: Required build target
> 'core-image-minimal' has no buildable providers." in res.output,
> msg=res.output)
> +
> +    def test_not_all_units_installed(self):
> +        """
> +        Summary:   Test QA check that we have required mount units in the
> image
> +        Expected:  Fail because mount unit for overlay partition is not
> installed
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> +IMAGE_INSTALL_append = "overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +        self.write_config(config)
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "Unit name mnt-overlay.mount not found
> in systemd unit directories")
> +        self.assertTrue(line and line.startswith("WARNING:"),
> msg=res.output)
> +        line = self.getline(res, "Not all mount units are installed by
> the BSP")
> +        self.assertTrue(line and line.startswith("ERROR:"),
> msg=res.output)
> +
> +    def test_mount_unit_not_set(self):
> +        """
> +        Summary:   Test whether mount unit was set properly
> +        Expected:  Fail because mount unit was not set
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +IMAGE_INSTALL_append = "overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +        self.write_config(config)
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "A recipe uses overlayfs class but there
> is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
> +        self.assertTrue(line and line.startswith("Parsing
> recipes...ERROR:"), msg=res.output)
> +
> +    def test_wrong_mount_unit_set(self):
> +        """
> +        Summary:   Test whether mount unit was set properly
> +        Expected:  Fail because not the correct flag used for mount unit
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay"
> +IMAGE_INSTALL_append = "overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +        self.write_config(config)
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "Missing required mount point for
> OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration")
> +        self.assertTrue(line and line.startswith("Parsing
> recipes...ERROR:"), msg=res.output)
> +
> +    def test_correct_image(self):
> +        """
> +        Summary:   Check that we can create an image when all parameters
> are
> +                   set correctly
> +        Expected:  Image is created successfully
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> +IMAGE_INSTALL_append = "overlayfs-user systemd-machine-units"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +
> +        systemd_machine_unit_append = """
> +SYSTEMD_SERVICE_${PN} += " \
> +    mnt-overlay.mount \
> +"
> +
> +do_install() {
> +    install -d ${D}${systemd_unitdir}/system
> +    cat <<EOT > ${D}${systemd_unitdir}/system/mnt-overlay.mount
> +[Unit]
> +Description=Tmpfs directory
> +DefaultDependencies=no
> +
> +[Mount]
> +What=tmpfs
> +Where=/mnt/overlay
> +Type=tmpfs
> +Options=mode=1777,strictatime,nosuid,nodev
> +
> +[Install]
> +WantedBy=multi-user.target
> +EOT
> +}
> +
> +"""
> +        self.write_config(config)
> +        self.write_recipeinc('systemd-machine-units',
> systemd_machine_unit_append)
> +        bitbake('core-image-minimal')
> --
> 2.28.0
>
>
> 
>
>

[-- Attachment #2: Type: text/html, Size: 7900 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [OE-core] [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests
  2021-07-09 11:31 ` [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests Vyacheslav Yurkov
  2021-07-10  9:01   ` [OE-core] " Alexander Kanavin
@ 2021-07-10  9:41   ` Alexandre Belloni
  2021-07-10 12:47     ` Vyacheslav Yurkov
  1 sibling, 1 reply; 16+ messages in thread
From: Alexandre Belloni @ 2021-07-10  9:41 UTC (permalink / raw)
  To: Vyacheslav Yurkov; +Cc: Openembedded-core

Hello,

On 09/07/2021 13:31:45+0200, Vyacheslav Yurkov wrote:
> Unit tests for overlayfs.bbclass
> 

I believe I properly applied the series but it fails with:

Parsing recipes...ERROR: /home/pokybuild/yocto-worker/oe-selftest-centos/build/build-st-1517413/meta-selftest/recipes-test/overlayfs/overlayfs-user.bb: A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration

See https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/2290/steps/14/logs/stdio

> Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
> ---
>  meta/lib/oeqa/selftest/cases/overlayfs.py | 126 ++++++++++++++++++++++
>  1 file changed, 126 insertions(+)
>  create mode 100644 meta/lib/oeqa/selftest/cases/overlayfs.py
> 
> diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
> new file mode 100644
> index 0000000000..74bf1c4167
> --- /dev/null
> +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
> @@ -0,0 +1,126 @@
> +#
> +# SPDX-License-Identifier: MIT
> +#
> +
> +from oeqa.selftest.case import OESelftestTestCase
> +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
> +
> +class OverlayFSTests(OESelftestTestCase):
> +    """Overlayfs class usage tests"""
> +
> +    def getline(self, res, line):
> +        for l in res.output.split('\n'):
> +            if line in l:
> +                return l
> +
> +    def test_distro_features_missing(self):
> +        """
> +        Summary:   Check that required DISTRO_FEATURES are set
> +        Expected:  Fail when either systemd or overlayfs are not in DISTRO_FEATURES
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> +IMAGE_INSTALL_append = "overlayfs-user"
> +"""
> +        self.write_config(config)
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "overlayfs-user was skipped: missing required distro features")
> +        self.assertTrue("overlayfs" in res.output, msg=res.output)
> +        self.assertTrue("systemd" in res.output, msg=res.output)
> +        self.assertTrue("ERROR: Required build target 'core-image-minimal' has no buildable providers." in res.output, msg=res.output)
> +
> +    def test_not_all_units_installed(self):
> +        """
> +        Summary:   Test QA check that we have required mount units in the image
> +        Expected:  Fail because mount unit for overlay partition is not installed
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> +IMAGE_INSTALL_append = "overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +        self.write_config(config)
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "Unit name mnt-overlay.mount not found in systemd unit directories")
> +        self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
> +        line = self.getline(res, "Not all mount units are installed by the BSP")
> +        self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
> +
> +    def test_mount_unit_not_set(self):
> +        """
> +        Summary:   Test whether mount unit was set properly
> +        Expected:  Fail because mount unit was not set
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +IMAGE_INSTALL_append = "overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +        self.write_config(config)
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
> +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
> +
> +    def test_wrong_mount_unit_set(self):
> +        """
> +        Summary:   Test whether mount unit was set properly
> +        Expected:  Fail because not the correct flag used for mount unit
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay"
> +IMAGE_INSTALL_append = "overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +        self.write_config(config)
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "Missing required mount point for OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration")
> +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
> +
> +    def test_correct_image(self):
> +        """
> +        Summary:   Check that we can create an image when all parameters are
> +                   set correctly
> +        Expected:  Image is created successfully
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> +IMAGE_INSTALL_append = "overlayfs-user systemd-machine-units"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +
> +        systemd_machine_unit_append = """
> +SYSTEMD_SERVICE_${PN} += " \
> +    mnt-overlay.mount \
> +"
> +
> +do_install() {
> +    install -d ${D}${systemd_unitdir}/system
> +    cat <<EOT > ${D}${systemd_unitdir}/system/mnt-overlay.mount
> +[Unit]
> +Description=Tmpfs directory
> +DefaultDependencies=no
> +
> +[Mount]
> +What=tmpfs
> +Where=/mnt/overlay
> +Type=tmpfs
> +Options=mode=1777,strictatime,nosuid,nodev
> +
> +[Install]
> +WantedBy=multi-user.target
> +EOT
> +}
> +
> +"""
> +        self.write_config(config)
> +        self.write_recipeinc('systemd-machine-units', systemd_machine_unit_append)
> +        bitbake('core-image-minimal')
> -- 
> 2.28.0
> 

> 
> 
> 


-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [OE-core] [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests
  2021-07-10  9:41   ` Alexandre Belloni
@ 2021-07-10 12:47     ` Vyacheslav Yurkov
  2021-07-10 17:15       ` Alexandre Belloni
  0 siblings, 1 reply; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-10 12:47 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: Openembedded-core, Alexander Kanavin

Hi Alexandre,
Thanks for the build.
Seems like I forgot a space in _append :/

I'd like to address Alex request too to include a run-time test. Is 
there a way to update only this patch without resending the whole series?

Thanks,
Vyacheslav

On 10.07.2021 11:41, Alexandre Belloni wrote:
> Hello,
>
> On 09/07/2021 13:31:45+0200, Vyacheslav Yurkov wrote:
>> Unit tests for overlayfs.bbclass
>>
> I believe I properly applied the series but it fails with:
>
> Parsing recipes...ERROR: /home/pokybuild/yocto-worker/oe-selftest-centos/build/build-st-1517413/meta-selftest/recipes-test/overlayfs/overlayfs-user.bb: A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration
>
> See https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/2290/steps/14/logs/stdio
>
>> Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
>> ---
>>   meta/lib/oeqa/selftest/cases/overlayfs.py | 126 ++++++++++++++++++++++
>>   1 file changed, 126 insertions(+)
>>   create mode 100644 meta/lib/oeqa/selftest/cases/overlayfs.py
>>
>> diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
>> new file mode 100644
>> index 0000000000..74bf1c4167
>> --- /dev/null
>> +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
>> @@ -0,0 +1,126 @@
>> +#
>> +# SPDX-License-Identifier: MIT
>> +#
>> +
>> +from oeqa.selftest.case import OESelftestTestCase
>> +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
>> +
>> +class OverlayFSTests(OESelftestTestCase):
>> +    """Overlayfs class usage tests"""
>> +
>> +    def getline(self, res, line):
>> +        for l in res.output.split('\n'):
>> +            if line in l:
>> +                return l
>> +
>> +    def test_distro_features_missing(self):
>> +        """
>> +        Summary:   Check that required DISTRO_FEATURES are set
>> +        Expected:  Fail when either systemd or overlayfs are not in DISTRO_FEATURES
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
>> +IMAGE_INSTALL_append = "overlayfs-user"
>> +"""
>> +        self.write_config(config)
>> +        res = bitbake('core-image-minimal', ignore_status=True)
>> +        line = self.getline(res, "overlayfs-user was skipped: missing required distro features")
>> +        self.assertTrue("overlayfs" in res.output, msg=res.output)
>> +        self.assertTrue("systemd" in res.output, msg=res.output)
>> +        self.assertTrue("ERROR: Required build target 'core-image-minimal' has no buildable providers." in res.output, msg=res.output)
>> +
>> +    def test_not_all_units_installed(self):
>> +        """
>> +        Summary:   Test QA check that we have required mount units in the image
>> +        Expected:  Fail because mount unit for overlay partition is not installed
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
>> +IMAGE_INSTALL_append = "overlayfs-user"
>> +DISTRO_FEATURES += "systemd overlayfs"
>> +"""
>> +        self.write_config(config)
>> +        res = bitbake('core-image-minimal', ignore_status=True)
>> +        line = self.getline(res, "Unit name mnt-overlay.mount not found in systemd unit directories")
>> +        self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
>> +        line = self.getline(res, "Not all mount units are installed by the BSP")
>> +        self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
>> +
>> +    def test_mount_unit_not_set(self):
>> +        """
>> +        Summary:   Test whether mount unit was set properly
>> +        Expected:  Fail because mount unit was not set
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +IMAGE_INSTALL_append = "overlayfs-user"
>> +DISTRO_FEATURES += "systemd overlayfs"
>> +"""
>> +        self.write_config(config)
>> +        res = bitbake('core-image-minimal', ignore_status=True)
>> +        line = self.getline(res, "A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
>> +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
>> +
>> +    def test_wrong_mount_unit_set(self):
>> +        """
>> +        Summary:   Test whether mount unit was set properly
>> +        Expected:  Fail because not the correct flag used for mount unit
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay"
>> +IMAGE_INSTALL_append = "overlayfs-user"
>> +DISTRO_FEATURES += "systemd overlayfs"
>> +"""
>> +        self.write_config(config)
>> +        res = bitbake('core-image-minimal', ignore_status=True)
>> +        line = self.getline(res, "Missing required mount point for OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration")
>> +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
>> +
>> +    def test_correct_image(self):
>> +        """
>> +        Summary:   Check that we can create an image when all parameters are
>> +                   set correctly
>> +        Expected:  Image is created successfully
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
>> +IMAGE_INSTALL_append = "overlayfs-user systemd-machine-units"
>> +DISTRO_FEATURES += "systemd overlayfs"
>> +"""
>> +
>> +        systemd_machine_unit_append = """
>> +SYSTEMD_SERVICE_${PN} += " \
>> +    mnt-overlay.mount \
>> +"
>> +
>> +do_install() {
>> +    install -d ${D}${systemd_unitdir}/system
>> +    cat <<EOT > ${D}${systemd_unitdir}/system/mnt-overlay.mount
>> +[Unit]
>> +Description=Tmpfs directory
>> +DefaultDependencies=no
>> +
>> +[Mount]
>> +What=tmpfs
>> +Where=/mnt/overlay
>> +Type=tmpfs
>> +Options=mode=1777,strictatime,nosuid,nodev
>> +
>> +[Install]
>> +WantedBy=multi-user.target
>> +EOT
>> +}
>> +
>> +"""
>> +        self.write_config(config)
>> +        self.write_recipeinc('systemd-machine-units', systemd_machine_unit_append)
>> +        bitbake('core-image-minimal')
>> -- 
>> 2.28.0
>>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [OE-core] [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests
  2021-07-10 12:47     ` Vyacheslav Yurkov
@ 2021-07-10 17:15       ` Alexandre Belloni
  2021-07-11 15:16         ` Vyacheslav Yurkov
  0 siblings, 1 reply; 16+ messages in thread
From: Alexandre Belloni @ 2021-07-10 17:15 UTC (permalink / raw)
  To: Vyacheslav Yurkov; +Cc: Openembedded-core, Alexander Kanavin

On 10/07/2021 14:47:01+0200, Vyacheslav Yurkov wrote:
> Hi Alexandre,
> Thanks for the build.
> Seems like I forgot a space in _append :/
> 
> I'd like to address Alex request too to include a run-time test. Is there a
> way to update only this patch without resending the whole series?
> 

If you send a v2, of this one, I can queue it with the other ones,
please use --in-reply-to

> Thanks,
> Vyacheslav
> 
> On 10.07.2021 11:41, Alexandre Belloni wrote:
> > Hello,
> > 
> > On 09/07/2021 13:31:45+0200, Vyacheslav Yurkov wrote:
> > > Unit tests for overlayfs.bbclass
> > > 
> > I believe I properly applied the series but it fails with:
> > 
> > Parsing recipes...ERROR: /home/pokybuild/yocto-worker/oe-selftest-centos/build/build-st-1517413/meta-selftest/recipes-test/overlayfs/overlayfs-user.bb: A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration
> > 
> > See https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/2290/steps/14/logs/stdio
> > 
> > > Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
> > > ---
> > >   meta/lib/oeqa/selftest/cases/overlayfs.py | 126 ++++++++++++++++++++++
> > >   1 file changed, 126 insertions(+)
> > >   create mode 100644 meta/lib/oeqa/selftest/cases/overlayfs.py
> > > 
> > > diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
> > > new file mode 100644
> > > index 0000000000..74bf1c4167
> > > --- /dev/null
> > > +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
> > > @@ -0,0 +1,126 @@
> > > +#
> > > +# SPDX-License-Identifier: MIT
> > > +#
> > > +
> > > +from oeqa.selftest.case import OESelftestTestCase
> > > +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
> > > +
> > > +class OverlayFSTests(OESelftestTestCase):
> > > +    """Overlayfs class usage tests"""
> > > +
> > > +    def getline(self, res, line):
> > > +        for l in res.output.split('\n'):
> > > +            if line in l:
> > > +                return l
> > > +
> > > +    def test_distro_features_missing(self):
> > > +        """
> > > +        Summary:   Check that required DISTRO_FEATURES are set
> > > +        Expected:  Fail when either systemd or overlayfs are not in DISTRO_FEATURES
> > > +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> > > +        """
> > > +
> > > +        config = """
> > > +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> > > +IMAGE_INSTALL_append = "overlayfs-user"
> > > +"""
> > > +        self.write_config(config)
> > > +        res = bitbake('core-image-minimal', ignore_status=True)
> > > +        line = self.getline(res, "overlayfs-user was skipped: missing required distro features")
> > > +        self.assertTrue("overlayfs" in res.output, msg=res.output)
> > > +        self.assertTrue("systemd" in res.output, msg=res.output)
> > > +        self.assertTrue("ERROR: Required build target 'core-image-minimal' has no buildable providers." in res.output, msg=res.output)
> > > +
> > > +    def test_not_all_units_installed(self):
> > > +        """
> > > +        Summary:   Test QA check that we have required mount units in the image
> > > +        Expected:  Fail because mount unit for overlay partition is not installed
> > > +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> > > +        """
> > > +
> > > +        config = """
> > > +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> > > +IMAGE_INSTALL_append = "overlayfs-user"
> > > +DISTRO_FEATURES += "systemd overlayfs"
> > > +"""
> > > +        self.write_config(config)
> > > +        res = bitbake('core-image-minimal', ignore_status=True)
> > > +        line = self.getline(res, "Unit name mnt-overlay.mount not found in systemd unit directories")
> > > +        self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
> > > +        line = self.getline(res, "Not all mount units are installed by the BSP")
> > > +        self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
> > > +
> > > +    def test_mount_unit_not_set(self):
> > > +        """
> > > +        Summary:   Test whether mount unit was set properly
> > > +        Expected:  Fail because mount unit was not set
> > > +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> > > +        """
> > > +
> > > +        config = """
> > > +IMAGE_INSTALL_append = "overlayfs-user"
> > > +DISTRO_FEATURES += "systemd overlayfs"
> > > +"""
> > > +        self.write_config(config)
> > > +        res = bitbake('core-image-minimal', ignore_status=True)
> > > +        line = self.getline(res, "A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
> > > +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
> > > +
> > > +    def test_wrong_mount_unit_set(self):
> > > +        """
> > > +        Summary:   Test whether mount unit was set properly
> > > +        Expected:  Fail because not the correct flag used for mount unit
> > > +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> > > +        """
> > > +
> > > +        config = """
> > > +OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay"
> > > +IMAGE_INSTALL_append = "overlayfs-user"
> > > +DISTRO_FEATURES += "systemd overlayfs"
> > > +"""
> > > +        self.write_config(config)
> > > +        res = bitbake('core-image-minimal', ignore_status=True)
> > > +        line = self.getline(res, "Missing required mount point for OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration")
> > > +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
> > > +
> > > +    def test_correct_image(self):
> > > +        """
> > > +        Summary:   Check that we can create an image when all parameters are
> > > +                   set correctly
> > > +        Expected:  Image is created successfully
> > > +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> > > +        """
> > > +
> > > +        config = """
> > > +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> > > +IMAGE_INSTALL_append = "overlayfs-user systemd-machine-units"
> > > +DISTRO_FEATURES += "systemd overlayfs"
> > > +"""
> > > +
> > > +        systemd_machine_unit_append = """
> > > +SYSTEMD_SERVICE_${PN} += " \
> > > +    mnt-overlay.mount \
> > > +"
> > > +
> > > +do_install() {
> > > +    install -d ${D}${systemd_unitdir}/system
> > > +    cat <<EOT > ${D}${systemd_unitdir}/system/mnt-overlay.mount
> > > +[Unit]
> > > +Description=Tmpfs directory
> > > +DefaultDependencies=no
> > > +
> > > +[Mount]
> > > +What=tmpfs
> > > +Where=/mnt/overlay
> > > +Type=tmpfs
> > > +Options=mode=1777,strictatime,nosuid,nodev
> > > +
> > > +[Install]
> > > +WantedBy=multi-user.target
> > > +EOT
> > > +}
> > > +
> > > +"""
> > > +        self.write_config(config)
> > > +        self.write_recipeinc('systemd-machine-units', systemd_machine_unit_append)
> > > +        bitbake('core-image-minimal')
> > > -- 
> > > 2.28.0
> > > 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests
  2021-07-10 17:15       ` Alexandre Belloni
@ 2021-07-11 15:16         ` Vyacheslav Yurkov
  2021-07-12  9:14           ` Alexandre Belloni
  0 siblings, 1 reply; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-11 15:16 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Alexander Kanavin, Alexandre Belloni, Vyacheslav Yurkov

Unit tests for overlayfs.bbclass

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 meta/lib/oeqa/selftest/cases/overlayfs.py | 167 ++++++++++++++++++++++
 1 file changed, 167 insertions(+)
 create mode 100644 meta/lib/oeqa/selftest/cases/overlayfs.py

diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
new file mode 100644
index 0000000000..a5a4792eb0
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
@@ -0,0 +1,167 @@
+#
+# SPDX-License-Identifier: MIT
+#
+
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
+
+class OverlayFSTests(OESelftestTestCase):
+    """Overlayfs class usage tests"""
+
+    def getline(self, res, line):
+        for l in res.output.split('\n'):
+            if line in l:
+                return l
+
+    def add_overlay_conf_to_machine(self):
+        machine_inc = """
+OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
+"""
+        self.set_machine_config(machine_inc)
+
+    def test_distro_features_missing(self):
+        """
+        Summary:   Check that required DISTRO_FEATURES are set
+        Expected:  Fail when either systemd or overlayfs are not in DISTRO_FEATURES
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user"
+"""
+        self.write_config(config)
+        self.add_overlay_conf_to_machine()
+
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "overlayfs-user was skipped: missing required distro features")
+        self.assertTrue("overlayfs" in res.output, msg=res.output)
+        self.assertTrue("systemd" in res.output, msg=res.output)
+        self.assertTrue("ERROR: Required build target 'core-image-minimal' has no buildable providers." in res.output, msg=res.output)
+
+    def test_not_all_units_installed(self):
+        """
+        Summary:   Test QA check that we have required mount units in the image
+        Expected:  Fail because mount unit for overlay partition is not installed
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+
+        self.write_config(config)
+        self.add_overlay_conf_to_machine()
+
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "Unit name mnt-overlay.mount not found in systemd unit directories")
+        self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
+        line = self.getline(res, "Not all mount units are installed by the BSP")
+        self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
+
+    def test_mount_unit_not_set(self):
+        """
+        Summary:   Test whether mount unit was set properly
+        Expected:  Fail because mount unit was not set
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+
+        self.write_config(config)
+
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
+        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
+
+    def test_wrong_mount_unit_set(self):
+        """
+        Summary:   Test whether mount unit was set properly
+        Expected:  Fail because not the correct flag used for mount unit
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+
+        wrong_machine_config = """
+OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay"
+"""
+
+        self.write_config(config)
+        self.set_machine_config(wrong_machine_config)
+
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "Missing required mount point for OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration")
+        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
+
+    def test_correct_image(self):
+        """
+        Summary:   Check that we can create an image when all parameters are
+                   set correctly
+        Expected:  Image is created successfully
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user systemd-machine-units"
+DISTRO_FEATURES += "systemd overlayfs"
+
+# Use systemd as init manager
+VIRTUAL-RUNTIME_init_manager = "systemd"
+
+# enable overlayfs in the kernel
+KERNEL_EXTRA_FEATURES_append = " features/overlayfs/overlayfs.scc"
+"""
+
+        systemd_machine_unit_append = """
+SYSTEMD_SERVICE_${PN} += " \
+    mnt-overlay.mount \
+"
+
+do_install_append() {
+    install -d ${D}${systemd_system_unitdir}
+    cat <<EOT > ${D}${systemd_system_unitdir}/mnt-overlay.mount
+[Unit]
+Description=Tmpfs directory
+DefaultDependencies=no
+
+[Mount]
+What=tmpfs
+Where=/mnt/overlay
+Type=tmpfs
+Options=mode=1777,strictatime,nosuid,nodev
+
+[Install]
+WantedBy=multi-user.target
+EOT
+}
+
+"""
+
+        self.write_config(config)
+        self.add_overlay_conf_to_machine()
+        self.write_recipeinc('systemd-machine-units', systemd_machine_unit_append)
+
+        bitbake('core-image-minimal')
+
+        def getline_qemu(out, line):
+            for l in out.split('\n'):
+                if line in l:
+                    return l
+
+        with runqemu('core-image-minimal') as qemu:
+            # Check that we have /mnt/overlay fs mounted as tmpfs and
+            # /usr/share/my-application as an overlay (see overlayfs-user recipe)
+            status, output = qemu.run_serial("/bin/mount -t tmpfs,overlay")
+
+            line = getline_qemu(output, "on /mnt/overlay")
+            self.assertTrue(line and line.startswith("tmpfs"), msg=output)
+
+            line = getline_qemu(output, "upperdir=/mnt/overlay/upper/usr/share/my-application")
+            self.assertTrue(line and line.startswith("overlay"), msg=output)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests
  2021-07-11 15:16         ` Vyacheslav Yurkov
@ 2021-07-12  9:14           ` Alexandre Belloni
  2021-07-12  9:42             ` Vyacheslav Yurkov
  0 siblings, 1 reply; 16+ messages in thread
From: Alexandre Belloni @ 2021-07-12  9:14 UTC (permalink / raw)
  To: Vyacheslav Yurkov; +Cc: Openembedded-core, Alexander Kanavin

Hello,

On 11/07/2021 17:16:29+0200, Vyacheslav Yurkov wrote:
> Unit tests for overlayfs.bbclass
> 

This still seems to fail the tests:
https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/2299/steps/14/logs/stdio

> Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
> ---
>  meta/lib/oeqa/selftest/cases/overlayfs.py | 167 ++++++++++++++++++++++
>  1 file changed, 167 insertions(+)
>  create mode 100644 meta/lib/oeqa/selftest/cases/overlayfs.py
> 
> diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
> new file mode 100644
> index 0000000000..a5a4792eb0
> --- /dev/null
> +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
> @@ -0,0 +1,167 @@
> +#
> +# SPDX-License-Identifier: MIT
> +#
> +
> +from oeqa.selftest.case import OESelftestTestCase
> +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
> +
> +class OverlayFSTests(OESelftestTestCase):
> +    """Overlayfs class usage tests"""
> +
> +    def getline(self, res, line):
> +        for l in res.output.split('\n'):
> +            if line in l:
> +                return l
> +
> +    def add_overlay_conf_to_machine(self):
> +        machine_inc = """
> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
> +"""
> +        self.set_machine_config(machine_inc)
> +
> +    def test_distro_features_missing(self):
> +        """
> +        Summary:   Check that required DISTRO_FEATURES are set
> +        Expected:  Fail when either systemd or overlayfs are not in DISTRO_FEATURES
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +IMAGE_INSTALL_append = " overlayfs-user"
> +"""
> +        self.write_config(config)
> +        self.add_overlay_conf_to_machine()
> +
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "overlayfs-user was skipped: missing required distro features")
> +        self.assertTrue("overlayfs" in res.output, msg=res.output)
> +        self.assertTrue("systemd" in res.output, msg=res.output)
> +        self.assertTrue("ERROR: Required build target 'core-image-minimal' has no buildable providers." in res.output, msg=res.output)
> +
> +    def test_not_all_units_installed(self):
> +        """
> +        Summary:   Test QA check that we have required mount units in the image
> +        Expected:  Fail because mount unit for overlay partition is not installed
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +IMAGE_INSTALL_append = " overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +
> +        self.write_config(config)
> +        self.add_overlay_conf_to_machine()
> +
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "Unit name mnt-overlay.mount not found in systemd unit directories")
> +        self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
> +        line = self.getline(res, "Not all mount units are installed by the BSP")
> +        self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
> +
> +    def test_mount_unit_not_set(self):
> +        """
> +        Summary:   Test whether mount unit was set properly
> +        Expected:  Fail because mount unit was not set
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +IMAGE_INSTALL_append = " overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +
> +        self.write_config(config)
> +
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
> +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
> +
> +    def test_wrong_mount_unit_set(self):
> +        """
> +        Summary:   Test whether mount unit was set properly
> +        Expected:  Fail because not the correct flag used for mount unit
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +IMAGE_INSTALL_append = " overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +"""
> +
> +        wrong_machine_config = """
> +OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay"
> +"""
> +
> +        self.write_config(config)
> +        self.set_machine_config(wrong_machine_config)
> +
> +        res = bitbake('core-image-minimal', ignore_status=True)
> +        line = self.getline(res, "Missing required mount point for OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration")
> +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
> +
> +    def test_correct_image(self):
> +        """
> +        Summary:   Check that we can create an image when all parameters are
> +                   set correctly
> +        Expected:  Image is created successfully
> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
> +        """
> +
> +        config = """
> +IMAGE_INSTALL_append = " overlayfs-user systemd-machine-units"
> +DISTRO_FEATURES += "systemd overlayfs"
> +
> +# Use systemd as init manager
> +VIRTUAL-RUNTIME_init_manager = "systemd"
> +
> +# enable overlayfs in the kernel
> +KERNEL_EXTRA_FEATURES_append = " features/overlayfs/overlayfs.scc"
> +"""
> +
> +        systemd_machine_unit_append = """
> +SYSTEMD_SERVICE_${PN} += " \
> +    mnt-overlay.mount \
> +"
> +
> +do_install_append() {
> +    install -d ${D}${systemd_system_unitdir}
> +    cat <<EOT > ${D}${systemd_system_unitdir}/mnt-overlay.mount
> +[Unit]
> +Description=Tmpfs directory
> +DefaultDependencies=no
> +
> +[Mount]
> +What=tmpfs
> +Where=/mnt/overlay
> +Type=tmpfs
> +Options=mode=1777,strictatime,nosuid,nodev
> +
> +[Install]
> +WantedBy=multi-user.target
> +EOT
> +}
> +
> +"""
> +
> +        self.write_config(config)
> +        self.add_overlay_conf_to_machine()
> +        self.write_recipeinc('systemd-machine-units', systemd_machine_unit_append)
> +
> +        bitbake('core-image-minimal')
> +
> +        def getline_qemu(out, line):
> +            for l in out.split('\n'):
> +                if line in l:
> +                    return l
> +
> +        with runqemu('core-image-minimal') as qemu:
> +            # Check that we have /mnt/overlay fs mounted as tmpfs and
> +            # /usr/share/my-application as an overlay (see overlayfs-user recipe)
> +            status, output = qemu.run_serial("/bin/mount -t tmpfs,overlay")
> +
> +            line = getline_qemu(output, "on /mnt/overlay")
> +            self.assertTrue(line and line.startswith("tmpfs"), msg=output)
> +
> +            line = getline_qemu(output, "upperdir=/mnt/overlay/upper/usr/share/my-application")
> +            self.assertTrue(line and line.startswith("overlay"), msg=output)
> -- 
> 2.28.0
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests
  2021-07-12  9:14           ` Alexandre Belloni
@ 2021-07-12  9:42             ` Vyacheslav Yurkov
  0 siblings, 0 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-12  9:42 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: Openembedded-core

Hi Alexandre,
I updated 6/8, could you please run them again?

Thanks,
Vyacheslav

On 12.07.2021 11:14, Alexandre Belloni wrote:
> Hello,
>
> On 11/07/2021 17:16:29+0200, Vyacheslav Yurkov wrote:
>> Unit tests for overlayfs.bbclass
>>
> This still seems to fail the tests:
> https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/2299/steps/14/logs/stdio
>
>> Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
>> ---
>>   meta/lib/oeqa/selftest/cases/overlayfs.py | 167 ++++++++++++++++++++++
>>   1 file changed, 167 insertions(+)
>>   create mode 100644 meta/lib/oeqa/selftest/cases/overlayfs.py
>>
>> diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
>> new file mode 100644
>> index 0000000000..a5a4792eb0
>> --- /dev/null
>> +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
>> @@ -0,0 +1,167 @@
>> +#
>> +# SPDX-License-Identifier: MIT
>> +#
>> +
>> +from oeqa.selftest.case import OESelftestTestCase
>> +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
>> +
>> +class OverlayFSTests(OESelftestTestCase):
>> +    """Overlayfs class usage tests"""
>> +
>> +    def getline(self, res, line):
>> +        for l in res.output.split('\n'):
>> +            if line in l:
>> +                return l
>> +
>> +    def add_overlay_conf_to_machine(self):
>> +        machine_inc = """
>> +OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
>> +"""
>> +        self.set_machine_config(machine_inc)
>> +
>> +    def test_distro_features_missing(self):
>> +        """
>> +        Summary:   Check that required DISTRO_FEATURES are set
>> +        Expected:  Fail when either systemd or overlayfs are not in DISTRO_FEATURES
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +IMAGE_INSTALL_append = " overlayfs-user"
>> +"""
>> +        self.write_config(config)
>> +        self.add_overlay_conf_to_machine()
>> +
>> +        res = bitbake('core-image-minimal', ignore_status=True)
>> +        line = self.getline(res, "overlayfs-user was skipped: missing required distro features")
>> +        self.assertTrue("overlayfs" in res.output, msg=res.output)
>> +        self.assertTrue("systemd" in res.output, msg=res.output)
>> +        self.assertTrue("ERROR: Required build target 'core-image-minimal' has no buildable providers." in res.output, msg=res.output)
>> +
>> +    def test_not_all_units_installed(self):
>> +        """
>> +        Summary:   Test QA check that we have required mount units in the image
>> +        Expected:  Fail because mount unit for overlay partition is not installed
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +IMAGE_INSTALL_append = " overlayfs-user"
>> +DISTRO_FEATURES += "systemd overlayfs"
>> +"""
>> +
>> +        self.write_config(config)
>> +        self.add_overlay_conf_to_machine()
>> +
>> +        res = bitbake('core-image-minimal', ignore_status=True)
>> +        line = self.getline(res, "Unit name mnt-overlay.mount not found in systemd unit directories")
>> +        self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
>> +        line = self.getline(res, "Not all mount units are installed by the BSP")
>> +        self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
>> +
>> +    def test_mount_unit_not_set(self):
>> +        """
>> +        Summary:   Test whether mount unit was set properly
>> +        Expected:  Fail because mount unit was not set
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +IMAGE_INSTALL_append = " overlayfs-user"
>> +DISTRO_FEATURES += "systemd overlayfs"
>> +"""
>> +
>> +        self.write_config(config)
>> +
>> +        res = bitbake('core-image-minimal', ignore_status=True)
>> +        line = self.getline(res, "A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
>> +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
>> +
>> +    def test_wrong_mount_unit_set(self):
>> +        """
>> +        Summary:   Test whether mount unit was set properly
>> +        Expected:  Fail because not the correct flag used for mount unit
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +IMAGE_INSTALL_append = " overlayfs-user"
>> +DISTRO_FEATURES += "systemd overlayfs"
>> +"""
>> +
>> +        wrong_machine_config = """
>> +OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay"
>> +"""
>> +
>> +        self.write_config(config)
>> +        self.set_machine_config(wrong_machine_config)
>> +
>> +        res = bitbake('core-image-minimal', ignore_status=True)
>> +        line = self.getline(res, "Missing required mount point for OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration")
>> +        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
>> +
>> +    def test_correct_image(self):
>> +        """
>> +        Summary:   Check that we can create an image when all parameters are
>> +                   set correctly
>> +        Expected:  Image is created successfully
>> +        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
>> +        """
>> +
>> +        config = """
>> +IMAGE_INSTALL_append = " overlayfs-user systemd-machine-units"
>> +DISTRO_FEATURES += "systemd overlayfs"
>> +
>> +# Use systemd as init manager
>> +VIRTUAL-RUNTIME_init_manager = "systemd"
>> +
>> +# enable overlayfs in the kernel
>> +KERNEL_EXTRA_FEATURES_append = " features/overlayfs/overlayfs.scc"
>> +"""
>> +
>> +        systemd_machine_unit_append = """
>> +SYSTEMD_SERVICE_${PN} += " \
>> +    mnt-overlay.mount \
>> +"
>> +
>> +do_install_append() {
>> +    install -d ${D}${systemd_system_unitdir}
>> +    cat <<EOT > ${D}${systemd_system_unitdir}/mnt-overlay.mount
>> +[Unit]
>> +Description=Tmpfs directory
>> +DefaultDependencies=no
>> +
>> +[Mount]
>> +What=tmpfs
>> +Where=/mnt/overlay
>> +Type=tmpfs
>> +Options=mode=1777,strictatime,nosuid,nodev
>> +
>> +[Install]
>> +WantedBy=multi-user.target
>> +EOT
>> +}
>> +
>> +"""
>> +
>> +        self.write_config(config)
>> +        self.add_overlay_conf_to_machine()
>> +        self.write_recipeinc('systemd-machine-units', systemd_machine_unit_append)
>> +
>> +        bitbake('core-image-minimal')
>> +
>> +        def getline_qemu(out, line):
>> +            for l in out.split('\n'):
>> +                if line in l:
>> +                    return l
>> +
>> +        with runqemu('core-image-minimal') as qemu:
>> +            # Check that we have /mnt/overlay fs mounted as tmpfs and
>> +            # /usr/share/my-application as an overlay (see overlayfs-user recipe)
>> +            status, output = qemu.run_serial("/bin/mount -t tmpfs,overlay")
>> +
>> +            line = getline_qemu(output, "on /mnt/overlay")
>> +            self.assertTrue(line and line.startswith("tmpfs"), msg=output)
>> +
>> +            line = getline_qemu(output, "upperdir=/mnt/overlay/upper/usr/share/my-application")
>> +            self.assertTrue(line and line.startswith("overlay"), msg=output)
>> -- 
>> 2.28.0
>>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests
       [not found] <169101D2B14E1B11.4752@lists.openembedded.org>
@ 2021-07-12 15:00 ` Vyacheslav Yurkov
  0 siblings, 0 replies; 16+ messages in thread
From: Vyacheslav Yurkov @ 2021-07-12 15:00 UTC (permalink / raw)
  To: Openembedded-core; +Cc: Alexandre Belloni, Vyacheslav Yurkov

Unit tests for overlayfs.bbclass

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 meta/lib/oeqa/selftest/cases/overlayfs.py | 171 ++++++++++++++++++++++
 1 file changed, 171 insertions(+)
 create mode 100644 meta/lib/oeqa/selftest/cases/overlayfs.py

diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
new file mode 100644
index 0000000000..f679a71182
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
@@ -0,0 +1,171 @@
+#
+# SPDX-License-Identifier: MIT
+#
+
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
+
+class OverlayFSTests(OESelftestTestCase):
+    """Overlayfs class usage tests"""
+
+    def getline(self, res, line):
+        for l in res.output.split('\n'):
+            if line in l:
+                return l
+
+    def add_overlay_conf_to_machine(self):
+        machine_inc = """
+OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
+"""
+        self.set_machine_config(machine_inc)
+
+    def test_distro_features_missing(self):
+        """
+        Summary:   Check that required DISTRO_FEATURES are set
+        Expected:  Fail when either systemd or overlayfs are not in DISTRO_FEATURES
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user"
+"""
+        overlayfs_recipe_append = """
+inherit overlayfs
+"""
+        self.write_config(config)
+        self.add_overlay_conf_to_machine()
+        self.write_recipeinc('overlayfs-user', overlayfs_recipe_append)
+
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "overlayfs-user was skipped: missing required distro features")
+        self.assertTrue("overlayfs" in res.output, msg=res.output)
+        self.assertTrue("systemd" in res.output, msg=res.output)
+        self.assertTrue("ERROR: Required build target 'core-image-minimal' has no buildable providers." in res.output, msg=res.output)
+
+    def test_not_all_units_installed(self):
+        """
+        Summary:   Test QA check that we have required mount units in the image
+        Expected:  Fail because mount unit for overlay partition is not installed
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+
+        self.write_config(config)
+        self.add_overlay_conf_to_machine()
+
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "Unit name mnt-overlay.mount not found in systemd unit directories")
+        self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
+        line = self.getline(res, "Not all mount units are installed by the BSP")
+        self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
+
+    def test_mount_unit_not_set(self):
+        """
+        Summary:   Test whether mount unit was set properly
+        Expected:  Fail because mount unit was not set
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+
+        self.write_config(config)
+
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")
+        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
+
+    def test_wrong_mount_unit_set(self):
+        """
+        Summary:   Test whether mount unit was set properly
+        Expected:  Fail because not the correct flag used for mount unit
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+"""
+
+        wrong_machine_config = """
+OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay"
+"""
+
+        self.write_config(config)
+        self.set_machine_config(wrong_machine_config)
+
+        res = bitbake('core-image-minimal', ignore_status=True)
+        line = self.getline(res, "Missing required mount point for OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration")
+        self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output)
+
+    def test_correct_image(self):
+        """
+        Summary:   Check that we can create an image when all parameters are
+                   set correctly
+        Expected:  Image is created successfully
+        Author:    Vyacheslav Yurkov <uvv.mail@gmail.com>
+        """
+
+        config = """
+IMAGE_INSTALL_append = " overlayfs-user systemd-machine-units"
+DISTRO_FEATURES += "systemd overlayfs"
+
+# Use systemd as init manager
+VIRTUAL-RUNTIME_init_manager = "systemd"
+
+# enable overlayfs in the kernel
+KERNEL_EXTRA_FEATURES_append = " features/overlayfs/overlayfs.scc"
+"""
+
+        systemd_machine_unit_append = """
+SYSTEMD_SERVICE_${PN} += " \
+    mnt-overlay.mount \
+"
+
+do_install_append() {
+    install -d ${D}${systemd_system_unitdir}
+    cat <<EOT > ${D}${systemd_system_unitdir}/mnt-overlay.mount
+[Unit]
+Description=Tmpfs directory
+DefaultDependencies=no
+
+[Mount]
+What=tmpfs
+Where=/mnt/overlay
+Type=tmpfs
+Options=mode=1777,strictatime,nosuid,nodev
+
+[Install]
+WantedBy=multi-user.target
+EOT
+}
+
+"""
+
+        self.write_config(config)
+        self.add_overlay_conf_to_machine()
+        self.write_recipeinc('systemd-machine-units', systemd_machine_unit_append)
+
+        bitbake('core-image-minimal')
+
+        def getline_qemu(out, line):
+            for l in out.split('\n'):
+                if line in l:
+                    return l
+
+        with runqemu('core-image-minimal') as qemu:
+            # Check that we have /mnt/overlay fs mounted as tmpfs and
+            # /usr/share/my-application as an overlay (see overlayfs-user recipe)
+            status, output = qemu.run_serial("/bin/mount -t tmpfs,overlay")
+
+            line = getline_qemu(output, "on /mnt/overlay")
+            self.assertTrue(line and line.startswith("tmpfs"), msg=output)
+
+            line = getline_qemu(output, "upperdir=/mnt/overlay/upper/usr/share/my-application")
+            self.assertTrue(line and line.startswith("overlay"), msg=output)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-07-12 15:00 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 11:31 [PATCH v2 1/8] overlayfs-qa: common functions for overlayfs Vyacheslav Yurkov
2021-07-09 11:31 ` [PATCH v2 2/8] overlayfs.bbclass: generate overlayfs mount units Vyacheslav Yurkov
2021-07-09 11:31 ` [PATCH v2 3/8] maintainers.inc: overlayfs bbclass maintainer Vyacheslav Yurkov
2021-07-09 11:31 ` [PATCH v2 4/8] rootfs-postcommands: add QA check for overlayfs Vyacheslav Yurkov
2021-07-09 11:31 ` [PATCH v2 5/8] systemd-machine-units: add bbappend for meta-selftest Vyacheslav Yurkov
2021-07-09 11:31 ` [PATCH v2 6/8] overlayfs: meta-selftest recipe Vyacheslav Yurkov
2021-07-09 11:31 ` [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests Vyacheslav Yurkov
2021-07-10  9:01   ` [OE-core] " Alexander Kanavin
2021-07-10  9:41   ` Alexandre Belloni
2021-07-10 12:47     ` Vyacheslav Yurkov
2021-07-10 17:15       ` Alexandre Belloni
2021-07-11 15:16         ` Vyacheslav Yurkov
2021-07-12  9:14           ` Alexandre Belloni
2021-07-12  9:42             ` Vyacheslav Yurkov
2021-07-09 11:31 ` [PATCH v2 8/8] docs: add overlayfs class Vyacheslav Yurkov
     [not found] <169101D2B14E1B11.4752@lists.openembedded.org>
2021-07-12 15:00 ` [PATCH v2 7/8] oeqa/selftest: overlayfs unit tests Vyacheslav Yurkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.