1# 2# SPDX-License-Identifier: MIT 3# 4 5import os 6 7from oeqa.selftest.case import OESelftestTestCase 8from oeqa.utils.commands import bitbake, get_bb_vars, runCmd 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# 23class ContainerImageTests(OESelftestTestCase): 24 25 # Verify that when specifying a IMAGE_TYPEDEP: of the form "foo.bar" that 26 # the conversion type bar gets added as a dep as well 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" 41IMAGE_FSTYPES = "container" 42PACKAGE_CLASSES = "package_ipk" 43IMAGE_FEATURES = "" 44IMAGE_BUILDINFO_FILE = "" 45INIT_MANAGER = "sysvinit" 46IMAGE_INSTALL:remove = "ssh-pregen-hostkeys" 47 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/', 63 '.{localstatedir}/lib/' 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) 88