Пример #1
0
def test_discovered_host_labels_store_save(labels, discovered_host_labels_dir):
    store = DiscoveredHostLabelsStore("host")
    labels["xyz"] = "äbc"
    label_dict = labels.to_dict()

    assert not store.file_path.exists()  # pylint: disable=no-member

    store.save(label_dict)
    assert store.file_path.exists()  # pylint: disable=no-member
    assert store.load() == label_dict
Пример #2
0
def test_discovered_host_labels_store_save(discovered_host_labels_dir):
    store = DiscoveredHostLabelsStore("host")

    labels = DiscoveredHostLabels(HostLabel(u"xyz", u"äbc"))
    label_dict = labels.to_dict()

    assert not store.file_path.exists()

    store.save(label_dict)
    assert store.file_path.exists()
    assert store.load() == label_dict
Пример #3
0
def test_discovered_host_labels_store_save(discovered_host_labels_dir):
    store = DiscoveredHostLabelsStore(HostName("host"))

    labels = DiscoveredHostLabels(
        HostLabel("xyz", "äbc", SectionName("sectionname")))
    label_dict = labels.to_dict()

    assert not store.file_path.exists()

    store.save(label_dict)
    assert store.file_path.exists()
    assert store.load() == label_dict
Пример #4
0
def test_discovered_host_labels_store_save(
        discovered_host_labels_dir: Path) -> None:
    store = DiscoveredHostLabelsStore(HostName("host"))

    label_dict: Dict[
        str, HostLabelValueDict] = {  # save below expects Dict[Any, Any] :-|
            "xyz": {
                "value": "äbc",
                "plugin_name": "sectionname"
            }
        }

    assert not store.file_path.exists()

    store.save(label_dict)
    assert store.file_path.exists()
    assert store.load() == label_dict
Пример #5
0
def test_perform_host_label_discovery(discovered_host_labels_dir,
                                      existing_labels, new_labels,
                                      expected_labels, load_labels):
    hostname = "testhost"
    config.get_config_cache().initialize()
    store = DiscoveredHostLabelsStore(hostname)
    store.save(
        DiscoveredHostLabels(*[HostLabel(*x)
                               for x in existing_labels]).to_dict())

    discovery_parameters = DiscoveryParameters(
        on_error="raise",
        load_labels=load_labels,
        save_labels=False,
    )

    new_host_labels, _host_labels_per_plugin = _perform_host_label_discovery(
        hostname, DiscoveredHostLabels(*[HostLabel(*x) for x in new_labels]),
        discovery_parameters)

    labels_expected = DiscoveredHostLabels(
        *[HostLabel(*x) for x in expected_labels])
    assert new_host_labels.to_dict() == labels_expected.to_dict()