From: Michael Fritch Date: Tue, 18 May 2021 16:21:23 +0000 (-0600) Subject: cephadm: move `json_loads_retry` func X-Git-Tag: v16.2.5~72^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f4ba1e6762e532b01296f14ac191eb7997963a62;p=ceph.git cephadm: move `json_loads_retry` func move inner func `json_loads_retry` so it can be mocked during unit tests Signed-off-by: Michael Fritch (cherry picked from commit dc8b7db7729cbb24b350de3c8bf2db34e73cd789) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index fb3723ee7570..158f0fa335fb 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -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