From: Michael Fritch Date: Tue, 18 May 2021 16:21:23 +0000 (-0600) Subject: cephadm: move `json_loads_retry` func X-Git-Tag: v17.1.0~1711^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dc8b7db7729cbb24b350de3c8bf2db34e73cd789;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 --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index ce73fe0d50a4..ae67122af75b 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -1474,6 +1474,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 """ @@ -4118,15 +4128,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