Exemplo n.º 1
0
def test_add_replication_paths():
    activate_changes.add_replication_paths([
        ReplicationPath("dir", "abc", "path/to/abc", ["e1", "e2"]),
    ])

    assert activate_changes.get_replication_paths()[-1] == ReplicationPath(
        "dir", "abc", "path/to/abc", ["e1", "e2"])
Exemplo n.º 2
0
def test_get_replication_components(edition_short, monkeypatch, replicate_ec,
                                    replicate_mkps, is_pre_17_remote_site):
    partial_site_config = {}
    if replicate_ec is not None:
        partial_site_config["replicate_ec"] = replicate_ec
    if replicate_mkps is not None:
        partial_site_config["replicate_mkps"] = replicate_mkps

    expected = _expected_replication_paths()

    if not replicate_ec:
        expected = [
            e for e in expected if e.ident not in ["mkeventd", "mkeventd_mkp"]
        ]

    if not replicate_mkps:
        expected = [e for e in expected if e.ident not in ["local", "mkps"]]

    if is_pre_17_remote_site:
        for repl_path in expected:
            if repl_path.ident in {
                    "check_mk",
                    "multisite",
                    "liveproxyd",
                    "mkeventd",
                    "dcd",
                    "mknotify",
            }:
                if "sitespecific.mk" not in repl_path.excludes:
                    repl_path.excludes.append("sitespecific.mk")

            if repl_path.ident == "dcd" and "distributed.mk" not in repl_path.excludes:
                repl_path.excludes.append("distributed.mk")

        expected += [
            ReplicationPath(
                ty="file",
                ident="sitespecific",
                site_path="site_globals/sitespecific.mk",
                excludes=[],
            ),
        ]

    if not is_pre_17_remote_site:
        expected += [
            ReplicationPath(
                ty="file",
                ident="distributed_wato",
                site_path="etc/check_mk/conf.d/distributed_wato.mk",
                excludes=[".*new*"],
            ),
        ]

    assert sorted(
        activate_changes._get_replication_components(
            partial_site_config, is_pre_17_remote_site)) == sorted(expected)
Exemplo n.º 3
0
def test_add_replication_paths_pre_17():
    # dir/file, ident, path, optional list of excludes
    activate_changes.add_replication_paths([
        ("dir", "abc", "/path/to/abc"),
        ("dir", "abc", "/path/to/abc", ["e1", "e2"]),
    ])

    assert activate_changes.get_replication_paths()[-2] == ReplicationPath(
        "dir", "abc", "/path/to/abc", [])
    assert activate_changes.get_replication_paths()[-1] == ReplicationPath(
        "dir", "abc", "/path/to/abc", ["e1", "e2"])
Exemplo n.º 4
0
def test_add_replication_paths_pre_17(monkeypatch):
    monkeypatch.setattr(cmk.utils.paths, "omd_root", Path("/path"))
    # dir/file, ident, path, optional list of excludes
    activate_changes.add_replication_paths([
        ("dir", "abc", "/path/to/abc"),
        ("dir", "abc", "/path/to/abc", ["e1", "e2"]),
    ])
    monkeypatch.undo()

    assert activate_changes.get_replication_paths()[-2] == ReplicationPath(
        "dir", "abc", "to/abc", [])
    assert activate_changes.get_replication_paths()[-1] == ReplicationPath(
        "dir", "abc", "to/abc", ["e1", "e2"])
Exemplo n.º 5
0
def test_automation_get_config_sync_state():
    get_state = activate_changes.AutomationGetConfigSyncState()
    response = get_state.execute([ReplicationPath("dir", "abc", "etc", [])])
    assert response == (
        {
            "etc/check_mk/multisite.mk": (
                33200,
                0,
                None,
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            ),
            "etc/check_mk/mkeventd.mk": (
                33200,
                0,
                None,
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            ),
            "etc/htpasswd": (
                33200,
                0,
                None,
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            ),
        },
        0,
    )
