Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimic: ceph-volume: VolumeGroups.filter shouldn't purge itself #30808

Merged
merged 3 commits into from Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/ceph-volume/ceph_volume/api/lvm.py
Expand Up @@ -680,8 +680,9 @@ class VolumeGroups(list):
to filter them via keyword arguments.
"""

def __init__(self):
self._populate()
def __init__(self, populate=True):
if populate:
self._populate()

def _populate(self):
# get all the vgs in the current system
Expand Down Expand Up @@ -733,15 +734,10 @@ def filter(self, vg_name=None, vg_tags=None):
"""
if not any([vg_name, vg_tags]):
raise TypeError('.filter() requires vg_name or vg_tags (none given)')
# first find the filtered volumes with the values in self
filtered_groups = self._filter(
vg_name=vg_name,
vg_tags=vg_tags
)
# then purge everything
self._purge()
# and add the filtered items
self.extend(filtered_groups)

filtered_vgs = VolumeGroups(populate=False)
filtered_vgs.extend(self._filter(vg_name, vg_tags))
return filtered_vgs

def get(self, vg_name=None, vg_tags=None):
"""
Expand Down
8 changes: 4 additions & 4 deletions src/ceph-volume/ceph_volume/tests/api/test_lvm.py
Expand Up @@ -337,15 +337,15 @@ def test_filter_by_tag(self, volume_groups):
journal = api.VolumeGroup(vg_name='volume2', vg_tags='ceph.group=plain')
volume_groups.append(osd)
volume_groups.append(journal)
volume_groups.filter(vg_tags={'ceph.group': 'dmcache'})
volume_groups = volume_groups.filter(vg_tags={'ceph.group': 'dmcache'})
assert len(volume_groups) == 1
assert volume_groups[0].vg_name == 'volume1'

def test_filter_by_tag_does_not_match_one(self, volume_groups):
vg_tags = "ceph.group=dmcache,ceph.disk_type=ssd"
osd = api.VolumeGroup(vg_name='volume1', vg_path='/dev/vg/lv', vg_tags=vg_tags)
volume_groups.append(osd)
volume_groups.filter(vg_tags={'ceph.group': 'data', 'ceph.disk_type': 'ssd'})
volume_groups = volume_groups.filter(vg_tags={'ceph.group': 'data', 'ceph.disk_type': 'ssd'})
assert volume_groups == []

def test_filter_by_vg_name(self, volume_groups):
Expand All @@ -354,13 +354,13 @@ def test_filter_by_vg_name(self, volume_groups):
journal = api.VolumeGroup(vg_name='volume2', vg_tags='ceph.type=journal')
volume_groups.append(osd)
volume_groups.append(journal)
volume_groups.filter(vg_name='ceph_vg')
volume_groups = volume_groups.filter(vg_name='ceph_vg')
assert len(volume_groups) == 1
assert volume_groups[0].vg_name == 'ceph_vg'

def test_filter_requires_params(self, volume_groups):
with pytest.raises(TypeError):
volume_groups.filter()
volume_groups = volume_groups.filter()


class TestVolumeGroupFree(object):
Expand Down
4 changes: 4 additions & 0 deletions src/ceph-volume/ceph_volume/tests/conftest.py
Expand Up @@ -153,6 +153,10 @@ def volume_groups(monkeypatch):
vgs._purge()
return vgs

def volume_groups_empty(monkeypatch):
monkeypatch.setattr('ceph_volume.process.call', lambda x, **kw: ('', '', 0))
vgs = lvm_api.VolumeGroups(populate=False)
return vgs

@pytest.fixture
def stub_vgs(monkeypatch, volume_groups):
Expand Down