Merge pull request #10 from YunoHost/refactoring

Complete refactoring
This commit is contained in:
Maniack Crudelis 2017-04-05 20:01:59 +02:00 committed by GitHub
commit 9fc7e05480
9 changed files with 1388 additions and 1312 deletions

155
README-fr.md Normal file
View file

@ -0,0 +1,155 @@
Package checker for YunoHost
==================
[Yunohost project](https://yunohost.org/#/)
> [Read this readme in english](README.md)
Ensemble de tests unitaires pour vérifier les packages Yunohost.
Le script `package_check.sh` effectue une succession de test sur un package afin de vérifier sa capacité à s'installer et se désinstaller dans différents cas.
Le résultats des tests est affiché directement et stocké dans le fichier Test_results.log
Le script est capable d'effectuer les tests suivant:
- Vérification du package avec [package linter](https://github.com/YunoHost/package_linter)
- Installation en sous-dossier
- Installation à la racine du domaine
- Installation sans accès par url (Pour les applications n'ayant pas d'interface web)
- Installation en privé
- Installation en public
- Upgrade sur la même version du package
- Backup
- Restore après suppression de l'application
- Restore sans installation préalable
- Installation multi-instance
- Test de path mal formé (path/ au lieu de /path)
- Test de port déjà utilisé
Package check utilise un conteneur LXC pour créer un environnement de test propre sans résidus d'installations précédentes.
Usage:
Pour une app dans un dossier: `./package_check.sh APP_ynh`
Pour une app sur github: `./package_check.sh https://github.com/USER/APP_ynh`
Il est nécessaire de fournir, à la racine du package de l'app à tester, un fichier `check_process` pour indiquer au script les arguments attendu et les tests à effectuer.
Si ce fichier n'est pas présent, package_check sera utilisé en mode dégradé. Il va tenter de repérer les arguments domain, path et admin dans le manifest pour exécuter un nombre restreint de test, en fonction des arguments trouvés.
---
## Déploiement du script de test
```
git clone https://github.com/YunoHost/package_check
package_check/sub_scripts/lxc_build.sh
package_check/package_check.sh APP_ynh
```
---
## Syntaxe du fichier `check_process`
> A l'exception des espaces, la syntaxe du fichier doit être scrupuleusement respectée.
```
;; Nom du test
# Commentaire ignoré
; Manifest
domain="$DOMAIN" (DOMAIN)
path="$PATH" (PATH)
admin="$USER" (USER)
language="fr"
is_public=1 (PUBLIC|public=1|private=0)
password="$PASSWORD" (PASSWORD)
port="666" (PORT)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
backup_restore=1
multi_instance=1
incorrect_path=1
port_already_use=1 (XXXX)
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
Level 4=0
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
```
### `;; Nom du test`
Nom du scénario de test qui sera effectué.
On peut créer autant de scénario de test que voulu, tous ayant la même syntaxe.
Les différents scénarios de test seront exécutés successivement.
### `; Manifest`
Ensemble des clés du manifest.
Toutes les clés du manifest doivent être renseignée afin de procéder à l'installation.
> Les clés de manifest données ici ne le sont qu'à titre d'exemple. Voir le manifest de l'application.
Certaines clés de manifest sont indispensables au script pour effectuer certains test. Ces clés doivent être mises en évidence afin que le script soit capable de les retrouver et de changer leur valeur.
`(DOMAIN)`, `(PATH)`, `(USER)` et `(PORT)` doivent être mis en bout de ligne des clés correspondantes. Ces clés seront modifiées par le script.
`(PUBLIC|public=1|private=0)` doit, en plus de correspondre à la clé de visibilité public, indiquer les valeurs du manifest pour public et privé.
### `; Checks`
Ensemble des tests à effectuer.
Chaque test marqué à 1 sera effectué par le script.
Si un test est absent de la liste, il sera ignoré. Cela revient à le noter à 0.
- `pkg_linter`: Vérification du package avec [package linter](https://github.com/YunoHost/package_linter)
- `setup_sub_dir`: Installation dans le path /check.
- `setup_root`: Installation à la racine du domaine.
- `setup_nourl`: Installation sans accès http. Ce test ne devrait être choisi que pour les applications ne disposant pas d'une interface web.
- `setup_private`: Installation en privé.
- `setup_public`: Installation en public.
- `upgrade`: Upgrade du package sur la même version. Test uniquement le script upgrade.
- `backup_restore`: Backup et restauration.
- `multi_instance`: Installation de l'application 3 fois de suite, pour vérifier sa capacité à être multi-instance. Les 2e et 3e installations se font respectivement en ajoutant un suffixe et un préfixe au path.
- `incorrect_path`: Provoque une erreur avec un path malformé, path/.
- `port_already_use`: Provoque une erreur sur le port en l'ouvrant avant le script d'install.
Le test` port_already_use` peut éventuellement prendre en argument un numéro de port. Si celui-ci n'est pas dans le manifest.
Le numéro de port doit alors être noté entre parenthèse, il servira au test de port.
### `;;; Levels`
Permet de choisir comment [chaque niveau](https://yunohost.org/#/packaging_apps_levels_fr) est déterminé.
Chaque niveau fixé à *auto* sera déterminé par le script. Il est également possible de fixer le niveau à *1* ou à *0* pour respectivement le valider ou l'invalider.
Il est à noter que les niveaux 4, 8, 9 et 10 ne peuvent être fixés à *auto* car ils ne peuvent être testés par le script et nécessitent une vérification manuelle. Il est toutefois possible de les fixer à *na* pour indiquer que le niveau n'est pas applicable (par exemple pour le niveau 4 quand une app ne propose pas de SSO LDAP). Un niveau *na* sera tout simplement ignoré dans le calcul du niveau final.
- Niveau 1 : L'application s'installe et se désinstalle correctement. -- Peut être vérifié par package_check
- Niveau 2 : L'application s'installe et se désinstalle dans toutes les configurations communes. -- Peut être vérifié par package_check
- Niveau 3 : L'application supporte l'upgrade depuis une ancienne version du package. -- Peut être vérifié par package_check
- Niveau 4 : L'application prend en charge de LDAP et/ou HTTP Auth. -- Doit être vérifié manuellement
- Niveau 5 : Aucune erreur dans package_linter. -- Peut être vérifié par package_check
- Niveau 6 : L'application peut-être sauvegardée et restaurée sans erreurs sur la même machine ou une autre. -- Peut être vérifié par package_check
- Niveau 7 : Aucune erreur dans package check. -- Peut être vérifié par package_check
- Niveau 8 : L'application respecte toutes les YEP recommandées. -- Doit être vérifié manuellement
- Niveau 9 : L'application respecte toutes les YEP optionnelles. -- Doit être vérifié manuellement
- Niveau 10 : L'application est jugée parfaite. -- Doit être vérifié manuellement
---
Le script `package_check.sh` accepte 6 arguments en plus du package à tester.
- `--bash-mode`: Rend le script autonome. Aucune intervention de l'utilisateur ne sera nécessaire.
La valeur de auto_remove est ignorée.
- `--branch=nom-de-branche`: Teste une branche du dépôt plutôt que de tester master. Permet de tester les pull request.
- `--build-lxc`: Installe LXC et créer le conteneur debian Yunohost si nécessaire.
- `--force-install-ok`: Force la réussite des installations, même si elles échouent. Permet d'effectuer les tests qui suivent même si l'installation a échouée.
- `--interrupt`: Force l'option auto_remove à 0, le script marquera une pause avant chaque suppression d'application.
- `--help`: Affiche l'aide du script
---
## LXC
Package check utilise la virtualisation en conteneur pour assurer l'intégrité de l'environnement de test.
L'usage de LXC apporte une meilleure stabilité au processus de test, un test de suppression échoué n'entraine pas l'échec des tests suivant, et permet de garder un environnement de test sans résidus de test précédents. En revanche, l'usage de LXC augmente la durée des tests, en raison des manipulations du conteneur et de la réinstallation systématique des dépendances de l'application.
Il faut prévoir également un espace suffisant sur l'hôte, au minimum 4Go pour le conteneur, son snapshot et sa copie de sauvegarde.
L'usage de LXC est facilité par 4 scripts, permettant de gérer la création, la mise à jour, la suppression et la réparation du conteneur.
- `lxc_build.sh`: lxc_build installe LXC et ses dépendances, puis créer le conteneur debian.
Il ajoute ensuite le support réseau, installe Yunohost et le configure. Et enfin configure un accès ssh.
L'accès ssh par défaut est `ssh -t pchecker_lxc`
- `lxc_upgrade.sh`: Effectue la mise à jour du conteneur à l'aide d'apt-get et recréer le snapshot.
- `lxc_remove.sh`: Supprime le conteneur LXC, son snapshot et sa sauvegarde. Désinstalle LXC et déconfigure le réseau associé.
- `lxc_check.sh`: Vérifie le conteneur LXC et tente de le réparer si nécessaire.

207
README.md
View file

@ -3,176 +3,7 @@ Package checker for YunoHost
[Yunohost project](https://yunohost.org/#/)
Ensemble de tests unitaires pour vérifier les packages Yunohost.
Le script `package_check.sh` effectue une succession de test sur un package afin de vérifier sa capacité à s'installer et se désinstaller dans différents cas.
Le résultats des tests est affiché directement et stocké dans le fichier Test_results.log
Le script est capable d'effectuer les tests suivant:
- Vérification du package avec [package linter](https://github.com/YunoHost/package_linter)
- Installation en sous-dossier
- Installation à la racine du domaine
- Installation sans accès par url (Pour les applications n'ayant pas d'interface web)
- Installation en privé
- Installation en public
- Upgrade sur la même version du package
- Backup
- Restore après suppression de l'application
- Restore sans installation préalable
- Installation multi-instance
- Test d'utilisateur incorrect
- Test de domaine incorrect
- Test de path mal formé (path/ au lieu de /path)
- Test de port déjà utilisé
Par défaut, Package check utilise un conteneur LXC pour créer un environnement de test propre sans résidus d'installations précédentes. Ce comportement peut être contourné avec le paramètre --no-lxc
> ATTENTION: Si LXC n'est pas utilisé, le script devrait être utilisé uniquement dans un environnement de test dédié, jamais sur un serveur en production. Il va provoquer de nombreuses erreurs d'installation du package et pourrait donc laisser des résidus indésirables.
Usage:
Pour une app dans un dossier: `./package_check.sh APP_ynh`
Pour une app sur github: `./package_check.sh https://github.com/USER/APP_ynh`
Il est nécessaire de fournir, à la racine du package de l'app à tester, un fichier `check_process` pour indiquer au script les arguments attendu et les tests à effectuer.
Si ce fichier n'est pas présent, package_check sera utilisé en mode dégradé. Il va tenter de repérer les arguments domain, path et admin dans le manifest pour exécuter un nombre restreint de test, en fonction des arguments trouvés.
---
## Déploiement du script de test
```
git clone https://github.com/YunoHost/package_check
package_check/sub_scripts/lxc_build.sh
package_check/package_check.sh APP_ynh
```
---
## Syntaxe du fichier `check_process`
> A l'exception des espaces, la syntaxe du fichier doit être scrupuleusement respectée.
```
;; Nom du test
auto_remove=1
# Commentaire ignoré
; Manifest
domain="$DOMAIN" (DOMAIN)
path="$PATH" (PATH)
admin="$USER" (USER)
language="fr"
is_public=1 (PUBLIC|public=1|private=0)
password="$PASSWORD" (PASSWORD)
port="666" (PORT)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
backup_restore=1
multi_instance=1
wrong_user=1
wrong_path=1
incorrect_path=1
corrupt_source=0
fail_download_source=0
port_already_use=1 (XXXX)
final_path_already_use=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
Level 4=0
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
```
### `;; Nom du test`
Nom du scénario de test qui sera effectué.
On peut créer autant de scénario de test que voulu, tous ayant la même syntaxe.
Les différents scénarios de test seront exécutés successivement.
### `auto_remove`
Si `auto_remove` est à 0, le script marque une pause avant chaque suppression de l'app. Afin d'éffectuer des vérifications manuelles si nécessaire.
Sinon, l'app est supprimée automatiquement et les tests continuent.
### `; Manifest`
Ensemble des clés du manifest.
Toutes les clés du manifest doivent être renseignée afin de procéder à l'installation.
> Les clés de manifest données ici ne le sont qu'à titre d'exemple. Voir le manifest de l'application.
Certaines clés de manifest sont indispensables au script pour effectuer certains test. Ces clés doivent être mises en évidence afin que le script soit capable de les retrouver et de changer leur valeur.
`(DOMAIN)`, `(PATH)`, `(USER)`, `(PASSWORD)` et `(PORT)` doivent être mis en bout de ligne des clés correspondantes. Ces clés seront modifiées par le script.
`(PUBLIC|public=1|private=0)` doit, en plus de correspondre à la clé de visibilité public, indiquer les valeurs du manifest pour public et privé.
### `; Checks`
Ensemble des tests à effectuer.
Chaque test marqué à 1 sera effectué par le script.
Si un test est absent de la liste, il sera ignoré. Cela revient à le noter à 0.
- `pkg_linter`: Vérification du package avec [package linter](https://github.com/YunoHost/package_linter)
- `setup_sub_dir`: Installation dans le path /check.
- `setup_root`: Installation à la racine du domaine.
- `setup_nourl`: Installation sans accès http. Ce test ne devrait être choisi que pour les applications ne disposant pas d'une interface web.
- `setup_private`: Installation en privé.
- `setup_public`: Installation en public.
- `upgrade`: Upgrade du package sur la même version. Test uniquement le script upgrade.
- `backup_restore`: Backup et restauration.
- `multi_instance`: Installation de l'application 3 fois de suite, pour vérifier sa capacité à être multi-instance. Les 2e et 3e installations se font respectivement en ajoutant un suffixe et un préfixe au path.
- `wrong_user`: Provoque une erreur avec un nom d'utilisateur incorrect.
- `wrong_path`: Provoque une erreur avec un domain incorrect.
- `incorrect_path`: Provoque une erreur avec un path malformé, path/.
- `corrupt_source`: *Non implémenté pour le moment...*
- `fail_download_source`: *Non implémenté pour le moment...*
- `port_already_use`: Provoque une erreur sur le port en l'ouvrant avant le script d'install.
Le test` port_already_use` peut éventuellement prendre en argument un numéro de port. Si celui-ci n'est pas dans le manifest.
Le numéro de port doit alors être noté entre parenthèse, il servira au test de port.
- `final_path_already_use`: *Non implémenté pour le moment...*
### `;;; Levels`
Permet de choisir comment [chaque niveau](https://yunohost.org/#/packaging_apps_levels_fr) est déterminé.
Chaque niveau fixé à *auto* sera déterminé par le script. Il est également possible de fixer le niveau à *1* ou à *0* pour respectivement le valider ou l'invalider.
Il est à noter que les niveaux 4, 8, 9 et 10 ne peuvent être fixés à *auto* car ils ne peuvent être testés par le script et nécessitent une vérification manuelle. Il est toutefois possible de les fixer à *na* pour indiquer que le niveau n'est pas applicable (par exemple pour le niveau 4 quand une app ne propose pas de SSO LDAP). Un niveau *na* sera tout simplement ignoré dans le calcul du niveau final.
- Niveau 1 : L'application s'installe et se désinstalle correctement. -- Peut être vérifié par package_check
- Niveau 2 : L'application s'installe et se désinstalle dans toutes les configurations communes. -- Peut être vérifié par package_check
- Niveau 3 : L'application supporte l'upgrade depuis une ancienne version du package. -- Peut être vérifié par package_check
- Niveau 4 : L'application prend en charge de LDAP et/ou HTTP Auth. -- Doit être vérifié manuellement
- Niveau 5 : Aucune erreur dans package_linter. -- Peut être vérifié par package_check
- Niveau 6 : L'application peut-être sauvegardée et restaurée sans erreurs sur la même machine ou une autre. -- Peut être vérifié par package_check
- Niveau 7 : Aucune erreur dans package check. -- Peut être vérifié par package_check
- Niveau 8 : L'application respecte toutes les YEP recommandées. -- Doit être vérifié manuellement
- Niveau 9 : L'application respecte toutes les YEP optionnelles. -- Doit être vérifié manuellement
- Niveau 10 : L'application est jugée parfaite. -- Doit être vérifié manuellement
---
Le script `package_check.sh` accepte 6 arguments en plus du package à tester.
- `--bash-mode`: Rend le script autonome. Aucune intervention de l'utilisateur ne sera nécessaire.
La valeur de auto_remove est ignorée.
- `--branch=nom-de-branche`: Teste une branche du dépôt plutôt que de tester master. Permet de tester les pull request.
- `--build-lxc`: Installe LXC et créer le conteneur debian Yunohost si nécessaire.
- `--force-install-ok`: Force la réussite des installations, même si elles échouent. Permet d'effectuer les tests qui suivent même si l'installation a échouée.
- `--interrupt`: Force l'option auto_remove à 0, le script marquera une pause avant chaque suppression d'application.
- `--no-lxc`: N'utilise pas la virtualisation en conteneur LXC. Les tests seront effectué directement sur la machine hôte.
- `--help`: Affiche l'aide du script
---
## LXC
Package check utilise la virtualisation en conteneur pour assurer l'intégrité de l'environnement de test.
L'usage de LXC apporte une meilleure stabilité au processus de test, un test de suppression échoué n'entraine pas l'échec des tests suivant, et permet de garder un environnement de test sans résidus de test précédents. En revanche, l'usage de LXC augmente la durée des tests, en raison des manipulations du conteneur et de la réinstallation systématique des dépendances de l'application.
Il faut prévoir également un espace suffisant sur l'hôte, au minimum 4Go pour le conteneur, son snapshot et sa copie de sauvegarde.
L'usage de LXC est facilité par 4 scripts, permettant de gérer la création, la mise à jour, la suppression et la réparation du conteneur.
- `lxc_build.sh`: lxc_build installe LXC et ses dépendances, puis créer le conteneur debian.
Il ajoute ensuite le support réseau, installe Yunohost et le configure. Et enfin configure un accès ssh.
L'accès ssh par défaut est `ssh -t pchecker_lxc`
- `lxc_upgrade.sh`: Effectue la mise à jour du conteneur à l'aide d'apt-get et recréer le snapshot.
- `lxc_remove.sh`: Supprime le conteneur LXC, son snapshot et sa sauvegarde. Désinstalle LXC et déconfigure le réseau associé.
- `lxc_check.sh`: Vérifie le conteneur LXC et tente de le réparer si nécessaire.
---
---
## Package checker for YunoHost
> [Lire ce readme en francais](README-fr.md)
Set of unit tests for check Yunohost packages.
The `package_check.sh` script perform a series of tests on a package for check its capability to install and remove in différents cases.
@ -190,13 +21,10 @@ The script is able to perform following tests:
- Restore after application uninstall
- Restore without installation before
- Multi-instances installation
- Test with wrong user
- Test with wrong domain
- Test malformed path (path/ instead od /path)
- Test port already use
As default, package_check script use an LXC container to manipulate the package in a non parasited environnement by previous installs. This behavior can be overriden with --no-lxc parameter.
> BE CAREFUL, If LXC is not used, this script should be used only in a dedicated test environnement, never on a prod server. It will causes many installations errors and risk to leave residues.
Package_check script use an LXC container to manipulate the package in a non parasited environnement by previous installs.
Usage:
For an app in a dir: `./package_check.sh APP_ynh`
@ -220,8 +48,7 @@ package_check/package_check.sh APP_ynh
```
;; Test name
auto_remove=1
# Comment ignore
# Comment ignored
; Manifest
domain="$DOMAIN" (DOMAIN)
path="$PATH" (PATH)
@ -240,29 +67,31 @@ package_check/package_check.sh APP_ynh
upgrade=1
backup_restore=1
multi_instance=1
wrong_user=1
wrong_path=1
incorrect_path=1
corrupt_source=0
fail_download_source=0
port_already_use=1 (XXXX)
final_path_already_use=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
Level 4=0
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
```
### `;; Test name`
Name of tests series that will be perform.
It's possible to create multiples tests series, all with the same syntax.
All different tests series will be perform sequentialy.
### `auto_remove`
If `auto_remove` is at 0, the script pause before each deleting of app. To lets you check manually if necessary.
Otherwise, the app is automaticaly removed and tests continue.
### `; Manifest`
Set of manifest keys.
All manifest keys need to be filled to perform installation.
> The manifest keys filled here are simply an exemple. Check the app's manifest.
Some manifest keys are necessary for the script to performs some tests. This keys must be highlighted for the script is able to find them and modify their values.
`(DOMAIN)`, `(PATH)`, `(USER)`, `(PASSWORD)` and `(PORT)` must be placed at the end of corresponding key. This key will be changed by the script.
`(DOMAIN)`, `(PATH)`, `(USER)` and `(PORT)` must be placed at the end of corresponding key. This key will be changed by the script.
`(PUBLIC|public=1|private=0)` must, in addition to match the public key, indicate the values for public and private.
### `; Checks`
@ -278,15 +107,10 @@ If a test is not in the list, it will be ignored. It's similar to marked at 0.
- `upgrade`: Upgrade package on same version. Only test the upgrade script.
- `backup_restore`: Backup then restore.
- `multi_instance`: Installing the application 3 times to verify its ability to be multi-instance. The 2nd and 3rd respectively installs are adding a suffix then prefix path.
- `wrong_user`: Causes an errror with a wrong user name.
- `wrong_path`: Causes an error with a wrong domain.
- `incorrect_path`: Causes an arror with a malformed path, path/.
- `corrupt_source`: *Not implemented yet...*
- `fail_download_source`: *Not implemented yet...*
- `port_already_use`: Causes an error on the port by opening before.
The `port_already_use` test may eventually take in argument the port number.
The port number must be written into parentheses, it will serve to test port.
- `final_path_already_use`: *Not implemented yet...*
### `;;; Levels`
Allow to choose how [each level](https://yunohost.org/#/packaging_apps_levels_fr) is determined
@ -312,7 +136,6 @@ The `package_check.sh` script accept 6 arguments in addition of package to be ch
- `--build-lxc`: Install LXC and create the Debian Yunohost container if necessary.
- `--force-install-ok`: Force success of installation, even if they fail. Allow to perform following tests even if installation fail.
- `--interrupt`: Force auto_remove value, break before each remove.
- `--no-lxc`: Not use virtualization with LXC container. All tests will perform directly on the hosts machine.
- `--help`: Display help.
---

View file

@ -1,5 +1,4 @@
;; Nom du test
auto_remove=1
# Commentaire ignoré
; Manifest
domain="domain.tld" (DOMAIN)
@ -8,7 +7,7 @@
language="fr"
# is_public="Yes" (PUBLIC|public=Yes|private=No)
is_public=1 (PUBLIC|public=1|private=0)
password="pass" (PASSWORD)
password="pass"
port="666" (PORT)
; Checks
pkg_linter=1
@ -20,13 +19,8 @@
upgrade=1
backup_restore=1
multi_instance=1
wrong_user=1
wrong_path=1
incorrect_path=1
corrupt_source=0
fail_download_source=0
port_already_use=1 (66)
final_path_already_use=0
;;; Levels
Level 1=auto
Level 2=auto

File diff suppressed because it is too large Load diff

View file

@ -1,15 +0,0 @@
# Merci a Bram pour ce code python.
# https://github.com/YunoHost/ci
import sys
import json
from default_args import argument_for_question
if __name__ == '__main__':
manifest_path = sys.argv[1:][0]
manifest = json.load(open(manifest_path, "r"))
for question in manifest["arguments"]["install"]:
print ":".join(argument_for_question(question, all_choices=True))

View file

@ -1,12 +1,17 @@
#!/bin/bash
# #!/bin/bash
echo -e "Loads functions from launcher.sh"
#=================================================
# Globals variables
#=================================================
# arg_ssh="-t"
arg_ssh="-tt"
echo -e "Load functions from lxc_launcher.sh"
#=================================================
is_lxc_running () {
sudo lxc-info --name=$LXC_NAME | grep --quiet "RUNNING"
sudo lxc-info --name=$lxc_name | grep --quiet "RUNNING"
}
LXC_INIT () {
@ -14,13 +19,13 @@ LXC_INIT () {
# Activate the bridge
echo "Initialize network for LXC."
sudo ifup $LXC_BRIDGE --interfaces=/etc/network/interfaces.d/$LXC_BRIDGE | tee --append "$test_result" 2>&1
sudo ifup $lxc_bridge --interfaces=/etc/network/interfaces.d/$lxc_bridge | tee --append "$test_result" 2>&1
# Activate iptables rules
echo "Activate iptables rules."
sudo iptables --append FORWARD --in-interface $LXC_BRIDGE --out-interface $main_iface --jump ACCEPT | tee --append "$test_result" 2>&1
sudo iptables --append FORWARD --in-interface $main_iface --out-interface $LXC_BRIDGE --jump ACCEPT | tee --append "$test_result" 2>&1
sudo iptables --table nat --append POSTROUTING --source $PLAGE_IP.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1
sudo iptables --append FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT | tee --append "$test_result" 2>&1
sudo iptables --append FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT | tee --append "$test_result" 2>&1
sudo iptables --table nat --append POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1
}
LXC_START () {
@ -35,7 +40,10 @@ LXC_START () {
# Start the container and log the booting process in $script_dir/lxc_boot.log
# Try to start only if the container is not already started
if ! is_lxc_running; then
sudo lxc-start --name=$LXC_NAME --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$test_result" 2>&1
echo "Start the LXC container" | tee --append "$test_result"
sudo lxc-start --name=$lxc_name --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$test_result" 2>&1
else
echo "A LXC container is already running" | tee --append "$test_result"
fi
# Check during 20 seconds if the container has finished to start.
@ -44,7 +52,7 @@ LXC_START () {
do
echo -n .
# Try to connect with ssh to check if the container is ready to work.
if ssh $arg_ssh $LXC_NAME "exit 0" > /dev/null 2>&1; then
if ssh $arg_ssh $lxc_name "exit 0" > /dev/null 2>&1; then
# Break the for loop if the container is ready.
break
fi
@ -54,19 +62,19 @@ LXC_START () {
local failstart=0
# Check if the container is running
if ! is_lxc_running; then
ECHO_FORMAT "The LXC container didn't start...\n" "lred" "bold"
ECHO_FORMAT "The LXC container didn't start...\n" "red" "bold"
failstart=1
if [ $i -ne $max_try ]; then
ECHO_FORMAT "Rebooting the container...\n" "lred" "bold"
ECHO_FORMAT "Rebooting the container...\n" "red" "bold"
fi
LXC_STOP # Stop the LXC container
elif ! ssh $arg_ssh $LXC_NAME "sudo ping -q -c 2 security.debian.org > /dev/null 2>&1; exit \$?" >> "$test_result" 2>&1
elif ! ssh $arg_ssh $lxc_name "sudo ping -q -c 2 security.debian.org > /dev/null 2>&1; exit \$?" >> "$test_result" 2>&1
then
# Try to ping security.debian.org to check the connectivity from the container
ECHO_FORMAT "The container failed to connect to internet...\n" "lred" "bold"
ECHO_FORMAT "The container failed to connect to internet...\n" "red" "bold"
failstart=1
if [ $i -ne $max_try ]; then
ECHO_FORMAT "Rebooting the container...\n" "lred" "bold"
ECHO_FORMAT "Rebooting the container...\n" "red" "bold"
fi
LXC_STOP # Stop the LXC container
else
@ -74,29 +82,29 @@ LXC_START () {
break
fi
# Failed if the container failed to start
# Fail if the container failed to start
if [ $i -eq $max_try ] && [ $failstart -eq 1 ]
then
ECHO_FORMAT "The container failed to start $max_try times...\nIf this problem is persistent, try to fix it with lxc_check.sh." "lred" "bold"
ECHO_FORMAT "The container failed to start $max_try times...\nIf this problem is persistent, try to fix it with lxc_check.sh." "red" "bold"
ECHO_FORMAT "Boot log:\n" clog
cat "$script_dir/lxc_boot.log" | tee --append "$test_result"
return 1
fi
done
# Count the number of line of the current yunohost log file.
# Count the number of lines of the current yunohost log file.
COPY_LOG 1
# Copy the package into the container.
scp -rq "$APP_CHECK" "$LXC_NAME": >> "$test_result" 2>&1
scp -rq "$package_path" "$lxc_name": >> "$test_result" 2>&1
# Execute the command given in argument in the container and log its results.
ssh $arg_ssh $LXC_NAME "$1 > /dev/null 2>> temp_yunohost-cli.log; exit \$?" >> "$test_result" 2>&1
ssh $arg_ssh $lxc_name "$1 > /dev/null 2>> temp_yunohost-cli.log; exit \$?" >> "$test_result" 2>&1
# Store the return code of the command
local returncode=$?
# Retrieve the log of the previous command and copy its content in the temporary log
sudo cat "/var/lib/lxc/$LXC_NAME/rootfs/home/pchecker/temp_yunohost-cli.log" >> "$temp_log"
sudo cat "/var/lib/lxc/$lxc_name/rootfs/home/pchecker/temp_yunohost-cli.log" >> "$temp_log"
# Return the exit code of the ssh command
return $returncode
@ -105,68 +113,68 @@ LXC_START () {
LXC_STOP () {
# Stop and restore the LXC container
local snapshot_path="/var/lib/lxcsnaps/$LXC_NAME/snap0"
local snapshot_path="/var/lib/lxcsnaps/$lxc_name/snap0"
# Stop the LXC container
if is_lxc_running; then
echo "Stop the LXC container" | tee --append "$test_result"
sudo lxc-stop --name=$LXC_NAME | tee --append "$test_result" 2>&1
sudo lxc-stop --name=$lxc_name | tee --append "$test_result" 2>&1
fi
# Fix the missing hostname in the hosts file
# If the hostname is missing in /etc/hosts inside the snapshot
if ! sudo grep --quiet "$LXC_NAME" "$snapshot_path/rootfs/etc/hosts"
if ! sudo grep --quiet "$lxc_name" "$snapshot_path/rootfs/etc/hosts"
then
# If the hostname was replaced by snap0, fix it
if sudo grep --quiet "snap0" "$snapshot_path/rootfs/etc/hosts"
then
# Replace snap0 by the real hostname
sudo sed --in-place "s/snap0/$LXC_NAME/" "$snapshot_path/rootfs/etc/hosts"
sudo sed --in-place "s/snap0/$lxc_name/" "$snapshot_path/rootfs/etc/hosts"
else
# Otherwise, simply add the hostname
echo "127.0.0.1 $LXC_NAME" | sudo tee --append "$snapshot_path/rootfs/etc/hosts" > /dev/null
echo "127.0.0.1 $lxc_name" | sudo tee --append "$snapshot_path/rootfs/etc/hosts" > /dev/null
fi
fi
# Restore the snapshot.
echo "Restore the previous snapshot." | tee --append "$test_result"
sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/rootfs/" "/var/lib/lxc/$LXC_NAME/rootfs/" > /dev/null 2>> "$test_result"
sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/rootfs/" "/var/lib/lxc/$lxc_name/rootfs/" > /dev/null 2>> "$test_result"
}
LXC_TURNOFF () {
# Deactivate LXC network
# Disable LXC network
echo "Deactivate iptables rules."
if sudo iptables --check FORWARD --in-interface $LXC_BRIDGE --out-interface $main_iface --jump ACCEPT 2> /dev/null
echo "Disable iptables rules."
if sudo iptables --check FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT 2> /dev/null
then
sudo iptables --delete FORWARD --in-interface $LXC_BRIDGE --out-interface $main_iface --jump ACCEPT >> "$test_result" 2>&1
sudo iptables --delete FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT >> "$test_result" 2>&1
fi
if sudo iptables --check FORWARD --in-interface $main_iface --out-interface $LXC_BRIDGE --jump ACCEPT 2> /dev/null
if sudo iptables --check FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT 2> /dev/null
then
sudo iptables --delete FORWARD --in-interface $main_iface --out-interface $LXC_BRIDGE --jump ACCEPT | tee --append "$test_result" 2>&1
sudo iptables --delete FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT | tee --append "$test_result" 2>&1
fi
if sudo iptables --table nat --check POSTROUTING --source $PLAGE_IP.0/24 --jump MASQUERADE 2> /dev/null
if sudo iptables --table nat --check POSTROUTING --source $ip_range.0/24 --jump MASQUERADE 2> /dev/null
then
sudo iptables --table nat --delete POSTROUTING --source $PLAGE_IP.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1
sudo iptables --table nat --delete POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1
fi
echo "Deactivate the network bridge."
if sudo ifquery $LXC_BRIDGE --state > /dev/null
echo "Disable the network bridge."
if sudo ifquery $lxc_bridge --state > /dev/null
then
sudo ifdown --force $LXC_BRIDGE | tee --append "$test_result" 2>&1
sudo ifdown --force $lxc_bridge | tee --append "$test_result" 2>&1
fi
}
LXC_CONNECT_INFO () {
# Print access information
echo "> For access the container:"
echo "> To access the container:"
echo "To execute one command:"
echo -e "\e[1msudo lxc-attach -n $LXC_NAME -- command\e[0m"
echo -e "\e[1msudo lxc-attach -n $lxc_name -- command\e[0m"
echo "To establish a ssh connection:"
if [ $(cat "$script_dir/setup_user") = "root" ]; then
echo -ne "\e[1msudo "
fi
echo -e "\e[1mssh $arg_ssh $LXC_NAME\e[0m"
echo -e "\e[1mssh $arg_ssh $lxc_name\e[0m"
}

View file

@ -1,12 +1,6 @@
#!/bin/bash
temp_log="$script_dir/temp_yunohost-cli.log"
# yunohost_log="/var/lib/lxc/$LXC_NAME/rootfs/var/log/yunohost/yunohost-cli.log"
yunohost_log="/var/lib/lxc/pchecker_lxc/rootfs/var/log/yunohost/yunohost-cli.log"
complete_log="$script_dir/Complete.log"
temp_result="$script_dir/temp_result.log"
echo "Load functions from log_extractor.sh"
echo "Loads functions from log_extractor.sh"
ECHO_FORMAT () {
# Simply an echo with color and typo
@ -20,9 +14,6 @@ ECHO_FORMAT () {
if [ "$2" == "lyellow" ]; then
echo -en "\e[93m"
fi
if [ "$2" == "lred" ]; then
echo -en "\e[91m"
fi
if [ "$2" == "lgreen" ]; then
echo -en "\e[92m"
fi

View file

@ -1,10 +1,8 @@
# Merci a Bram pour ce code python.
# https://github.com/YunoHost/ci
import os
import sys
import json
from urllib import urlretrieve
def argument_for_question(question, all_choices=False):
question_type = question.get("type")
@ -51,23 +49,9 @@ def argument_for_question(question, all_choices=False):
else:
raise Exception("Unknow question type: %s\n" % question_type, question)
def default_arguments_for_app(app_data):
answers = []
for question in app_data["manifest"]["arguments"]["install"]:
answers.append(argument_for_question(question))
return "&".join(["=".join([x[0], x[1]]) for x in answers])
def main():
if not os.path.exists("/tmp/yunohost_official_apps_list.json"):
urlretrieve("https://app.yunohost.org/official.json", "/tmp/yunohost_official_apps_list.json")
app_list = json.load(open("/tmp/yunohost_official_apps_list.json"))
for name, data in sorted(app_list.items(), key=lambda x: x[0]):
print "%s:" % name, default_arguments_for_app(data)
if __name__ == '__main__':
main()
manifest_path = sys.argv[1:][0]
manifest = json.load(open(manifest_path, "r"))
for question in manifest["arguments"]["install"]:
print ":".join(argument_for_question(question, all_choices=True))

View file

@ -1,14 +1,16 @@
#!/bin/bash
test_result="$script_dir/Test_results.log"
backup_hooks="conf_ssowat data_home conf_ynh_firewall conf_cron" # La liste des hooks disponible pour le backup se trouve dans /usr/share/yunohost/hooks/backup/
echo -e "Load functions from testing_process.sh"
echo -e "Loads functions from testing_process.sh"
#=================================================
# Globals variables
#=================================================
# A complete list of backup hooks is available at /usr/share/yunohost/hooks/backup/
backup_hooks="conf_ssowat data_home conf_ynh_firewall conf_cron"
#=================================================
break_before_continue () {
# Make a break if auto_remove is set
@ -27,7 +29,7 @@ SETUP_APP () {
# Install an application in a LXC container
# Install the application in a LXC container
LXC_START "sudo yunohost --debug app install \"$APP_PATH_YUNO\" -a \"$manifest_args_mod\""
LXC_START "sudo yunohost --debug app install \"$package_dir\" -a \"$manifest_args_mod\""
# yunohost_result gets the return code of the installation
yunohost_result=$?
@ -54,14 +56,14 @@ REMOVE_APP () {
# Remove the application from the LXC container
LXC_START "sudo yunohost --debug app remove \"$ynh_app_id\""
# YUNOHOST_REMOVE gets the return code of the deletion
YUNOHOST_REMOVE=$?
# yunohost_remove gets the return code of the deletion
yunohost_remove=$?
# Print the result of the remove command
if [ "$YUNOHOST_REMOVE" -eq 0 ]; then
ECHO_FORMAT "Deleting successful. ($YUNOHOST_REMOVE)\n" "white" clog
if [ "$yunohost_remove" -eq 0 ]; then
ECHO_FORMAT "Deleting successful. ($yunohost_remove)\n" "white" clog
else
ECHO_FORMAT "Deleting failed. ($YUNOHOST_REMOVE)\n" "white" clog
ECHO_FORMAT "Deleting failed. ($yunohost_remove)\n" "white" clog
fi
}
@ -77,23 +79,23 @@ CHECK_URL () {
ECHO_FORMAT "\nTry to access by url...\n" "white" "bold"
# Force a skipped_uris if public mode is not set
if [ "$MANIFEST_PUBLIC" = "null" ]
if [ -z "$public_arg" ]
then
# Add a skipped_uris on / for the app
LXC_START "sudo yunohost app setting \"$ynh_app_id\" skipped_uris -v \"/\""
# Regen the sso's config
# Regen the config of sso
LXC_START "sudo yunohost app ssowatconf"
ECHO_FORMAT "Public access forced by a skipped_uris to check.\n" "lyellow" "bold"
fi
# Inform /etc/hosts of LXC's IP to resolve the domain.
# Inform /etc/hosts with the IP of LXC to resolve the domain.
# This is set only here and not before to prevent to help the app's scripts
echo -e "$PLAGE_IP.2 $DOMAIN #package_check\n$PLAGE_IP.2 $SOUS_DOMAIN #package_check" | sudo tee --append /etc/hosts > /dev/null
echo -e "$ip_range.2 $main_domain #package_check\n$ip_range.2 $sub_domain #package_check" | sudo tee --append /etc/hosts > /dev/null
# Try to resolv the domain during 10 seconds maximum.
local i=0
for i in `seq 1 10`; do
curl --location --insecure $SOUS_DOMAIN > /dev/null 2>&1
curl --location --insecure $sub_domain > /dev/null 2>&1
# If curl return 6, it's an error "Could not resolve host"
if [ $? -ne 6 ]; then
# If not, curl is ready to work.
@ -146,18 +148,18 @@ CHECK_URL () {
# Remove the previous curl output
rm -f "$script_dir/url_output"
# Call curl to try to access to the appp's url
curl --location --insecure --silent --show-error --write-out "%{http_code};%{url_effective}\n" $SOUS_DOMAIN$curl_check_path --output "$script_dir/url_output" > "$script_dir/curl_print"
# Call curl to try to access to the url of the app
curl --location --insecure --silent --show-error --write-out "%{http_code};%{url_effective}\n" $sub_domain$curl_check_path --output "$script_dir/url_output" > "$script_dir/curl_print"
# Analyze the result of curl command
if [ $? -ne 0 ]
then
ECHO_FORMAT "Connection error...\n" "lred" "bold"
ECHO_FORMAT "Connection error...\n" "red" "bold"
curl_error=1
fi
# Print informations about the connection
ECHO_FORMAT "Test url: $SOUS_DOMAIN$curl_check_path\n" "white"
ECHO_FORMAT "Test url: $sub_domain$curl_check_path\n" "white"
ECHO_FORMAT "Real url: $(cat "$script_dir/curl_print" | cut --delimiter=';' --fields=2)\n" "white"
local http_code=$(cat "$script_dir/curl_print" | cut -d ';' -f1)
ECHO_FORMAT "HTTP code: $http_code\n" "white"
@ -200,9 +202,9 @@ CHECK_URL () {
# Analyze the output of curl
if [ -e "$script_dir/url_output" ]
then
# Print the page's title
# Print the title of the page
local url_title=$(grep "<title>" "$script_dir/url_output" | cut --delimiter='>' --fields=2 | cut --delimiter='<' --fields=1)
ECHO_FORMAT "Titre de la page: $url_title\n" "white"
ECHO_FORMAT "Title of the page: $url_title\n" "white"
# Check if the page title is neither the YunoHost portail or default nginx page
if [ "$url_title" = "YunoHost Portal" ]
@ -219,7 +221,7 @@ CHECK_URL () {
fi
# Print the first 20 lines of the body
ECHO_FORMAT "Extract of page's body:\n" "white"
ECHO_FORMAT "Extract of the body:\n" "white"
echo -e "\e[37m" # Write in 'light grey'
grep "<body" --after-context=20 "$script_dir/url_output" | sed 1d | tee --append "$test_result"
echo -e "\e[0m"
@ -255,9 +257,9 @@ check_manifest_key () {
# Check if a manifest key is set
# $1 = manifest key
if [ -z "$MANIFEST_$1" ]
if [ -z "${1}_arg" ]
then
ECHO_FORMAT "Unable to find a manifest key for '${1,,}' in the check_process file. Impossible to perform this test\n" "lred" clog
ECHO_FORMAT "Unable to find a manifest key for '${1,,}' in the check_process file. Impossible to perform this test\n" "red" clog
return 1
fi
}
@ -267,14 +269,12 @@ replace_manifest_key () {
# $1 = Manifest key
# $2 = Replacement value
# Build the variable name by concatenate MANIFEST and $1
local manifest_key=$(eval echo \$MANIFEST_$1)
# Build the variable name by concatenate $1 and _arg
local manifest_key=$(eval echo \$${1}_arg)
if [ -n "$manifest_key" ]
then
manifest_args_mod=$(echo $manifest_args_mod | sed "s@$manifest_key=[^&]*\&@${manifest_key}=${2}\&@")
else
ECHO_FORMAT "The manifest key $manifest_key doesn't found in the check_process\n" "lred" clog
fi
}
@ -283,7 +283,7 @@ check_success () {
}
check_failed () {
ECHO_FORMAT "--- FAIL ---\n" "lred" "bold"
ECHO_FORMAT "--- FAIL ---\n" "red" "bold"
}
check_test_result () {
@ -302,7 +302,7 @@ check_test_result () {
check_test_result_remove () {
# Check the result of a remove and print SUCCESS or FAIL
if [ $YUNOHOST_REMOVE -eq 0 ]
if [ $yunohost_remove -eq 0 ]
then
check_success
return 0
@ -315,16 +315,16 @@ check_test_result_remove () {
is_install_failed () {
# Check if an install have previously work
if [ $GLOBAL_CHECK_ROOT -eq 1 ]
if [ $RESULT_check_root -eq 1 ]
then
# If root installation worked, return root.
echo root
elif [ $GLOBAL_CHECK_SUB_DIR -eq 1 ] || [ $force_install_ok -eq 1 ]
elif [ $RESULT_check_sub_dir -eq 1 ] || [ $force_install_ok -eq 1 ]
then
# If subdir installation worked or force_install_ok setted, return subdir.
echo subdir
else
ECHO_FORMAT "All install checks failed, impossible to perform this test...\n" "lred" clog
ECHO_FORMAT "All installs failed, impossible to perform this test...\n" "red" clog
return 1
fi
}
@ -350,24 +350,23 @@ CHECK_SETUP () {
# Check if the needed manifest key are set or abort the test
if [ "$install_type" != "no_url" ]; then
check_manifest_key "DOMAIN" || return
check_manifest_key "PATH" || return
check_manifest_key "domain" || return
check_manifest_key "path" || return
fi
# Copy original arguments
local manifest_args_mod=$MANIFEST_ARGS
local manifest_args_mod=$manifest_arguments
# Replace manifest key for the test
replace_manifest_key "DOMAIN" "$SOUS_DOMAIN"
replace_manifest_key "domain" "$sub_domain"
if [ "$install_type" = "subdir" ]; then
local check_path=$PATH_TEST
local check_path=$test_path
elif [ "$install_type" = "root" ]; then
local check_path=/
fi
replace_manifest_key "PATH" "$check_path"
replace_manifest_key "USER" "$USER_TEST"
replace_manifest_key "PASSWORD" "$PASSWORD_TEST"
replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public"
replace_manifest_key "path" "$check_path"
replace_manifest_key "user" "$test_user"
replace_manifest_key "public" "$public_public_arg"
# Install the application in a LXC container
SETUP_APP
@ -381,12 +380,12 @@ CHECK_SETUP () {
# Check the result and print SUCCESS or FAIL
if check_test_result
then # Success
GLOBAL_CHECK_SETUP=1 # Installation succeed
RESULT_global_setup=1 # Installation succeed
local check_result_setup=1 # Installation in a sub path succeed
else # Fail
# The global success for a installation can't be failed if another installation succeed
if [ $GLOBAL_CHECK_SETUP -ne 1 ]; then
GLOBAL_CHECK_SETUP=-1 # Installation failed
if [ $RESULT_global_setup -ne 1 ]; then
RESULT_global_setup=-1 # Installation failed
fi
local check_result_setup=-1 # Installation in a sub path failed
fi
@ -401,11 +400,11 @@ CHECK_SETUP () {
if check_test_result_remove
then # Success
local check_result_remove=1 # Remove in sub path succeed
GLOBAL_CHECK_REMOVE=1 # Remove succeed
RESULT_global_remove=1 # Remove succeed
else # Fail
# The global success for a deletion can't be failed if another remove succeed
if [ $GLOBAL_CHECK_REMOVE -ne 1 ]; then
GLOBAL_CHECK_REMOVE=-1 # Remove failed
if [ $RESULT_global_remove -ne 1 ]; then
RESULT_global_remove=-1 # Remove failed
fi
local check_result_remove=-1 # Remove in sub path failed
fi
@ -413,11 +412,11 @@ CHECK_SETUP () {
# Fill the correct variable depend on the type of test
if [ "$install_type" = "subdir" ]
then
GLOBAL_CHECK_SUB_DIR=$check_result_setup
GLOBAL_CHECK_REMOVE_SUBDIR=$check_result_remove
RESULT_check_sub_dir=$check_result_setup
RESULT_check_remove_sub_dir=$check_result_remove
else # root and no_url
GLOBAL_CHECK_ROOT=$check_result_setup
GLOBAL_CHECK_REMOVE_ROOT=$check_result_remove
RESULT_check_root=$check_result_setup
RESULT_check_remove_root=$check_result_remove
fi
}
@ -432,20 +431,19 @@ CHECK_UPGRADE () {
[ "$previous_install" = "1" ] && return
# Copy original arguments
local manifest_args_mod=$MANIFEST_ARGS
local manifest_args_mod=$manifest_arguments
# Replace manifest key for the test
replace_manifest_key "DOMAIN" "$SOUS_DOMAIN"
replace_manifest_key "domain" "$sub_domain"
# Use a path according to previous succeeded installs
if [ "$previous_install" = "subdir" ]; then
local check_path=$PATH_TEST
local check_path=$test_path
elif [ "$previous_install" = "root" ]; then
local check_path=/
fi
replace_manifest_key "PATH" "$check_path"
replace_manifest_key "USER" "$USER_TEST"
replace_manifest_key "PASSWORD" "$PASSWORD_TEST"
replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public"
replace_manifest_key "path" "$check_path"
replace_manifest_key "user" "$test_user"
replace_manifest_key "public" "$public_public_arg"
# Install the application in a LXC container
ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog
@ -457,12 +455,12 @@ CHECK_UPGRADE () {
# Check if the install had work
if [ $yunohost_result -ne 0 ]
then
ECHO_FORMAT "\nInstallation failed...\n" "lred" "bold"
ECHO_FORMAT "\nInstallation failed...\n" "red" "bold"
else
ECHO_FORMAT "\nUpgrade on the same version...\n" "white" "bold" clog
# Upgrade the application in a LXC container
LXC_START "sudo yunohost --debug app upgrade $ynh_app_id -f \"$APP_PATH_YUNO\""
LXC_START "sudo yunohost --debug app upgrade $ynh_app_id -f \"$package_dir\""
# yunohost_result gets the return code of the upgrade
yunohost_result=$?
@ -484,9 +482,9 @@ CHECK_UPGRADE () {
# Check the result and print SUCCESS or FAIL
if check_test_result
then # Success
GLOBAL_CHECK_UPGRADE=1 # Upgrade succeed
RESULT_check_upgrade=1 # Upgrade succeed
else # Fail
GLOBAL_CHECK_UPGRADE=-1 # Upgrade failed
RESULT_check_upgrade=-1 # Upgrade failed
fi
# Remove the application
@ -505,9 +503,9 @@ CHECK_PUBLIC_PRIVATE () {
fi
# Check if the needed manifest key are set or abort the test
check_manifest_key "PUBLIC" || return
check_manifest_key "PUBLIC_public" || return
check_manifest_key "PUBLIC_private" || return
check_manifest_key "public" || return
check_manifest_key "public_public" || return
check_manifest_key "public_private" || return
# Check if an install have previously work
local previous_install=$(is_install_failed)
@ -515,17 +513,16 @@ CHECK_PUBLIC_PRIVATE () {
[ "$previous_install" = "1" ] && return
# Copy original arguments
local manifest_args_mod=$MANIFEST_ARGS
local manifest_args_mod=$manifest_arguments
# Replace manifest key for the test
replace_manifest_key "DOMAIN" "$SOUS_DOMAIN"
replace_manifest_key "USER" "$USER_TEST"
replace_manifest_key "PASSWORD" "$PASSWORD_TEST"
replace_manifest_key "domain" "$sub_domain"
replace_manifest_key "user" "$test_user"
# Set public or private according to type of test requested
if [ "$install_type" = "private" ]; then
replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_private"
replace_manifest_key "public" "$public_private_arg"
elif [ "$install_type" = "public" ]; then
replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public"
replace_manifest_key "public" "$public_public_arg"
fi
# Initialize the value
@ -539,14 +536,14 @@ CHECK_PUBLIC_PRIVATE () {
if [ $i -eq 0 ]
then
# Check if root installation worked, or if force_install_ok is setted.
if [ $GLOBAL_CHECK_ROOT -eq 1 ] || [ $force_install_ok -eq 1 ]
if [ $RESULT_check_root -eq 1 ] || [ $force_install_ok -eq 1 ]
then
# Replace manifest key for path
local check_path=/
replace_manifest_key "PATH" "$check_path"
replace_manifest_key "path" "$check_path"
else
# Jump to the second path if this check cannot be do
ECHO_FORMAT "Root install check failed, impossible to perform this test...\n" "lyellow" clog
ECHO_FORMAT "Root install failed, impossible to perform this test...\n" "lyellow" clog
continue
fi
@ -554,14 +551,14 @@ CHECK_PUBLIC_PRIVATE () {
elif [ $i -eq 1 ]
then
# Check if sub path installation worked, or if force_install_ok is setted.
if [ $GLOBAL_CHECK_SUB_DIR -eq 1 ] || [ $force_install_ok -eq 1 ]
if [ $RESULT_check_sub_dir -eq 1 ] || [ $force_install_ok -eq 1 ]
then
# Replace manifest key for path
local check_path=$PATH_TEST
replace_manifest_key "PATH" "$check_path"
local check_path=$test_path
replace_manifest_key "path" "$check_path"
else
# Jump to the second path if this check cannot be do
ECHO_FORMAT "Sub path install check failed, impossible to perform this test...\n" "lyellow" clog
ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "lyellow" clog
return
fi
fi
@ -606,9 +603,9 @@ CHECK_PUBLIC_PRIVATE () {
# Fill the correct variable depend on the type of test
if [ "$install_type" = "private" ]
then
GLOBAL_CHECK_PRIVATE=$check_result_public_private
RESULT_check_private=$check_result_public_private
else # public
GLOBAL_CHECK_PUBLIC=$check_result_public_private
RESULT_check_public=$check_result_public_private
fi
# Make a break if auto_remove is set
@ -622,24 +619,23 @@ CHECK_PUBLIC_PRIVATE () {
CHECK_MULTI_INSTANCE () {
# Try multi-instance installations
unit_test_title "Installation multi-instance..."
unit_test_title "Multi-instance installations..."
# Check if the sub path install have previously work
if [ $GLOBAL_CHECK_SUB_DIR -ne 1 ] && [ $force_install_ok -ne 1 ]
if [ $RESULT_check_sub_dir -ne 1 ] && [ $force_install_ok -ne 1 ]
then
# If subdir installation doesn't worked and force_install_ok not setted, aborted this test.
ECHO_FORMAT "Sub path install check failed, impossible to perform this test...\n" "lred" clog
ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "red" clog
return
fi
# Copy original arguments
local manifest_args_mod=$MANIFEST_ARGS
local manifest_args_mod=$manifest_arguments
# Replace manifest key for the test
replace_manifest_key "DOMAIN" "$SOUS_DOMAIN"
replace_manifest_key "USER" "$USER_TEST"
replace_manifest_key "PASSWORD" "$PASSWORD_TEST"
replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public"
replace_manifest_key "domain" "$sub_domain"
replace_manifest_key "user" "$test_user"
replace_manifest_key "public" "$public_public_arg"
# Install 3 times the same app
local i=0
@ -648,24 +644,24 @@ CHECK_MULTI_INSTANCE () {
# First installation
if [ $i -eq 1 ]
then
local path_1=$PATH_TEST
local path_1=$test_path
ECHO_FORMAT "First installation: path=$path_1\n" clog
check_path=$path_1
# Second installation
elif [ $i -eq 2 ]
then
local path_2=$PATH_TEST-2
local path_2=$test_path-2
ECHO_FORMAT "Second installation: path=$path_2\n" clog
check_path=$path_2
# Third installation
else
local path_3="/3-${PATH_TEST#/}"
local path_3="/3-${test_path#/}"
ECHO_FORMAT "Third installation: path=$path_3\n" clog
check_path=$path_3
fi
# Replace path manifest key for the test
replace_manifest_key "PATH" "$check_path"
replace_manifest_key "path" "$check_path"
# Install the application in a LXC container
SETUP_APP
@ -731,10 +727,10 @@ CHECK_MULTI_INSTANCE () {
if [ $multi_yunohost_result_1 -eq 0 ] && ( [ $multi_yunohost_result_2 -eq 0 ] || [ $multi_yunohost_result_3 -eq 0 ] )
then # Success
check_success
GLOBAL_CHECK_MULTI_INSTANCE=1
RESULT_check_multi_instance=1
else # Fail
check_failed
GLOBAL_CHECK_MULTI_INSTANCE=-1
RESULT_check_multi_instance=-1
fi
# Make a break if auto_remove is set
@ -749,11 +745,11 @@ CHECK_COMMON_ERROR () {
if [ "$install_type" = "incorrect_path" ]; then
unit_test_title "Malformed path..."
# Check if the needed manifest key are set or abort the test
check_manifest_key "PATH" || return
check_manifest_key "path" || return
else [ "$install_type" = "port_already_use" ]
unit_test_title "Port already used..."
# Check if the needed manifest key are set or abort the test
check_manifest_key "PORT" || return
check_manifest_key "port" || return
fi
# Check if an install have previously work
@ -762,29 +758,28 @@ CHECK_COMMON_ERROR () {
[ "$previous_install" = "1" ] && return
# Copy original arguments
local manifest_args_mod=$MANIFEST_ARGS
local manifest_args_mod=$manifest_arguments
# Replace manifest key for the test
replace_manifest_key "DOMAIN" "$SOUS_DOMAIN"
replace_manifest_key "USER" "$USER_TEST"
replace_manifest_key "PASSWORD" "$PASSWORD_TEST"
replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public"
replace_manifest_key "domain" "$sub_domain"
replace_manifest_key "user" "$test_user"
replace_manifest_key "public" "$public_public_arg"
# Replace path manifest key for the test
if [ "$install_type" = "incorrect_path" ]; then
# Change the path from /path to path/
local wrong_path=${PATH_TEST#/}/
local wrong_path=${test_path#/}/
# Use this wrong path only for the arguments that will give to yunohost for installation.
replace_manifest_key "PATH" "$wrong_path"
local check_path=$PATH_TEST
replace_manifest_key "path" "$wrong_path"
local check_path=$test_path
else [ "$install_type" = "port_already_use" ]
# Use a path according to previous succeeded installs
if [ "$previous_install" = "subdir" ]; then
local check_path=$PATH_TEST
local check_path=$test_path
elif [ "$previous_install" = "root" ]; then
local check_path=/
fi
replace_manifest_key "PATH" "$check_path"
replace_manifest_key "path" "$check_path"
fi
# Open the specified port to force the script to find another
@ -792,16 +787,16 @@ CHECK_COMMON_ERROR () {
then
# If the first character is a #, that means it this port number is not in the manifest
if [ "${MANIFEST_PORT:0:1}" = "#" ]
if [ "${port_arg:0:1}" = "#" ]
then
# Retrieve the port number
local check_port="${MANIFEST_PORT:1}"
local check_port="${port_arg:1}"
# Else, the port number is in the manifest. So the port number is set at a fixed value.
else
local check_port=6660
# Replace port manifest key for the test
replace_manifest_key "PORT" "$check_port"
replace_manifest_key "port" "$check_port"
fi
# Open the port before the installation
@ -828,9 +823,9 @@ CHECK_COMMON_ERROR () {
# Fill the correct variable depend on the type of test
if [ "$install_type" = "incorrect_path" ]
then
GLOBAL_CHECK_PATH=$check_result_setup
RESULT_check_path=$check_result_setup
elif [ "$install_type" = "port_already_use" ]; then
GLOBAL_CHECK_PORT=$check_result_setup
RESULT_check_port=$check_result_setup
fi
# Make a break if auto_remove is set
@ -848,13 +843,12 @@ CHECK_BACKUP_RESTORE () {
[ "$previous_install" = "1" ] && return
# Copy original arguments
local manifest_args_mod=$MANIFEST_ARGS
local manifest_args_mod=$manifest_arguments
# Replace manifest key for the test
replace_manifest_key "DOMAIN" "$SOUS_DOMAIN"
replace_manifest_key "USER" "$USER_TEST"
replace_manifest_key "PASSWORD" "$PASSWORD_TEST"
replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public"
replace_manifest_key "domain" "$sub_domain"
replace_manifest_key "user" "$test_user"
replace_manifest_key "public" "$public_public_arg"
# Try in 2 times, first in root and second in sub path.
local i=0
@ -864,15 +858,15 @@ CHECK_BACKUP_RESTORE () {
if [ $i -eq 0 ]
then
# Check if root installation worked, or if force_install_ok is setted.
if [ $GLOBAL_CHECK_ROOT -eq 1 ] || [ $force_install_ok -eq 1 ]
if [ $RESULT_check_root -eq 1 ] || [ $force_install_ok -eq 1 ]
then
# Replace manifest key for path
local check_path=/
replace_manifest_key "PATH" "$check_path"
replace_manifest_key "path" "$check_path"
ECHO_FORMAT "\nPreliminary installation on the root...\n" "white" "bold" clog
else
# Jump to the second path if this check cannot be do
ECHO_FORMAT "Root install check failed, impossible to perform this test...\n" "lyellow" clog
ECHO_FORMAT "Root install failed, impossible to perform this test...\n" "lyellow" clog
continue
fi
@ -880,15 +874,15 @@ CHECK_BACKUP_RESTORE () {
elif [ $i -eq 1 ]
then
# Check if sub path installation worked, or if force_install_ok is setted.
if [ $GLOBAL_CHECK_SUB_DIR -eq 1 ] || [ $force_install_ok -eq 1 ]
if [ $RESULT_check_sub_dir -eq 1 ] || [ $force_install_ok -eq 1 ]
then
# Replace manifest key for path
local check_path=$PATH_TEST
replace_manifest_key "PATH" "$check_path"
local check_path=$test_path
replace_manifest_key "path" "$check_path"
ECHO_FORMAT "\nPreliminary installation in a sub path...\n" "white" "bold" clog
else
# Jump to the second path if this check cannot be do
ECHO_FORMAT "Sub path install check failed, impossible to perform this test...\n" "lyellow" clog
ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "lyellow" clog
return
fi
fi
@ -903,7 +897,7 @@ CHECK_BACKUP_RESTORE () {
# Made a backup if the installation succeed
if [ $yunohost_result -ne 0 ]
then
ECHO_FORMAT "\nInstallation failed...\n" "lred" "bold"
ECHO_FORMAT "\nInstallation failed...\n" "red" "bold"
else
ECHO_FORMAT "\nBackup of the application...\n" "white" "bold" clog
@ -929,16 +923,16 @@ CHECK_BACKUP_RESTORE () {
then # Success
check_success
# The global success for a backup can't be a success if another backup failed
if [ $GLOBAL_CHECK_BACKUP -ne -1 ]; then
GLOBAL_CHECK_BACKUP=1 # Backup succeed
if [ $RESULT_check_backup -ne -1 ]; then
RESULT_check_backup=1 # Backup succeed
fi
else # Fail
check_failed
GLOBAL_CHECK_BACKUP=-1 # Backup failed
RESULT_check_backup=-1 # Backup failed
fi
# Grab the backup archive into the LXC container, and keep a copy
sudo cp -a /var/lib/lxc/$LXC_NAME/rootfs/home/yunohost.backup/archives ./
sudo cp -a /var/lib/lxc/$lxc_name/rootfs/home/yunohost.backup/archives ./
# RESTORE
# Try the restore process in 2 times, first after removing the app, second after a restore of the container.
@ -960,7 +954,7 @@ CHECK_BACKUP_RESTORE () {
LXC_STOP
# Place the copy of the backup archive in the container.
sudo mv -f ./archives /var/lib/lxc/$LXC_NAME/rootfs/home/yunohost.backup/
sudo mv -f ./archives /var/lib/lxc/$lxc_name/rootfs/home/yunohost.backup/
ECHO_FORMAT "\nRestore on a clean YunoHost system...\n" "white" "bold" clog
fi
@ -988,11 +982,11 @@ CHECK_BACKUP_RESTORE () {
if check_test_result
then # Success
# The global success for a restore can't be a success if another restore failed
if [ $GLOBAL_CHECK_RESTORE -ne -1 ]; then
GLOBAL_CHECK_RESTORE=1 # Restore succeed
if [ $RESULT_check_restore -ne -1 ]; then
RESULT_check_restore=1 # Restore succeed
fi
else # Fail
GLOBAL_CHECK_RESTORE=-1 # Restore failed
RESULT_check_restore=-1 # Restore failed
fi
# Make a break if auto_remove is set
@ -1010,7 +1004,7 @@ PACKAGE_LINTER () {
unit_test_title "Package linter..."
# Execute package linter and linter_result gets the return code of the package linter
"$script_dir/package_linter/package_linter.py" "$APP_CHECK" > "$temp_result"
"$script_dir/package_linter/package_linter.py" "$package_path" > "$temp_result"
# linter_result gets the return code of the package linter
local linter_result=$?
@ -1022,10 +1016,10 @@ PACKAGE_LINTER () {
if [ $linter_result -eq 0 ]
then # Success
check_success
GLOBAL_LINTER=1
RESULT_linter=1
else # Fail
check_failed
GLOBAL_LINTER=-1
RESULT_linter=-1
fi
}
@ -1036,7 +1030,7 @@ TEST_LAUNCHER () {
# Intialize values
yunohost_result=-1
YUNOHOST_REMOVE=-1
yunohost_remove=-1
# Execute the test
$1 $2
@ -1048,7 +1042,7 @@ TEST_LAUNCHER () {
TESTING_PROCESS () {
# Launch all tests successively
ECHO_FORMAT "\nScénario de test: $PROCESS_NAME\n" "white" "underlined" clog
ECHO_FORMAT "\nTests serie: ${tests_serie#;; }\n" "white" "underlined" clog
# Init the value for the current test
cur_test=1