test_docker_compose.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_DOCKER_CLI=y
  21. BR2_PACKAGE_DOCKER_COMPOSE=y
  22. BR2_PACKAGE_DOCKER_ENGINE=y
  23. BR2_TARGET_ROOTFS_EXT2=y
  24. BR2_TARGET_ROOTFS_EXT2_SIZE="512M"
  25. # BR2_TARGET_ROOTFS_TAR is not set
  26. """.format(
  27. infra.filepath("tests/package/copy-sample-script-to-target.sh"),
  28. infra.filepath("conf/docker-compose.yml"),
  29. infra.filepath("conf/docker-compose-kernel.config"))
  30. def wait_for_dockerd(self):
  31. # dockerd takes a while to start up
  32. _, _ = self.emulator.run('while [ ! -e /var/run/docker.sock ]; do sleep 1; done', 120)
  33. def docker_test(self):
  34. # will download container if not available, which may take some time
  35. _, exit_code = self.emulator.run('docker run --rm -p 8888:8888 busybox:latest /bin/true', 120)
  36. self.assertEqual(exit_code, 0)
  37. def docker_compose_test(self):
  38. # will download container if not available, which may take some time
  39. self.assertRunOk('docker-compose up -d', 120)
  40. # container may take some time to start
  41. self.assertRunOk('while ! docker inspect root_busybox_1 2>&1 >/dev/null; do sleep 1; done', 120)
  42. self.assertRunOk('wget -O /tmp/busybox http://127.0.0.1/busybox', 120)
  43. self.assertRunOk('cmp /bin/busybox /tmp/busybox', 120)
  44. def test_run(self):
  45. kernel = os.path.join(self.builddir, "images", "bzImage")
  46. rootfs = os.path.join(self.builddir, "images", "rootfs.ext2")
  47. self.emulator.boot(arch="x86_64",
  48. kernel=kernel,
  49. kernel_cmdline=["root=/dev/vda", "console=ttyS0"],
  50. options=["-cpu", "core2duo",
  51. "-m", "512M",
  52. "-device", "virtio-rng-pci",
  53. "-drive", "file={},format=raw,if=virtio".format(rootfs),
  54. "-net", "nic,model=virtio",
  55. "-net", "user"])
  56. self.emulator.login()
  57. self.wait_for_dockerd()
  58. self.docker_test()
  59. self.docker_compose_test()