Пример #1
0
def test_get_all_hosts_effective_attributes(web):
    try:
        web.add_host("test-host", attributes={
            "ipaddress": "127.0.0.1",
        })

        hosts = web.get_all_hosts(effective_attributes=False)
        host = hosts["test-host"]
        assert "tag_networking" not in host["attributes"]

        hosts = web.get_all_hosts(effective_attributes=True)
        host = hosts["test-host"]
        assert "tag_networking" in host["attributes"]
        assert host["attributes"]["tag_networking"] == "lan"
    finally:
        web.delete_host("test-host")
Пример #2
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"])
Пример #3
0
def test_get_all_hosts_basic(web):
    try:
        web.add_host("test-host-list", attributes={
            "ipaddress": "127.0.0.1",
        })

        hosts = web.get_all_hosts()
        assert "test-host-list" in hosts
    finally:
        web.delete_host("test-host-list")
Пример #4
0
def test_get_all_hosts_basic(web):  # noqa: F811 # pylint: disable=redefined-outer-name
    try:
        web.add_host("test-host-list", attributes={
            "ipaddress": "127.0.0.1",
        })

        hosts = web.get_all_hosts()
        assert "test-host-list" in hosts
    finally:
        web.delete_host("test-host-list")
Пример #5
0
def test_get_all_hosts_basic(web):
    try:
        web.add_host("test-host-list", attributes={
            "ipaddress": "127.0.0.1",
        })

        hosts = web.get_all_hosts()
        assert "test-host-list" in hosts
    finally:
        web.delete_host("test-host-list")
Пример #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": [],
            "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_host("test-host-lan2")
        web.delete_host("test-host-lan")
        web.delete_host("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": {},
        }

        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"])