]> git-server-git.apps.pok.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:53 +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 bafe550f7cad45710b5384e290a8e045762a697e..328dd9fcd8325d0c107ad10ea8078b8b4105c5a9 100644 (file)
@@ -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):
         """
index 9e0f186090cc9018218ae3d3de6f19a28033d82f..bd27c792c8b98d33bb85ce962c77dfd6cdccb103 100644 (file)
@@ -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))