示例#1
0
def test_write_host_labels(web, site):
    try:
        web.add_host("test-host-lan",
                     attributes={
                         "ipaddress": "127.0.0.1",
                         'labels': {
                             'blä': 'blüb'
                         }
                     },
                     verify_set_attributes=False)

        hosts = web.get_all_hosts(effective_attributes=True)
        assert hosts["test-host-lan"]["attributes"]["labels"] == {u'blä': u'blüb'}

        cfg = {
            "FOLDER_PATH": "/",
            "all_hosts": [],
            "host_tags": {},
            "host_labels": {},
            "ipaddresses": {},
            "host_attributes": {},
        }  # type: Dict[str, Any]

        exec(site.read_file("etc/check_mk/conf.d/wato/hosts.mk"), cfg, cfg)

        assert cfg["host_labels"]["test-host-lan"] == {
            u"blä": u"blüb",
        }

        for label_id, label_value in cfg["host_labels"]["test-host-lan"].items():
            assert isinstance(label_id, six.text_type)
            assert isinstance(label_value, six.text_type)

    finally:
        web.delete_hosts(["test-host-lan"])
示例#2
0
def test_add_hosts(web):
    hosts = ["test-hosts1", "test-hosts2"]
    try:
        web.add_hosts([(hostname, "", {
            "ipaddress": "127.0.0.1",
        }) for hostname in hosts])
    finally:
        web.delete_hosts(hosts)
示例#3
0
def test_add_hosts(web):  # noqa: F811 # pylint: disable=redefined-outer-name
    hosts = ["test-hosts1", "test-hosts2"]
    try:
        web.add_hosts([(hostname, "", {
            "ipaddress": "127.0.0.1",
        }) for hostname in hosts])
    finally:
        web.delete_hosts(hosts)
示例#4
0
def test_delete_hosts(web):
    try:
        web.add_host("test-hosts-delete1", attributes={
            "ipaddress": "127.0.0.1",
        })
        web.add_host("test-hosts-delete2", attributes={
            "ipaddress": "127.0.0.1",
        })
    finally:
        web.delete_hosts(["test-hosts-delete1", "test-hosts-delete2"])
示例#5
0
def test_delete_hosts(web):  # noqa: F811 # pylint: disable=redefined-outer-name
    try:
        web.add_host("test-hosts-delete1", attributes={
            "ipaddress": "127.0.0.1",
        })
        web.add_host("test-hosts-delete2", attributes={
            "ipaddress": "127.0.0.1",
        })
    finally:
        web.delete_hosts(["test-hosts-delete1", "test-hosts-delete2"])
示例#6
0
def test_write_host_tags(web, site):
    try:
        web.add_host("test-host-dmz",
                     attributes={
                         "ipaddress": "127.0.0.1",
                         "tag_networking": "dmz",
                     })

        web.add_host("test-host-lan",
                     attributes={
                         "ipaddress": "127.0.0.1",
                         "tag_networking": "lan",
                     })

        web.add_host("test-host-lan2", attributes={
            "ipaddress": "127.0.0.1",
        })

        hosts = web.get_all_hosts(effective_attributes=True)
        assert hosts["test-host-dmz"]["attributes"]["tag_networking"] == "dmz"
        assert hosts["test-host-lan"]["attributes"]["tag_networking"] == "lan"
        assert hosts["test-host-lan2"]["attributes"]["tag_networking"] == "lan"

        cfg = {
            "FOLDER_PATH": "/",
            "all_hosts": [],
            "host_tags": {},
            "host_labels": {},
            "ipaddresses": {},
            "host_attributes": {},
        }

        exec(site.read_file("etc/check_mk/conf.d/wato/hosts.mk"), cfg, cfg)

        tags_by_host = {}
        for entry in cfg["all_hosts"]:
            hostname, tag_txt = entry.split("|", 1)
            tags_by_host[hostname] = tag_txt.split("|")

        assert "dmz" in tags_by_host["test-host-dmz"]
        assert "lan" not in tags_by_host["test-host-dmz"]

        assert "dmz" not in tags_by_host["test-host-lan"]
        assert "lan" in tags_by_host["test-host-lan"]

        assert "dmz" not in tags_by_host["test-host-lan2"]
        assert "lan" in tags_by_host["test-host-lan2"]

    finally:
        web.delete_hosts(["test-host-lan2", "test-host-lan", "test-host-dmz"])
示例#7
0
def test_write_host_tags(web, site):
    try:
        web.add_host("test-host-dmz",
                     attributes={
                         "ipaddress": "127.0.0.1",
                         "tag_networking": "dmz",
                     })

        web.add_host("test-host-lan",
                     attributes={
                         "ipaddress": "127.0.0.1",
                         "tag_networking": "lan",
                     })

        web.add_host("test-host-lan2", attributes={
            "ipaddress": "127.0.0.1",
        })

        hosts = web.get_all_hosts(effective_attributes=True)
        assert hosts["test-host-dmz"]["attributes"]["tag_networking"] == "dmz"
        assert hosts["test-host-lan"]["attributes"]["tag_networking"] == "lan"
        assert hosts["test-host-lan2"]["attributes"]["tag_networking"] == "lan"

        cfg = {
            "FOLDER_PATH": "/",
            "all_hosts": [],
            "host_tags": {},
            "host_labels": {},
            "ipaddresses": {},
            "host_attributes": {},
        }  # type: Dict[str, Any]

        exec(site.read_file("etc/check_mk/conf.d/wato/hosts.mk"), cfg, cfg)

        assert "dmz" in cfg["host_tags"]["test-host-dmz"]["networking"]
        assert "lan" not in cfg["host_tags"]["test-host-dmz"]["networking"]

        assert "dmz" not in cfg["host_tags"]["test-host-lan"]["networking"]
        assert "lan" in cfg["host_tags"]["test-host-lan"]["networking"]

        assert "dmz" not in cfg["host_tags"]["test-host-lan2"]["networking"]
        assert "lan" in cfg["host_tags"]["test-host-lan2"]["networking"]

    finally:
        web.delete_hosts(["test-host-lan2", "test-host-lan", "test-host-dmz"])
示例#8
0
def test_edit_hosts(web):
    try:
        web.add_host("test-edit-hosts1", attributes={
            "ipaddress": "127.0.0.1",
        })
        web.add_host("test-edit-hosts2", attributes={
            "ipaddress": "127.0.0.1",
        })

        web.edit_hosts([
            ("test-edit-hosts1", {
                "ipaddress": "127.10.0.1"
            }, []),
            ("test-edit-hosts2", {
                "ipaddress": "127.20.0.1"
            }, []),
        ])
    finally:
        web.delete_hosts(["test-edit-hosts1", "test-edit-hosts2"])
示例#9
0
def test_edit_hosts(web):  # noqa: F811 # pylint: disable=redefined-outer-name
    try:
        web.add_host("test-edit-hosts1", attributes={
            "ipaddress": "127.0.0.1",
        })
        web.add_host("test-edit-hosts2", attributes={
            "ipaddress": "127.0.0.1",
        })

        web.edit_hosts([
            ("test-edit-hosts1", {
                "ipaddress": "127.10.0.1"
            }, []),
            ("test-edit-hosts2", {
                "ipaddress": "127.20.0.1"
            }, []),
        ])
    finally:
        web.delete_hosts(["test-edit-hosts1", "test-edit-hosts2"])