From: Rishabh Dave Date: Thu, 3 Oct 2019 11:18:46 +0000 (+0530) Subject: ceph-volume: PVolumes.filter shouldn't purge itself X-Git-Tag: v13.2.7~54^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bc7248ded1dc17a63d79f6d5a98f8b37c3c61303;p=ceph.git ceph-volume: PVolumes.filter shouldn't purge itself PVolumes.filter removes the PVs that do not match the filters from its list. This approach is problematic since the code calling this method has to create a copy beforehand. Therefore, it's better to return a new object that contains PVs that matches the filters. Fixes: https://tracker.ceph.com/issues/42170 Signed-off-by: Rishabh Dave (cherry picked from commit fcec33ee50457d43add844aef3b81bbf9dd2ad58) --- diff --git a/src/ceph-volume/ceph_volume/api/lvm.py b/src/ceph-volume/ceph_volume/api/lvm.py index bafe550f7cad..328dd9fcd832 100644 --- a/src/ceph-volume/ceph_volume/api/lvm.py +++ b/src/ceph-volume/ceph_volume/api/lvm.py @@ -930,24 +930,19 @@ class PVolumes(list): def filter(self, pv_name=None, pv_uuid=None, pv_tags=None): """ Filter out volumes on top level attributes like ``pv_name`` or by - ``pv_tags`` where a dict is required. For example, to find a physical volume - that has an OSD ID of 0, the filter would look like:: + ``pv_tags`` where a dict is required. For example, to find a physical + volume that has an OSD ID of 0, the filter would look like:: pv_tags={'ceph.osd_id': '0'} """ if not any([pv_name, pv_uuid, pv_tags]): - raise TypeError('.filter() requires pv_name, pv_uuid, or pv_tags (none given)') - # first find the filtered volumes with the values in self - filtered_volumes = self._filter( - pv_name=pv_name, - pv_uuid=pv_uuid, - pv_tags=pv_tags - ) - # then purge everything - self._purge() - # and add the filtered items - self.extend(filtered_volumes) + raise TypeError('.filter() requires pv_name, pv_uuid, or pv_tags' + '(none given)') + + filtered_pvs = PVolumes(populate=False) + filtered_pvs.extend(self._filter(pv_name, pv_uuid, pv_tags)) + return filtered_pvs def get(self, pv_name=None, pv_uuid=None, pv_tags=None): """ diff --git a/src/ceph-volume/ceph_volume/util/device.py b/src/ceph-volume/ceph_volume/util/device.py index 9e0f186090cc..bd27c792c8b9 100644 --- a/src/ceph-volume/ceph_volume/util/device.py +++ b/src/ceph-volume/ceph_volume/util/device.py @@ -227,8 +227,7 @@ class Device(object): for path in self._get_pv_paths(): # check if there was a pv created with the # name of device - pvs = lvm.PVolumes() - pvs.filter(pv_name=path) + pvs = lvm.PVolumes().filter(pv_name=path) has_vgs = [pv.vg_name for pv in pvs if pv.vg_name] if has_vgs: self.vgs = list(set(has_vgs))