Dan Kenigsberg has submitted this change and it was merged.
Change subject: DeferableContext: Change to RollbackContext for easy undoing ......................................................................
DeferableContext: Change to RollbackContext for easy undoing
We often need to perform a series of operations: op[0], op[1], ... op[N] These operations may allocate files, locks, connections, and op[K] may depend on op[K-1] 's result
Sometimes it's not feasible to create context manager for each resource, because the number of the resource involved in a transaction can be a variable, for example, reading from a configuration file, but there is no way to use a variable number of the "with" statement, and contextlib.nested is being deprecated. So we need a concise framework to do rollback.
This patch subclass DeferableContext and proposes an idiom to do this kind of rollback. DeferableContext re-raises the last exception, while this patch re-raises the first exception, for the earliest exception may be the root cause and most helpful when investigate the problem.
Change-Id: Ibc932637dd81c3becf92de34ea647c1cea136111 Signed-off-by: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com --- M tests/miscTests.py M vdsm/storage/misc.py M vdsm/storage/resourceManager.py 3 files changed, 51 insertions(+), 37 deletions(-)
Approvals: Dan Kenigsberg: Looks good to me, approved Zhou Zheng Sheng: Verified; Looks good to me, but someone else must approve
-- To view, visit http://gerrit.ovirt.org/8671 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: merged Gerrit-Change-Id: Ibc932637dd81c3becf92de34ea647c1cea136111 Gerrit-PatchSet: 8 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Royce Lv lvroyce@linux.vnet.ibm.com Gerrit-Reviewer: Ryan Harper ryanh@us.ibm.com Gerrit-Reviewer: Saggi Mizrahi smizrahi@redhat.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Vinzenz Feenstra vfeenstr@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server