Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame^] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
| 5 | from oeqa.selftest.case import OESelftestTestCase |
| 6 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu |
| 7 | |
| 8 | class OverlayFSTests(OESelftestTestCase): |
| 9 | """Overlayfs class usage tests""" |
| 10 | |
| 11 | def getline(self, res, line): |
| 12 | for l in res.output.split('\n'): |
| 13 | if line in l: |
| 14 | return l |
| 15 | |
| 16 | def add_overlay_conf_to_machine(self): |
| 17 | machine_inc = """ |
| 18 | OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay" |
| 19 | """ |
| 20 | self.set_machine_config(machine_inc) |
| 21 | |
| 22 | def test_distro_features_missing(self): |
| 23 | """ |
| 24 | Summary: Check that required DISTRO_FEATURES are set |
| 25 | Expected: Fail when either systemd or overlayfs are not in DISTRO_FEATURES |
| 26 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> |
| 27 | """ |
| 28 | |
| 29 | config = """ |
| 30 | IMAGE_INSTALL:append = " overlayfs-user" |
| 31 | """ |
| 32 | overlayfs_recipe_append = """ |
| 33 | inherit overlayfs |
| 34 | """ |
| 35 | self.write_config(config) |
| 36 | self.add_overlay_conf_to_machine() |
| 37 | self.write_recipeinc('overlayfs-user', overlayfs_recipe_append) |
| 38 | |
| 39 | res = bitbake('core-image-minimal', ignore_status=True) |
| 40 | line = self.getline(res, "overlayfs-user was skipped: missing required distro features") |
| 41 | self.assertTrue("overlayfs" in res.output, msg=res.output) |
| 42 | self.assertTrue("systemd" in res.output, msg=res.output) |
| 43 | self.assertTrue("ERROR: Required build target 'core-image-minimal' has no buildable providers." in res.output, msg=res.output) |
| 44 | |
| 45 | def test_not_all_units_installed(self): |
| 46 | """ |
| 47 | Summary: Test QA check that we have required mount units in the image |
| 48 | Expected: Fail because mount unit for overlay partition is not installed |
| 49 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> |
| 50 | """ |
| 51 | |
| 52 | config = """ |
| 53 | IMAGE_INSTALL:append = " overlayfs-user" |
| 54 | DISTRO_FEATURES += "systemd overlayfs" |
| 55 | """ |
| 56 | |
| 57 | self.write_config(config) |
| 58 | self.add_overlay_conf_to_machine() |
| 59 | |
| 60 | res = bitbake('core-image-minimal', ignore_status=True) |
| 61 | line = self.getline(res, "Unit name mnt-overlay.mount not found in systemd unit directories") |
| 62 | self.assertTrue(line and line.startswith("WARNING:"), msg=res.output) |
| 63 | line = self.getline(res, "Not all mount units are installed by the BSP") |
| 64 | self.assertTrue(line and line.startswith("ERROR:"), msg=res.output) |
| 65 | |
| 66 | def test_mount_unit_not_set(self): |
| 67 | """ |
| 68 | Summary: Test whether mount unit was set properly |
| 69 | Expected: Fail because mount unit was not set |
| 70 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> |
| 71 | """ |
| 72 | |
| 73 | config = """ |
| 74 | IMAGE_INSTALL:append = " overlayfs-user" |
| 75 | DISTRO_FEATURES += "systemd overlayfs" |
| 76 | """ |
| 77 | |
| 78 | self.write_config(config) |
| 79 | |
| 80 | res = bitbake('core-image-minimal', ignore_status=True) |
| 81 | line = self.getline(res, "A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration") |
| 82 | self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output) |
| 83 | |
| 84 | def test_wrong_mount_unit_set(self): |
| 85 | """ |
| 86 | Summary: Test whether mount unit was set properly |
| 87 | Expected: Fail because not the correct flag used for mount unit |
| 88 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> |
| 89 | """ |
| 90 | |
| 91 | config = """ |
| 92 | IMAGE_INSTALL:append = " overlayfs-user" |
| 93 | DISTRO_FEATURES += "systemd overlayfs" |
| 94 | """ |
| 95 | |
| 96 | wrong_machine_config = """ |
| 97 | OVERLAYFS_MOUNT_POINT[usr-share-overlay] = "/usr/share/overlay" |
| 98 | """ |
| 99 | |
| 100 | self.write_config(config) |
| 101 | self.set_machine_config(wrong_machine_config) |
| 102 | |
| 103 | res = bitbake('core-image-minimal', ignore_status=True) |
| 104 | line = self.getline(res, "Missing required mount point for OVERLAYFS_MOUNT_POINT[mnt-overlay] in your MACHINE configuration") |
| 105 | self.assertTrue(line and line.startswith("Parsing recipes...ERROR:"), msg=res.output) |
| 106 | |
| 107 | def test_correct_image(self): |
| 108 | """ |
| 109 | Summary: Check that we can create an image when all parameters are |
| 110 | set correctly |
| 111 | Expected: Image is created successfully |
| 112 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> |
| 113 | """ |
| 114 | |
| 115 | config = """ |
| 116 | IMAGE_INSTALL:append = " overlayfs-user systemd-machine-units" |
| 117 | DISTRO_FEATURES += "systemd overlayfs" |
| 118 | |
| 119 | # Use systemd as init manager |
| 120 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 121 | |
| 122 | # enable overlayfs in the kernel |
| 123 | KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc" |
| 124 | """ |
| 125 | |
| 126 | systemd_machine_unit_append = """ |
| 127 | SYSTEMD_SERVICE:${PN} += " \ |
| 128 | mnt-overlay.mount \ |
| 129 | " |
| 130 | |
| 131 | do_install:append() { |
| 132 | install -d ${D}${systemd_system_unitdir} |
| 133 | cat <<EOT > ${D}${systemd_system_unitdir}/mnt-overlay.mount |
| 134 | [Unit] |
| 135 | Description=Tmpfs directory |
| 136 | DefaultDependencies=no |
| 137 | |
| 138 | [Mount] |
| 139 | What=tmpfs |
| 140 | Where=/mnt/overlay |
| 141 | Type=tmpfs |
| 142 | Options=mode=1777,strictatime,nosuid,nodev |
| 143 | |
| 144 | [Install] |
| 145 | WantedBy=multi-user.target |
| 146 | EOT |
| 147 | } |
| 148 | |
| 149 | """ |
| 150 | |
| 151 | self.write_config(config) |
| 152 | self.add_overlay_conf_to_machine() |
| 153 | self.write_recipeinc('systemd-machine-units', systemd_machine_unit_append) |
| 154 | |
| 155 | bitbake('core-image-minimal') |
| 156 | |
| 157 | def getline_qemu(out, line): |
| 158 | for l in out.split('\n'): |
| 159 | if line in l: |
| 160 | return l |
| 161 | |
| 162 | with runqemu('core-image-minimal') as qemu: |
| 163 | # Check that we have /mnt/overlay fs mounted as tmpfs and |
| 164 | # /usr/share/my-application as an overlay (see overlayfs-user recipe) |
| 165 | status, output = qemu.run_serial("/bin/mount -t tmpfs,overlay") |
| 166 | |
| 167 | line = getline_qemu(output, "on /mnt/overlay") |
| 168 | self.assertTrue(line and line.startswith("tmpfs"), msg=output) |
| 169 | |
| 170 | line = getline_qemu(output, "upperdir=/mnt/overlay/upper/usr/share/my-application") |
| 171 | self.assertTrue(line and line.startswith("overlay"), msg=output) |