]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: PVolumes.filter shouldn't purge itself
authorRishabh Dave <ridave@redhat.com>
Thu, 3 Oct 2019 11:18:46 +0000 (16:48 +0530)
committerJan Fajerski <jfajerski@suse.com>
Wed, 9 Oct 2019 11:50:20 +0000 (13:50 +0200)
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 <ridave@redhat.com>
(cherry picked from commit fcec33ee50457d43add844aef3b81bbf9dd2ad58)

src/ceph-volume/ceph_volume/api/lvm.py
src/ceph-volume/ceph_volume/util/device.py

index 7f96771cb040c3993101db56c95c9119c04f8668..80fbaa885e03a6a9208c169fdc554d266626640a 100644 (file)
@@ -958,24 +958,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):
         """
index ddec0e84804f599d703987b1169b4be3391d967c..12c4ce18eafa202b883f7e52d8fcc941f89a1710 100644 (file)
@@ -232,8 +232,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))