start of fixing race condition by not having test+s6 both run /start.sh

Signed-off-by: Adam Hill <adam@diginc.us>
This commit is contained in:
Adam Hill 2018-08-05 17:58:41 -05:00
parent cb0fffa26f
commit 999f02b598
No known key found for this signature in database
GPG Key ID: 2193804FCA429855
2 changed files with 11 additions and 13 deletions

View File

@ -5,11 +5,11 @@ check_output = testinfra.get_backend(
"local://"
).get_module("Command").check_output
def DockerGeneric(request, args, image, cmd):
def DockerGeneric(request, args, image, cmd, entrypoint=''):
assert 'docker' in check_output('id'), "Are you in the docker group?"
if 'pihole' in image:
args += " --dns 127.0.0.1 -v /dev/null:/etc/pihole/adlists.default -e PYTEST=\"True\""
docker_run = "docker run -d {} {} {}".format(args, image, cmd)
docker_run = "docker run -d {args} {entry} {image} {cmd}".format(args, image, cmd)
print docker_run
docker_id = check_output(docker_run)
@ -37,10 +37,11 @@ def DockerGeneric(request, args, image, cmd):
docker_container.run = funcType(run_bash, docker_container, testinfra.backend.docker.DockerBackend)
return docker_container
@pytest.fixture
def Docker(request, args, image, cmd):
def Docker(request, args, image, cmd, entrypoint):
''' One-off Docker container run '''
return DockerGeneric(request, args, image, cmd)
return DockerGeneric(request, args, image, cmd, entrypoint)
@pytest.fixture(scope='module')
def DockerPersist(request, persist_args, persist_image, persist_cmd, Dig):
@ -51,6 +52,10 @@ def DockerPersist(request, persist_args, persist_image, persist_cmd, Dig):
persistent_container.dig = Dig(persistent_container.id)
return persistent_container
@pytest.fixture
def entrypoint():
return ''
@pytest.fixture()
def args(request):
return '-e ServerIP="127.0.0.1" -e ServerIPv6="::1"'

View File

@ -4,15 +4,7 @@ import time
''' Note, testinfra builtins don't seem fully compatible with
docker containers (esp. musl based OSs) stripped down nature '''
def test_pihole_default_run_command(Docker, tag):
expected_proc = '/sbin/tini -- /start.sh'
pgrep = 'pgrep -f "{}" | wc -l || echo 0'.format(expected_proc)
find_proc = Docker.run(pgrep).stdout
if int(find_proc) < 1:
print Docker.run('ps -ef')
print "{} : {}".format(pgrep, find_proc)
assert False, '{}: Couldn\'t find proc {}'.format(tag, expected_proc)
@pytest.mark.parametrize('entrypoint', ['--entrypoint=/bin/bash'])
@pytest.mark.parametrize('args', [ '' ])
def test_ServerIP_missing_triggers_start_error(Docker):
''' When args to docker are empty start.sh exits saying ServerIP is required '''
@ -21,6 +13,7 @@ def test_ServerIP_missing_triggers_start_error(Docker):
assert start.rc == 1
assert error_msg in start.stdout
@pytest.mark.parametrize('entrypoint', ['--entrypoint=/bin/bash'])
@pytest.mark.parametrize('args,error_msg,expect_rc', [
('-e ServerIP="1.2.3.z"', "ServerIP Environment variable (1.2.3.z) doesn't appear to be a valid IPv4 address",1),
('-e ServerIP="1.2.3.4" -e ServerIPv6="1234:1234:1234:ZZZZ"', "Environment variable (1234:1234:1234:ZZZZ) doesn't appear to be a valid IPv6 address",1),