From dc8b7db7729cbb24b350de3c8bf2db34e73cd789 Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Tue, 18 May 2021 10:21:23 -0600 Subject: [PATCH] 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 --- src/cephadm/cephadm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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 -- 2.47.3