Check if the migration is possible

This commit is contained in:
Josué Tille 2019-05-10 23:47:08 +02:00
parent fde8cafa4e
commit 0c0db4c8a4
No known key found for this signature in database
GPG key ID: D5E068C6DFA8681D
2 changed files with 9 additions and 3 deletions

View file

@ -357,6 +357,7 @@
"migration_0011_can_not_backup_before_migration": "The backup of the system before the migration failed. Migration failed. Error: {error:s}",
"migration_0011_create_group": "Create group for each user.",
"migration_0011_done": "Migration sucess. You are now able to use groups of user.",
"migration_0011_LDAP_config_dirty": "It look like that you customized your LDAP configuration. For this migration the LDAP configuration need to be updated.\nYou need to save your actual configuration, reintialize the original configuration by the command 'yunohost tools regen-conf -f' and after retry the migration",
"migration_0011_LDAP_update_failed": "LDAP update failed. Error: {error:s}",
"migration_0011_migrate_permission": "Migrate permission from apps settings to LDAP",
"migration_0011_migration_failed_trying_to_rollback": "Migration failed ... trying to rollback the system.",
@ -460,7 +461,6 @@
"regenconf_dry_pending_applying": "Checking pending configuration which would have been applied for category '{category}'…",
"regenconf_failed": "Unable to regenerate the configuration for category(s): {categories}",
"regenconf_pending_applying": "Applying pending configuration for category '{category}'…",
>>>>>>> upstream/stretch-unstable
"restore_action_required": "You must specify something to restore",
"restore_already_installed_app": "An app is already installed with the id '{app:s}'",
"restore_app_failed": "Unable to restore the app '{app:s}'",

View file

@ -10,7 +10,7 @@ from moulinette.utils.log import getActionLogger
from yunohost.tools import Migration
from yunohost.user import user_group_add, user_group_update
from yunohost.app import app_setting, app_list
from yunohost.service import service_regen_conf
from yunohost.regenconf import regen_conf
from yunohost.permission import permission_add, permission_sync_to_user
from yunohost.user import user_permission_add
@ -90,6 +90,12 @@ class MyMigration(Migration):
required = True
def migrate(self):
# Check if the migration can be processed
ldap_regen_conf_status = regen_conf(names=['slapd'], dry_run=True)
# By this we check if the have been customized
if ldap_regen_conf_status and ldap_regen_conf_status['slapd']['pending']:
raise YunohostError("migration_0011_LDAP_config_dirty")
# Backup LDAP and the apps settings before to do the migration
logger.info(m18n.n("migration_0011_backup_before_migration"))
try:
@ -107,7 +113,7 @@ class MyMigration(Migration):
try:
# Update LDAP schema restart slapd
logger.info(m18n.n("migration_0011_update_LDAP_schema"))
service_regen_conf(names=['slapd'], force=True)
regen_conf(names=['slapd'], force=True)
# Do the authentication to LDAP after LDAP as been updated
AUTH_IDENTIFIER = ('ldap', 'as-root')