diff --git a/pytest/tests/sanity/docker.py b/pytest/tests/sanity/docker.py index a1513b2e353..87672e61bed 100644 --- a/pytest/tests/sanity/docker.py +++ b/pytest/tests/sanity/docker.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """Verifies that node can be started inside of a Docker image. -The script builds Docker image using ‘make docker-nearcore’ command and then +The script builds Docker image using 'make docker-nearcore' command and then starts a cluster with all nodes running inside of containers. As sanity check to see if the cluster works correctly, the test waits for a several blocks and then interrogates each node about block with specified hash expecting all of @@ -48,7 +48,7 @@ def run(cmd: _Command, *, capture_output: bool = False) -> typing.Optional[str]: capture_output: If true, captures standard output of the command and returns it. Returns: - Command’s stripped standard output if `capture_output` is true, None + Command's stripped standard output if `capture_output` is true, None otherwise. """ global _CD_PRINTED @@ -73,7 +73,7 @@ def docker_run(shell_cmd: typing.Optional[str] = None, Args: shell_cmd: Optionally a shell command to execute inside of the - container. It’s going to be run using `sh -c` and it’s caller’s + container. It's going to be run using `sh -c` and it's caller's responsibility to make sure all data inside is properly sanitised. If not given, command configured via CMD when building the container will be executed as typical for Docker images. @@ -82,16 +82,22 @@ def docker_run(shell_cmd: typing.Optional[str] = None, test outputs. If True, the container will be detached and the function will return its container id. network: Whether to enable network. If True, the container will be - configured to use host’s network. This allows processes in + configured to use host's network. This allows processes in different containers to connect with each other easily. volume: A (path, container_path) tuple denoting that local `path` should be mounted under `container_path` inside of the container. env: *Additional* environment variables set inside of the container. Returns: - Command’s stripped standard output if `detach` is true, None otherwise. + Command's stripped standard output if `detach` is true, None otherwise. """ - cmd = ['docker', 'run', '--read-only', f'-v{volume[0]}:{volume[1]}'] + + # When --network=none, ipv6 is disabled by default in docker images. + # Required as neard localnet is binding on V6 address instead of V4 + cmd = [ + 'docker', 'run', '--read-only', f'-v{volume[0]}:{volume[1]}', + '--sysctl', 'net.ipv6.conf.all.disable_ipv6=0' + ] # Either run detached or attach standard output and standard error so they # are visible. @@ -187,12 +193,12 @@ def output_logs(self): def main(): nodes = [] - # Build the container + logger.info("Build the container") run(('make', 'DOCKER_TAG=' + _DOCKER_IMAGE_TAG, 'docker-nearcore')) try: dot_near = pathlib.Path.home() / '.near' - # Initialise local network + logger.info("Initialise local network nodes config.") cmd = f'neard --home /home/near localnet --v {NUM_NODES} --prefix test' docker_run(cmd, volume=(dot_near, '/home/near'))