Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: setup: Make pki transactional ......................................................................
packaging: setup: Make pki transactional Change-Id: I81b25a3febc9fa80ea980b9b284d99a5459217b9 Signed-off-by: Yedidyah Bar David <d...@redhat.com> --- M packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/pki/ca.py 1 file changed, 57 insertions(+), 14 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/89/41789/1 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/pki/ca.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/pki/ca.py index 1a73b60..7fe4465 100644 --- a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/pki/ca.py +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/pki/ca.py @@ -23,6 +23,9 @@ import os import re import random +import shutil +import string +import time import gettext _ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup') @@ -52,25 +55,52 @@ """CA plugin.""" class CATransaction(transaction.TransactionElement): - """yum transaction element.""" + """CA transaction element.""" - def __init__(self, parent, uninstall_files): + def __init__(self, parent): self._parent = parent - self._uninstall_files = uninstall_files + self._backup = None def __str__(self): return _("CA Transaction") def prepare(self): - pass + self._backup = '{path}-{time}-{rnd}'.format( + path=oenginecons.FileLocations.OVIRT_ENGINE_PKIDIR, + time=time.strftime("%Y%m%d%H%M%S"), + rnd=''.join( + random.choice( + string.ascii_lowercase + + string.digits + ) for i in range(6) + ), + ) + shutil.copytree( + oenginecons.FileLocations.OVIRT_ENGINE_PKIDIR, + self._backup + ) def abort(self): - for f in self._uninstall_files: - if os.path.exists(f): - os.unlink(f) + if self._backup is not None and os.path.exists(self._backup): + tmp = '{path}-{time}-{rnd}'.format( + path=oenginecons.FileLocations.OVIRT_ENGINE_PKIDIR, + time=time.strftime("%Y%m%d%H%M%S"), + rnd=''.join( + random.choice( + string.ascii_lowercase + + string.digits + ) for i in range(6) + ), + ) + os.rename(oenginecons.FileLocations.OVIRT_ENGINE_PKIDIR, tmp) + os.rename( + self._backup, + oenginecons.FileLocations.OVIRT_ENGINE_PKIDIR + ) + self._parent._remove_at_end = tmp def commit(self): - pass + self._parent._remove_at_end = self._backup def _subjectComponentEscape(self, s): return outil.escape(s, '/\\') @@ -313,6 +343,7 @@ super(Plugin, self).__init__(context=context) self._enabled = False self._ca_was_renewed = False + self._remove_at_end = None @plugin.event( stage=plugin.Stages.STAGE_BOOT, @@ -346,6 +377,11 @@ ) def _setup(self): self.command.detect('openssl') + self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( + self.CATransaction( + parent=self, + ) + ) @plugin.event( stage=plugin.Stages.STAGE_CUSTOMIZATION, @@ -515,12 +551,6 @@ # for now just delete files if we fail uninstall_files = [] self._setupUninstall(uninstall_files) - self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( - self.CATransaction( - parent=self, - uninstall_files=uninstall_files, - ) - ) # LEGACY NOTE # This is needed for avoiding error in create_ca when supporting @@ -663,5 +693,18 @@ ), ) + @plugin.event( + stage=plugin.Stages.STAGE_CLEANUP, + condition=lambda self: self._remove_at_end is not None, + ) + def _cleanup(self): + try: + shutil.rmtree(self._remove_at_end) + except: + self.logger.debug( + 'Failed to remove temporary pki backup %s', + self._remove_at_end, + ) + # vim: expandtab tabstop=4 shiftwidth=4 -- To view, visit https://gerrit.ovirt.org/41789 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I81b25a3febc9fa80ea980b9b284d99a5459217b9 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Yedidyah Bar David <d...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches