containerimage.py 3.5 KB

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