containerimage.py 3.4 KB

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