Skip to content

Commit

Permalink
Cleanup all direct config.is_ipv6_host calls
Browse files Browse the repository at this point in the history
Change-Id: I9f51e9504bfba1cef6a7242db2b9c3f55e134302
  • Loading branch information
LarsMichelsen committed Apr 16, 2019
1 parent 26d3681 commit 6e270d6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
5 changes: 0 additions & 5 deletions cmk_base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,11 +833,6 @@ def parents_of(hostname):
#


# TODO: Replace call sites with HostConfig access and remove this
def is_ipv6_host(hostname):
return get_config_cache().get_host_config(hostname).is_ipv6_host


# TODO: Replace call sites with HostConfig access and remove this
def is_ipv4_host(hostname):
return get_config_cache().get_host_config(hostname).is_ipv4_host
Expand Down
4 changes: 2 additions & 2 deletions cmk_base/core_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def get_host_attributes(hostname, config_cache):
else:
attrs["_ADDRESS_4"] = ""

if config.is_ipv6_host(hostname):
if host_config.is_ipv6_host:
attrs["_ADDRESS_6"] = _ip_address_of(host_config, 6)
if attrs["_ADDRESS_6"] is None:
attrs["_ADDRESS_6"] = ""
Expand Down Expand Up @@ -492,7 +492,7 @@ def get_cluster_attributes(config_cache, host_config, nodes):
node_ips_4.append(fallback_ip_for(node_config, 4))

node_ips_6 = []
if config.is_ipv6_host(host_config.hostname):
if host_config.is_ipv6_host:
for h in sorted_nodes:
node_config = config_cache.get_host_config(h)
addr = _ip_address_of(node_config, 6)
Expand Down
14 changes: 9 additions & 5 deletions cmk_base/core_nagios.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,10 +981,12 @@ def precompile_hostchecks():
if not os.path.exists(cmk.utils.paths.precompiled_hostchecks_dir):
os.makedirs(cmk.utils.paths.precompiled_hostchecks_dir)

config_cache = config.get_config_cache()

console.verbose("Precompiling host checks...\n")
for host in config.all_active_hosts():
try:
_precompile_hostcheck(host)
_precompile_hostcheck(config_cache, host)
except Exception as e:
if cmk.utils.debug.enabled():
raise
Expand All @@ -1008,8 +1010,9 @@ def stripped_python_file(filename):
return a


def _precompile_hostcheck(hostname):
def _precompile_hostcheck(config_cache, hostname):
import cmk_base.check_table as check_table
host_config = config_cache.get_host_config(hostname)

console.verbose("%s%s%-16s%s:", tty.bold, tty.blue, hostname, tty.normal, stream=sys.stderr)

Expand Down Expand Up @@ -1118,10 +1121,11 @@ def _precompile_hostcheck(hostname):
needed_ipaddresses, needed_ipv6addresses, = {}, {}
if config.is_cluster(hostname):
for node in config.nodes_of(hostname):
node_config = config_cache.get_host_config(node)
if config.is_ipv4_host(node):
needed_ipaddresses[node] = ip_lookup.lookup_ipv4_address(node)

if config.is_ipv6_host(node):
if node_config.is_ipv6_host:
needed_ipv6addresses[node] = ip_lookup.lookup_ipv6_address(node)

try:
Expand All @@ -1131,15 +1135,15 @@ def _precompile_hostcheck(hostname):
pass

try:
if config.is_ipv6_host(hostname):
if host_config.is_ipv6_host:
needed_ipv6addresses[hostname] = ip_lookup.lookup_ipv6_address(hostname)
except:
pass
else:
if config.is_ipv4_host(hostname):
needed_ipaddresses[hostname] = ip_lookup.lookup_ipv4_address(hostname)

if config.is_ipv6_host(hostname):
if host_config.is_ipv6_host:
needed_ipv6addresses[hostname] = ip_lookup.lookup_ipv6_address(hostname)

output.write("config.ipaddresses = %r\n\n" % needed_ipaddresses)
Expand Down
8 changes: 6 additions & 2 deletions cmk_base/ip_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,17 @@ def update_dns_cache():
if e.errno != errno.ENOENT:
raise

config_cache = config.get_config_cache()

console.verbose("Updating DNS cache...\n")
for hostname in config.all_active_hosts():
host_config = config_cache.get_host_config(hostname)

# Use intelligent logic. This prevents DNS lookups for hosts
# with statically configured addresses, etc.
for family in [4, 6]:
if (family == 4 and config.is_ipv4_host(hostname)) \
or (family == 6 and config.is_ipv6_host(hostname)):
if (family == 4 and host_config.is_ipv4_host) \
or (family == 6 and host_config.is_ipv6_host):
console.verbose("%s (IPv%d)..." % (hostname, family))
try:
if family == 4:
Expand Down
1 change: 0 additions & 1 deletion tests/unit/cmk_base/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_is_ipv4_host(monkeypatch, hostname, tags, result):
])
def test_is_ipv6_host(monkeypatch, hostname, tags, result):
config_cache = _setup_host(monkeypatch, hostname, tags)
assert config.is_ipv6_host(hostname) == result
assert config_cache.get_host_config(hostname).is_ipv6_host == result


Expand Down

0 comments on commit 6e270d6

Please sign in to comment.