[v3] classes: rootfs-postcommands: add skip option to overlayfs_qa_check

Message ID 20220503082231.1971123-1-ch@denx.de
State Accepted, archived
Commit 2ce9173169a2a86392c4a85fe9be7fbbd7353b7f
Headers show
Series [v3] classes: rootfs-postcommands: add skip option to overlayfs_qa_check | expand

Commit Message

Claudius Heine May 3, 2022, 8:22 a.m. UTC
The overlayfs_qa_check checks if the current root file system has a
mount configured for each overlayfs, when the overlayfs class is used.

However there are certain instances where this mount point is created at
runtime and not static in a fstab entry or systemd mount unit.

One such case would be if overlayfs-etc is used, where the device is
mounted in the preinit script and not via a mount unit or fstab entry.

However there are other possibilities for this as well, like startup
scripts that support a dynamic partition layout. For instance when
systemd-repart is used.

This adds the `OVERLAYFS_QA_SKIP` variable, which allows to define QA
skips via its flags. In principle it supports multiple QA skip flags
separated by whitespace, but only one (`mount-configured`) is
implemented here. To skip this QA check simply add `mount-configured` to
the flag of `OVERLAYFS_QA_SKIP` with the same name. For instance if a
overlayfs is configured as:

	OVERLAYFS_MOUNT_POINT[data] = "/data"

Skipping this QA check can be done by setting:

	OVERLAYFS_QA_SKIP[data] = "mount-configured"

Also add a testcase and fix a typo (fstat -> fstab).

Signed-off-by: Claudius Heine <ch@denx.de>
---

Changes from v2:
- Fix typo 'fstat' -> 'fstab' in testcase
- Add testcase for successful build when QA check is skipped.

Changes from v1:
- `getVarFag` -> `getVarFlag`

---
 meta/classes/rootfs-postcommands.bbclass  | 10 ++++++++--
 meta/lib/oeqa/selftest/cases/overlayfs.py | 20 +++++++++++++++++++-
 2 files changed, 27 insertions(+), 3 deletions(-)

Comments

