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