def test_attribute_defaults(monkeypatch): ipaddress = "1.2.3.4" hostname = HostName("testhost") Scenario().add_host(hostname).apply(monkeypatch) source = TCPSource(hostname, ipaddress) monkeypatch.setattr(source, "file_cache_base_path", Path("/my/path/")) assert source.fetcher_configuration == { "file_cache": { "hostname": "testhost", "disabled": False, "max_age": MaxAge.none(), "base_path": "/my/path", "simulation": False, "use_outdated": False, }, "family": socket.AF_INET, "address": (ipaddress, 6556), "host_name": str(hostname), "timeout": 5.0, "encryption_settings": { "use_realtime": "enforce", "use_regular": "disable", }, "use_only_cache": False, } assert source.description == "TCP: %s:%s" % (ipaddress, 6556) assert source.id == "agent"
def file_cache(self) -> DefaultAgentFileCache: return DefaultAgentFileCache( HostName("hostname"), base_path=Path(os.devnull), max_age=MaxAge.none(), disabled=True, use_outdated=True, simulation=False, )
def file_cache(self, request) -> FileCache: return request.param( HostName("hostname"), base_path=Path(os.devnull), max_age=MaxAge.none(), disabled=True, use_outdated=False, simulation=True, )
def file_cache(self, path: Path, request): return request.param( HostName("hostname"), base_path=path, max_age=MaxAge(checking=0, discovery=999, inventory=0), disabled=False, use_outdated=False, simulation=False, )
def file_cache(self): return StubFileCache( "hostname", base_path=Path(os.devnull), max_age=MaxAge.none(), disabled=True, use_outdated=True, simulation=False, )
def file_cache(self, path): return NoCache( "hostname", base_path=path, max_age=MaxAge(checking=0, discovery=999, inventory=0), disabled=False, use_outdated=False, simulation=False, )
def file_cache(self) -> SNMPFileCache: return SNMPFileCache( HostName("hostname"), base_path=Path(os.devnull), max_age=MaxAge.none(), disabled=True, use_outdated=True, simulation=True, use_only_cache=True, )
def test_fetching_without_cache_raises_in_non_checking_mode(self) -> None: with TCPFetcher( StubFileCache( HostName("hostname"), base_path=Path(os.devnull), max_age=MaxAge.none(), disabled=False, use_outdated=True, simulation=False, use_only_cache=False, ), family=socket.AF_INET, address=("127.0.0.1", 6556), host_name=HostName("irrelevant_for_this_test"), timeout=0.1, encryption_settings={"use_regular": "allow"}, ) as fetcher: for mode in Mode: if mode is Mode.CHECKING: continue fetched = fetcher.fetch(mode) assert isinstance(fetched.error, MKFetcherError)
def test_mode_check_discovery_default(mocker): _patch_data_source(mocker, max_age=MaxAge(checking=0, discovery=0, inventory=120)) assert cmk.base.modes.check_mk.mode_check_discovery(HostName("ds-test-host1")) == 1 assert Source.parse.call_count == 2 # type: ignore[attr-defined]
def test_get(self): max_age = MaxAge(checking=42, discovery=69, inventory=1337) assert max_age.get(Mode.CHECKING) == 42 assert max_age.get(Mode.DISCOVERY) == 69 assert max_age.get(Mode.INVENTORY) == 1337 assert max_age.get(Mode.NONE) == 0
def test_serialize(self): max_age = MaxAge(checking=42, discovery=69, inventory=1337) assert MaxAge(*json.loads(json.dumps(max_age))) == max_age
def test_repr(self): max_age = MaxAge(checking=42, discovery=69, inventory=1337) assert isinstance(repr(max_age), str)