]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: move `json_loads_retry` func
authorMichael Fritch <mfritch@suse.com>
Tue, 18 May 2021 16:21:23 +0000 (10:21 -0600)
committerSebastian Wagner <sewagner@redhat.com>
Fri, 11 Jun 2021 09:49:19 +0000 (11:49 +0200)
move inner func `json_loads_retry` so it can be mocked during unit tests

Signed-off-by: Michael Fritch <mfritch@suse.com>
(cherry picked from commit dc8b7db7729cbb24b350de3c8bf2db34e73cd789)

src/cephadm/cephadm

index fb3723ee7570b04b4f3fe039d50abb87ca19f888..158f0fa335fbfdaff1fccd4430ae1ad53848da06 100755 (executable)
@@ -1473,6 +1473,16 @@ def call_timeout(ctx, command, timeout):
 ##################################
 
 
+def json_loads_retry(cli_func):
+    for sleep_secs in [1, 4, 4]:
+        try:
+            return json.loads(cli_func())
+        except json.JSONDecodeError:
+            logger.debug('Invalid JSON. Retrying in %s seconds...' % sleep_secs)
+            time.sleep(sleep_secs)
+    return json.loads(cli_func())
+
+
 def is_available(ctx, what, func):
     # type: (CephadmContext, str, Callable[[], bool]) -> None
     """
@@ -4089,15 +4099,6 @@ def command_bootstrap(ctx):
                  '-i', '/var/lib/ceph/user.conf'],
                 {tmp.name: '/var/lib/ceph/user.conf:z'})
 
-    def json_loads_retry(cli_func):
-        for sleep_secs in [1, 4, 4]:
-            try:
-                return json.loads(cli_func())
-            except json.JSONDecodeError:
-                logger.debug('Invalid JSON. Retrying in %s seconds...' % sleep_secs)
-                time.sleep(sleep_secs)
-        return json.loads(cli_func())
-
     # wait for mgr to restart (after enabling a module)
     def wait_for_mgr_restart():
         # first get latest mgrmap epoch from the mon.  try newer 'mgr