예제 #1
0
def test_tag_config_save(mocker):
    export_mock = mocker.patch.object(cmk.gui.watolib.tags, "_export_hosttags_to_php")

    config_file = TagConfigFile()

    cfg = tags.TagConfig()
    cfg.insert_tag_group(tags.TagGroup(("tgid2", "Topics/titlor", [("tgid2", "tagid2", [])])))
    config_file.save(cfg.get_dict_format())

    export_mock.assert_called_once()

    cfg = tags.TagConfig()
    cfg.parse_config(config_file.load_for_reading())
    assert len(cfg.tag_groups) == 1
    assert cfg.tag_groups[0].id == "tgid2"
예제 #2
0
def test_cfg():
    multisite_dir = Path(cmk.gui.watolib.utils.multisite_dir())
    tags_mk = multisite_dir / "tags.mk"
    hosttags_mk = multisite_dir / "hosttags.mk"

    with tags_mk.open("w", encoding="utf-8") as f:
        f.write(
            """# Created by WATO
# encoding: utf-8

wato_tags = %s
"""
            % repr(_tag_test_cfg())
        )

    with hosttags_mk.open("w", encoding="utf-8") as f:
        f.write("")

    cfg = tags.TagConfig()
    cfg.parse_config(TagConfigFile().load_for_reading())

    yield cfg

    if tags_mk.exists():
        tags_mk.unlink()
예제 #3
0
def test_pre_16_cfg(monkeypatch):
    multisite_dir = Path(cmk.gui.watolib.utils.multisite_dir())
    multisite_dir.mkdir(parents=True, exist_ok=True)
    hosttags_mk = multisite_dir / "hosttags.mk"

    with hosttags_mk.open("w", encoding="utf-8") as f:  # pylint: disable=no-member
        f.write(u"""# Created by WATO
# encoding: utf-8

wato_host_tags += [
    ('criticality', u'Criticality', [
        ('prod', u'Productive system', ['bla']),
        ('critical', u'Business critical', []),
        ('test', u'Test system', []),
        ('offline', u'Do not monitor this host', [])]),
    ('networking', u'Networking Segment', [
        ('lan', u'Local network (low latency)', []),
        ('wan', u'WAN (high latency)', []),
        ('dmz', u'DMZ (low latency, secure access)', []),
    ]),
]

wato_aux_tags += [("bla", u"bläää")]
""")

    cfg = tags.TagConfig()
    cfg.parse_config(TagConfigFile().load_for_reading())

    yield cfg

    if hosttags_mk.exists():  # pylint: disable=no-member
        hosttags_mk.unlink()  # pylint: disable=no-member
예제 #4
0
def test_tag_config_save(mocker):
    export_mock = mocker.patch.object(cmk.gui.watolib.tags, "_export_hosttags_to_php")

    config_file = TagConfigFile()
    base_config_mock = mocker.patch.object(config_file, "_save_base_config")

    cfg = tags.TagConfig()
    cfg.insert_tag_group(
        tags.TagGroup.from_config(
            {
                "id": "tgid2",
                "topic": "Topics",
                "title": "titlor",
                "tags": [{"id": "tgid2", "title": "tagid2", "aux_tags": []}],
            }
        )
    )
    config_file.save(cfg.get_dict_format())

    export_mock.assert_called_once()
    base_config_mock.assert_called_once()

    cfg = tags.TagConfig.from_config(config_file.load_for_reading())
    assert len(cfg.tag_groups) == 1
    assert cfg.tag_groups[0].id == "tgid2"
예제 #5
0
def test_iadd_tag_config(test_cfg: tags.TagConfig) -> None:
    cfg2 = tags.TagConfig()
    cfg2.insert_tag_group(
        tags.TagGroup.from_config({
            "id":
            "tgid3",
            "title":
            "titlor",
            "topic":
            "Topics",
            "tags": [{
                "id": "tgid3",
                "title": "tagid3",
                "aux_tags": [],
            }],
        }))
    cfg2.insert_tag_group(
        tags.TagGroup.from_config({
            "id":
            "tgid2",
            "title":
            "BLAAA",
            "tags": [{
                "id": "tgid2",
                "title": "tagid2",
                "aux_tags": []
            }],
        }))
    cfg2.aux_tag_list.append(
        tags.AuxTag.from_config({
            "id": "blub",
            "title": "BLUB"
        }))
    cfg2.aux_tag_list.append(
        tags.AuxTag.from_config({
            "id": "bla",
            "title": "BLUB"
        }))

    test_cfg += cfg2

    assert len(test_cfg.tag_groups) == 6
    assert test_cfg.tag_groups[0].id == "criticality"
    assert test_cfg.tag_groups[1].id == "networking"
    assert test_cfg.tag_groups[2].id == "none_choice"
    assert test_cfg.tag_groups[3].id == "none_2"
    assert test_cfg.tag_groups[4].id == "tgid3"
    assert test_cfg.tag_groups[4].title == "titlor"

    aux_tags = test_cfg.get_aux_tags()
    assert len(aux_tags) == 2
    assert aux_tags[0].id == "bla"
    assert aux_tags[0].title == "bläää"
    assert aux_tags[1].id == "blub"
