is_snmpv2or3_without_bulkwalk_host calls
Message-ID: <5cc0179a.lrWTRkuL9CjNKIAM%lm(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 8af1e4d577870ab4496eb040fa7307c39e2181ad
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8af1e4d577870a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Apr 18 21:15:26 2019 +0200
Cleanup all direct config.is_bulkwalk_host/is_snmpv2or3_without_bulkwalk_host calls
Change-Id: I5a314ab298682c9555e7b048180957e4a0dbcd1e
---
cmk_base/config.py | 17 +++--------------
tests/unit/cmk_base/snmp/test_snmp_unit.py | 11 +++++++----
2 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 167f487..f10b0d6 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -912,14 +912,6 @@ def snmp_port_of(hostname):
return ports[0]
-def is_bulkwalk_host(hostname):
- # type: (str) -> bool
- if bulkwalk_hosts:
- return get_config_cache().in_binary_hostlist(hostname, bulkwalk_hosts)
-
- return False
-
-
def bulk_walk_size_of(hostname):
bulk_sizes = get_config_cache().host_extra_conf(hostname, snmp_bulk_size)
if not bulk_sizes:
@@ -928,10 +920,6 @@ def bulk_walk_size_of(hostname):
return bulk_sizes[0]
-def is_snmpv2or3_without_bulkwalk_host(hostname):
- return get_config_cache().in_binary_hostlist(hostname, snmpv2c_hosts)
-
-
# TODO: Replace call sites with HostConfig access and remove this
def is_usewalk_host(hostname):
return get_config_cache().get_host_config(hostname).is_usewalk_host
@@ -2697,8 +2685,9 @@ class HostConfig(object):
ipaddress=ipaddress,
credentials=snmp_credentials_of(self.hostname),
port=snmp_port_of(self.hostname),
- is_bulkwalk_host=is_bulkwalk_host(self.hostname),
-
is_snmpv2or3_without_bulkwalk_host=is_snmpv2or3_without_bulkwalk_host(self.hostname),
+ is_bulkwalk_host=self._config_cache.in_binary_hostlist(self.hostname,
bulkwalk_hosts),
+ is_snmpv2or3_without_bulkwalk_host=self._config_cache.in_binary_hostlist(
+ self.hostname, snmpv2c_hosts),
bulk_walk_size_of=bulk_walk_size_of(self.hostname),
timing=snmp_timing_of(self.hostname),
oid_range_limits=oid_range_limits_of(self.hostname),
diff --git a/tests/unit/cmk_base/snmp/test_snmp_unit.py
b/tests/unit/cmk_base/snmp/test_snmp_unit.py
index 6f160c8..f0fc37d 100644
--- a/tests/unit/cmk_base/snmp/test_snmp_unit.py
+++ b/tests/unit/cmk_base/snmp/test_snmp_unit.py
@@ -1,6 +1,8 @@
# encoding: utf-8
-import pytest
+import pytest # type: ignore
+from testlib.base import Scenario
+
import cmk_base.config as config
import cmk_base.snmp as snmp
@@ -22,8 +24,9 @@ def test_sanitize_snmp_encoding(monkeypatch, encoding, columns,
expected):
def test_is_bulkwalk_host(monkeypatch):
- monkeypatch.setattr(config, "bulkwalk_hosts", [
+ ts = Scenario().set_ruleset("bulkwalk_hosts", [
([], ["localhost"], {}),
])
- assert config.is_bulkwalk_host("abc") is False
- assert config.is_bulkwalk_host("localhost") is True
+ config_cache = ts.apply(monkeypatch)
+ assert
config_cache.get_host_config("abc").snmp_config("").is_bulkwalk_host
is False
+ assert
config_cache.get_host_config("localhost").snmp_config("").is_bulkwalk_host
is True