Fix and improve migration

This commit is contained in:
Josué Tille 2020-04-02 16:58:24 +02:00
parent 7afe07018e
commit 756237c051
No known key found for this signature in database
GPG key ID: 716A6C99B04194EF
3 changed files with 8 additions and 20 deletions

View file

@ -428,6 +428,8 @@
"migration_0011_update_LDAP_database": "Updating LDAP database…",
"migration_0011_update_LDAP_schema": "Updating LDAP schema…",
"migration_0011_failed_to_remove_stale_object": "Could not remove stale object {dn}: {error}",
"migration_0015_add_new_attributes_in_ldap": "Add new attributes for permissions in LDAP database",
"migration_0015_migrate_old_app_settings": "Migrate old apps settings 'skipped_uris', 'unprotected_uris', 'protected_uris' in permissions system.",
"migrations_already_ran": "Those migrations are already done: {ids}",
"migrations_cant_reach_migration_file": "Could not access migrations files at the path '%s'",
"migrations_dependencies_not_satisfied": "Run these migrations: '{dependencies_id}', before migration {id}.",

View file

@ -1208,10 +1208,6 @@ def app_ssowatconf():
redirected_regex = {main_domain + '/yunohost[\/]?$': 'https://' + main_domain + '/yunohost/sso/'}
redirected_urls = {}
def _get_setting(settings, name):
s = settings.get(name, None)
return s.split(',') if s else []
for app in _installed_apps():
app_settings = read_yaml(APPS_SETTING_PATH + app + '/settings.yml')

View file

@ -6,8 +6,8 @@ from yunohost.utils.error import YunohostError
from moulinette.utils.log import getActionLogger
from yunohost.tools import Migration
from yunohost.app import app_setting, app_ssowatconf
from yunohost.permission import user_permission_list, SYSTEM_PERMS
from yunohost.app import app_setting, app_ssowatconf, _installed_apps
from yunohost.permission import user_permission_list, SYSTEM_PERMS, permission_sync_to_user
logger = getActionLogger('yunohost.migration')
@ -29,10 +29,12 @@ class MyMigration(Migration):
if ldap_regen_conf_status and ldap_regen_conf_status['slapd']['pending']:
logger.warning(m18n.n("migration_0011_slapd_config_will_be_overwritten", conf_backup_folder=BACKUP_CONF_DIR))
# Update LDAP schema restart slapd
logger.info(m18n.n("migration_0011_update_LDAP_schema"))
regen_conf(names=['slapd'], force=True)
logger.info(m18n.n("migration_0015_add_new_attributes_in_ldap"))
ldap = _get_ldap_interface()
permission_list = user_permission_list(short=True)["permissions"]
for permission in permission_list:
@ -62,18 +64,13 @@ class MyMigration(Migration):
})
app_setting(permission.split('.')[0], 'label', delete=True)
def run(self):
# FIXME : what do we really want to do here ...
# Imho we should just force-regen the conf in all case, and maybe
# just display a warning if we detect that the conf was manually modified
# 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']:
logger.warning(m18n.n("migration_0011_slapd_config_will_be_overwritten", conf_backup_folder=BACKUP_CONF_DIR))
# Backup LDAP and the apps settings before to do the migration
logger.info(m18n.n("migration_0011_backup_before_migration"))
try:
@ -89,10 +86,6 @@ class MyMigration(Migration):
os.system("systemctl start slapd")
try:
# Update LDAP schema restart slapd
logger.info(m18n.n("migration_0011_update_LDAP_schema"))
regen_conf(names=['slapd'], force=True)
# Update LDAP database
self.add_new_ldap_attributes()
@ -111,6 +104,3 @@ class MyMigration(Migration):
raise
else:
os.system("rm -r " + backup_folder)
logger.info(m18n.n("migration_0011_done"))