def _initialize_mgmt_boards(self) -> None: protocol = self._host_config.management_protocol if protocol is None: return ip_address = config.lookup_mgmt_board_ip_address(self._host_config) if ip_address is None: # HostAddress is not Optional. # # See above. return if protocol == "snmp": self._add( SNMPSource.management_board( self._hostname, ip_address, mode=self._mode, selected_sections=self._selected_sections, on_scan_error=self._on_scan_error, force_cache_refresh=self._force_snmp_cache_refresh, )) elif protocol == "ipmi": self._add(IPMISource( self._hostname, ip_address, mode=self._mode, )) else: raise LookupError()
def test_lookup_mgmt_board_ip_address_unresolveable(monkeypatch, tags, family): hostname = "unresolveable-hostname" ts = Scenario() ts.add_host(hostname, tags=tags) ts.apply(monkeypatch) host_config = config.get_config_cache().get_host_config(hostname) assert config.lookup_mgmt_board_ip_address(host_config) is None
def test_lookup_mgmt_board_ip_address_ipv4_host(monkeypatch, hostname, tags, result_address): ts = Scenario() ts.add_host(hostname, tags=tags) ts.apply(monkeypatch) host_config = config.get_config_cache().get_host_config(hostname) assert config.lookup_mgmt_board_ip_address(host_config) == result_address
def test_lookup_mgmt_board_ip_address_unresolveable( monkeypatch: MonkeyPatch, tags: Dict[str, str], family: socket.AddressFamily) -> None: hostname = HostName("unresolveable-hostname") ts = Scenario() ts.add_host(hostname, tags=tags) ts.apply(monkeypatch) host_config = config.get_config_cache().get_host_config(hostname) assert config.lookup_mgmt_board_ip_address(host_config) is None
def test_lookup_mgmt_board_ip_address_dual_host(monkeypatch, hostname, result_address): ts = Scenario() ts.add_host(hostname, tags={ "address_family": "ip-v4v6", }) ts.apply(monkeypatch) host_config = config.get_config_cache().get_host_config(hostname) assert config.lookup_mgmt_board_ip_address(host_config) == result_address
def test_lookup_mgmt_board_ip_address_ipv4_host(monkeypatch: MonkeyPatch, hostname_str: str, tags: Dict[str, str], result_address: str) -> None: hostname = HostName(hostname_str) ts = Scenario() ts.add_host(hostname, tags=tags) ts.apply(monkeypatch) host_config = config.get_config_cache().get_host_config(hostname) assert config.lookup_mgmt_board_ip_address(host_config) == result_address
def test_snmp_ipaddress_from_mgmt_board_unresolvable(hostname, monkeypatch): def fake_lookup_ip_address(*_a, **_kw): raise MKIPAddressLookupError("Failed to ...") Scenario().add_host(hostname).apply(monkeypatch) monkeypatch.setattr(ip_lookup, "lookup_ip_address", fake_lookup_ip_address) monkeypatch.setattr(config, "host_attributes", { "hostname": { "management_address": "lolo" }, }) host_config = config.get_config_cache().get_host_config(hostname) assert config.lookup_mgmt_board_ip_address(host_config) is None
def test_lookup_mgmt_board_ip_address_ipv6_host(monkeypatch: MonkeyPatch, hostname_str: str, result_address: str) -> None: hostname = HostName(hostname_str) ts = Scenario() ts.add_host( hostname, tags={ "address_family": "ip-v6-only", }, ) ts.apply(monkeypatch) host_config = config.get_config_cache().get_host_config(hostname) assert config.lookup_mgmt_board_ip_address(host_config) == result_address
def test_attribute_defaults(mode, monkeypatch): hostname = HostName("testhost") Scenario().add_host(hostname).apply(monkeypatch) host_config = config.get_config_cache().get_host_config(hostname) ipaddress = config.lookup_mgmt_board_ip_address(host_config) source = IPMISource(hostname, ipaddress) assert source.hostname == hostname assert source.ipaddress == ipaddress assert source.description == "Management board - IPMI" assert source.source_type is SourceType.MANAGEMENT assert source.summarize(result.OK(AgentHostSections()), mode=mode) == (0, "Version: unknown") assert source.id == "mgmt_ipmi"
def test_attribute_defaults(monkeypatch): hostname = HostName("testhost") ts = Scenario() ts.add_host(hostname) ts.apply(monkeypatch) host_config = config.get_config_cache().get_host_config(hostname) ipaddress = config.lookup_mgmt_board_ip_address(host_config) source = IPMISource(hostname, ipaddress) assert source.hostname == hostname assert source.ipaddress == ipaddress assert source.description == "Management board - IPMI" assert source.source_type is SourceType.MANAGEMENT assert source.summarize(result.OK(HostSections[AgentRawDataSection]())) == [ ActiveCheckResult(0, "Success") ] assert source.id == "mgmt_ipmi"