Module: check_mk
Branch: master
Commit: 145ff86ee4df50ffd09fac0476b403e8d39725fd
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=145ff86ee4df50…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 2 13:55:07 2019 +0200
Fix some IP resolve related unit tests
Change-Id: I86599b213f84edbc0303c9e8d5d1652f7684d7be
---
tests/unit/cmk_base/test_core_config.py | 3 ++-
tests/unit/conftest.py | 19 ++++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/tests/unit/cmk_base/test_core_config.py b/tests/unit/cmk_base/test_core_config.py
index f51e76c..5d9a0af 100644
--- a/tests/unit/cmk_base/test_core_config.py
+++ b/tests/unit/cmk_base/test_core_config.py
@@ -1,5 +1,6 @@
# encoding: utf-8
import pytest # type: ignore
+import socket
from testlib.base import Scenario
from cmk.utils.exceptions import MKGeneralException
@@ -19,7 +20,7 @@ def test_active_check_arguments(mocker):
assert prepare_check_command.called_once()
-def test_get_host_attributes(monkeypatch):
+def test_get_host_attributes(fixup_ip_lookup, monkeypatch):
ts = Scenario().add_host("test-host", ["abc"])
ts.set_option("host_tags", {
"test-host": {
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
index 02c0ef1..e1e4fc8 100644
--- a/tests/unit/conftest.py
+++ b/tests/unit/conftest.py
@@ -1,4 +1,5 @@
-import pytest
+import socket
+import pytest # type: ignore
# Unit tests should not be executed in site.
@@ -6,3 +7,19 @@ import pytest
@pytest.fixture(scope="session")
def site(request):
pass
+
+
+# TODO: This fixes our unit tests when executing the tests while the local
+# resolver uses a search domain which uses wildcard resolution. e.g. in a
+# network where mathias-kettner.de is in the domain search list and
+# [anything].mathias-kettner.de resolves to an IP address.
+# Clean this up once we don't have this situation anymore e.g. via VPN.
+(a)pytest.fixture()
+def fixup_ip_lookup(monkeypatch):
+ # Fix IP lookup when
+ def _getaddrinfo(hostname, family):
+ if family == socket.AF_INET:
+ return "0.0.0.0"
+ raise NotImplementedError()
+
+ monkeypatch.setattr(socket, "getaddrinfo", _getaddrinfo)