summaryrefslogtreecommitdiff
path: root/nova/utils.py
diff options
context:
space:
mode:
authorMatthew Booth <mbooth@redhat.com>2018-10-05 16:38:38 +0100
committerMatthew Booth <mbooth@redhat.com>2018-10-06 18:16:58 +0100
commitb5af1633a79d25222be6c0b1a3d5055040fc00c5 (patch)
treeb94e4435701b32163392196bc47e51ab4b4297d9 /nova/utils.py
parent5c0235a579ccb52f7bce5de9bcb3c927c94b23b7 (diff)
downloadnova-b5af1633a79d25222be6c0b1a3d5055040fc00c5.tar.gz
Move test.nested to utils.nested_contexts
This function is generally useful in supporting py2/3 cross-over code, and should be available to non-test code. Change-Id: I81d13418d75b46fbdb9f6d44889a207528c8d6de
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 44ef1162ac..f3eb785702 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -1303,3 +1303,12 @@ def monkey_patch():
# be green. To workaround this, reload the module after calling
# monkey_patch()
reload_module(importutils.import_module('oslo_context.context'))
+
+
+if six.PY2:
+ nested_contexts = contextlib.nested
+else:
+ @contextlib.contextmanager
+ def nested_contexts(*contexts):
+ with contextlib.ExitStack() as stack:
+ yield [stack.enter_context(c) for c in contexts]