Vyacheslav Yurkov May 9, 2022, 5:02 a.m. UTC | #1
On 03.05.2022 10:22, Claudius Heine wrote:
> The overlayfs_qa_check checks if the current root file system has a
> mount configured for each overlayfs, when the overlayfs class is used.
>
> However there are certain instances where this mount point is created at
> runtime and not static in a fstab entry or systemd mount unit.
>
> One such case would be if overlayfs-etc is used, where the device is
> mounted in the preinit script and not via a mount unit or fstab entry.
>
> However there are other possibilities for this as well, like startup
> scripts that support a dynamic partition layout. For instance when
> systemd-repart is used.
>
> This adds the `OVERLAYFS_QA_SKIP` variable, which allows to define QA
> skips via its flags. In principle it supports multiple QA skip flags
> separated by whitespace, but only one (`mount-configured`) is
> implemented here. To skip this QA check simply add `mount-configured` to
> the flag of `OVERLAYFS_QA_SKIP` with the same name. For instance if a
> overlayfs is configured as:
>
> 	OVERLAYFS_MOUNT_POINT[data] = "/data"
>
> Skipping this QA check can be done by setting:
>
> 	OVERLAYFS_QA_SKIP[data] = "mount-configured"
>
> Also add a testcase and fix a typo (fstat -> fstab).
>
> Signed-off-by: Claudius Heine <ch@denx.de>
> ---
>
> Changes from v2:
> - Fix typo 'fstat' -> 'fstab' in testcase
> - Add testcase for successful build when QA check is skipped.
>
> Changes from v1:
> - `getVarFag` -> `getVarFlag`
>
> ---
>   meta/classes/rootfs-postcommands.bbclass  | 10 ++++++++--
>   meta/lib/oeqa/selftest/cases/overlayfs.py | 20 +++++++++++++++++++-
>   2 files changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/meta/classes/rootfs-postcommands.bbclass b/meta/classes/rootfs-postcommands.bbclass
> index 7b92df69c5..9b6824043c 100644
> --- a/meta/classes/rootfs-postcommands.bbclass
> +++ b/meta/classes/rootfs-postcommands.bbclass
> @@ -398,6 +398,10 @@ python overlayfs_qa_check() {
>   
>       allUnitExist = True;
>       for mountPoint in overlayMountPoints:
> +        qaSkip = (d.getVarFlag("OVERLAYFS_QA_SKIP", mountPoint) or "").split()
> +        if "mount-configured" in qaSkip:
> +            continue
> +
>           mountPath = d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint)
>           if mountPath in fstabDevices:
>               continue
> @@ -407,8 +411,10 @@ python overlayfs_qa_check() {
>                  for dirpath in searchpaths):
>               continue
>   
> -        bb.warn('Mount path %s not found in fstat and unit %s not found '
> -                'in systemd unit directories' % (mountPath, mountUnit))
> +        bb.warn(f'Mount path {mountPath} not found in fstab and unit '
> +                f'{mountUnit} not found in systemd unit directories.')
> +        bb.warn(f'Skip this check by setting OVERLAYFS_QA_SKIP[{mountPoint}] = '
> +                '"mount-configured"')
>           allUnitExist = False;
>   
>       if not allUnitExist:
> diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
> index 472746a64f..ce1d2f1ec3 100644
> --- a/meta/lib/oeqa/selftest/cases/overlayfs.py
> +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
> @@ -62,11 +62,29 @@ DISTRO_FEATURES += "systemd overlayfs"
>           self.add_overlay_conf_to_machine()
>   
>           res = bitbake('core-image-minimal', ignore_status=True)
> -        line = getline(res, " Mount path /mnt/overlay not found in fstat and unit mnt-overlay.mount not found in systemd unit directories")
> +        line = getline(res, " Mount path /mnt/overlay not found in fstab and unit mnt-overlay.mount not found in systemd unit directories")
>           self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
>           line = getline(res, "Not all mount paths and units are installed in the image")
>           self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
>   
> +    def test_not_all_units_installed_but_qa_skipped(self):
> +        """
> +        Summary:   Test skipping the QA check
> +        Expected:  Image is created successfully
> +        Author:    Claudius Heine <ch@denx.de>
> +        """
> +
> +        config = """
> +IMAGE_INSTALL:append = " overlayfs-user"
> +DISTRO_FEATURES += "systemd overlayfs"
> +OVERLAYFS_QA_SKIP[mnt-overlay] = "mount-configured"
> +"""
> +
> +        self.write_config(config)
> +        self.add_overlay_conf_to_machine()
> +
> +        bitbake('core-image-minimal')
> +
>       def test_mount_unit_not_set(self):
>           """
>           Summary:   Test whether mount unit was set properly
Hi Claudius,
Thanks a lot for the patch

Could you please also extend the header of overlayfs.bbclass to describe 
the use case? I will update the documentation accordingly after that.

Thanks,
Vyacheslav
Claudius Heine May 10, 2022, 7:06 a.m. UTC | #2
On 2022-05-09 07:02, Vyacheslav Yurkov wrote:
> On 03.05.2022 10:22, Claudius Heine wrote:
>> The overlayfs_qa_check checks if the current root file system has a
>> mount configured for each overlayfs, when the overlayfs class is used.
>>
>> However there are certain instances where this mount point is created at
>> runtime and not static in a fstab entry or systemd mount unit.
>>
>> One such case would be if overlayfs-etc is used, where the device is
>> mounted in the preinit script and not via a mount unit or fstab entry.
>>
>> However there are other possibilities for this as well, like startup
>> scripts that support a dynamic partition layout. For instance when
>> systemd-repart is used.
>>
>> This adds the `OVERLAYFS_QA_SKIP` variable, which allows to define QA
>> skips via its flags. In principle it supports multiple QA skip flags
>> separated by whitespace, but only one (`mount-configured`) is
>> implemented here. To skip this QA check simply add `mount-configured` to
>> the flag of `OVERLAYFS_QA_SKIP` with the same name. For instance if a
>> overlayfs is configured as:
>>
>>     OVERLAYFS_MOUNT_POINT[data] = "/data"
>>
>> Skipping this QA check can be done by setting:
>>
>>     OVERLAYFS_QA_SKIP[data] = "mount-configured"
>>
>> Also add a testcase and fix a typo (fstat -> fstab).
>>
>> Signed-off-by: Claudius Heine <ch@denx.de>
>> ---
>>
>> Changes from v2:
>> - Fix typo 'fstat' -> 'fstab' in testcase
>> - Add testcase for successful build when QA check is skipped.
>>
>> Changes from v1:
>> - `getVarFag` -> `getVarFlag`
>>
>> ---
>>   meta/classes/rootfs-postcommands.bbclass  | 10 ++++++++--
>>   meta/lib/oeqa/selftest/cases/overlayfs.py | 20 +++++++++++++++++++-
>>   2 files changed, 27 insertions(+), 3 deletions(-)
>>
>> diff --git a/meta/classes/rootfs-postcommands.bbclass 
>> b/meta/classes/rootfs-postcommands.bbclass
>> index 7b92df69c5..9b6824043c 100644
>> --- a/meta/classes/rootfs-postcommands.bbclass
>> +++ b/meta/classes/rootfs-postcommands.bbclass
>> @@ -398,6 +398,10 @@ python overlayfs_qa_check() {
>>       allUnitExist = True;
>>       for mountPoint in overlayMountPoints:
>> +        qaSkip = (d.getVarFlag("OVERLAYFS_QA_SKIP", mountPoint) or 
>> "").split()
>> +        if "mount-configured" in qaSkip:
>> +            continue
>> +
>>           mountPath = d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint)
>>           if mountPath in fstabDevices:
>>               continue
>> @@ -407,8 +411,10 @@ python overlayfs_qa_check() {
>>                  for dirpath in searchpaths):
>>               continue
>> -        bb.warn('Mount path %s not found in fstat and unit %s not 
>> found '
>> -                'in systemd unit directories' % (mountPath, mountUnit))
>> +        bb.warn(f'Mount path {mountPath} not found in fstab and unit '
>> +                f'{mountUnit} not found in systemd unit directories.')
>> +        bb.warn(f'Skip this check by setting 
>> OVERLAYFS_QA_SKIP[{mountPoint}] = '
>> +                '"mount-configured"')
>>           allUnitExist = False;
>>       if not allUnitExist:
>> diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py 
>> b/meta/lib/oeqa/selftest/cases/overlayfs.py
>> index 472746a64f..ce1d2f1ec3 100644
>> --- a/meta/lib/oeqa/selftest/cases/overlayfs.py
>> +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
>> @@ -62,11 +62,29 @@ DISTRO_FEATURES += "systemd overlayfs"
>>           self.add_overlay_conf_to_machine()
>>           res = bitbake('core-image-minimal', ignore_status=True)
>> -        line = getline(res, " Mount path /mnt/overlay not found in 
>> fstat and unit mnt-overlay.mount not found in systemd unit directories")
>> +        line = getline(res, " Mount path /mnt/overlay not found in 
>> fstab and unit mnt-overlay.mount not found in systemd unit directories")
>>           self.assertTrue(line and line.startswith("WARNING:"), 
>> msg=res.output)
>>           line = getline(res, "Not all mount paths and units are 
>> installed in the image")
>>           self.assertTrue(line and line.startswith("ERROR:"), 
>> msg=res.output)
>> +    def test_not_all_units_installed_but_qa_skipped(self):
>> +        """
>> +        Summary:   Test skipping the QA check
>> +        Expected:  Image is created successfully
>> +        Author:    Claudius Heine <ch@denx.de>
>> +        """
>> +
>> +        config = """
>> +IMAGE_INSTALL:append = " overlayfs-user"
>> +DISTRO_FEATURES += "systemd overlayfs"
>> +OVERLAYFS_QA_SKIP[mnt-overlay] = "mount-configured"
>> +"""
>> +
>> +        self.write_config(config)
>> +        self.add_overlay_conf_to_machine()
>> +
>> +        bitbake('core-image-minimal')
>> +
>>       def test_mount_unit_not_set(self):
>>           """
>>           Summary:   Test whether mount unit was set properly
> Hi Claudius,
> Thanks a lot for the patch
> 
> Could you please also extend the header of overlayfs.bbclass to describe 
> the use case? I will update the documentation accordingly after that.

