containerimage.py 3.4 KB

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