diff options
| author | Vyacheslav Yurkov <uvv.mail@gmail.com> | 2021-12-10 14:01:43 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-12-12 11:27:24 +0000 |
| commit | 5221ca9296ca6eaeddf021e8b58e00b213431dfe (patch) | |
| tree | 5ce38686da06e09a7f9ff58d1fc9839594d533dd | |
| parent | ae56b390210678cbf95593080d9385725b8a958f (diff) | |
| download | poky-5221ca9296ca6eaeddf021e8b58e00b213431dfe.tar.gz | |
oeqa/selftest: unit tests for overlayfs-etc
(From OE-Core rev: 3ca1ce7a3779d0b875385eb4045bd5a51dc839da)
Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/overlayfs.py | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py index 43415778ce..82007fade7 100644 --- a/meta/lib/oeqa/selftest/cases/overlayfs.py +++ b/meta/lib/oeqa/selftest/cases/overlayfs.py | |||
| @@ -209,3 +209,187 @@ EOT | |||
| 209 | 209 | ||
| 210 | line = getline_qemu(output, "upperdir=/mnt/overlay/upper/usr/share/another-overlay-mount") | 210 | line = getline_qemu(output, "upperdir=/mnt/overlay/upper/usr/share/another-overlay-mount") |
| 211 | self.assertTrue(line and line.startswith("overlay"), msg=output) | 211 | self.assertTrue(line and line.startswith("overlay"), msg=output) |
| 212 | |||
| 213 | class OverlayFSEtcRunTimeTests(OESelftestTestCase): | ||
| 214 | """overlayfs-etc class tests""" | ||
| 215 | |||
| 216 | def test_all_required_variables_set(self): | ||
| 217 | """ | ||
| 218 | Summary: Check that required variables are set | ||
| 219 | Expected: Fail when any of required variables is missing | ||
| 220 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> | ||
| 221 | """ | ||
| 222 | |||
| 223 | configBase = """ | ||
| 224 | DISTRO_FEATURES += "systemd" | ||
| 225 | |||
| 226 | # Use systemd as init manager | ||
| 227 | VIRTUAL-RUNTIME_init_manager = "systemd" | ||
| 228 | |||
| 229 | # enable overlayfs in the kernel | ||
| 230 | KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc" | ||
| 231 | |||
| 232 | # Image configuration for overlayfs-etc | ||
| 233 | EXTRA_IMAGE_FEATURES += "overlayfs-etc" | ||
| 234 | IMAGE_FEATURES:remove = "package-management" | ||
| 235 | """ | ||
| 236 | configMountPoint = """ | ||
| 237 | OVERLAYFS_ETC_MOUNT_POINT = "/data" | ||
| 238 | """ | ||
| 239 | configDevice = """ | ||
| 240 | OVERLAYFS_ETC_DEVICE = "/dev/mmcblk0p1" | ||
| 241 | """ | ||
| 242 | |||
| 243 | self.write_config(configBase) | ||
| 244 | res = bitbake('core-image-minimal', ignore_status=True) | ||
| 245 | line = getline(res, "OVERLAYFS_ETC_MOUNT_POINT must be set in your MACHINE configuration") | ||
| 246 | self.assertTrue(line, msg=res.output) | ||
| 247 | |||
| 248 | self.append_config(configMountPoint) | ||
| 249 | res = bitbake('core-image-minimal', ignore_status=True) | ||
| 250 | line = getline(res, "OVERLAYFS_ETC_DEVICE must be set in your MACHINE configuration") | ||
| 251 | self.assertTrue(line, msg=res.output) | ||
| 252 | |||
| 253 | self.append_config(configDevice) | ||
| 254 | res = bitbake('core-image-minimal', ignore_status=True) | ||
| 255 | line = getline(res, "OVERLAYFS_ETC_FSTYPE should contain a valid file system type on /dev/mmcblk0p1") | ||
| 256 | self.assertTrue(line, msg=res.output) | ||
| 257 | |||
| 258 | def test_image_feature_conflict(self): | ||
| 259 | """ | ||
| 260 | Summary: Overlayfs-etc is not allowed to be used with package-management | ||
| 261 | Expected: Feature conflict | ||
| 262 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> | ||
| 263 | """ | ||
| 264 | |||
| 265 | config = """ | ||
| 266 | DISTRO_FEATURES += "systemd" | ||
| 267 | |||
| 268 | # Use systemd as init manager | ||
| 269 | VIRTUAL-RUNTIME_init_manager = "systemd" | ||
| 270 | |||
| 271 | # enable overlayfs in the kernel | ||
| 272 | KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc" | ||
| 273 | EXTRA_IMAGE_FEATURES += "overlayfs-etc" | ||
| 274 | EXTRA_IMAGE_FEATURES += "package-management" | ||
| 275 | """ | ||
| 276 | |||
| 277 | self.write_config(config) | ||
| 278 | |||
| 279 | res = bitbake('core-image-minimal', ignore_status=True) | ||
| 280 | line = getline(res, "contains conflicting IMAGE_FEATURES") | ||
| 281 | self.assertTrue("overlayfs-etc" in res.output, msg=res.output) | ||
| 282 | self.assertTrue("package-management" in res.output, msg=res.output) | ||
| 283 | |||
| 284 | def test_image_feature_is_missing_class_included(self): | ||
| 285 | configAppend = """ | ||
| 286 | INHERIT += "overlayfs-etc" | ||
| 287 | """ | ||
| 288 | self.run_check_image_feature(configAppend) | ||
| 289 | |||
| 290 | def test_image_feature_is_missing(self): | ||
| 291 | self.run_check_image_feature() | ||
| 292 | |||
| 293 | def run_check_image_feature(self, appendToConfig=""): | ||
| 294 | """ | ||
| 295 | Summary: Overlayfs-etc class is not applied when image feature is not set | ||
| 296 | even if we inherit it directly, | ||
| 297 | Expected: Image is created successfully but /etc is not an overlay | ||
| 298 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> | ||
| 299 | """ | ||
| 300 | |||
| 301 | config = f""" | ||
| 302 | DISTRO_FEATURES += "systemd" | ||
| 303 | |||
| 304 | # Use systemd as init manager | ||
| 305 | VIRTUAL-RUNTIME_init_manager = "systemd" | ||
| 306 | |||
| 307 | # enable overlayfs in the kernel | ||
| 308 | KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc" | ||
| 309 | |||
| 310 | IMAGE_FSTYPES += "wic" | ||
| 311 | WKS_FILE = "overlayfs_etc.wks.in" | ||
| 312 | |||
| 313 | EXTRA_IMAGE_FEATURES += "read-only-rootfs" | ||
| 314 | # Image configuration for overlayfs-etc | ||
| 315 | OVERLAYFS_ETC_MOUNT_POINT = "/data" | ||
| 316 | OVERLAYFS_ETC_DEVICE = "/dev/sda3" | ||
| 317 | {appendToConfig} | ||
| 318 | """ | ||
| 319 | |||
| 320 | self.write_config(config) | ||
| 321 | |||
| 322 | bitbake('core-image-minimal') | ||
| 323 | |||
| 324 | with runqemu('core-image-minimal', image_fstype='wic') as qemu: | ||
| 325 | status, output = qemu.run_serial("/bin/mount") | ||
| 326 | |||
| 327 | line = getline_qemu(output, "upperdir=/data/overlay-etc/upper") | ||
| 328 | self.assertFalse(line, msg=output) | ||
| 329 | |||
| 330 | def test_sbin_init_preinit(self): | ||
| 331 | self.run_sbin_init(False) | ||
| 332 | |||
| 333 | def test_sbin_init_original(self): | ||
| 334 | self.run_sbin_init(True) | ||
| 335 | |||
| 336 | def run_sbin_init(self, origInit): | ||
| 337 | """ | ||
| 338 | Summary: Confirm we can replace original init and mount overlay on top of /etc | ||
| 339 | Expected: Image is created successfully and /etc is mounted as an overlay | ||
| 340 | Author: Vyacheslav Yurkov <uvv.mail@gmail.com> | ||
| 341 | """ | ||
| 342 | |||
| 343 | config = """ | ||
| 344 | DISTRO_FEATURES += "systemd" | ||
| 345 | |||
| 346 | # Use systemd as init manager | ||
| 347 | VIRTUAL-RUNTIME_init_manager = "systemd" | ||
| 348 | |||
| 349 | # enable overlayfs in the kernel | ||
| 350 | KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc" | ||
| 351 | |||
| 352 | IMAGE_FSTYPES += "wic" | ||
| 353 | OVERLAYFS_INIT_OPTION = "{OVERLAYFS_INIT_OPTION}" | ||
| 354 | WKS_FILE = "overlayfs_etc.wks.in" | ||
| 355 | |||
| 356 | EXTRA_IMAGE_FEATURES += "read-only-rootfs" | ||
| 357 | # Image configuration for overlayfs-etc | ||
| 358 | EXTRA_IMAGE_FEATURES += "overlayfs-etc" | ||
| 359 | IMAGE_FEATURES:remove = "package-management" | ||
| 360 | OVERLAYFS_ETC_MOUNT_POINT = "/data" | ||
| 361 | OVERLAYFS_ETC_FSTYPE = "ext4" | ||
| 362 | OVERLAYFS_ETC_DEVICE = "/dev/sda3" | ||
| 363 | OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "{OVERLAYFS_ETC_USE_ORIG_INIT_NAME}" | ||
| 364 | """ | ||
| 365 | |||
| 366 | args = { | ||
| 367 | 'OVERLAYFS_INIT_OPTION': "" if origInit else "init=/sbin/preinit", | ||
| 368 | 'OVERLAYFS_ETC_USE_ORIG_INIT_NAME': int(origInit == True) | ||
| 369 | } | ||
| 370 | |||
| 371 | self.write_config(config.format(**args)) | ||
| 372 | |||
| 373 | bitbake('core-image-minimal') | ||
| 374 | testFile = "/etc/my-test-data" | ||
| 375 | |||
| 376 | with runqemu('core-image-minimal', image_fstype='wic', discard_writes=False) as qemu: | ||
| 377 | status, output = qemu.run_serial("/bin/mount") | ||
| 378 | |||
| 379 | line = getline_qemu(output, "/dev/sda3") | ||
| 380 | self.assertTrue("/data" in output, msg=output) | ||
| 381 | |||
| 382 | line = getline_qemu(output, "upperdir=/data/overlay-etc/upper") | ||
| 383 | self.assertTrue(line and line.startswith("/data/overlay-etc/upper on /etc type overlay"), msg=output) | ||
| 384 | |||
| 385 | status, output = qemu.run_serial("touch " + testFile) | ||
| 386 | status, output = qemu.run_serial("sync") | ||
| 387 | status, output = qemu.run_serial("ls -1 " + testFile) | ||
| 388 | line = getline_qemu(output, testFile) | ||
| 389 | self.assertTrue(line and line.startswith(testFile), msg=output) | ||
| 390 | |||
| 391 | # Check that file exists in /etc after reboot | ||
| 392 | with runqemu('core-image-minimal', image_fstype='wic') as qemu: | ||
| 393 | status, output = qemu.run_serial("ls -1 " + testFile) | ||
| 394 | line = getline_qemu(output, testFile) | ||
| 395 | self.assertTrue(line and line.startswith(testFile), msg=output) | ||