Hi Vyacheslav,

sure. I will try to work that in.

regards,
Claudius

Patch

diff --git a/meta/classes/rootfs-postcommands.bbclass b/meta/classes/rootfs-postcommands.bbclass
index 7b92df69c5..9b6824043c 100644
--- a/meta/classes/rootfs-postcommands.bbclass
+++ b/meta/classes/rootfs-postcommands.bbclass
@@ -398,6 +398,10 @@  python overlayfs_qa_check() {
 
     allUnitExist = True;
     for mountPoint in overlayMountPoints:
+        qaSkip = (d.getVarFlag("OVERLAYFS_QA_SKIP", mountPoint) or "").split()
+        if "mount-configured" in qaSkip:
+            continue
+
         mountPath = d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint)
         if mountPath in fstabDevices:
             continue
@@ -407,8 +411,10 @@  python overlayfs_qa_check() {
                for dirpath in searchpaths):
             continue
 
-        bb.warn('Mount path %s not found in fstat and unit %s not found '
-                'in systemd unit directories' % (mountPath, mountUnit))
+        bb.warn(f'Mount path {mountPath} not found in fstab and unit '
+                f'{mountUnit} not found in systemd unit directories.')
+        bb.warn(f'Skip this check by setting OVERLAYFS_QA_SKIP[{mountPoint}] = '
+                '"mount-configured"')
         allUnitExist = False;
 
     if not allUnitExist:
diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
index 472746a64f..ce1d2f1ec3 100644
--- a/meta/lib/oeqa/selftest/cases/overlayfs.py
+++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
@@ -62,11 +62,29 @@  DISTRO_FEATURES += "systemd overlayfs"
         self.add_overlay_conf_to_machine()
 
         res = bitbake('core-image-minimal', ignore_status=True)
-        line = getline(res, " Mount path /mnt/overlay not found in fstat and unit mnt-overlay.mount not found in systemd unit directories")
+        line = getline(res, " Mount path /mnt/overlay not found in fstab and unit mnt-overlay.mount not found in systemd unit directories")
         self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
         line = getline(res, "Not all mount paths and units are installed in the image")
         self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
 
+    def test_not_all_units_installed_but_qa_skipped(self):
+        """
+        Summary:   Test skipping the QA check
+        Expected:  Image is created successfully
+        Author:    Claudius Heine <ch@denx.de>
+        """
+
+        config = """
+IMAGE_INSTALL:append = " overlayfs-user"
+DISTRO_FEATURES += "systemd overlayfs"
+OVERLAYFS_QA_SKIP[mnt-overlay] = "mount-configured"
+"""
+
+        self.write_config(config)
+        self.add_overlay_conf_to_machine()
+
+        bitbake('core-image-minimal')
+
     def test_mount_unit_not_set(self):
         """
         Summary:   Test whether mount unit was set properly