test_docker_compose.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import os
  2. import infra.basetest
  3. class TestDockerCompose(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_x86_64=y
  7. BR2_x86_core2=y
  8. BR2_TOOLCHAIN_EXTERNAL=y
  9. BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
  10. BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
  11. BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-x86-64-core2-full-2018.05.tar.bz2"
  12. BR2_TOOLCHAIN_EXTERNAL_GCC_6=y
  13. BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_16=y
  14. BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
  15. # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
  16. BR2_TOOLCHAIN_EXTERNAL_CXX=y
  17. BR2_SYSTEM_DHCP="eth0"
  18. BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
  19. BR2_ROOTFS_POST_SCRIPT_ARGS="{}"
  20. BR2_LINUX_KERNEL=y
  21. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  22. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19"
  23. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  24. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="{}"
  25. BR2_PACKAGE_CA_CERTIFICATES=y
  26. BR2_PACKAGE_CGROUPFS_MOUNT=y
  27. BR2_PACKAGE_DOCKER_CLI=y
  28. BR2_PACKAGE_DOCKER_COMPOSE=y
  29. BR2_PACKAGE_DOCKER_ENGINE=y
  30. BR2_TARGET_ROOTFS_EXT2=y
  31. BR2_TARGET_ROOTFS_EXT2_SIZE="512M"
  32. # BR2_TARGET_ROOTFS_TAR is not set
  33. """.format(
  34. infra.filepath("tests/package/copy-sample-script-to-target.sh"),
  35. infra.filepath("conf/docker-compose.yml"),
  36. infra.filepath("conf/docker-compose-kernel.config"))
  37. def wait_for_dockerd(self):
  38. # dockerd takes a while to start up
  39. _, _ = self.emulator.run('while [ ! -e /var/run/docker.sock ]; do sleep 1; done', 120)
  40. def docker_test(self):
  41. # will download container if not available, which may take some time
  42. _, exit_code = self.emulator.run('docker run --rm busybox:latest /bin/true', 120)
  43. self.assertEqual(exit_code, 0)
  44. def docker_compose_test(self):
  45. # will download container if not available, which may take some time
  46. _, exit_code = self.emulator.run('docker-compose up', 120)
  47. self.assertEqual(exit_code, 0)
  48. def test_run(self):
  49. kernel = os.path.join(self.builddir, "images", "bzImage")
  50. rootfs = os.path.join(self.builddir, "images", "rootfs.ext2")
  51. self.emulator.boot(arch="x86_64",
  52. kernel=kernel,
  53. kernel_cmdline=["root=/dev/vda", "console=ttyS0"],
  54. options=["-cpu", "core2duo",
  55. "-m", "512M",
  56. "-device", "virtio-rng-pci",
  57. "-drive", "file={},format=raw,if=virtio".format(rootfs),
  58. "-net", "nic,model=virtio",
  59. "-net", "user"])
  60. self.emulator.login()
  61. self.wait_for_dockerd()
  62. self.docker_test()
  63. self.docker_compose_test()