From: Alfredo Deza Date: Tue, 29 Aug 2017 17:25:28 +0000 (-0400) Subject: ceph-volume tests add pv* related unit tests X-Git-Tag: v12.2.1~94^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9b20da46761c92f3e39e44383bc0b3e3625ee26c;p=ceph.git ceph-volume tests add pv* related unit tests Signed-off-by: Alfredo Deza (cherry picked from commit 7c22743c9aa1306242fc09ccae5dedf94e025cc4) --- diff --git a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_api.py b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_api.py index 089afa1a8c0..cfbe699b16e 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_api.py +++ b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_api.py @@ -76,6 +76,14 @@ def volumes(monkeypatch): return volumes +@pytest.fixture +def pvolumes(monkeypatch): + monkeypatch.setattr(process, 'call', lambda x: ('', '', 0)) + pvolumes = api.PVolumes() + pvolumes._purge() + return pvolumes + + @pytest.fixture def volume_groups(monkeypatch): monkeypatch.setattr(process, 'call', lambda x: ('', '', 0)) @@ -96,6 +104,40 @@ class TestGetLV(object): monkeypatch.setattr(api, 'Volumes', lambda: volumes) assert api.get_lv(lv_name='foo') == FooVolume + def test_single_lv_is_matched_by_uuid(self, volumes, monkeypatch): + FooVolume = api.Volume( + lv_name='foo', lv_path='/dev/vg/foo', + lv_uuid='1111', lv_tags="ceph.type=data") + volumes.append(FooVolume) + monkeypatch.setattr(api, 'Volumes', lambda: volumes) + assert api.get_lv(lv_uuid='1111') == FooVolume + + +class TestGetPV(object): + + def test_nothing_is_passed_in(self): + # so we return a None + assert api.get_pv() is None + + def test_single_pv_is_not_matched(self, pvolumes, monkeypatch): + FooPVolume = api.PVolume(pv_name='/dev/sda', pv_uuid="0000", pv_tags={}) + pvolumes.append(FooPVolume) + monkeypatch.setattr(api, 'PVolumes', lambda: pvolumes) + assert api.get_pv(pv_uuid='foo') is None + + def test_single_pv_is_matched(self, pvolumes, monkeypatch): + FooPVolume = api.PVolume(pv_name='/dev/sda', pv_uuid="0000", pv_tags={}) + pvolumes.append(FooPVolume) + monkeypatch.setattr(api, 'PVolumes', lambda: pvolumes) + assert api.get_pv(pv_uuid='0000') == FooPVolume + + def test_single_pv_is_matched_by_uuid(self, volumes, monkeypatch): + FooVolume = api.Volume( + lv_name='foo', lv_path='/dev/vg/foo', + lv_uuid='1111', lv_tags="ceph.type=data") + volumes.append(FooVolume) + monkeypatch.setattr(api, 'Volumes', lambda: volumes) + assert api.get_lv(lv_uuid='1111') == FooVolume class TestGetVG(object): @@ -161,6 +203,23 @@ class TestVolumes(object): assert len(volumes) == 1 assert volumes[0].lv_name == 'volume1' + def test_filter_by_lv_uuid(self, volumes): + osd = api.Volume(lv_name='volume1', lv_path='/dev/volume1', lv_uuid='1111', lv_tags='') + journal = api.Volume(lv_name='volume2', lv_path='/dev/volume2', lv_uuid='', lv_tags='') + volumes.append(osd) + volumes.append(journal) + volumes.filter(lv_uuid='1111') + assert len(volumes) == 1 + assert volumes[0].lv_name == 'volume1' + + def test_filter_by_lv_uuid_nothing_found(self, volumes): + osd = api.Volume(lv_name='volume1', lv_path='/dev/volume1', lv_uuid='1111', lv_tags='') + journal = api.Volume(lv_name='volume2', lv_path='/dev/volume2', lv_uuid='', lv_tags='') + volumes.append(osd) + volumes.append(journal) + volumes.filter(lv_uuid='22222') + assert volumes == [] + def test_filter_requires_params(self, volumes): with pytest.raises(TypeError): volumes.filter()