test_docker_compose.py 2.7 KB

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