Exemplo n.º 6
0
def test_get_replication_components(edition_short, monkeypatch, replicate_ec,
                                    replicate_mkps):
    monkeypatch.setattr(cmk_version, "edition_short", lambda: edition_short)

    partial_site_config = {}
    if replicate_ec is not None:
        partial_site_config["replicate_ec"] = replicate_ec
    if replicate_mkps is not None:
        partial_site_config["replicate_mkps"] = replicate_mkps

    expected = _expected_replication_paths()

    if not replicate_ec:
        expected = [
            e for e in expected if e.ident not in ["mkeventd", "mkeventd_mkp"]
        ]

    if not replicate_mkps:
        expected = [e for e in expected if e.ident not in ["local", "mkps"]]

    work_dir = cmk.utils.paths.omd_root
    expected += [
        ReplicationPath(
            ty="file",
            ident="sitespecific",
            path="%s/site_globals/sitespecific.mk" % work_dir,
            excludes=[],
        )
    ]

    assert sorted(
        activate_changes._get_replication_components(
            work_dir, partial_site_config)) == sorted(expected)
Exemplo n.º 7
0
def test_automation_get_config_sync_state():
    get_state = activate_changes.AutomationGetConfigSyncState()
    response = get_state.execute([ReplicationPath("dir", "abc", "etc", [])])
    assert response == (
        {
            "etc/check_mk/multisite.mk": (
                33200,
                0,
                None,
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            ),
            "etc/check_mk/mkeventd.mk": (
                33200,
                0,
                None,
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            ),
            "etc/check_mk/mkeventd.d/wato/rules.mk": (
                33200,
                147,
                None,
                "b129ce86d7aa063c31b0de5062196082744813a1ab506308aae36e5919badc50",
            ),
            "etc/htpasswd": (
                33200,
                0,
                None,
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            ),
            "etc/omd/site.conf": (
                33200,
                677,
                None,
                "d20618bd8e3d002617b76f55eeba48bb4b73b530c6bc198edf280d136efcb9bc",
            ),
        },
        0,
    )
Exemplo n.º 8
0
def test_automation_get_config_sync_state():
    get_state = activate_changes.AutomationGetConfigSyncState()
    response = get_state.execute([ReplicationPath("dir", "abc", "etc", [])])
    assert response == (
        {
            "etc/check_mk/multisite.mk": (
                33200,
                0,
                None,
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            ),
            "etc/check_mk/mkeventd.mk": (
                33200,
                0,
                None,
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            ),
            "etc/check_mk/mkeventd.d/wato/rules.mk": (
                33200,
                147,
                None,
                "b129ce86d7aa063c31b0de5062196082744813a1ab506308aae36e5919badc50",
            ),
            "etc/htpasswd": (
                33200,
                0,
                None,
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            ),
            "etc/omd/site.conf": (
                33200,
                683,
                None,
                "f549a7f82c6841c886b56d4290c325faa939aa74f37a4b577e46d5789d10d0f5",
            ),
        },
        0,
    )
