test_docker_compose.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import os
  2. import infra.basetest
  3. class TestDockerCompose(infra.basetest.BRTest):
  4. scripts = ["conf/docker-compose.yml",
  5. "tests/package/sample_python_docker.py"]
  6. config = \
  7. """
  8. BR2_x86_64=y
  9. BR2_x86_corei7=y
  10. BR2_TOOLCHAIN_EXTERNAL=y
  11. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_CORE_I7_GLIBC_STABLE=y
  12. BR2_SYSTEM_DHCP="eth0"
  13. BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
  14. BR2_ROOTFS_POST_SCRIPT_ARGS="{}"
  15. BR2_LINUX_KERNEL=y
  16. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  17. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.262"
  18. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  19. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="{}"
  20. BR2_PACKAGE_PYTHON3=y
  21. BR2_PACKAGE_PYTHON_DOCKER=y
  22. BR2_PACKAGE_CA_CERTIFICATES=y
  23. BR2_PACKAGE_DOCKER_CLI=y
  24. BR2_PACKAGE_DOCKER_COMPOSE=y
  25. BR2_PACKAGE_DOCKER_ENGINE=y
  26. BR2_TARGET_ROOTFS_EXT2=y
  27. BR2_TARGET_ROOTFS_EXT2_SIZE="512M"
  28. # BR2_TARGET_ROOTFS_TAR is not set
  29. """.format(
  30. infra.filepath("tests/package/copy-sample-script-to-target.sh"),
  31. " ".join([infra.filepath(i) for i in scripts]),
  32. infra.filepath("conf/docker-compose-kernel.config"))
  33. def wait_for_dockerd(self):
  34. # dockerd takes a while to start up
  35. _, _ = self.emulator.run('while [ ! -e /var/run/docker.sock ]; do sleep 1; done', 120)
  36. def docker_test(self):
  37. # will download container if not available, which may take some time
  38. self.assertRunOk('docker run --rm -p 8888:8888 busybox:latest /bin/true', 120)
  39. def docker_compose_test(self):
  40. # will download container if not available, which may take some time
  41. self.assertRunOk('docker compose up -d --quiet-pull', 120)
  42. # container may take some time to start
  43. self.assertRunOk('while ! docker inspect root-busybox-1 2>&1 >/dev/null; do sleep 1; done', 120)
  44. self.assertRunOk('wget -q -O /tmp/busybox http://127.0.0.1/busybox', 120)
  45. self.assertRunOk('cmp /bin/busybox /tmp/busybox', 120)
  46. def python_docker_test(self):
  47. self.assertRunOk('python3 ./sample_python_docker.py', 120)
  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", "Nehalem",
  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()
  64. self.python_docker_test()