Adding test and check for resolv.conf

Signed-off-by: Adam Hill <adam@diginc.us>
This commit is contained in:
Adam Hill 2019-01-10 00:28:33 -06:00
parent 19fee6fa5e
commit f3cf5dc858
No known key found for this signature in database
GPG Key ID: 2193804FCA429855
4 changed files with 42 additions and 4 deletions

5
CHANGELOG.md Normal file
View File

@ -0,0 +1,5 @@
# Docker Pi-Hole changelog
Notes about releases will be documented on [docker-pi-hole's github releases page](https://github.com/pi-hole/docker-pi-hole/releases). Breaking changes will be copied to the top of the docker repo's README file to assist with common upgrade issues.
See the [Pi-hole releases](https://github.com/pi-hole/pi-hole/releases) for details on updates unreleated to docker image releases

View File

@ -12,7 +12,7 @@ Starting with the v4.1.1 release your Pi-hole container may encounter issues sta
- `--cap-add=NET_ADMIN` This previously optional argument is now required or strongly encouraged
- Starting in version 4.1.2 FTL, the DNS Service, is going to check this setting automatically
- `--dns=127.0.0.1 --dns=1.1.1.1` The second server can be any DNS IP of your choosing, but the **first dns must be 127.0.0.1**
- A WARNING stating "resolv.conf misconfiguration, see v4.1.1 release notes" may show in docker logs without this.
- A WARNING stating "Misconfigured DNS in /etc/resolv.conf" may show in docker logs without this.
These are the raw [docker run cli](https://docs.docker.com/engine/reference/commandline/cli/) versions of the commands. We provide no official support for docker GUIs but the community forums may be able to help if you do not see a place for these settings. Remember, always consult your manual too!

View File

@ -1,7 +1,28 @@
#!/bin/bash
docker_checks() {
echo hi
warn_msg='WARNING Misconfigured DNS in /etc/resolv.conf'
ns_count="$(grep -c nameserver /etc/resolv.conf)"
ns_primary="$(grep nameserver /etc/resolv.conf | head -1)"
ns_primary="${ns_primary/nameserver /}"
warned=false
if [ "$ns_count" -lt 2 ] ; then
echo "$warn_msg: Two DNS servers are recommended, 127.0.0.1 and any backup server"
warned=true
fi
if [ "$ns_primary" != "127.0.0.1" ] ; then
echo "$warn_msg: Primary DNS should be 127.0.0.1 (found ${ns_primary})"
warned=true
fi
if ! $warned ; then
echo "OK: Checks passed for /etc/resolv.conf DNS servers"
fi
echo
cat /etc/resolv.conf
}
prepare_configs() {

View File

@ -179,5 +179,17 @@ def test_webPassword_env_assigns_password_to_file_or_removes_if_empty(Docker, ar
def test_docker_checks_for_resolvconf_misconfiguration(Docker):
pass
@pytest.mark.parametrize('args_dns, expected_stdout', [
# No DNS passed will vary by the host this is ran on, bad idea for a test
#('', 'WARNING Misconfigured DNS in /etc/resolv.conf: Primary DNS should be 127.0.0.1'),
('--dns 1.1.1.1', 'WARNING Misconfigured DNS in /etc/resolv.conf: Two DNS servers are recommended, 127.0.0.1 and any backup server\n'
'WARNING Misconfigured DNS in /etc/resolv.conf: Primary DNS should be 127.0.0.1 (found 1.1.1.1)'),
('--dns 127.0.0.1', 'WARNING Misconfigured DNS in /etc/resolv.conf: Two DNS servers are recommended, 127.0.0.1 and any backup server'),
('--dns 1.1.1.1 --dns 127.0.0.1', 'WARNING Misconfigured DNS in /etc/resolv.conf: Primary DNS should be 127.0.0.1 (found 1.1.1.1)'),
('--dns 127.0.0.1 --dns 1.1.1.1', 'OK: Checks passed for /etc/resolv.conf DNS servers'),
])
def test_docker_checks_for_resolvconf_misconfiguration(Docker, args_dns, expected_stdout):
''' The container checks for misconfigured resolv.conf '''
function = Docker.run('. /bash_functions.sh ; eval `grep docker_checks /start.sh`')
print function.stdout
assert expected_stdout in function.stdout