diff options
author | Matthew Booth <mbooth@redhat.com> | 2018-10-05 16:38:38 +0100 |
---|---|---|
committer | Matthew Booth <mbooth@redhat.com> | 2018-10-06 18:16:58 +0100 |
commit | b5af1633a79d25222be6c0b1a3d5055040fc00c5 (patch) | |
tree | b94e4435701b32163392196bc47e51ab4b4297d9 /nova/utils.py | |
parent | 5c0235a579ccb52f7bce5de9bcb3c927c94b23b7 (diff) | |
download | nova-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.py | 9 |
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] |