blob: 23c0a1408a3fb67a4444cb1cf987bae299af4854 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007import os
8
9from oeqa.selftest.case import OESelftestTestCase
10from oeqa.utils.commands import bitbake, get_bb_vars, runCmd
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011
12# This test builds an image with using the "container" IMAGE_FSTYPE, and
13# ensures that then files in the image are only the ones expected.
14#
15# The only package added to the image is container_image_testpkg, which
16# contains one file. However, due to some other things not cleaning up during
17# rootfs creation, there is some cruft. Ideally bugs will be filed and the
Andrew Geissler9aee5002022-03-30 16:27:02 +000018# cruft removed, but for now we ignore some known set.
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019#
20# Also for performance reasons we're only checking the cruft when using ipk.
21# When using deb, and rpm it is a bit different and we could test all
22# of them, but this test is more to catch if other packages get added by
23# default other than what is in ROOTFS_BOOTSTRAP_INSTALL.
24#
25class ContainerImageTests(OESelftestTestCase):
26
Patrick Williams213cb262021-08-07 19:21:33 -050027 # Verify that when specifying a IMAGE_TYPEDEP: of the form "foo.bar" that
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028 # the conversion type bar gets added as a dep as well
Brad Bishopd7bf8c12018-02-25 22:55:05 -050029 def test_expected_files(self):
30
31 def get_each_path_part(path):
32 if path:
33 part = [ '.' + path + '/' ]
34 result = get_each_path_part(path.rsplit('/', 1)[0])
35 if result:
36 return part + result
37 else:
38 return part
39 else:
40 return None
41
42 self.write_config("""PREFERRED_PROVIDER_virtual/kernel = "linux-dummy"
43IMAGE_FSTYPES = "container"
44PACKAGE_CLASSES = "package_ipk"
45IMAGE_FEATURES = ""
Brad Bishopf86d0552018-12-04 14:18:15 -080046IMAGE_BUILDINFO_FILE = ""
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050047INIT_MANAGER = "sysvinit"
Patrick Williams213cb262021-08-07 19:21:33 -050048IMAGE_INSTALL:remove = "ssh-pregen-hostkeys"
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050049
Brad Bishopd7bf8c12018-02-25 22:55:05 -050050""")
51
52 bbvars = get_bb_vars(['bindir', 'sysconfdir', 'localstatedir',
53 'DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'],
54 target='container-test-image')
55 expected_files = [
56 './',
57 '.{bindir}/theapp',
58 '.{sysconfdir}/default/',
59 '.{sysconfdir}/default/postinst',
60 '.{sysconfdir}/ld.so.cache',
61 '.{sysconfdir}/timestamp',
62 '.{sysconfdir}/version',
63 './run/',
64 '.{localstatedir}/cache/',
Andrew Geissler09209ee2020-12-13 08:44:15 -060065 '.{localstatedir}/lib/'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050066 ]
67
68 expected_files = [ x.format(bindir=bbvars['bindir'],
69 sysconfdir=bbvars['sysconfdir'],
70 localstatedir=bbvars['localstatedir'])
71 for x in expected_files ]
72
73 # Since tar lists all directories individually, make sure each element
74 # from bindir, sysconfdir, etc is added
75 expected_files += get_each_path_part(bbvars['bindir'])
76 expected_files += get_each_path_part(bbvars['sysconfdir'])
77 expected_files += get_each_path_part(bbvars['localstatedir'])
78
79 expected_files = sorted(expected_files)
80
81 # Build the image of course
82 bitbake('container-test-image')
83
84 image = os.path.join(bbvars['DEPLOY_DIR_IMAGE'],
85 bbvars['IMAGE_LINK_NAME'] + '.tar.bz2')
86
87 # Ensure the files in the image are what we expect
88 result = runCmd("tar tf {} | sort".format(image), shell=True)
89 self.assertEqual(result.output.split('\n'), expected_files)