test_docker_compose.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 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. _, exit_code = self.emulator.run('docker-compose up', 120)
  40. self.assertEqual(exit_code, 0)
  41. def test_run(self):
  42. kernel = os.path.join(self.builddir, "images", "bzImage")
  43. rootfs = os.path.join(self.builddir, "images", "rootfs.ext2")
  44. self.emulator.boot(arch="x86_64",
  45. kernel=kernel,
  46. kernel_cmdline=["root=/dev/vda", "console=ttyS0"],
  47. options=["-cpu", "core2duo",
  48. "-m", "512M",
  49. "-device", "virtio-rng-pci",
  50. "-drive", "file={},format=raw,if=virtio".format(rootfs),
  51. "-net", "nic,model=virtio",
  52. "-net", "user"])
  53. self.emulator.login()
  54. self.wait_for_dockerd()
  55. self.docker_test()
  56. self.docker_compose_test()