mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
commit
06745d3865
3 changed files with 100 additions and 44 deletions
97
README.md
97
README.md
|
@ -3,11 +3,12 @@ Package checker for YunoHost
|
||||||
|
|
||||||
[YunoHost project](https://yunohost.org/#/)
|
[YunoHost project](https://yunohost.org/#/)
|
||||||
|
|
||||||
Set of unit tests to check YunoHost packages.
|
Set of unit tests to check YunoHost packages.
|
||||||
The `package_check.sh` script perform a series of tests on a package for verify its capability to be installed and removed in different situation.
|
The `package_check.sh` script perform a series of tests on a package for verify its capability to be installed and removed in different situation.
|
||||||
The test results are printed directly in the terminal and stored in the log file Test_results.log
|
The test results are printed directly in the terminal and stored in the log file Test_results.log
|
||||||
|
|
||||||
The script is able to perform the following tests:
|
The script is able to perform the following tests:
|
||||||
|
|
||||||
- [Linter](https://github.com/YunoHost/package_linter)
|
- [Linter](https://github.com/YunoHost/package_linter)
|
||||||
- Install/remove/reinstall at the root of a domain (`domain.tld/`)
|
- Install/remove/reinstall at the root of a domain (`domain.tld/`)
|
||||||
- Install/remove/reinstall in a subpath (`domain.tld/foobar`)
|
- Install/remove/reinstall in a subpath (`domain.tld/foobar`)
|
||||||
|
@ -22,20 +23,20 @@ The script is able to perform the following tests:
|
||||||
|
|
||||||
Package_check script uses a LXC container to manipulate the package in a clean environment without any previous installations.
|
Package_check script uses a LXC container to manipulate the package in a clean environment without any previous installations.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
For a package in a directory: `./package_check.sh APP_ynh`
|
For a package in a directory: `./package_check.sh APP_ynh`
|
||||||
For a package on GitHub: `./package_check.sh https://github.com/YunoHost-Apps/APP_ynh`
|
For a package on GitHub: `./package_check.sh https://github.com/YunoHost-Apps/APP_ynh`
|
||||||
|
|
||||||
You need to provide, at the root of the package, a `check_process` file to help the script to test the package with the correct arguments.
|
You need to provide, at the root of the package, a `check_process` file to help the script to test the package with the correct arguments.
|
||||||
If this file is not present, package_check will be used in downgraded mode. It will try to retrieve domain, path and admin user arguments in the manifest and execute some tests, based on the arguments it can find.
|
If this file is not present, package_check will be used in downgraded mode. It will try to retrieve domain, path and admin user arguments in the manifest and execute some tests, based on the arguments it can find.
|
||||||
|
|
||||||
## Deploying package_check
|
## Deploying package_check
|
||||||
|
|
||||||
First you need to install the system dependencies.
|
First you need to install the system dependencies.
|
||||||
|
|
||||||
Package check is based on the LXD/LXC ecosystem. Be careful that
|
Package check is based on the LXD/LXC ecosystem. Be careful that
|
||||||
**LXD can conflict with other installed virtualization technologies such as
|
**LXD can conflict with other installed virtualization technologies such as
|
||||||
libvirt or vanilla LXCs**, especially because they all require a daemon based
|
libvirt or vanilla LXCs**, especially because they all require a daemon based
|
||||||
on DNSmasq which may list on port 53.
|
on DNSmasq which may list on port 53.
|
||||||
|
|
||||||
On a Debian-based system (regular Debian, Ubuntu, Mint ...), LXD can be
|
On a Debian-based system (regular Debian, Ubuntu, Mint ...), LXD can be
|
||||||
|
@ -64,10 +65,11 @@ to propagate (sigh))
|
||||||
Then you shall initialize LXD which will ask you a bunch of question. Usually
|
Then you shall initialize LXD which will ask you a bunch of question. Usually
|
||||||
answering the default (just pressing enter) to all questions is fine. Just pay
|
answering the default (just pressing enter) to all questions is fine. Just pay
|
||||||
attention to :
|
attention to :
|
||||||
- the storage backend driver. Possibly `zfs` is the best, but requires a kernel >= 5.x
|
|
||||||
and corresponding kernel module loaded. You can fallback to the `dir` driver.
|
- the storage backend driver. Possibly `zfs` is the best, but requires a kernel >= 5.x
|
||||||
|
and corresponding kernel module loaded. You can fallback to the `dir` driver.
|
||||||
- the size of the default storage it'll create (the default is 5G but you may
|
- the size of the default storage it'll create (the default is 5G but you may
|
||||||
want 10G for heavy usage ?) (if you're using the 'dir' driver, this won't be asked)
|
want 10G for heavy usage ?) (if you're using the 'dir' driver, this won't be asked)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxd init
|
lxd init
|
||||||
|
@ -81,14 +83,14 @@ lxc remote add yunohost https://devbaseimgs.yunohost.org --public
|
||||||
|
|
||||||
(At the time this README is written, fingerprint is d9ae6e76c374e3c58c3c20a881cffe7435809adb3b222ec393805f5bd01bb522 )
|
(At the time this README is written, fingerprint is d9ae6e76c374e3c58c3c20a881cffe7435809adb3b222ec393805f5bd01bb522 )
|
||||||
|
|
||||||
Then you can install package check :
|
Then you can install package check :
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://github.com/YunoHost/package_check
|
git clone https://github.com/YunoHost/package_check
|
||||||
cd package_check
|
cd package_check
|
||||||
```
|
```
|
||||||
|
|
||||||
Then test your packages :
|
Then test your packages :
|
||||||
|
|
||||||
```
|
```
|
||||||
./package_check.sh your_app_ynh
|
./package_check.sh your_app_ynh
|
||||||
|
@ -109,6 +111,7 @@ lxc image export images:debian/buster/armhf
|
||||||
```
|
```
|
||||||
|
|
||||||
This command will create two files.
|
This command will create two files.
|
||||||
|
|
||||||
- rootfs.squashfs
|
- rootfs.squashfs
|
||||||
- lxd.tar.xz
|
- lxd.tar.xz
|
||||||
|
|
||||||
|
@ -136,17 +139,27 @@ lxc exec inspired-lamprey -- dpkg --print-architecture
|
||||||
If the `build_base_lxc.sh` script detects that you are trying a cross container architecture, it will try to perform this hack
|
If the `build_base_lxc.sh` script detects that you are trying a cross container architecture, it will try to perform this hack
|
||||||
|
|
||||||
## Syntax of `check_process`
|
## Syntax of `check_process`
|
||||||
|
|
||||||
> Except spaces, the syntax of this file must be respected.
|
> Except spaces, the syntax of this file must be respected.
|
||||||
|
|
||||||
```
|
```
|
||||||
;; Default test serie
|
;; Default test serie
|
||||||
# Comment ignored
|
# Comment ignored
|
||||||
; pre-install
|
; pre-install
|
||||||
|
set -euxo pipefail
|
||||||
echo -n "Here your commands to execute in the container"
|
echo -n "Here your commands to execute in the container"
|
||||||
echo ", before each installation of the app."
|
echo ", before each installation of the app."
|
||||||
|
; pre-upgrade
|
||||||
|
set -euxo pipefail
|
||||||
|
if [ "$FROM_COMMIT" == '65c382d138596fcb32b4c97c39398815a1dcd4e8' ]
|
||||||
|
then
|
||||||
|
resolve=127.0.0.1:443:$DOMAIN
|
||||||
|
# Example of request using curl
|
||||||
|
curl -X POST --data '{"some-key": "some-value"}' https://$DOMAIN/$PATH --resolve "$resolve"
|
||||||
|
fi
|
||||||
; Manifest
|
; Manifest
|
||||||
# You need to provide default values for installation parameters ...
|
# You need to provide default values for installation parameters ...
|
||||||
# EXCEPT for special args: domain, path, admin, and is_public
|
# EXCEPT for special args: domain, path, admin, and is_public
|
||||||
# which will be filled automatically during tests
|
# which will be filled automatically during tests
|
||||||
language="fr"
|
language="fr"
|
||||||
password="password"
|
password="password"
|
||||||
|
@ -181,38 +194,46 @@ If the `build_base_lxc.sh` script detects that you are trying a cross container
|
||||||
```
|
```
|
||||||
|
|
||||||
### `;; Default test serie`
|
### `;; Default test serie`
|
||||||
A name for the series of tests to perform.
|
|
||||||
It's possible to create multiple tests series, all with the same syntax.
|
A name for the series of tests to perform.
|
||||||
|
It's possible to create multiple tests series, all with the same syntax.
|
||||||
All different series will be performed sequentially.
|
All different series will be performed sequentially.
|
||||||
|
|
||||||
### `; pre-install`
|
### `; pre-install`
|
||||||
*Optional instruction*
|
|
||||||
If you have to execute a command or a group of commands before the installation. You can use this instruction.
|
_Optional instruction_
|
||||||
|
If you have to execute a command or a group of commands before the installation. You can use this instruction.
|
||||||
All the commands added after the instruction `; pre-install` will be executed in the container before each installation of the app.
|
All the commands added after the instruction `; pre-install` will be executed in the container before each installation of the app.
|
||||||
|
|
||||||
### `; Manifest`
|
### `; Manifest`
|
||||||
List of manifest keys.
|
|
||||||
|
List of manifest keys.
|
||||||
All manifest keys need to be filled to perform the installation.
|
All manifest keys need to be filled to perform the installation.
|
||||||
> The manifest keys already in the file here are simply examples. Check the package manifest.
|
|
||||||
|
> The manifest keys already in the file here are simply examples. Check the package manifest.
|
||||||
|
|
||||||
### `; Actions`
|
### `; Actions`
|
||||||
List of arguments for each action that needs an argument.
|
|
||||||
`action_argument` is the name of the argument, as you can find at the end of [action.arguments.**action_argument**].
|
List of arguments for each action that needs an argument.
|
||||||
|
`action_argument` is the name of the argument, as you can find at the end of [action.arguments.**action_argument**].
|
||||||
`arg1|arg2` are the different arguments to use for the tests. You can have as many arguments as you want, each separated by `|`.
|
`arg1|arg2` are the different arguments to use for the tests. You can have as many arguments as you want, each separated by `|`.
|
||||||
|
|
||||||
*Only `actions.toml` can be tested by package_check, not `actions.json`.*
|
_Only `actions.toml` can be tested by package_check, not `actions.json`._
|
||||||
|
|
||||||
### `; Config_panel`
|
### `; Config_panel`
|
||||||
List of arguments for each config_panel configuration.
|
|
||||||
`main.categorie.config_example` is the complete toml entry for the argument of a configuration.
|
List of arguments for each config_panel configuration.
|
||||||
|
`main.categorie.config_example` is the complete toml entry for the argument of a configuration.
|
||||||
`arg1|arg2` are the different arguments to use for the tests. You can as many arguments as you want, each separated by `|`.
|
`arg1|arg2` are the different arguments to use for the tests. You can as many arguments as you want, each separated by `|`.
|
||||||
|
|
||||||
*Only `config_panel.toml` can be tested by package_check, not `config_panel.json`.*
|
_Only `config_panel.toml` can be tested by package_check, not `config_panel.json`._
|
||||||
|
|
||||||
### `; Checks`
|
### `; Checks`
|
||||||
List of tests to perform.
|
|
||||||
Each test set to 1 will be performed by the script.
|
List of tests to perform.
|
||||||
|
Each test set to 1 will be performed by the script.
|
||||||
If a test is not in the list, it will be ignored. It's similar to set the test at 0.
|
If a test is not in the list, it will be ignored. It's similar to set the test at 0.
|
||||||
|
|
||||||
- `pkg_linter`: Check the package with [package linter](https://github.com/YunoHost/package_linter)
|
- `pkg_linter`: Check the package with [package linter](https://github.com/YunoHost/package_linter)
|
||||||
- `setup_root`: Installation at the root of a domain.
|
- `setup_root`: Installation at the root of a domain.
|
||||||
- `setup_sub_dir`: Installation in a path.
|
- `setup_sub_dir`: Installation in a path.
|
||||||
|
@ -222,23 +243,27 @@ If a test is not in the list, it will be ignored. It's similar to set the test a
|
||||||
- `upgrade from_commit`: Upgrade the package from the specified commit to the latest version.
|
- `upgrade from_commit`: Upgrade the package from the specified commit to the latest version.
|
||||||
- `backup_restore`: Backup then restore.
|
- `backup_restore`: Backup then restore.
|
||||||
- `multi_instance`: Install the application 2 times, to verify its ability to be multi-instanced.
|
- `multi_instance`: Install the application 2 times, to verify its ability to be multi-instanced.
|
||||||
- `port_already_use`: Provoke an error by opening the port before.
|
- `port_already_use`: Provoke an error by opening the port before.
|
||||||
The `port_already_use` test may eventually take as argument the port number.
|
The `port_already_use` test may eventually take as argument the port number.
|
||||||
The port number must be written into parentheses.
|
The port number must be written into parentheses.
|
||||||
- `change_url`: Try to change the url by 6 different ways. Root to path, path to another path and path to root. And the same thing, to another domain.
|
- `change_url`: Try to change the url by 6 different ways. Root to path, path to another path and path to root. And the same thing, to another domain.
|
||||||
- `actions`: All actions available in actions.toml
|
- `actions`: All actions available in actions.toml
|
||||||
- `config_panel`: All configurations available in config_panel.toml
|
- `config_panel`: All configurations available in config_panel.toml
|
||||||
|
|
||||||
### `;;; Upgrade options`
|
### `;;; Upgrade options`
|
||||||
*Optional instruction*
|
|
||||||
For each specified commit for an upgrade, allow to give a name for this version and the manifest parameters which will be used for the preliminary installation.
|
_Optional instruction_
|
||||||
If there's no name specified, the commit will be used.
|
For each specified commit for an upgrade, allow to give a name for this version and the manifest parameters which will be used for the preliminary installation.
|
||||||
And if there's no manifest arguments, the default arguments of the check process will be used.
|
If there's no name specified, the commit will be used.
|
||||||
|
And if there's no manifest arguments, the default arguments of the check process will be used.
|
||||||
|
|
||||||
> 3 variables have to be used for the arguments of the manifest, DOMAIN, PATH and USER.
|
> 3 variables have to be used for the arguments of the manifest, DOMAIN, PATH and USER.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
The `package_check.sh` script accept 6 arguments in addition of the package to be checked.
|
The `package_check.sh` script accept 6 arguments in addition of the package to be checked.
|
||||||
|
|
||||||
- `--branch=branch-name`: Check a branch of the repository instead of master. Allow to check a pull request.
|
- `--branch=branch-name`: Check a branch of the repository instead of master. Allow to check a pull request.
|
||||||
You can use an url with a branch, https://github.com/YunoHost-Apps/APP_ynh/tree/my_branch, to implicitly use this argument.
|
You can use an url with a branch, https://github.com/YunoHost-Apps/APP_ynh/tree/my_branch, to implicitly use this argument.
|
||||||
- `--interactive`: Wait for user input between each tests
|
- `--interactive`: Wait for user input between each tests
|
||||||
- `--help`: Display help.
|
- `--help`: Display help.
|
||||||
|
|
43
lib/tests.sh
43
lib/tests.sh
|
@ -32,10 +32,10 @@ _PREINSTALL () {
|
||||||
local preinstall_script="$TEST_CONTEXT/preinstall.sh"
|
local preinstall_script="$TEST_CONTEXT/preinstall.sh"
|
||||||
echo "$preinstall_template" > "$preinstall_script"
|
echo "$preinstall_template" > "$preinstall_script"
|
||||||
# Hydrate the template with variables
|
# Hydrate the template with variables
|
||||||
sed -i "s/\$USER/$TEST_USER/" "$preinstall_script"
|
sed -i "s/\$USER/$TEST_USER/g" "$preinstall_script"
|
||||||
sed -i "s/\$DOMAIN/$DOMAIN/" "$preinstall_script"
|
sed -i "s/\$DOMAIN/$DOMAIN/g" "$preinstall_script"
|
||||||
sed -i "s/\$SUBDOMAIN/$SUBDOMAIN/" "$preinstall_script"
|
sed -i "s/\$SUBDOMAIN/$SUBDOMAIN/g" "$preinstall_script"
|
||||||
sed -i "s/\$PASSWORD/$YUNO_PWD/" "$preinstall_script"
|
sed -i "s/\$PASSWORD/$YUNO_PWD/g" "$preinstall_script"
|
||||||
# Copy the pre-install script into the container.
|
# Copy the pre-install script into the container.
|
||||||
lxc file push "$preinstall_script" "$LXC_NAME/preinstall.sh"
|
lxc file push "$preinstall_script" "$LXC_NAME/preinstall.sh"
|
||||||
# Then execute the script to execute the pre-install commands.
|
# Then execute the script to execute the pre-install commands.
|
||||||
|
@ -43,6 +43,31 @@ _PREINSTALL () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_PREUPGRADE () {
|
||||||
|
local preupgrade_template="$(jq -r '.preupgrade_template' $current_test_infos)"
|
||||||
|
local commit=${1:-HEAD}
|
||||||
|
|
||||||
|
# Exec the pre-upgrade instruction, if there one
|
||||||
|
if [ -n "$preupgrade_template" ]
|
||||||
|
then
|
||||||
|
log_small_title "Running pre-upgrade steps"
|
||||||
|
# Copy all the instructions into a script
|
||||||
|
local preupgrade_script="$TEST_CONTEXT/preupgrade.sh"
|
||||||
|
echo "$preupgrade_template" >> "$preupgrade_script"
|
||||||
|
# Hydrate the template with variables
|
||||||
|
sed -i "s/\$USER/$TEST_USER/g" "$preupgrade_script"
|
||||||
|
sed -i "s/\$DOMAIN/$DOMAIN/g" "$preupgrade_script"
|
||||||
|
sed -i "s/\$SUBDOMAIN/$SUBDOMAIN/g" "$preupgrade_script"
|
||||||
|
sed -i "s/\$PASSWORD/$YUNO_PWD/g" "$preupgrade_script"
|
||||||
|
sed -i "s/\$FROM_COMMIT/$commit/g" "$preupgrade_script"
|
||||||
|
# Copy the pre-upgrade script into the container.
|
||||||
|
lxc file push "$preupgrade_script" "$LXC_NAME/preupgrade.sh"
|
||||||
|
# Then execute the script to execute the pre-upgrade commands.
|
||||||
|
LXC_EXEC "bash /preupgrade.sh"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
_INSTALL_APP () {
|
_INSTALL_APP () {
|
||||||
local install_args="$(jq -r '.install_args' $current_test_infos)"
|
local install_args="$(jq -r '.install_args' $current_test_infos)"
|
||||||
|
|
||||||
|
@ -435,6 +460,10 @@ TEST_UPGRADE () {
|
||||||
|
|
||||||
log_small_title "Upgrade..."
|
log_small_title "Upgrade..."
|
||||||
|
|
||||||
|
_PREUPGRADE "${commit}"
|
||||||
|
ret=$?
|
||||||
|
[ $ret -eq 0 ] || { log_error "Pre-upgrade instruction failed"; return 1; }
|
||||||
|
|
||||||
# Upgrade the application in a LXC container
|
# Upgrade the application in a LXC container
|
||||||
_RUN_YUNOHOST_CMD "app upgrade $app_id --file /app_folder --force" \
|
_RUN_YUNOHOST_CMD "app upgrade $app_id --file /app_folder --force" \
|
||||||
&& _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" "upgrade"
|
&& _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" "upgrade"
|
||||||
|
@ -518,7 +547,7 @@ TEST_BACKUP_RESTORE () {
|
||||||
_RUN_YUNOHOST_CMD "backup create -n Backup_test --apps $app_id"
|
_RUN_YUNOHOST_CMD "backup create -n Backup_test --apps $app_id"
|
||||||
ret=$?
|
ret=$?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ $ret -eq 0 ] || { main_result=1; break_before_continue; continue; }
|
[ $ret -eq 0 ] || { main_result=1; break_before_continue; continue; }
|
||||||
|
|
||||||
# Grab the backup archive into the LXC container, and keep a copy
|
# Grab the backup archive into the LXC container, and keep a copy
|
||||||
|
@ -548,7 +577,7 @@ TEST_BACKUP_RESTORE () {
|
||||||
|
|
||||||
# Place the copy of the backup archive in the container.
|
# Place the copy of the backup archive in the container.
|
||||||
lxc file push -r $TEST_CONTEXT/ynh_backups/archives $LXC_NAME/home/yunohost.backup/
|
lxc file push -r $TEST_CONTEXT/ynh_backups/archives $LXC_NAME/home/yunohost.backup/
|
||||||
|
|
||||||
_PREINSTALL
|
_PREINSTALL
|
||||||
|
|
||||||
log_small_title "Restore on a fresh YunoHost system..."
|
log_small_title "Restore on a fresh YunoHost system..."
|
||||||
|
@ -611,7 +640,7 @@ TEST_CHANGE_URL () {
|
||||||
elif [ $i -eq 4 ]; then
|
elif [ $i -eq 4 ]; then
|
||||||
local new_path=/path
|
local new_path=/path
|
||||||
local new_domain=$DOMAIN
|
local new_domain=$DOMAIN
|
||||||
|
|
||||||
# Other domain, same path
|
# Other domain, same path
|
||||||
elif [ $i -eq 5 ]; then
|
elif [ $i -eq 5 ]; then
|
||||||
local new_path=/path
|
local new_path=/path
|
||||||
|
|
|
@ -80,6 +80,7 @@ parse_check_process() {
|
||||||
# during tests
|
# during tests
|
||||||
local install_args=$( extract_check_process_section "^; Manifest" "^; " $test_serie_rawconf | sed 's/\s*(.*)$//g' | tr -d '"' | tr '\n' '&')
|
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 preinstall_template=$(extract_check_process_section "^; pre-install" "^; " $test_serie_rawconf)
|
||||||
|
local preupgrade_template=$(extract_check_process_section "^; pre-upgrade" "^; " $test_serie_rawconf)
|
||||||
local action_infos=$( extract_check_process_section "^; Actions" "^; " $test_serie_rawconf)
|
local action_infos=$( extract_check_process_section "^; Actions" "^; " $test_serie_rawconf)
|
||||||
local configpanel_infos=$( extract_check_process_section "^; Config_panel" "^; " $test_serie_rawconf)
|
local configpanel_infos=$( extract_check_process_section "^; Config_panel" "^; " $test_serie_rawconf)
|
||||||
|
|
||||||
|
@ -130,9 +131,10 @@ parse_check_process() {
|
||||||
--arg test_type "$test_type" \
|
--arg test_type "$test_type" \
|
||||||
--arg test_arg "$test_arg" \
|
--arg test_arg "$test_arg" \
|
||||||
--arg preinstall_template "$preinstall_template" \
|
--arg preinstall_template "$preinstall_template" \
|
||||||
|
--arg preupgrade_template "$preupgrade_template" \
|
||||||
--arg install_args "${_install_args//\"}" \
|
--arg install_args "${_install_args//\"}" \
|
||||||
--argjson extra "$extra" \
|
--argjson extra "$extra" \
|
||||||
'{ $test_serie, $test_type, $test_arg, $preinstall_template, $install_args, $extra }' \
|
'{ $test_serie, $test_type, $test_arg, $preinstall_template, $preupgrade_template, $install_args, $extra }' \
|
||||||
> "$TEST_CONTEXT/tests/$test_id.json"
|
> "$TEST_CONTEXT/tests/$test_id.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue