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)"
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)"
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)"
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" ]
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"
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"
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"
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
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
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", [])
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
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"]
def test_ipmi_parse_sensor_reading(reading, parsed): assert IPMIManagementBoardDataSource._parse_sensor_reading( 0, reading) == parsed