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