Exemplo n.º 9
0
def _expected_replication_paths():
    expected = [
        ReplicationPath("dir", "check_mk", "etc/check_mk/conf.d/wato/", []),
        ReplicationPath("dir", "multisite", "etc/check_mk/multisite.d/wato/",
                        []),
        ReplicationPath("file", "htpasswd", "etc/htpasswd", []),
        ReplicationPath("file", "auth.secret", "etc/auth.secret", []),
        ReplicationPath("file", "password_store.secret",
                        "etc/password_store.secret", []),
        ReplicationPath("file", "auth.serials", "etc/auth.serials", []),
        ReplicationPath("file", "stored_passwords",
                        "var/check_mk/stored_passwords", []),
        ReplicationPath("dir", "usersettings", "var/check_mk/web",
                        ["report-thumbnails", "session_info.mk"]),
        ReplicationPath("dir", "mkps", "var/check_mk/packages", []),
        ReplicationPath("dir", "local", "local", []),
    ]

    if not cmk_version.is_raw_edition():
        expected += [
            ReplicationPath("dir", "liveproxyd",
                            "etc/check_mk/liveproxyd.d/wato/", []),
        ]

    if testlib.is_enterprise_repo():
        expected += [
            ReplicationPath("dir", "dcd", "etc/check_mk/dcd.d/wato/", []),
            ReplicationPath("dir", "mknotify", "etc/check_mk/mknotifyd.d/wato",
                            []),
        ]

    expected += [
        ReplicationPath("dir", "mkeventd", "etc/check_mk/mkeventd.d/wato", []),
        ReplicationPath("dir", "mkeventd_mkp",
                        "etc/check_mk/mkeventd.d/mkp/rule_packs", []),
        ReplicationPath("file", "diskspace", "etc/diskspace.conf", []),
    ]

    if cmk_version.is_managed_edition():
        expected += [
            ReplicationPath(
                ty="file",
                ident="customer_check_mk",
                site_path="etc/check_mk/conf.d/customer.mk",
                excludes=[],
            ),
            ReplicationPath(
                ty="file",
                ident="customer_gui_design",
                site_path="etc/check_mk/multisite.d/zzz_customer_gui_design.mk",
                excludes=[],
            ),
            ReplicationPath(
                ty="file",
                ident="customer_multisite",
                site_path="etc/check_mk/multisite.d/customer.mk",
                excludes=[],
            ),
            ReplicationPath(
                ty="file",
                ident="gui_logo",
                site_path=
                "local/share/check_mk/web/htdocs/themes/classic/images/sidebar_top.png",
                excludes=[],
            ),
            ReplicationPath(
                ty="file",
                ident="gui_logo_dark",
                site_path=
                "local/share/check_mk/web/htdocs/themes/modern-dark/images/mk-logo.png",
                excludes=[],
            ),
            ReplicationPath(
                ty="file",
                ident="gui_logo_facelift",
                site_path=
                "local/share/check_mk/web/htdocs/themes/facelift/images/mk-logo.png",
                excludes=[],
            ),
        ]

    return expected
Exemplo n.º 10
0
def test_get_config_sync_file_infos():
    base_dir = cmk.utils.paths.omd_root / "replication"
    _create_get_config_sync_file_infos_test_config(base_dir)

    replication_paths = [
        ReplicationPath("dir", "d1-empty", "etc/d1", []),
        ReplicationPath("dir", "d2-not-existing", "etc/d2", []),
        ReplicationPath("dir", "d3-single-file", "etc/d3", []),
        ReplicationPath("dir", "d4-multiple-files", "etc/d4", []),
        ReplicationPath("file", "f1-not-existing", "etc/f1", []),
        ReplicationPath("file", "f2", "bla/blub/f2", []),
        ReplicationPath("dir", "links", "links", []),
    ]
    sync_infos = activate_changes._get_config_sync_file_infos(
        replication_paths, base_dir)

    assert sync_infos == {
        "bla/blub/f2":
        ConfigSyncFileInfo(
            st_mode=33200,
            st_size=7,
            link_target=None,
            file_hash=
            "ae973806ace987a1889dc02cfa6b320912b68b6eb3929e425762795955990f35",
        ),
        "etc/d3/xyz":
        ConfigSyncFileInfo(
            st_mode=33200,
            st_size=5,
            link_target=None,
            file_hash=
            "780518619e3c5dfc931121362c7f14fa8d06457995c762bd818072ed42e6e69e",
        ),
        "etc/d4/layer1/layer2/x3.xyz":
        ConfigSyncFileInfo(
            st_mode=33200,
            st_size=6,
            link_target=None,
            file_hash=
            "c213b1ced86472704fdc0f77e15cc41f67341c4370def7a0ae9d90bedf37c8ca",
        ),
        "etc/d4/layer1/layer2/x4.xyz":
        ConfigSyncFileInfo(
            st_mode=33200,
            st_size=6,
            link_target=None,
            file_hash=
            "c213b1ced86472704fdc0f77e15cc41f67341c4370def7a0ae9d90bedf37c8ca",
        ),
        "etc/d4/x1":
        ConfigSyncFileInfo(
            st_mode=33200,
            st_size=6,
            link_target=None,
            file_hash=
            "1c77fe07e738fd6cbf0075195a773043a7507d53d6deeb1161549244c02ea0ff",
        ),
        "etc/d4/x2":
        ConfigSyncFileInfo(
            st_mode=33200,
            st_size=6,
            link_target=None,
            file_hash=
            "c213b1ced86472704fdc0f77e15cc41f67341c4370def7a0ae9d90bedf37c8ca",
        ),
        "etc/f1":
        ConfigSyncFileInfo(
            st_mode=33200,
            st_size=7,
            link_target=None,
            file_hash=
            "4dd985602450dfdeb261cedf8562cb62c5173d1d8bb5f3ca26cd3519add67cf7",
        ),
        "links/broken-symlink":
        ConfigSyncFileInfo(
            st_mode=41471,
            st_size=3,
            link_target="eeg",
            file_hash=None,
        ),
        "links/working-symlink-to-file":
        ConfigSyncFileInfo(
            st_mode=41471,
            st_size=13,
            link_target="../etc/d3/xyz",
            file_hash=None,
        ),
        "links/working-symlink-to-dir":
        ConfigSyncFileInfo(
            st_mode=41471,
            st_size=9,
            link_target="../etc/d3",
            file_hash=None,
        ),
    }
