Exemple #1
0
def test_discovered_host_labels_add():
    labels_1 = DiscoveredHostLabels()
    labels_1.add_label(HostLabel(u"äbc", u"123", "plugin_1"))

    labels_2 = DiscoveredHostLabels()
    labels_2.add_label(HostLabel(u"xyz", u"blä", "plugin_2"))

    new_labels = labels_1 + labels_2
    assert new_labels.to_dict() == {
        u"äbc": {
            "value": u"123",
            "plugin_name": "plugin_1",
        },
        u"xyz": {
            "value": u"blä",
            "plugin_name": "plugin_2",
        },
    }

    labels_1 += labels_2
    assert labels_1.to_dict() == {
        u"äbc": {
            "value": u"123",
            "plugin_name": "plugin_1",
        },
        u"xyz": {
            "value": u"blä",
            "plugin_name": "plugin_2",
        },
    }
Exemple #2
0
def test_discovered_host_labels_to_dict():
    labels = DiscoveredHostLabels()
    assert labels.to_dict() == {}

    labels.add_label(HostLabel(u"äbc", u"123", "plugin_1"))
    labels.add_label(HostLabel(u"xyz", u"blä", "plugin_2"))

    assert labels.to_dict() == {
        u"äbc": {
            "value": u"123",
            "plugin_name": "plugin_1",
        },
        u"xyz": {
            "value": u"blä",
            "plugin_name": "plugin_2",
        },
    }
def test_discovered_host_labels_to_dict():
    labels = DiscoveredHostLabels()
    assert labels.to_dict() == {}

    labels.add_label(HostLabel("äbc", "123", SectionName("plugin_1")))
    labels.add_label(HostLabel("xyz", "blä", SectionName("plugin_2")))

    assert labels.to_dict() == {
        "äbc": {
            "value": "123",
            "plugin_name": "plugin_1",
        },
        "xyz": {
            "value": "blä",
            "plugin_name": "plugin_2",
        },
    }
Exemple #4
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()  # pylint: disable=no-member

    store.save(label_dict)
    assert store.file_path.exists()  # pylint: disable=no-member
    assert store.load() == label_dict
def test_discovered_host_labels_store_save(discovered_host_labels_dir):
    store = DiscoveredHostLabelsStore("host")

    labels = DiscoveredHostLabels(
        HostLabel(u"xyz", u"ä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
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()