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