blob: 99a5cc9e5751279492c8f8e66ac3237d7b9570a8 [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 = ""
42""")
43
44 bbvars = get_bb_vars(['bindir', 'sysconfdir', 'localstatedir',
45 'DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'],
46 target='container-test-image')
47 expected_files = [
48 './',
49 '.{bindir}/theapp',
50 '.{sysconfdir}/default/',
51 '.{sysconfdir}/default/postinst',
52 '.{sysconfdir}/ld.so.cache',
53 '.{sysconfdir}/timestamp',
54 '.{sysconfdir}/version',
55 './run/',
56 '.{localstatedir}/cache/',
57 '.{localstatedir}/cache/ldconfig/',
58 '.{localstatedir}/cache/ldconfig/aux-cache',
59 '.{localstatedir}/cache/opkg/',
60 '.{localstatedir}/lib/',
61 '.{localstatedir}/lib/opkg/'
62 ]
63
64 expected_files = [ x.format(bindir=bbvars['bindir'],
65 sysconfdir=bbvars['sysconfdir'],
66 localstatedir=bbvars['localstatedir'])
67 for x in expected_files ]
68
69 # Since tar lists all directories individually, make sure each element
70 # from bindir, sysconfdir, etc is added
71 expected_files += get_each_path_part(bbvars['bindir'])
72 expected_files += get_each_path_part(bbvars['sysconfdir'])
73 expected_files += get_each_path_part(bbvars['localstatedir'])
74
75 expected_files = sorted(expected_files)
76
77 # Build the image of course
78 bitbake('container-test-image')
79
80 image = os.path.join(bbvars['DEPLOY_DIR_IMAGE'],
81 bbvars['IMAGE_LINK_NAME'] + '.tar.bz2')
82
83 # Ensure the files in the image are what we expect
84 result = runCmd("tar tf {} | sort".format(image), shell=True)
85 self.assertEqual(result.output.split('\n'), expected_files)