]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: run coroutines in a new event loop 42982/head
authorMichael Fritch <mfritch@suse.com>
Mon, 30 Aug 2021 22:53:07 +0000 (16:53 -0600)
committerAdam King <adking@redhat.com>
Wed, 1 Sep 2021 12:17:08 +0000 (08:17 -0400)
`asyncio.run` does not exist until python37 or later

Signed-off-by: Michael Fritch <mfritch@suse.com>
src/pybind/mgr/cephadm/tests/fixtures.py

index 30314ed381667d8d730fa84d185d353c6119bffe..aea533990f2bda38100eccbac2a4504e91488a06 100644 (file)
@@ -1,5 +1,6 @@
 import fnmatch
 import asyncio
+import sys
 from tempfile import NamedTemporaryFile
 from contextlib import contextmanager
 
@@ -37,7 +38,16 @@ def match_glob(val, pat):
 
 class MockEventLoopThread:
     def get_result(self, coro):
-        asyncio.run(coro)
+        if sys.version_info >= (3, 7):
+            return asyncio.run(coro)
+
+        loop = asyncio.new_event_loop()
+        asyncio.set_event_loop(loop)
+        try:
+            return loop.run_until_complete(coro)
+        finally:
+            loop.close()
+            asyncio.set_event_loop(None)
 
 
 @contextmanager