summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/selftest/cases/overlayfs.py184
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
213class 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 = """
224DISTRO_FEATURES += "systemd"
225
226# Use systemd as init manager
227VIRTUAL-RUNTIME_init_manager = "systemd"
228
229# enable overlayfs in the kernel
230KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc"
231
232# Image configuration for overlayfs-etc
233EXTRA_IMAGE_FEATURES += "overlayfs-etc"
234IMAGE_FEATURES:remove = "package-management"
235"""
236 configMountPoint = """
237OVERLAYFS_ETC_MOUNT_POINT = "/data"
238"""
239 configDevice = """
240OVERLAYFS_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 = """
266DISTRO_FEATURES += "systemd"
267
268# Use systemd as init manager
269VIRTUAL-RUNTIME_init_manager = "systemd"
270
271# enable overlayfs in the kernel
272KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc"
273EXTRA_IMAGE_FEATURES += "overlayfs-etc"
274EXTRA_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 = """
286INHERIT += "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"""
302DISTRO_FEATURES += "systemd"
303
304# Use systemd as init manager
305VIRTUAL-RUNTIME_init_manager = "systemd"
306
307# enable overlayfs in the kernel
308KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc"
309
310IMAGE_FSTYPES += "wic"
311WKS_FILE = "overlayfs_etc.wks.in"
312
313EXTRA_IMAGE_FEATURES += "read-only-rootfs"
314# Image configuration for overlayfs-etc
315OVERLAYFS_ETC_MOUNT_POINT = "/data"
316OVERLAYFS_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 = """
344DISTRO_FEATURES += "systemd"
345
346# Use systemd as init manager
347VIRTUAL-RUNTIME_init_manager = "systemd"
348
349# enable overlayfs in the kernel
350KERNEL_EXTRA_FEATURES:append = " features/overlayfs/overlayfs.scc"
351
352IMAGE_FSTYPES += "wic"
353OVERLAYFS_INIT_OPTION = "{OVERLAYFS_INIT_OPTION}"
354WKS_FILE = "overlayfs_etc.wks.in"
355
356EXTRA_IMAGE_FEATURES += "read-only-rootfs"
357# Image configuration for overlayfs-etc
358EXTRA_IMAGE_FEATURES += "overlayfs-etc"
359IMAGE_FEATURES:remove = "package-management"
360OVERLAYFS_ETC_MOUNT_POINT = "/data"
361OVERLAYFS_ETC_FSTYPE = "ext4"
362OVERLAYFS_ETC_DEVICE = "/dev/sda3"
363OVERLAYFS_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)