From 92fa21641bfa8c3c323fe87a4dbb27086a9c8b38 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 9 Sep 2019 12:07:44 +0200 Subject: [PATCH] Fix some stuff about removing the --revert option --- locales/en.json | 8 +++----- .../0007_ssh_conf_managed_by_yunohost_step1.py | 9 +++++++++ src/yunohost/tools.py | 6 +++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/locales/en.json b/locales/en.json index 850d89032..a4596941f 100644 --- a/locales/en.json +++ b/locales/en.json @@ -320,7 +320,6 @@ "migrate_tsig_wait_3": "1min…", "migrate_tsig_wait_4": "30 secondes…", "migrate_tsig_not_needed": "You do not appear to use a dyndns domain, so no migration is needed!", - "migration_backward_impossible": "The migration {name} cannot be reverted.", "migration_description_0001_change_cert_group_to_sslcert": "Change certificates group permissions from 'metronome' to 'ssl-cert'", "migration_description_0002_migrate_to_tsig_sha256": "Improve security of dyndns TSIG by using SHA512 instead of MD5", "migration_description_0003_migrate_to_stretch": "Upgrade the system to Debian Stretch and YunoHost 3.0", @@ -372,20 +371,19 @@ "migrations_cant_reach_migration_file": "Can't access migrations files at path %s", "migrations_dependencies_not_satisfied": "Can't run migration {id} because first you need to run these migrations: {dependencies_id}", "migrations_failed_to_load_migration": "Failed to load migration {id} : {error}", - "migrations_exclusive_options": "--auto, --skip, --revert and --force-rerun are exclusive options.", + "migrations_exclusive_options": "--auto, --skip, and --force-rerun are exclusive options.", "migrations_list_conflict_pending_done": "You cannot use both --previous and --done at the same time.", "migrations_loading_migration": "Loading migration {id}…", "migrations_migration_has_failed": "Migration {id} has failed, aborting. Error: {exception}", - "migrations_must_provide_explicit_targets": "You must provide explicit targets when using --skip, --revert or --force-rerun", + "migrations_must_provide_explicit_targets": "You must provide explicit targets when using --skip or --force-rerun", "migrations_need_to_accept_disclaimer": "To run the migration {id}, your must accept the following disclaimer:\n---\n{disclaimer}\n---\nIf you accept to run the migration, please re-run the command with the option --accept-disclaimer.", "migrations_no_migrations_to_run": "No migrations to run", "migrations_no_such_migration": "No such migration called {id}", "migrations_not_pending_cant_skip": "Those migrations are not pending so cannot be skipped: {ids}", - "migrations_pending_cant_revert_or_rerun": "Those migrations are still pending so cannot be reverted or reran: {ids}", + "migrations_pending_cant_rerun": "Those migrations are still pending so cannot be reran: {ids}", "migrations_running_forward": "Running migration {id}…", "migrations_skip_migration": "Skipping migration {id}…", "migrations_success_forward": "Successfully ran migration {id}!", - "migrations_success_revert": "Successfully reverted migration {id}!", "migrations_to_be_ran_manually": "Migration {id} has to be ran manually. Please go to Tools > Migrations on the webadmin, or run `yunohost tools migrations migrate`.", "monitor_disabled": "The server monitoring has been disabled", "monitor_enabled": "The server monitoring has been enabled", diff --git a/src/yunohost/data_migrations/0007_ssh_conf_managed_by_yunohost_step1.py b/src/yunohost/data_migrations/0007_ssh_conf_managed_by_yunohost_step1.py index 818760e17..624288210 100644 --- a/src/yunohost/data_migrations/0007_ssh_conf_managed_by_yunohost_step1.py +++ b/src/yunohost/data_migrations/0007_ssh_conf_managed_by_yunohost_step1.py @@ -59,3 +59,12 @@ class MyMigration(Migration): copyfile(SSHD_CONF, '/etc/ssh/sshd_config.bkp') regen_conf(names=['ssh'], force=True) copyfile('/etc/ssh/sshd_config.bkp', SSHD_CONF) + + # Restart ssh and rollback if it failed + if not _run_service_command('restart', 'ssh'): + # We don't rollback completely but it should be enough + copyfile('/etc/ssh/sshd_config.bkp', SSHD_CONF) + if not _run_service_command('restart', 'ssh'): + raise YunohostError("migration_0007_cannot_restart") + else: + raise YunohostError("migration_0007_cancelled") diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index d2015adff..8e2635e2c 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -1081,7 +1081,7 @@ def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=Fal if skip and done: raise YunohostError("migrations_not_pending_cant_skip", ids=', '.join(done)) if force_rerun and pending: - raise YunohostError("migrations_pending_cant_revert_or_rerun", ids=', '.join(pending)) + raise YunohostError("migrations_pending_cant_rerun", ids=', '.join(pending)) if not (skip or force_rerun) and done: raise YunohostError("migrations_already_ran", ids=', '.join(done)) @@ -1304,11 +1304,11 @@ class Migration(object): def disclaimer(self): return None - # The followings shouldn't be overriden - def run(self): raise NotImplementedError() + # The followings shouldn't be overriden + def __init__(self, id_): self.id = id_ self.number = int(self.id.split("_", 1)[0])