Exemplo n.º 1
0
def package_create(args: List[str]) -> None:
    if len(args) != 1:
        raise PackageException("Usage: check_mk -P create NAME")

    pacname = args[0]
    if read_package_info(pacname):
        raise PackageException("Package %s already existing." % pacname)

    logger.log(VERBOSE, "Creating new package %s...", pacname)
    package = get_initial_package_info(pacname)
    filelists = package["files"]
    num_files = 0
    for part in get_package_parts():
        files = unpackaged_files_in_dir(part.ident, part.path)
        filelists[part.ident] = files
        num_files += len(files)
        if len(files) > 0:
            logger.log(VERBOSE, "  %s%s%s:", tty.bold, part.title, tty.normal)
            for f in files:
                logger.log(VERBOSE, "    %s", f)

    write_package_info(package)
    logger.log(VERBOSE, "New package %s created with %d files.", pacname,
               num_files)
    logger.log(VERBOSE, "Please edit package details in %s%s%s", tty.bold,
               package_dir() / pacname, tty.normal)
Exemplo n.º 2
0
def test_edit_package_rename_conflict():
    new_package_info = packaging.get_initial_package_info("bbb")
    _create_simple_test_package("aaa")
    _create_simple_test_package("bbb")

    with pytest.raises(packaging.PackageException):
        packaging.edit_package("aaa", new_package_info)
Exemplo n.º 3
0
def test_reload_gui_with_web_part(reload_apache, build_setup_search_index) -> None:
    package = packaging.get_initial_package_info("ding")
    package["files"] = {"web": ["a"]}

    packaging._execute_post_package_change_actions(package)
    build_setup_search_index.assert_called_once()
    reload_apache.assert_called_once()
Exemplo n.º 4
0
def test_edit_package_rename():
    new_package_info = packaging.get_initial_package_info("bbb")

    _create_simple_test_package("aaa")

    packaging.edit_package("aaa", new_package_info)

    assert packaging.read_package_info("bbb")["name"] == "bbb"
    assert packaging.read_package_info("aaa") is None
Exemplo n.º 5
0
def test_edit_package():
    new_package_info = packaging.get_initial_package_info("aaa")
    new_package_info["version"] = "2.0"

    package_info = _create_simple_test_package("aaa")
    assert package_info["version"] == "1.0"

    packaging.edit_package("aaa", new_package_info)

    assert packaging.read_package_info("aaa")["version"] == "2.0"
Exemplo n.º 6
0
def _create_simple_test_package(pacname):
    _create_test_file(pacname)
    package_info = packaging.get_initial_package_info(pacname)

    package_info["files"] = {
        "checks": [pacname],
    }

    packaging.create_package(package_info)
    return packaging.read_package_info("aaa")
Exemplo n.º 7
0
    def create_test_package(name):
        check_dir.mkdir(parents=True, exist_ok=True)

        with check_dir.joinpath(name).open("w", encoding="utf-8") as f:
            f.write("test-check\n")

        package_info = packaging.get_initial_package_info(name)
        package_info["files"] = {
            "checks": [name],
        }

        packaging.create(package_info)
Exemplo n.º 8
0
def test_parse_package_info():
    info_str = repr(packaging.get_initial_package_info("pkgname"))
    assert packaging.parse_package_info(info_str)["name"] == "pkgname"
Exemplo n.º 9
0
def test_edit_package_not_existing():
    new_package_info = packaging.get_initial_package_info("aaa")
    new_package_info["version"] = "2.0"

    with pytest.raises(packaging.PackageException):
        packaging.edit_package("aaa", new_package_info)
Exemplo n.º 10
0
def test_reload_gui_without_gui_files(reload_apache,
                                      build_setup_search_index) -> None:
    package = packaging.get_initial_package_info("ding")
    packaging._execute_post_package_change_actions(package)
    build_setup_search_index.assert_called_once()
    reload_apache.assert_not_called()