Sandro Bonazzola has uploaded a new change for review. Change subject: packaging: setup: rollback legacy sysconfig ......................................................................
packaging: setup: rollback legacy sysconfig Rolling back also /etc/sysconfig/ovirt-engine on cleanup after failure. Change-Id: Ie9e4a90a7e0e47aeb88a938fedb4f2088d533a70 Bug-Url: https://bugzilla.redhat.com/1049622 Signed-off-by: Sandro Bonazzola <[email protected]> --- M packaging/setup/plugins/ovirt-engine-setup/legacy/config.py 1 file changed, 52 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/92/23092/1 diff --git a/packaging/setup/plugins/ovirt-engine-setup/legacy/config.py b/packaging/setup/plugins/ovirt-engine-setup/legacy/config.py index 7e40b99..379f58d 100644 --- a/packaging/setup/plugins/ovirt-engine-setup/legacy/config.py +++ b/packaging/setup/plugins/ovirt-engine-setup/legacy/config.py @@ -20,6 +20,7 @@ import os +import stat import glob import gettext _ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup') @@ -43,6 +44,8 @@ def __init__(self, context): super(Plugin, self).__init__(context=context) + self._backup = None + self._backup_stat = None @plugin.event( stage=plugin.Stages.STAGE_CUSTOMIZATION, @@ -115,6 +118,27 @@ ) @plugin.event( + stage=plugin.Stages.STAGE_EARLY_MISC, + condition=lambda self: self.environment[ + osetupcons.CoreEnv.UPGRADE_FROM_LEGACY + ], + ) + def _early_misc(self): + if os.path.exists( + osetupcons.FileLocations.LEGACY_OVIRT_ENGINE_SYSCONFIG + ): + # keep a copy of sysconfig content before yum transaction, + # allowing rollback. + self._backup_stat = os.stat( + osetupcons.FileLocations.LEGACY_OVIRT_ENGINE_SYSCONFIG + ) + with open( + osetupcons.FileLocations.LEGACY_OVIRT_ENGINE_SYSCONFIG, + 'r', + ) as f: + self._backup = f.read() + + @plugin.event( stage=plugin.Stages.STAGE_MISC, condition=lambda self: self.environment[ osetupcons.CoreEnv.UPGRADE_FROM_LEGACY @@ -150,6 +174,34 @@ ) @plugin.event( + stage=plugin.Stages.STAGE_CLEANUP, + condition=lambda self: self.environment[ + osetupcons.CoreEnv.UPGRADE_FROM_LEGACY + ], + ) + def _cleanup(self): + if ( + self._backup is not None and + self.environment[otopicons.BaseEnv.ERROR] + ): + with open( + osetupcons.FileLocations.LEGACY_OVIRT_ENGINE_SYSCONFIG, + 'w', + ) as f: + f.write( + self._backup, + ) + os.chmod( + osetupcons.FileLocations.LEGACY_OVIRT_ENGINE_SYSCONFIG, + stat.S_IMODE(self._backup_stat.st_mode) + ) + os.chown( + osetupcons.FileLocations.LEGACY_OVIRT_ENGINE_SYSCONFIG, + self._backup_stat.st_uid, + self._backup_stat.st_gid + ) + + @plugin.event( stage=plugin.Stages.STAGE_CLOSEUP, condition=lambda self: self.environment[ osetupcons.CoreEnv.UPGRADE_FROM_LEGACY -- To view, visit http://gerrit.ovirt.org/23092 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie9e4a90a7e0e47aeb88a938fedb4f2088d533a70 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.3 Gerrit-Owner: Sandro Bonazzola <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
