From b3fe86ea965e591aa4949d2bfd0ad592f0e67931 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 16 Aug 2024 15:38:13 +0200 Subject: [PATCH] Trash legacy packaging v1 stuff --- lib/default_install_args.py | 7 +- lib/legacy.sh | 160 ------------------------------------ lib/parse_tests_toml.py | 8 +- lib/tests.sh | 20 +---- lib/tests_coordination.sh | 14 +--- 5 files changed, 8 insertions(+), 201 deletions(-) diff --git a/lib/default_install_args.py b/lib/default_install_args.py index 84daf69..3b15672 100755 --- a/lib/default_install_args.py +++ b/lib/default_install_args.py @@ -43,12 +43,9 @@ def get_default_value(app_name: str, name: str, question: dict, raise_if_no_defa def get_default_values_for_questions(manifest: dict, raise_if_no_default=True) -> dict[str, str]: - app_name = manifest["id"] - if manifest.get("packaging_format", 1) <= 1: - questions = {q["name"]: q for q in manifest["arguments"]["install"]} - else: - questions = manifest["install"] + app_name = manifest["id"] + questions = manifest["install"] args = { name: get_default_value(app_name, name, question, raise_if_no_default) diff --git a/lib/legacy.sh b/lib/legacy.sh index e3ca680..7abe65d 100644 --- a/lib/legacy.sh +++ b/lib/legacy.sh @@ -1,163 +1,3 @@ -#======================================================================= -# Parse the check_process and generate jsons that describe tests to run -#======================================================================= - -# Extract a section found between $1 and $2 from the file $3 -extract_check_process_section () { - local source_file="${3:-$check_process}" - local extract=0 - local line="" - while read line - do - # Extract the line - if [ $extract -eq 1 ] - then - # Check if the line is the second line to found - if echo $line | grep -q "$2"; then - # Break the loop to finish the extract process - break; - fi - # Copy the line in the partial check_process - echo "$line" - fi - - # Search for the first line - if echo $line | grep -q "$1"; then - # Activate the extract process - extract=1 - fi - done < "$source_file" -} - - -parse_check_process() { - - log_info "Parsing check_process file" - - # Remove all commented lines in the check_process - sed --in-place '/^#/d' "$check_process" - # Remove all spaces at the beginning of the lines - sed --in-place 's/^[ \t]*//g' "$check_process" - - # Extract the Upgrade infos - extract_check_process_section "^;;; Upgrade options" ";; " > $TEST_CONTEXT/check_process.upgrade_options - mkdir -p $TEST_CONTEXT/upgrades - local commit - for commit in $(cat $TEST_CONTEXT/check_process.upgrade_options | grep "^; commit=.*" | awk -F= '{print $2}') - do - cat $TEST_CONTEXT/check_process.upgrade_options | sed -n -e "/^; commit=$commit/,/^;/ p" | grep -v "^;;" > $TEST_CONTEXT/upgrades/$commit - done - rm $TEST_CONTEXT/check_process.upgrade_options - - local test_serie_id="0" - - # Parse each tests serie - while read <&3 tests_serie - do - test_serie_id=$((test_serie_id+1)) - local test_id=$((test_serie_id * 100)) - local test_serie_rawconf=$TEST_CONTEXT/raw_test_serie_config - - # Extract the section of the current tests serie - extract_check_process_section "^$tests_serie" "^;;" > $test_serie_rawconf - # This is the arg list to be later fed to "yunohost app install" - # Looking like domain=foo.com&path=/bar&password=stuff - # "Standard" arguments like domain/path will later be overwritten - # during tests - local install_args=$( extract_check_process_section "^; Manifest" "^; " $test_serie_rawconf | sed 's/\s*(.*)$//g' | tr -d '"' | tr '\n' '&') - local preinstall_template=$(extract_check_process_section "^; pre-install" "^; " $test_serie_rawconf) - local preupgrade_template=$(extract_check_process_section "^; pre-upgrade" "^; " $test_serie_rawconf) - - # Add (empty) special args if they ain't provided in check_process - echo "$install_args" | tr '&' '\n' | grep -q "^domain=" ||install_args+="domain=&" - echo "$install_args" | tr '&' '\n' | grep -q "^path=" ||install_args+="path=&" - echo "$install_args" | tr '&' '\n' | grep -q "^admin=" ||install_args+="admin=&" - echo "$install_args" | tr '&' '\n' | grep -q "^is_public=" ||install_args+="is_public=&" - echo "$install_args" | tr '&' '\n' | grep -q "^init_main_permission=" ||install_args+="init_main_permission=&" - - extract_check_process_section "^; Checks" "^; " $test_serie_rawconf > $TEST_CONTEXT/check_process.tests_infos - - is_test_enabled () { - # Find the line for the given check option - local value=$(grep -m1 -o "^$1=." "$TEST_CONTEXT/check_process.tests_infos" | awk -F= '{print $2}') - # And return this value - [ "${value:0:1}" = "1" ] - } - - add_test() { - local test_type="$1" - local test_arg="$2" - test_id="$((test_id+1))" - local extra="{}" - local _install_args="$install_args" - - # Upgrades with a specific commit - if [[ "$test_type" == "TEST_UPGRADE" ]] && [[ -n "$test_arg" ]] - then - if [ -f "$TEST_CONTEXT/upgrades/$test_arg" ]; then - local specific_upgrade_install_args="$(grep "^manifest_arg=" "$TEST_CONTEXT/upgrades/$test_arg" | cut -d'=' -f2-)" - [[ -n "$specific_upgrade_install_args" ]] && _install_args="$specific_upgrade_install_args" - - local upgrade_name="$(grep "^name=" "$TEST_CONTEXT/upgrades/$test_arg" | cut -d'=' -f2)" - else - local upgrade_name="$test_arg" - fi - extra="$(jq -n --arg upgrade_name "$upgrade_name" '{ $upgrade_name }')" - fi - - jq -n \ - --arg test_serie "$test_serie" \ - --arg test_type "$test_type" \ - --arg test_arg "$test_arg" \ - --arg preinstall_template "$preinstall_template" \ - --arg preupgrade_template "$preupgrade_template" \ - --arg install_args "${_install_args//\"}" \ - --argjson extra "$extra" \ - '{ $test_serie, $test_type, $test_arg, $preinstall_template, $preupgrade_template, $install_args, $extra }' \ - > "$TEST_CONTEXT/tests/$test_id.json" - } - - test_serie=${tests_serie//;; } - - is_test_enabled pkg_linter && add_test "TEST_PACKAGE_LINTER" - is_test_enabled setup_root && add_test "TEST_INSTALL" "root" - is_test_enabled setup_sub_dir && add_test "TEST_INSTALL" "subdir" - is_test_enabled setup_nourl && add_test "TEST_INSTALL" "nourl" - if [[ $DIST == "bullseye" ]] - then - # Testing private vs. public install doesnt make that much sense, remote it for bookworm etc... - is_test_enabled setup_private && add_test "TEST_INSTALL" "private" - fi - is_test_enabled multi_instance && add_test "TEST_INSTALL" "multi" - is_test_enabled backup_restore && add_test "TEST_BACKUP_RESTORE" - - # Upgrades - while IFS= read -r LINE; - do - commit="$(echo $LINE | grep -o "from_commit=.*" | awk -F= '{print $2}')" - add_test "TEST_UPGRADE" "$commit" - done < <(grep "^upgrade=1" "$TEST_CONTEXT/check_process.tests_infos") - - # "Advanced" features - - is_test_enabled change_url && add_test "TEST_CHANGE_URL" - - # Port already used ... do we really need this ... - - if grep -q -m1 "port_already_use=1" "$TEST_CONTEXT/check_process.tests_infos" - then - local check_port=$(grep -m1 "port_already_use=1" "$TEST_CONTEXT/check_process.tests_infos" | grep -o -E "\([0-9]+\)" | tr -d '()') - else - local check_port=6660 - fi - - is_test_enabled port_already_use && add_test "TEST_PORT_ALREADY_USED" "$check_port" - - done 3<<< "$(grep "^;; " "$check_process")" - - return 0 -} - guess_test_configuration() { log_error "No tests.toml file found." diff --git a/lib/parse_tests_toml.py b/lib/parse_tests_toml.py index ce699a8..86e0c02 100755 --- a/lib/parse_tests_toml.py +++ b/lib/parse_tests_toml.py @@ -139,12 +139,8 @@ def dump_for_package_check(test_list: dict[str, dict[str, Any]], package_check_t def build_test_list(basedir: Path) -> dict[str, dict[str, Any]]: test_manifest = toml.load((basedir / "tests.toml").open("r")) - if (basedir / "manifest.json").exists(): - manifest = json.load((basedir / "manifest.json").open("r")) - is_multi_instance = manifest.get("multi_instance") is True - else: - manifest = toml.load((basedir / "manifest.toml").open("r")) - is_multi_instance = manifest.get("integration").get("multi_instance") is True + manifest = toml.load((basedir / "manifest.toml").open("r")) + is_multi_instance = manifest.get("integration").get("multi_instance") is True is_webapp = os.system(f"grep -q '^ynh_add_nginx_config\|^ynh_nginx_add_config' '{str(basedir)}/scripts/install'") == 0 diff --git a/lib/tests.sh b/lib/tests.sh index 1e22bf5..54963f8 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -123,12 +123,6 @@ _INSTALL_APP () { key="$(echo $arg_override | cut -d '=' -f 1)" value="$(echo $arg_override | cut -d '=' -f 2-)" - # (Legacy stuff ... We don't override is_public if its type is not boolean) - [[ -e $package_path/manifest.json ]] \ - && [[ "$key" == "is_public" ]] \ - && [[ "$(jq -r '.arguments.install[] | select(.name=="is_public") | .type' $package_path/manifest.json)" != "boolean" ]] \ - && continue - install_args=$(echo $install_args | sed "s@\&$key=[^&]*\&@\&$key=$value\&@") if ! echo $install_args | grep -q $key; then install_args+="$key=$value&" @@ -139,24 +133,14 @@ _INSTALL_APP () { # because this also applies to upgrades ... ie older version may have different args and default values # Fetch and loop over all manifest arg - if [[ -e $package_path/manifest.json ]] - then - local manifest_args="$(jq -r '.arguments.install[].name' $package_path/manifest.json)" - else - local manifest_args="$(grep -oE '^\s*\[install\.\w+]' $package_path/manifest.toml | tr -d '[]' | awk -F. '{print $2}')" - fi + local manifest_args="$(grep -oE '^\s*\[install\.\w+]' $package_path/manifest.toml | tr -d '[]' | awk -F. '{print $2}')" for ARG in $manifest_args do # If the argument is not yet in install args, add its default value if ! echo "$install_args" | grep -q -E "\<$ARG=" then - if [[ -e $package_path/manifest.json ]] - then - local default_value=$(jq -e -r --arg ARG $ARG '.arguments.install[] | select(.name==$ARG) | .default' $package_path/manifest.json) - else - local default_value=$(python3 -c "import toml, sys; t = toml.loads(sys.stdin.read()); d = t['install']['$ARG'].get('default'); assert d is not None, 'Missing default value'; print(d)" < $package_path/manifest.toml) - fi + local default_value=$(python3 -c "import toml, sys; t = toml.loads(sys.stdin.read()); d = t['install']['$ARG'].get('default'); assert d is not None, 'Missing default value'; print(d)" < $package_path/manifest.toml) [[ $? -eq 0 ]] || { log_error "Missing install arg $ARG ?"; return 1; } [[ ${install_args: -1} == '&' ]] || install_args+="&" install_args+="$ARG=$default_value" diff --git a/lib/tests_coordination.sh b/lib/tests_coordination.sh index 3f06d63..38f5176 100644 --- a/lib/tests_coordination.sh +++ b/lib/tests_coordination.sh @@ -27,24 +27,14 @@ run_all_tests() { mkdir -p $TEST_CONTEXT/results mkdir -p $TEST_CONTEXT/logs - if [ -e $package_path/manifest.json ] - then - readonly app_id="$(jq -r .id $package_path/manifest.json)" - else - readonly app_id="$(grep '^id = ' $package_path/manifest.toml | tr -d '" ' | awk -F= '{print $2}')" - fi + readonly app_id="$(grep '^id = ' $package_path/manifest.toml | tr -d '" ' | awk -F= '{print $2}')" tests_toml="$package_path/tests.toml" if [ -e "$tests_toml" ] then DIST=$DIST "./lib/parse_tests_toml.py" "$package_path" --dump-to "$TEST_CONTEXT/tests" else - # Parse the check_process only if it's exist - check_process="$package_path/check_process" - - [ -e "$check_process" ] \ - && parse_check_process \ - || guess_test_configuration + guess_test_configuration fi # Start the timer for this test