예제 #6
0
def fixture_test_cfg() -> tags.TagConfig:
    cfg = tags.TagConfig()
    cfg.parse_config(
        {
            "aux_tags": [
                {
                    "id": "bla",
                    "topic": "Bluna",
                    "title": "bläää",
                }
            ],
            "tag_groups": [
                {
                    "id": "criticality",
                    "topic": "Blubberei",
                    "tags": [
                        {"aux_tags": ["bla"], "id": "prod", "title": "Productive system"},
                        {"aux_tags": [], "id": "critical", "title": "Business critical"},
                        {"aux_tags": [], "id": "test", "title": "Test system"},
                        {"aux_tags": [], "id": "offline", "title": "Do not monitor this host"},
                    ],
                    "title": "Criticality",
                },
                {
                    "id": "networking",
                    "tags": [
                        {"aux_tags": [], "id": "lan", "title": "Local network (low latency)"},
                        {"aux_tags": [], "id": "wan", "title": "WAN (high latency)"},
                        {"aux_tags": [], "id": "dmz", "title": "DMZ (low latency, secure access)"},
                    ],
                    "title": "Networking Segment",
                },
                {
                    "id": "none_choice",
                    "tags": [
                        {"aux_tags": ["bla"], "id": None, "title": "None"},
                        {"aux_tags": [], "id": "none_val", "title": "None value"},
                    ],
                    "title": "None choice",
                },
                {
                    "id": "none_2",
                    "tags": [
                        {"aux_tags": ["bla"], "id": "none_val", "title": "None value 2"},
                        {"aux_tags": [], "id": "none_val_2", "title": "None value again"},
                    ],
                    "title": "None 2",
                },
            ],
        }
    )
    return cfg
예제 #7
0
def test_iadd_tag_config(test_cfg):
    cfg2 = tags.TagConfig()
    cfg2.insert_tag_group(tags.TagGroup(("tgid3", "Topics/titlor", [("tgid3", "tagid3", [])])))
    cfg2.insert_tag_group(tags.TagGroup(("tgid2", "BLAAA", [("tgid2", "tagid2", [])])))
    cfg2.aux_tag_list.append(tags.AuxTag(("blub", "BLUB")))
    cfg2.aux_tag_list.append(tags.AuxTag(("bla", "BLUB")))

    test_cfg += cfg2

    assert len(test_cfg.tag_groups) == 5
    assert test_cfg.tag_groups[0].id == "criticality"
    assert test_cfg.tag_groups[1].id == "networking"
    assert test_cfg.tag_groups[2].id == "none_choice"
    assert test_cfg.tag_groups[3].id == "tgid3"
    assert test_cfg.tag_groups[3].title == "titlor"

    aux_tags = test_cfg.get_aux_tags()
    assert len(aux_tags) == 2
    assert aux_tags[0].id == "bla"
    assert aux_tags[0].title == u"bläää"
    assert aux_tags[1].id == "blub"
예제 #8
0
def test_cfg(test_pre_16_cfg):
    multisite_dir = Path(cmk.gui.watolib.utils.multisite_dir())
    tags_mk = multisite_dir / "tags.mk"
    hosttags_mk = multisite_dir / "hosttags.mk"

    with tags_mk.open("w", encoding="utf-8") as f:  # pylint: disable=no-member
        f.write(u"""# Created by WATO
# encoding: utf-8

wato_tags = %s
""" % repr(test_pre_16_cfg.get_dict_format()))

    with hosttags_mk.open("w", encoding="utf-8") as f:  # pylint: disable=no-member
        f.write(u"")

    cfg = tags.TagConfig()
    cfg.parse_config(TagConfigFile().load_for_reading())

    yield cfg

    if tags_mk.exists():  # pylint: disable=no-member
        tags_mk.unlink()  # pylint: disable=no-member
예제 #9
0
def fixture_cfg() -> tags.TagConfig:
    return tags.TagConfig()
예제 #10
0
def test_tag_config() -> None:
    cfg = tags.TagConfig()
    assert cfg.tag_groups == []
    assert cfg.aux_tag_list.get_tags() == []
예제 #11
0
def fixture_test_cfg() -> tags.TagConfig:
    cfg = tags.TagConfig()
    cfg.parse_config({
        "aux_tags": [{
            "id": "bla",
            "topic": u"Bluna",
            "title": u"bläää",
        }],
        'tag_groups': [
            {
                'id':
                'criticality',
                'topic':
                "Blubberei",
                'tags': [
                    {
                        'aux_tags': ["bla"],
                        'id': 'prod',
                        'title': u'Productive system'
                    },
                    {
                        'aux_tags': [],
                        'id': 'critical',
                        'title': u'Business critical'
                    },
                    {
                        'aux_tags': [],
                        'id': 'test',
                        'title': u'Test system'
                    },
                    {
                        'aux_tags': [],
                        'id': 'offline',
                        'title': u'Do not monitor this host'
                    },
                ],
                'title':
                u'Criticality'
            },
            {
                'id':
                'networking',
                'tags': [
                    {
                        'aux_tags': [],
                        'id': 'lan',
                        'title': u'Local network (low latency)'
                    },
                    {
                        'aux_tags': [],
                        'id': 'wan',
                        'title': u'WAN (high latency)'
                    },
                    {
                        'aux_tags': [],
                        'id': 'dmz',
                        'title': u'DMZ (low latency, secure access)'
                    },
                ],
                'title':
                u'Networking Segment',
            },
            {
                'id':
                'none_choice',
                'tags': [
                    {
                        'aux_tags': ['bla'],
                        'id': None,
                        'title': u'None'
                    },
                    {
                        'aux_tags': [],
                        'id': 'none_val',
                        'title': u'None value'
                    },
                ],
                'title':
                u'None choice',
            },
            {
                'id':
                'none_2',
                'tags': [
                    {
                        'aux_tags': ['bla'],
                        'id': 'none_val',
                        'title': 'None value 2'
                    },
                    {
                        'aux_tags': [],
                        'id': 'none_val_2',
                        'title': 'None value again'
                    },
                ],
                'title':
                'None 2',
            },
        ],
    })
    return cfg
예제 #12
0
def cfg():
    return tags.TagConfig()