Exemplo n.º 11
0
def test_get_replication_components(edition, monkeypatch, replicate_ec,
                                    replicate_mkps, is_pre_17_remote_site):
    partial_site_config = SiteConfiguration({})
    # Astroid 2.x bug prevents us from using NewType https://github.com/PyCQA/pylint/issues/2296
    # pylint: disable=unsupported-assignment-operation
    if replicate_ec is not None:
        partial_site_config["replicate_ec"] = replicate_ec
    if replicate_mkps is not None:
        partial_site_config["replicate_mkps"] = replicate_mkps

    expected = _expected_replication_paths()

    if not replicate_ec:
        expected = [
            e for e in expected if e.ident not in ["mkeventd", "mkeventd_mkp"]
        ]

    if not replicate_mkps:
        expected = [e for e in expected if e.ident not in ["local", "mkps"]]

    if is_pre_17_remote_site:
        for repl_path in expected:
            if repl_path.ident in {
                    "check_mk",
                    "multisite",
                    "liveproxyd",
                    "mkeventd",
                    "dcd",
                    "mknotify",
            }:
                if "sitespecific.mk" not in repl_path.excludes:
                    repl_path.excludes.append("sitespecific.mk")

            if repl_path.ident == "dcd" and "distributed.mk" not in repl_path.excludes:
                repl_path.excludes.append("distributed.mk")

        expected += [
            ReplicationPath(
                ty="file",
                ident="sitespecific",
                site_path="site_globals/sitespecific.mk",
                excludes=[],
            ),
        ]

    if not is_pre_17_remote_site:
        expected += [
            ReplicationPath(
                ty="file",
                ident="distributed_wato",
                site_path="etc/check_mk/conf.d/distributed_wato.mk",
                excludes=[".*new*"],
            ),
            ReplicationPath(
                ty="dir",
                ident="omd",
                site_path="etc/omd",
                excludes=["allocated_ports", "site.conf", ".*new*"],
            ),
        ]

    assert sorted(
        activate_changes._get_replication_components(
            partial_site_config, is_pre_17_remote_site)) == sorted(expected)
