Example #1
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"])
Example #2
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"])
Example #3
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"])
Example #4
0
def test_apply_pre_17_sync_snapshot(
    edition: cmk_version.Edition,
    monkeypatch,
    tmp_path,
    with_user_login,
    remote_site,
):
    snapshot_data_collector_class = ("CMESnapshotDataCollector"
                                     if edition is cmk_version.Edition.CME else
                                     "CRESnapshotDataCollector")

    is_pre_17_site = True
    monkeypatch.setattr(cmk_version, "is_raw_edition",
                        lambda: edition is cmk_version.Edition.CRE)
    monkeypatch.setattr(cmk_version, "is_managed_edition",
                        lambda: edition is cmk_version.Edition.CME)
    monkeypatch.setattr(utils, "is_pre_17_remote_site",
                        lambda s: is_pre_17_site)

    activation_manager = _get_activation_manager(monkeypatch, remote_site)
    snapshot_settings = _create_sync_snapshot(
        activation_manager,
        snapshot_data_collector_class,
        monkeypatch,
        tmp_path,
        is_pre_17_site=is_pre_17_site,
        remote_site=remote_site,
        edition=edition,
    )

    # Change unpack target directory from "unit test site" paths to a test specific path
    unpack_dir = tmp_path / "snapshot_unpack"
    if unpack_dir.exists():
        shutil.rmtree(str(unpack_dir))

    with open(snapshot_settings.snapshot_path, "rb") as f:
        activate_changes.apply_pre_17_sync_snapshot(
            remote_site, f.read(), unpack_dir,
            activate_changes.get_replication_paths())

    expected_paths = _get_expected_paths(
        user_id=with_user_login,
        is_pre_17_site=is_pre_17_site,
        with_local=config.sites[remote_site].get("replicate_mkps", False),
    )

    if cmk_version.is_managed_edition():
        expected_paths += [
            "etc/check_mk/dcd.d",
            "etc/check_mk/dcd.d/wato",
            "etc/check_mk/liveproxyd.d",
            "etc/check_mk/liveproxyd.d/wato",
            "etc/check_mk/mknotifyd.d",
            "etc/check_mk/mknotifyd.d/wato",
            "etc/check_mk/mkeventd.d/mkp",
            "etc/check_mk/mkeventd.d/mkp/rule_packs",
        ]

    paths = [str(p.relative_to(unpack_dir)) for p in unpack_dir.glob("**/*")]
    assert sorted(paths) == sorted(expected_paths)
Example #5
0
def test_get_replication_paths_defaults(edition, monkeypatch):
    expected = _expected_replication_paths()
    assert sorted(activate_changes.get_replication_paths()) == sorted(expected)
Example #6
0
def test_get_replication_paths_defaults(edition_short, monkeypatch):
    monkeypatch.setattr(cmk_version, "edition_short", lambda: edition_short)
    expected = _expected_replication_paths()
    assert sorted(activate_changes.get_replication_paths()) == sorted(expected)
Example #7
0
def test_apply_sync_snapshot(edition_short, snapshot_manager_class, monkeypatch, tmp_path,
                             with_user):
    user_id = with_user[0]
    monkeypatch.setattr(cmk_version, "edition_short", lambda: edition_short)

    environ = dict(create_environ(), REQUEST_URI='')
    with AppContext(DummyApplication(environ, None)), \
         RequestContext(htmllib.html(Request(environ))):
        login.login(user_id)

        _create_test_sync_config(monkeypatch)
        snapshot_settings = _create_sync_snapshot(snapshot_manager_class, monkeypatch, tmp_path)

        # Change unpack target directory from "unit test site" paths to a test specific path
        unpack_dir = tmp_path / "snapshot_unpack"
        components = [
            activate_changes._replace_omd_root(str(unpack_dir), p)
            for p in activate_changes.get_replication_paths()
        ]

        with open(snapshot_settings.snapshot_path, "rb") as f:
            activate_changes.apply_sync_snapshot("unit_remote_1", f.read(), components)

    expected_paths = [
        'etc',
        'var',
        'etc/check_mk',
        'etc/check_mk/conf.d',
        'etc/check_mk/mkeventd.d',
        'etc/check_mk/multisite.d',
        'etc/check_mk/conf.d/wato',
        'etc/check_mk/conf.d/wato/hosts.mk',
        'etc/check_mk/conf.d/wato/contacts.mk',
        'etc/check_mk/mkeventd.d/mkp',
        'etc/check_mk/mkeventd.d/wato',
        'etc/check_mk/mkeventd.d/mkp/rule_packs',
        'etc/check_mk/multisite.d/wato',
        'etc/check_mk/multisite.d/wato/global.mk',
        'var/check_mk',
        'var/check_mk/web',
        "etc/htpasswd",
        "etc/auth.serials",
        "etc/check_mk/multisite.d/wato/users.mk",
        six.ensure_str('var/check_mk/web/%s' % user_id),
        six.ensure_str('var/check_mk/web/%s/cached_profile.mk' % user_id),
        six.ensure_str('var/check_mk/web/%s/enforce_pw_change.mk' % user_id),
        six.ensure_str('var/check_mk/web/%s/last_pw_change.mk' % user_id),
        six.ensure_str('var/check_mk/web/%s/num_failed_logins.mk' % user_id),
        six.ensure_str('var/check_mk/web/%s/serial.mk' % user_id),
    ]

    # The paths are registered once the enterprise plugins are available, independent of the
    # cmk_version.edition_short() value.
    if is_enterprise_repo():
        expected_paths += [
            'etc/check_mk/dcd.d',
            'etc/check_mk/mknotifyd.d',
            'etc/check_mk/mknotifyd.d/wato',
            'etc/check_mk/dcd.d/wato',
        ]

    # TODO: Shouldn't we clean up these subtle differences?
    if cmk_version.is_managed_edition():
        expected_paths += [
            "etc/check_mk/conf.d/wato/groups.mk",
            "etc/check_mk/mkeventd.d/wato/rules.mk",
            "etc/check_mk/multisite.d/wato/bi.mk",
            "etc/check_mk/multisite.d/wato/customers.mk",
            "etc/check_mk/multisite.d/wato/groups.mk",
            "etc/check_mk/multisite.d/wato/user_connections.mk",
            #"etc/check_mk/conf.d/wato/sitespecific.mk",
            #"etc/check_mk/dcd.d/wato/distributed.mk",
            #"etc/check_mk/dcd.d/wato/sitespecific.mk",
            #"etc/check_mk/mkeventd.d/wato/sitespecific.mk",
            #"etc/check_mk/mknotifyd.d/wato/sitespecific.mk",
            #"etc/check_mk/multisite.d/wato/sitespecific.mk",
        ]

        expected_paths.remove("etc/check_mk/conf.d/wato/hosts.mk")

    if not cmk_version.is_raw_edition():
        expected_paths += [
            'etc/check_mk/liveproxyd.d',
            'etc/check_mk/liveproxyd.d/wato',
            #'etc/check_mk/multisite.d/wato/ca-certificates_sitespecific.mk',
        ]

    paths = [str(p.relative_to(unpack_dir)) for p in unpack_dir.glob("**/*")]
    assert sorted(paths) == sorted(expected_paths)