Exemple #1
0
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 ip_lookup.lookup_mgmt_board_ip_address(host_config) is None
Exemple #2
0
    def _initialize_mgmt_boards(self) -> None:
        protocol = self._host_config.management_protocol
        if protocol is None:
            return

        ip_address = ip_lookup.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,
                ))
        elif protocol == "ipmi":
            self._add(IPMISource(
                self._hostname,
                ip_address,
                mode=self._mode,
            ))
        else:
            raise LookupError()
def test_snmp_ipaddress_from_mgmt_board(monkeypatch):
    hostname = "testhost"
    ipaddress = "1.2.3.4"

    def fake_lookup_ip_address(host_config, family=None, for_mgmt_board=True):
        return ipaddress

    ts = Scenario()
    ts.add_host(hostname)
    ts.set_option("management_protocol", {hostname: "snmp"})
    ts.apply(monkeypatch)

    monkeypatch.setattr(ip_lookup, "lookup_ip_address", fake_lookup_ip_address)
    monkeypatch.setattr(config, "host_attributes", {
        hostname: {
            "management_address": ipaddress,
        },
    })

    host_config = config.get_config_cache().get_host_config(hostname)
    source = SNMPManagementBoardDataSource(
        hostname,
        ip_lookup.lookup_mgmt_board_ip_address(host_config),
    )

    assert source._host_config.management_address == ipaddress
    assert source.ipaddress == ipaddress
Exemple #4
0
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 ip_lookup.lookup_mgmt_board_ip_address(host_config) == result_address
Exemple #5
0
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 ip_lookup.lookup_mgmt_board_ip_address(
        host_config) == result_address
def test_snmp_ipaddress_from_mgmt_board_unresolvable(hostname, monkeypatch):
    def fake_lookup_ip_address(host_config, family=None, for_mgmt_board=True):
        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 ip_lookup.lookup_mgmt_board_ip_address(host_config) is None
def test_attribute_defaults(mode, monkeypatch):
    hostname = "testhost"
    Scenario().add_host(hostname).apply(monkeypatch)

    host_config = config.get_config_cache().get_host_config(hostname)
    ipaddress = ip_lookup.lookup_mgmt_board_ip_address(host_config)

    source = IPMISource(hostname, ipaddress, mode=mode)
    assert source.hostname == hostname
    assert source.ipaddress == ipaddress
    assert source.mode is mode
    assert source.description == "Management board - IPMI"
    assert source.source_type is SourceType.MANAGEMENT
    assert source.summarize(result.OK(AgentHostSections())) == (0, "Version: unknown")
    assert source.id == "mgmt_ipmi"
Exemple #8
0
    def _initialize_management_board_data_sources(self) -> None:
        protocol = self._host_config.management_protocol
        if protocol is None:
            return

        ip_address = ip_lookup.lookup_mgmt_board_ip_address(self._host_config)
        if protocol == "snmp":
            self._add_source(SNMPManagementBoardDataSource(
                self._hostname,
                ip_address,
            ))
        elif protocol == "ipmi":
            self._add_source(IPMIManagementBoardDataSource(
                self._hostname,
                ip_address,
            ))
        else:
            raise NotImplementedError()
Exemple #9
0
def test_attribute_defaults(monkeypatch):
    hostname = "testhost"
    Scenario().add_host(hostname).apply(monkeypatch)

    host_config = config.get_config_cache().get_host_config(hostname)
    source = IPMIManagementBoardDataSource(
        hostname,
        ip_lookup.lookup_mgmt_board_ip_address(host_config),
    )

    assert source.source_type is SourceType.MANAGEMENT
    assert source.hostname == hostname
    # Address comes from management board.
    assert source.ipaddress is None
    assert source.id == "mgmt_ipmi"
    assert source.title == "Management board - IPMI"
    assert source._cpu_tracking_id == source.id
    assert source._summary_result(True) == (0, "Version: unknown", [])
    assert source._get_ipmi_version() == "unknown"
Exemple #10
0
    def _initialize_mgmt_boards(self) -> None:
        protocol = self._host_config.management_protocol
        if protocol is None:
            return

        ip_address = ip_lookup.lookup_mgmt_board_ip_address(self._host_config)
        if protocol == "snmp":
            self._add(SNMPSource.management_board(
                self._hostname,
                ip_address,
                mode=self._mode,
            ))
        elif protocol == "ipmi":
            self._add(IPMISource(
                self._hostname,
                ip_address,
                mode=self._mode,
            ))
        else:
            raise LookupError()
Exemple #11
0
def test_attribute_defaults(mode, monkeypatch):
    hostname = "testhost"
    Scenario().add_host(hostname).apply(monkeypatch)

    host_config = config.get_config_cache().get_host_config(hostname)
    ipaddress = ip_lookup.lookup_mgmt_board_ip_address(host_config)

    configurator = IPMIConfigurator(hostname, ipaddress, mode=mode)
    assert configurator.hostname == hostname
    assert configurator.ipaddress == ipaddress
    assert configurator.mode is mode
    assert configurator.description == "Management board - IPMI"
    assert configurator.source_type is SourceType.MANAGEMENT

    summarizer = configurator.make_summarizer()
    assert summarizer.summarize(AgentHostSections()) == (0, "Version: unknown",
                                                         [])

    checker = configurator.make_checker()
    assert checker.id == "mgmt_ipmi"
    assert checker._cpu_tracking_id == checker.id
Exemple #12
0
def test_ipmi_ipaddress_from_mgmt_board(monkeypatch):
    hostname = "testhost"
    ipaddress = "127.0.0.1"

    def fake_lookup_ip_address(host_config, family=None, for_mgmt_board=True):
        return ipaddress

    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": ipaddress
        },
    })

    host_config = config.get_config_cache().get_host_config(hostname)
    source = IPMIManagementBoardDataSource(
        hostname,
        ip_lookup.lookup_mgmt_board_ip_address(host_config),
    )

    assert source._host_config.management_address == ipaddress
    assert source.ipaddress == ipaddress