From 9780d28028a40ecbfc327dab779e8a37c9aaed51 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Mon, 8 Mar 2021 09:59:26 +0100 Subject: [PATCH] ceph-volume: `get_first_*()` refactor As indicated by commit 17957d9beb42a04b8f180ccb7ba07d43179a41d3 those fuctions were meant to avoid writing something like following: ``` lvs = get_lvs() if len(lvs) >= 1: lvs = lv[0] ``` Those functions should return `None` if 0 or more than 1 item is returned. The current name of these functions are confusing and can lead to thinking that we just want the first item returned, even though it returns more than 1 item, let's rename them to `get_single_pv()`, `get_single_vg()` and `get_single_lv()` Closes: https://tracker.ceph.com/issues/49643 Signed-off-by: Guillaume Abrioux (cherry picked from commit a5e4216b49704783c55fb83b3ae6dde35b0082ad) --- src/ceph-volume/ceph_volume/api/lvm.py | 54 +++-- diff --git a/src/ceph-volume/ceph_volume/api/lvm.py b/src/ceph-volume/ceph_volume/api/lvm.py index e5551206e16..bbafa06831b 100644 --- a/src/ceph-volume/ceph_volume/api/lvm.py +++ b/src/ceph-volume/ceph_volume/api/lvm.py @@ -1144,7 +1144,7 @@ def get_lv_by_fullname(full_name): """ try: vg_name, lv_name = full_name.split('/') - res_lv = get_first_lv(filters={'lv_name': lv_name, + res_lv = get_single_lv(filters={'lv_name': lv_name, 'vg_name': vg_name}) except ValueError: res_lv = None