コード例 #1
0
def package_pack(args: List[str]) -> None:
    if len(args) != 1:
        raise PackageException("Usage: check_mk -P pack NAME")

    # Make sure, user is not in data directories of Checkmk
    abs_curdir = os.path.abspath(os.curdir)
    for directory in [cmk.utils.paths.var_dir] + [
            p.path for p in get_package_parts() + get_config_parts()
    ]:
        if abs_curdir == directory or abs_curdir.startswith(directory + "/"):
            raise PackageException(
                "You are in %s!\n"
                "Please leave the directories of Check_MK before creating\n"
                "a packet file. Foreign files lying around here will mix up things."
                % abs_curdir)

    pacname = args[0]
    package = read_package_info(pacname)
    if not package:
        raise PackageException("Package %s not existing or corrupt." % pacname)
    tarfilename = packaging.format_file_name(name=pacname,
                                             version=package["version"])

    logger.log(VERBOSE, "Packing %s into %s...", pacname, tarfilename)
    with Path(tarfilename).open("wb") as f:
        packaging.write_file(package, cast(BinaryIO, f))
    logger.log(VERBOSE, "Successfully created %s", tarfilename)
コード例 #2
0
def fixture_mkp_bytes():
    # Create package information
    _create_simple_test_package("aaa")
    package_info = _read_package_info("aaa")

    # Build MKP in memory
    mkp = BytesIO()
    packaging.write_file(package_info, mkp)
    mkp.seek(0)

    # Remove files from local hierarchy
    packaging.remove(package_info)
    assert packaging._package_exists("aaa") is False

    return mkp
コード例 #3
0
def test_get_optional_package_infos(monkeypatch, tmp_path):
    mkp_dir = tmp_path.joinpath("optional_packages")
    mkp_dir.mkdir(parents=True, exist_ok=True)
    monkeypatch.setattr(cmk.utils.paths, "optional_packages_dir", mkp_dir)

    # Create package
    _create_simple_test_package("optional")
    package_info = _read_package_info("optional")

    # Write MKP file
    mkp_path = mkp_dir.joinpath("optional.mkp")
    with mkp_path.open("wb") as mkp:
        packaging.write_file(package_info, mkp)

    assert packaging.get_optional_package_infos() == {"optional.mkp": package_info}
コード例 #4
0
ファイル: test_packaging.py プロジェクト: Yogibaer75/checkmk
def fixture_mkp_bytes(build_setup_search_index):
    # Create package information
    _create_simple_test_package("aaa")
    package_info = _read_package_info("aaa")

    # Build MKP in memory
    mkp = BytesIO()
    packaging.write_file(package_info, mkp)
    mkp.seek(0)

    # Remove files from local hierarchy
    packaging.remove(package_info)
    build_setup_search_index.assert_called_once()
    build_setup_search_index.reset_mock()
    assert packaging._package_exists("aaa") is False

    return mkp
コード例 #5
0
def test_write_file():
    package_info = _create_simple_test_package("aaa")

    mkp = BytesIO()
    packaging.write_file(package_info, mkp)
    mkp.seek(0)

    tar = tarfile.open(fileobj=mkp, mode="r:gz")
    assert sorted(tar.getnames()) == sorted(["info", "info.json", "checks.tar"])

    info_file = tar.extractfile("info")
    assert info_file is not None
    info = ast.literal_eval(info_file.read().decode())
    assert info["name"] == "aaa"

    info_json_file = tar.extractfile("info.json")
    assert info_json_file is not None
    info2 = json.loads(info_json_file.read())
    assert info2["name"] == "aaa"
コード例 #6
0
    "version.packaged":
    cmk_version.__version__,
    "version.min_required":
    cmk_version.__version__,
    "version.usable_until":
    None,
    "author":
    "tribe29 GmbH",
    "download_url":
    "https://checkmk.com/",
    "files": {
        "web": [
            ntop_file.replace(ENTERPRISE_PREFIX, "")
            for ntop_file in MKP_ABLE_NTOP_FILES
        ]
    },
    "git_hash_short":
    GIT_HASH_SHORT,
}

TARFILENAME = packaging.format_file_name(name="ntop",
                                         version=NTOP_PACKAGE_INFO["version"])

with Path(TARFILENAME).open("wb") as f:
    packaging.write_file(
        NTOP_PACKAGE_INFO,
        cast(BinaryIO, f),
        package_parts=packaging.get_repo_ntop_parts,
        config_parts=lambda: [],
    )