mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #774 from YunoHost/enh-remove-revert-mechanism
[enh] remove revert mechanism
This commit is contained in:
commit
e97c708b11
14 changed files with 42 additions and 77 deletions
|
@ -1735,9 +1735,6 @@ tools:
|
||||||
--skip:
|
--skip:
|
||||||
help: Skip specified migrations (to be used only if you know what you are doing)
|
help: Skip specified migrations (to be used only if you know what you are doing)
|
||||||
action: store_true
|
action: store_true
|
||||||
--revert:
|
|
||||||
help: Attempt to revert already-ran specified migrations (to be used only if you know what you are doing)
|
|
||||||
action: store_true
|
|
||||||
--force-rerun:
|
--force-rerun:
|
||||||
help: Re-run already-ran specified migration (to be used only if you know what you are doing)
|
help: Re-run already-ran specified migration (to be used only if you know what you are doing)
|
||||||
action: store_true
|
action: store_true
|
||||||
|
|
|
@ -297,7 +297,6 @@
|
||||||
"log_user_permission_remove": "Update '{}' permission",
|
"log_user_permission_remove": "Update '{}' permission",
|
||||||
"log_tools_maindomain": "Make '{}' as main domain",
|
"log_tools_maindomain": "Make '{}' as main domain",
|
||||||
"log_tools_migrations_migrate_forward": "Migrate forward",
|
"log_tools_migrations_migrate_forward": "Migrate forward",
|
||||||
"log_tools_migrations_migrate_backward": "Migrate backward",
|
|
||||||
"log_tools_postinstall": "Postinstall your YunoHost server",
|
"log_tools_postinstall": "Postinstall your YunoHost server",
|
||||||
"log_tools_upgrade": "Upgrade system packages",
|
"log_tools_upgrade": "Upgrade system packages",
|
||||||
"log_tools_shutdown": "Shutdown your server",
|
"log_tools_shutdown": "Shutdown your server",
|
||||||
|
@ -384,7 +383,6 @@
|
||||||
"migrations_not_pending_cant_skip": "Those migrations are not pending so cannot be skipped: {ids}",
|
"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_revert_or_rerun": "Those migrations are still pending so cannot be reverted or reran: {ids}",
|
||||||
"migrations_running_forward": "Running migration {id}…",
|
"migrations_running_forward": "Running migration {id}…",
|
||||||
"migrations_running_backward": "Attempting to revert migration {id}…",
|
|
||||||
"migrations_skip_migration": "Skipping migration {id}…",
|
"migrations_skip_migration": "Skipping migration {id}…",
|
||||||
"migrations_success_forward": "Successfully ran migration {id}!",
|
"migrations_success_forward": "Successfully ran migration {id}!",
|
||||||
"migrations_success_revert": "Successfully reverted migration {id}!",
|
"migrations_success_revert": "Successfully reverted migration {id}!",
|
||||||
|
|
|
@ -10,10 +10,6 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
all_certificate_files = glob.glob("/etc/yunohost/certs/*/*.pem")
|
all_certificate_files = glob.glob("/etc/yunohost/certs/*/*.pem")
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
for filename in self.all_certificate_files:
|
for filename in self.all_certificate_files:
|
||||||
chown(filename, uid="root", gid="ssl-cert")
|
chown(filename, uid="root", gid="ssl-cert")
|
||||||
|
|
||||||
def backward(self):
|
|
||||||
for filename in self.all_certificate_files:
|
|
||||||
chown(filename, uid="root", gid="metronome")
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
"Migrate Dyndns stuff from MD5 TSIG to SHA512 TSIG"
|
"Migrate Dyndns stuff from MD5 TSIG to SHA512 TSIG"
|
||||||
|
|
||||||
def migrate(self, dyn_host="dyndns.yunohost.org", domain=None, private_key_path=None):
|
def run(self, dyn_host="dyndns.yunohost.org", domain=None, private_key_path=None):
|
||||||
|
|
||||||
if domain is None or private_key_path is None:
|
if domain is None or private_key_path is None:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -29,7 +29,7 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
mode = "manual"
|
mode = "manual"
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
|
|
||||||
self.logfile = "/var/log/yunohost/{}.log".format(self.name)
|
self.logfile = "/var/log/yunohost/{}.log".format(self.name)
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,7 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
dependencies = ["migrate_to_stretch"]
|
dependencies = ["migrate_to_stretch"]
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
|
|
||||||
# Get list of php5 pool files
|
# Get list of php5 pool files
|
||||||
php5_pool_files = glob.glob("{}/*.conf".format(PHP5_POOLS))
|
php5_pool_files = glob.glob("{}/*.conf".format(PHP5_POOLS))
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
dependencies = ["migrate_to_stretch"]
|
dependencies = ["migrate_to_stretch"]
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
|
|
||||||
if not self.package_is_installed("postgresql-9.4"):
|
if not self.package_is_installed("postgresql-9.4"):
|
||||||
logger.warning(m18n.n("migration_0005_postgresql_94_not_installed"))
|
logger.warning(m18n.n("migration_0005_postgresql_94_not_installed"))
|
||||||
|
|
|
@ -20,7 +20,7 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
"Synchronize admin and root passwords"
|
"Synchronize admin and root passwords"
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
|
|
||||||
new_hash = self._get_admin_hash()
|
new_hash = self._get_admin_hash()
|
||||||
self._replace_root_hash(new_hash)
|
self._replace_root_hash(new_hash)
|
||||||
|
|
|
@ -34,7 +34,7 @@ class MyMigration(Migration):
|
||||||
use the recommended configuration, with an appropriate disclaimer.
|
use the recommended configuration, with an appropriate disclaimer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
|
|
||||||
# Check if deprecated DSA Host Key is in config
|
# Check if deprecated DSA Host Key is in config
|
||||||
dsa_rgx = r'^[ \t]*HostKey[ \t]+/etc/ssh/ssh_host_dsa_key[ \t]*(?:#.*)?$'
|
dsa_rgx = r'^[ \t]*HostKey[ \t]+/etc/ssh/ssh_host_dsa_key[ \t]*(?:#.*)?$'
|
||||||
|
@ -59,15 +59,3 @@ class MyMigration(Migration):
|
||||||
copyfile(SSHD_CONF, '/etc/ssh/sshd_config.bkp')
|
copyfile(SSHD_CONF, '/etc/ssh/sshd_config.bkp')
|
||||||
regen_conf(names=['ssh'], force=True)
|
regen_conf(names=['ssh'], force=True)
|
||||||
copyfile('/etc/ssh/sshd_config.bkp', SSHD_CONF)
|
copyfile('/etc/ssh/sshd_config.bkp', SSHD_CONF)
|
||||||
|
|
||||||
# Restart ssh and backward if it fail
|
|
||||||
if not _run_service_command('restart', 'ssh'):
|
|
||||||
self.backward()
|
|
||||||
raise YunohostError("migration_0007_cancel")
|
|
||||||
|
|
||||||
def backward(self):
|
|
||||||
|
|
||||||
# We don't backward 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")
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
dependencies = ["ssh_conf_managed_by_yunohost_step1"]
|
dependencies = ["ssh_conf_managed_by_yunohost_step1"]
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
settings_set("service.ssh.allow_deprecated_dsa_hostkey", False)
|
settings_set("service.ssh.allow_deprecated_dsa_hostkey", False)
|
||||||
regen_conf(names=['ssh'], force=True)
|
regen_conf(names=['ssh'], force=True)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class MyMigration(Migration):
|
||||||
Decouple the regen conf mechanism from the concept of services
|
Decouple the regen conf mechanism from the concept of services
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
|
|
||||||
if "conffiles" not in read_file("/etc/yunohost/services.yml") \
|
if "conffiles" not in read_file("/etc/yunohost/services.yml") \
|
||||||
or os.path.exists(REGEN_CONF_FILE):
|
or os.path.exists(REGEN_CONF_FILE):
|
||||||
|
|
|
@ -15,7 +15,7 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
"Migrate from official.json to apps.json"
|
"Migrate from official.json to apps.json"
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
|
|
||||||
# Backup current app list json
|
# Backup current app list json
|
||||||
os.system("cp %s %s" % (APPSLISTS_JSON, APPSLISTS_BACKUP))
|
os.system("cp %s %s" % (APPSLISTS_JSON, APPSLISTS_BACKUP))
|
||||||
|
@ -28,17 +28,21 @@ class MyMigration(Migration):
|
||||||
"labriqueinter.net/apps/labriqueinternet.json",
|
"labriqueinter.net/apps/labriqueinternet.json",
|
||||||
"labriqueinter.net/internetcube.json"
|
"labriqueinter.net/internetcube.json"
|
||||||
]
|
]
|
||||||
|
try:
|
||||||
|
appslists = _read_appslist_list()
|
||||||
|
for appslist, infos in appslists.items():
|
||||||
|
if infos["url"].split("//")[-1] in lists_to_remove:
|
||||||
|
app_removelist(name=appslist)
|
||||||
|
|
||||||
appslists = _read_appslist_list()
|
# Replace by apps.json list
|
||||||
for appslist, infos in appslists.items():
|
app_fetchlist(name="yunohost",
|
||||||
if infos["url"].split("//")[-1] in lists_to_remove:
|
url="https://app.yunohost.org/apps.json")
|
||||||
app_removelist(name=appslist)
|
except Exception:
|
||||||
|
if os.path.exists(APPSLISTS_BACKUP):
|
||||||
|
os.system("cp %s %s" % (APPSLISTS_BACKUP, APPSLISTS_JSON))
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
if os.path.exists(APPSLISTS_BACKUP):
|
||||||
|
os.remove(APPSLISTS_BACKUP)
|
||||||
|
|
||||||
# Replace by apps.json list
|
|
||||||
app_fetchlist(name="yunohost",
|
|
||||||
url="https://app.yunohost.org/apps.json")
|
|
||||||
|
|
||||||
def backward(self):
|
|
||||||
|
|
||||||
if os.path.exists(APPSLISTS_BACKUP):
|
|
||||||
os.system("cp %s %s" % (APPSLISTS_BACKUP, APPSLISTS_JSON))
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ class MyMigration(Migration):
|
||||||
app_setting(app, 'allowed_users', delete=True)
|
app_setting(app, 'allowed_users', delete=True)
|
||||||
|
|
||||||
|
|
||||||
def forward(self):
|
def run(self):
|
||||||
# Check if the migration can be processed
|
# Check if the migration can be processed
|
||||||
ldap_regen_conf_status = regen_conf(names=['slapd'], dry_run=True)
|
ldap_regen_conf_status = regen_conf(names=['slapd'], dry_run=True)
|
||||||
# By this we check if the have been customized
|
# By this we check if the have been customized
|
||||||
|
|
|
@ -1038,7 +1038,7 @@ def tools_migrations_list(pending=False, done=False):
|
||||||
return {"migrations": migrations}
|
return {"migrations": migrations}
|
||||||
|
|
||||||
|
|
||||||
def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=False, revert=False, accept_disclaimer=False):
|
def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=False, accept_disclaimer=False):
|
||||||
"""
|
"""
|
||||||
Perform migrations
|
Perform migrations
|
||||||
|
|
||||||
|
@ -1046,7 +1046,6 @@ def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=Fal
|
||||||
--skip Skip specified migrations (to be used only if you know what you are doing) (must explicit which migrations)
|
--skip Skip specified migrations (to be used only if you know what you are doing) (must explicit which migrations)
|
||||||
--auto Automatic mode, won't run manual migrations (to be used only if you know what you are doing)
|
--auto Automatic mode, won't run manual migrations (to be used only if you know what you are doing)
|
||||||
--force-rerun Re-run already-ran migrations (to be used only if you know what you are doing)(must explicit which migrations)
|
--force-rerun Re-run already-ran migrations (to be used only if you know what you are doing)(must explicit which migrations)
|
||||||
--revert Attempt to revert already-ran migrations (to be used only if you know what you are doing)(must explicit which migrations)
|
|
||||||
--accept-disclaimer Accept disclaimers of migrations (please read them before using this option) (only valid for one migration)
|
--accept-disclaimer Accept disclaimers of migrations (please read them before using this option) (only valid for one migration)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -1060,14 +1059,14 @@ def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=Fal
|
||||||
|
|
||||||
raise YunohostError("migrations_no_such_migration", id=target)
|
raise YunohostError("migrations_no_such_migration", id=target)
|
||||||
|
|
||||||
# auto, skip, revert and force are exclusive options
|
# auto, skip and force are exclusive options
|
||||||
if auto + skip + revert + force_rerun > 1:
|
if auto + skip + force_rerun > 1:
|
||||||
raise YunohostError("migrations_exclusive_options")
|
raise YunohostError("migrations_exclusive_options")
|
||||||
|
|
||||||
# If no target specified
|
# If no target specified
|
||||||
if not targets:
|
if not targets:
|
||||||
# skip, revert or force require explicit targets
|
# skip, revert or force require explicit targets
|
||||||
if (skip or revert or force_rerun):
|
if (skip or force_rerun):
|
||||||
raise YunohostError("migrations_must_provide_explicit_targets")
|
raise YunohostError("migrations_must_provide_explicit_targets")
|
||||||
|
|
||||||
# Otherwise, targets are all pending migrations
|
# Otherwise, targets are all pending migrations
|
||||||
|
@ -1081,9 +1080,9 @@ def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=Fal
|
||||||
|
|
||||||
if skip and done:
|
if skip and done:
|
||||||
raise YunohostError("migrations_not_pending_cant_skip", ids=', '.join(done))
|
raise YunohostError("migrations_not_pending_cant_skip", ids=', '.join(done))
|
||||||
if (revert or force_rerun) and pending:
|
if force_rerun and pending:
|
||||||
raise YunohostError("migrations_pending_cant_revert_or_rerun", ids=', '.join(pending))
|
raise YunohostError("migrations_pending_cant_revert_or_rerun", ids=', '.join(pending))
|
||||||
if not (skip or revert or force_rerun) and done:
|
if not (skip or force_rerun) and done:
|
||||||
raise YunohostError("migrations_already_ran", ids=', '.join(done))
|
raise YunohostError("migrations_already_ran", ids=', '.join(done))
|
||||||
|
|
||||||
# So, is there actually something to do ?
|
# So, is there actually something to do ?
|
||||||
|
@ -1105,7 +1104,7 @@ def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=Fal
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Check for migration dependencies
|
# Check for migration dependencies
|
||||||
if not revert and not skip:
|
if not skip:
|
||||||
dependencies = [get_matching_migration(dep) for dep in migration.dependencies]
|
dependencies = [get_matching_migration(dep) for dep in migration.dependencies]
|
||||||
pending_dependencies = [dep.id for dep in dependencies if dep.state == "pending"]
|
pending_dependencies = [dep.id for dep in dependencies if dep.state == "pending"]
|
||||||
if pending_dependencies:
|
if pending_dependencies:
|
||||||
|
@ -1115,7 +1114,7 @@ def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=Fal
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# If some migrations have disclaimers (and we're not trying to skip them)
|
# If some migrations have disclaimers (and we're not trying to skip them)
|
||||||
if migration.disclaimer and not skip and not revert:
|
if migration.disclaimer and not skip:
|
||||||
# require the --accept-disclaimer option.
|
# require the --accept-disclaimer option.
|
||||||
# Otherwise, go to the next migration
|
# Otherwise, go to the next migration
|
||||||
if not accept_disclaimer:
|
if not accept_disclaimer:
|
||||||
|
@ -1128,8 +1127,7 @@ def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=Fal
|
||||||
accept_disclaimer = False
|
accept_disclaimer = False
|
||||||
|
|
||||||
# Start register change on system
|
# Start register change on system
|
||||||
mode = "backward" if revert else "forward"
|
operation_logger = OperationLogger('tools_migrations_migrate_forward')
|
||||||
operation_logger = OperationLogger('tools_migrations_migrate_' + mode)
|
|
||||||
operation_logger.start()
|
operation_logger.start()
|
||||||
|
|
||||||
if skip:
|
if skip:
|
||||||
|
@ -1141,12 +1139,8 @@ def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=Fal
|
||||||
|
|
||||||
try:
|
try:
|
||||||
migration.operation_logger = operation_logger
|
migration.operation_logger = operation_logger
|
||||||
if revert:
|
logger.info(m18n.n('migrations_running_forward', id=migration.id))
|
||||||
logger.info(m18n.n('migrations_running_backward', id=migration.id))
|
migration.run()
|
||||||
migration.backward()
|
|
||||||
else:
|
|
||||||
logger.info(m18n.n('migrations_running_forward', id=migration.id))
|
|
||||||
migration.migrate()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# migration failed, let's stop here but still update state because
|
# migration failed, let's stop here but still update state because
|
||||||
# we managed to run the previous ones
|
# we managed to run the previous ones
|
||||||
|
@ -1155,14 +1149,9 @@ def tools_migrations_migrate(targets=[], skip=False, auto=False, force_rerun=Fal
|
||||||
logger.error(msg, exc_info=1)
|
logger.error(msg, exc_info=1)
|
||||||
operation_logger.error(msg)
|
operation_logger.error(msg)
|
||||||
else:
|
else:
|
||||||
if revert:
|
logger.success(m18n.n('migrations_success_forward', id=migration.id))
|
||||||
logger.success(m18n.n('migrations_success_revert', id=migration.id))
|
migration.state = "done"
|
||||||
migration.state = "pending"
|
_write_migration_state(migration.id, "done")
|
||||||
_write_migration_state(migration.id, "pending")
|
|
||||||
else:
|
|
||||||
logger.success(m18n.n('migrations_success_forward', id=migration.id))
|
|
||||||
migration.state = "done"
|
|
||||||
_write_migration_state(migration.id, "done")
|
|
||||||
|
|
||||||
operation_logger.success()
|
operation_logger.success()
|
||||||
|
|
||||||
|
@ -1311,20 +1300,14 @@ class Migration(object):
|
||||||
mode = "auto"
|
mode = "auto"
|
||||||
dependencies = [] # List of migration ids required before running this migration
|
dependencies = [] # List of migration ids required before running this migration
|
||||||
|
|
||||||
def forward(self):
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def backward(self):
|
|
||||||
raise YunohostError("migration_backward_impossible", name=self.name)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def disclaimer(self):
|
def disclaimer(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# The followings shouldn't be overriden
|
# The followings shouldn't be overriden
|
||||||
|
|
||||||
def migrate(self):
|
def run(self):
|
||||||
self.forward()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def __init__(self, id_):
|
def __init__(self, id_):
|
||||||
self.id = id_
|
self.id = id_
|
||||||
|
|
Loading…
Add table
Reference in a new issue