Exemplo n.º 12
0
def _expected_replication_paths():
    expected = [
        ReplicationPath('dir', 'check_mk', 'etc/check_mk/conf.d/wato/', []),
        ReplicationPath('dir', 'multisite', 'etc/check_mk/multisite.d/wato/', []),
        ReplicationPath('file', 'htpasswd', 'etc/htpasswd', []),
        ReplicationPath('file', 'auth.secret', 'etc/auth.secret', []),
        ReplicationPath('file', 'auth.serials', 'etc/auth.serials', []),
        ReplicationPath('dir', 'usersettings', 'var/check_mk/web', ['*/report-thumbnails']),
        ReplicationPath('dir', 'mkps', 'var/check_mk/packages', []),
        ReplicationPath('dir', 'local', 'local', []),
    ]

    if not cmk_version.is_raw_edition():
        expected += [
            ReplicationPath('dir', 'liveproxyd', 'etc/check_mk/liveproxyd.d/wato/', []),
        ]

    if testlib.is_enterprise_repo():
        expected += [
            ReplicationPath('dir', 'dcd', 'etc/check_mk/dcd.d/wato/', []),
            ReplicationPath('dir', 'mknotify', 'etc/check_mk/mknotifyd.d/wato', []),
        ]

    expected += [
        ReplicationPath('dir', 'mkeventd', 'etc/check_mk/mkeventd.d/wato', []),
        ReplicationPath('dir', 'mkeventd_mkp', 'etc/check_mk/mkeventd.d/mkp/rule_packs', []),
        ReplicationPath('file', 'diskspace', 'etc/diskspace.conf', []),
    ]

    if cmk_version.is_managed_edition():
        expected += [
            ReplicationPath(ty='file',
                            ident='customer_check_mk',
                            site_path='etc/check_mk/conf.d/customer.mk',
                            excludes=[]),
            ReplicationPath(ty='file',
                            ident='customer_gui_design',
                            site_path='etc/check_mk/multisite.d/zzz_customer_gui_design.mk',
                            excludes=[]),
            ReplicationPath(ty='file',
                            ident='customer_multisite',
                            site_path='etc/check_mk/multisite.d/customer.mk',
                            excludes=[]),
            ReplicationPath(
                ty='file',
                ident='gui_logo',
                site_path='local/share/check_mk/web/htdocs/themes/classic/images/sidebar_top.png',
                excludes=[]),
            ReplicationPath(
                ty='file',
                ident='gui_logo_dark',
                site_path='local/share/check_mk/web/htdocs/themes/modern-dark/images/mk-logo.png',
                excludes=[]),
            ReplicationPath(
                ty='file',
                ident='gui_logo_facelift',
                site_path='local/share/check_mk/web/htdocs/themes/facelift/images/mk-logo.png',
                excludes=[]),
        ]

    return expected
Exemplo n.º 13
0
def _expected_replication_paths():
    expected = [
        ReplicationPath(
            'dir', 'check_mk',
            '%s/etc/check_mk/conf.d/wato/' % cmk.utils.paths.omd_root,
            ['sitespecific.mk']),
        ReplicationPath(
            'dir', 'multisite',
            '%s/etc/check_mk/multisite.d/wato/' % cmk.utils.paths.omd_root,
            ['sitespecific.mk']),
        ReplicationPath('file', 'htpasswd',
                        '%s/etc/htpasswd' % cmk.utils.paths.omd_root, []),
        ReplicationPath('file', 'auth.secret',
                        '%s/etc/auth.secret' % cmk.utils.paths.omd_root, []),
        ReplicationPath('file', 'auth.serials',
                        '%s/etc/auth.serials' % cmk.utils.paths.omd_root, []),
        ReplicationPath('dir', 'usersettings',
                        '%s/var/check_mk/web' % cmk.utils.paths.omd_root,
                        ['*/report-thumbnails']),
        ReplicationPath('dir', 'mkps',
                        '%s/var/check_mk/packages' % cmk.utils.paths.omd_root,
                        []),
        ReplicationPath('dir', 'local', '%s/local' % cmk.utils.paths.omd_root,
                        []),
    ]

    if not cmk_version.is_raw_edition():
        expected += [
            ReplicationPath(
                'dir', 'liveproxyd', '%s/etc/check_mk/liveproxyd.d/wato/' %
                cmk.utils.paths.omd_root, ['sitespecific.mk']),
        ]

    if testlib.is_enterprise_repo():
        expected += [
            ReplicationPath(
                'dir', 'dcd',
                '%s/etc/check_mk/dcd.d/wato/' % cmk.utils.paths.omd_root,
                ['sitespecific.mk', 'distributed.mk']),
            ReplicationPath(
                'dir', 'mknotify',
                '%s/etc/check_mk/mknotifyd.d/wato/' % cmk.utils.paths.omd_root,
                ['sitespecific.mk']),
        ]

    expected += [
        ReplicationPath(
            'dir', 'mkeventd',
            '%s/etc/check_mk/mkeventd.d/wato' % cmk.utils.paths.omd_root,
            ['sitespecific.mk']),
        ReplicationPath(
            'dir', 'mkeventd_mkp',
            '%s/etc/check_mk/mkeventd.d/mkp/rule_packs' %
            cmk.utils.paths.omd_root, []),
        ReplicationPath('file', 'diskspace',
                        '%s/etc/diskspace.conf' % cmk.utils.paths.omd_root,
                        []),
    ]

    return expected