コード例 #1
0
def test_describe_with_ipaddress(monkeypatch):
    hostname = "testhost"
    Scenario().add_host(hostname).apply(monkeypatch)
    source = IPMIManagementBoardDataSource(hostname, None)
    source._ipaddress = "127.0.0.1"  # The API is lying.

    assert source.describe() == "Management board - IPMI (Address: 127.0.0.1)"
コード例 #2
0
def test_describe_with_credentials(monkeypatch):
    hostname = "testhost"
    Scenario().add_host(hostname).apply(monkeypatch)
    source = IPMIManagementBoardDataSource(hostname, None)
    source._credentials = {"username": "******"}

    assert source.describe() == "Management board - IPMI (User: Bobby)"
コード例 #3
0
def test_describe_with_ipaddress_and_credentials(monkeypatch):
    hostname = "testhost"
    Scenario().add_host(hostname).apply(monkeypatch)
    source = IPMIManagementBoardDataSource(hostname, "127.0.0.1")
    source._credentials = {"username": "******"}

    assert source.describe() == "Management board - IPMI (Address: 127.0.0.1, User: Bobby)"
コード例 #4
0
def test_parse_sensor_reading_false_positive():
    reading = SensorReading(  #
        ['Present'], 1, "Dingeling", 0.2, b"\xc2\xb0C", [], "FancyDevice",
        3.14159265, 1)
    assert IPMIManagementBoardDataSource._parse_sensor_reading(0, reading) == [
        b"0", "Dingeling", "FancyDevice", b"3.14", b"C", b"Present"
    ]
コード例 #5
0
def test_attribute_defaults(monkeypatch, ipaddress):
    hostname = "testhost"
    Scenario().add_host(hostname).apply(monkeypatch)
    # NOTE: pylint is quite buggy when it comes to class hierarchies and abstract methods!
    source = IPMIManagementBoardDataSource(hostname, ipaddress)  # pylint: disable=abstract-class-instantiated

    assert source.id() == "mgmt_ipmi"
    assert source.title() == "Management board - IPMI"
    assert source._cpu_tracking_id() == source.id()
    assert source._gather_check_plugin_names() == {"mgmt_ipmi_sensors"}
    assert source._summary_result("anything will do") == (0,
                                                          "Version: unknown",
                                                          [])
    assert source._get_ipmi_version() == "unknown"
コード例 #6
0
def test_attribute_defaults(monkeypatch, ipaddress):
    hostname = "testhost"
    Scenario().add_host(hostname).apply(monkeypatch)
    source = IPMIManagementBoardDataSource(hostname, ipaddress)

    assert source._for_mgmt_board is True
    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._gather_check_plugin_names() == {"mgmt_ipmi_sensors"}
    assert source._summary_result(True) == (0, "Version: unknown", [])
    assert source._get_ipmi_version() == "unknown"
コード例 #7
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"
コード例 #8
0
def test_ipmi_ipaddress_from_mgmt_board(monkeypatch):
    hostname = "testhost"
    ipaddress = "127.0.0.1"
    Scenario().add_host(hostname).apply(monkeypatch)
    monkeypatch.setattr(ip_lookup, "lookup_ip_address", lambda h: ipaddress)
    monkeypatch.setattr(config, "host_attributes", {
        hostname: {
            "management_address": ipaddress
        },
    })
    source = IPMIManagementBoardDataSource(hostname, None)

    assert source._host_config.management_address == ipaddress
    assert source._ipaddress == ipaddress
コード例 #9
0
def test_ipmi_ipaddress_from_mgmt_board(mode, 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
        },
    })

    configurator = IPMIConfigurator(hostname, ipaddress, mode=mode)
    assert configurator.host_config.management_address == ipaddress

    source = IPMIManagementBoardDataSource(configurator=configurator)
    assert source.ipaddress == ipaddress
コード例 #10
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

    source = IPMIManagementBoardDataSource(configurator=configurator)
    assert source.hostname == hostname
    # Address comes from management board.
    assert source.ipaddress is None
    assert source.id == "mgmt_ipmi"
    assert source._cpu_tracking_id == source.id

    summarizer = source.summarizer
    assert summarizer.summarize(AgentHostSections()) == (0, "Version: unknown", [])
コード例 #11
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
コード例 #12
0
def test_parse_sensor_reading_standard_case():
    reading = SensorReading(  #
        ['lower non-critical threshold'], 1, "Hugo", None, "", [42],
        "hugo-type", None, 0)
    assert IPMIManagementBoardDataSource._parse_sensor_reading(
        0, reading) == [b"0", "Hugo", "hugo-type", b"N/A", "", b"WARNING"]
コード例 #13
0
def test_ipmi_parse_sensor_reading(reading, parsed):
    assert IPMIManagementBoardDataSource._parse_sensor_reading(
        0, reading) == parsed