test_docker_compose.py 2.5 KB

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