From 0c0db4c8a4c3c9526eccd11d6c28bbf91e0eb776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 10 May 2019 23:47:08 +0200 Subject: [PATCH] Check if the migration is possible --- locales/en.json | 2 +- .../data_migrations/0011_setup_group_permission.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/locales/en.json b/locales/en.json index ff4155924..31513a546 100644 --- a/locales/en.json +++ b/locales/en.json @@ -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}'", diff --git a/src/yunohost/data_migrations/0011_setup_group_permission.py b/src/yunohost/data_migrations/0011_setup_group_permission.py index 89bad6306..a4b37fd87 100644 --- a/src/yunohost/data_migrations/0011_setup_group_permission.py +++ b/src/yunohost/data_migrations/0011_setup_group_permission.py @@ -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')