From b46d2bf0a6c03b870f4abbe44b36c100e08cc770 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Mon, 22 Mar 2021 14:46:55 +0100 Subject: [PATCH] ceph_volume: fix bug in `is_lv()` This function makes the `ceph_volume` module be not idempotent in containerized context because it tries to run a container and bindmount directories that no longer exist. In that case, the `lvs` command being executed returns something different than `0` so we can't call `json.loads(out)['report'][0]['lv']` since it might throw an python error. The idea is to return `True` only if `rc` is equal to `0` and `len(result)` is greater than `0`, which means the command matched an LV. Fixes: #6284 Signed-off-by: Guillaume Abrioux (cherry picked from commit ed79bc7a4e38e257f37faac50a5a19c06711dd8d) --- library/ceph_volume.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/library/ceph_volume.py b/library/ceph_volume.py index 81a782631..9bef51fe5 100644 --- a/library/ceph_volume.py +++ b/library/ceph_volume.py @@ -467,11 +467,12 @@ def is_lv(module, vg, lv, container_image): rc, cmd, out, err = exec_command(module, cmd) - result = json.loads(out)['report'][0]['lv'] - if rc == 0 and len(result) > 0: - return True - else: - return False + if rc == 0: + result = json.loads(out)['report'][0]['lv'] + if len(result) > 0: + return True + + return False def zap_devices(module, container_image):