Trash legacy packaging v1 stuff

This commit is contained in:
Alexandre Aubin 2024-08-16 15:38:13 +02:00
parent 127ffc18f3
commit b3fe86ea96
5 changed files with 8 additions and 201 deletions

View file

@ -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]: 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: app_name = manifest["id"]
questions = {q["name"]: q for q in manifest["arguments"]["install"]} questions = manifest["install"]
else:
questions = manifest["install"]
args = { args = {
name: get_default_value(app_name, name, question, raise_if_no_default) name: get_default_value(app_name, name, question, raise_if_no_default)

View file

@ -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() { guess_test_configuration() {
log_error "No tests.toml file found." log_error "No tests.toml file found."

View file

@ -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]]: def build_test_list(basedir: Path) -> dict[str, dict[str, Any]]:
test_manifest = toml.load((basedir / "tests.toml").open("r")) test_manifest = toml.load((basedir / "tests.toml").open("r"))
if (basedir / "manifest.json").exists(): manifest = toml.load((basedir / "manifest.toml").open("r"))
manifest = json.load((basedir / "manifest.json").open("r")) is_multi_instance = manifest.get("integration").get("multi_instance") is True
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
is_webapp = os.system(f"grep -q '^ynh_add_nginx_config\|^ynh_nginx_add_config' '{str(basedir)}/scripts/install'") == 0 is_webapp = os.system(f"grep -q '^ynh_add_nginx_config\|^ynh_nginx_add_config' '{str(basedir)}/scripts/install'") == 0

View file

@ -123,12 +123,6 @@ _INSTALL_APP () {
key="$(echo $arg_override | cut -d '=' -f 1)" key="$(echo $arg_override | cut -d '=' -f 1)"
value="$(echo $arg_override | cut -d '=' -f 2-)" 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\&@") install_args=$(echo $install_args | sed "s@\&$key=[^&]*\&@\&$key=$value\&@")
if ! echo $install_args | grep -q $key; then if ! echo $install_args | grep -q $key; then
install_args+="$key=$value&" 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 # because this also applies to upgrades ... ie older version may have different args and default values
# Fetch and loop over all manifest arg # Fetch and loop over all manifest arg
if [[ -e $package_path/manifest.json ]] local manifest_args="$(grep -oE '^\s*\[install\.\w+]' $package_path/manifest.toml | tr -d '[]' | awk -F. '{print $2}')"
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
for ARG in $manifest_args for ARG in $manifest_args
do do
# If the argument is not yet in install args, add its default value # If the argument is not yet in install args, add its default value
if ! echo "$install_args" | grep -q -E "\<$ARG=" if ! echo "$install_args" | grep -q -E "\<$ARG="
then then
if [[ -e $package_path/manifest.json ]] 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)
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
[[ $? -eq 0 ]] || { log_error "Missing install arg $ARG ?"; return 1; } [[ $? -eq 0 ]] || { log_error "Missing install arg $ARG ?"; return 1; }
[[ ${install_args: -1} == '&' ]] || install_args+="&" [[ ${install_args: -1} == '&' ]] || install_args+="&"
install_args+="$ARG=$default_value" install_args+="$ARG=$default_value"

View file

@ -27,24 +27,14 @@ run_all_tests() {
mkdir -p $TEST_CONTEXT/results mkdir -p $TEST_CONTEXT/results
mkdir -p $TEST_CONTEXT/logs mkdir -p $TEST_CONTEXT/logs
if [ -e $package_path/manifest.json ] readonly app_id="$(grep '^id = ' $package_path/manifest.toml | tr -d '" ' | awk -F= '{print $2}')"
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
tests_toml="$package_path/tests.toml" tests_toml="$package_path/tests.toml"
if [ -e "$tests_toml" ] if [ -e "$tests_toml" ]
then then
DIST=$DIST "./lib/parse_tests_toml.py" "$package_path" --dump-to "$TEST_CONTEXT/tests" DIST=$DIST "./lib/parse_tests_toml.py" "$package_path" --dump-to "$TEST_CONTEXT/tests"
else else
# Parse the check_process only if it's exist guess_test_configuration
check_process="$package_path/check_process"
[ -e "$check_process" ] \
&& parse_check_process \
|| guess_test_configuration
fi fi
# Start the timer for this test # Start the timer for this test