From: Rishabh Dave Date: Thu, 3 Oct 2019 11:30:38 +0000 (+0530) Subject: ceph-volume: update tests since PVolumes.filter returns a list X-Git-Tag: v15.1.0~1311^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=38ccfe089a86f86b6e48b9a60286f26bb2444596;p=ceph.git ceph-volume: update tests since PVolumes.filter returns a list ...returns a list of filtered PVs instead of removing the items that do not match the filters from itself. Signed-off-by: Rishabh Dave --- diff --git a/src/ceph-volume/ceph_volume/tests/api/test_lvm.py b/src/ceph-volume/ceph_volume/tests/api/test_lvm.py index ddf99f6ae1f80..d7e58c0c2a256 100644 --- a/src/ceph-volume/ceph_volume/tests/api/test_lvm.py +++ b/src/ceph-volume/ceph_volume/tests/api/test_lvm.py @@ -186,8 +186,8 @@ class TestPVolumes(object): pv_name='/dev/vg/foo', pv_uuid='1111', pv_tags=pv_tags, vg_name='vg') pvolumes.append(FooPVolume) - pvolumes.filter(pv_tags={'ceph.type': 'journal', 'ceph.osd_id': '2'}) - assert pvolumes == [] + assert pvolumes.filter(pv_tags={'ceph.type': 'journal', + 'ceph.osd_id': '2'}) == [] def test_filter_by_tags_matches(self, pvolumes, monkeypatch): pv_tags = "ceph.type=journal,ceph.osd_id=1" @@ -195,8 +195,8 @@ class TestPVolumes(object): pv_name='/dev/vg/foo', pv_uuid='1111', pv_tags=pv_tags, vg_name="vg") pvolumes.append(FooPVolume) - pvolumes.filter(pv_tags={'ceph.type': 'journal', 'ceph.osd_id': '1'}) - assert pvolumes == [FooPVolume] + assert pvolumes.filter(pv_tags={'ceph.type': 'journal', + 'ceph.osd_id': '1'}) == [FooPVolume] class TestGetVG(object): diff --git a/src/ceph-volume/ceph_volume/tests/conftest.py b/src/ceph-volume/ceph_volume/tests/conftest.py index fad7df44e305d..7359fc38d28e3 100644 --- a/src/ceph-volume/ceph_volume/tests/conftest.py +++ b/src/ceph-volume/ceph_volume/tests/conftest.py @@ -167,6 +167,12 @@ def pvolumes(monkeypatch): pvolumes = lvm_api.PVolumes() pvolumes._purge() return pvolumes +@pytest.fixture +def pvolumes_empty(monkeypatch): + monkeypatch.setattr('ceph_volume.process.call', lambda x, **kw: ('', '', 0)) + pvolumes = lvm_api.PVolumes(populate=False) + return pvolumes + @pytest.fixture diff --git a/src/ceph-volume/ceph_volume/tests/util/test_device.py b/src/ceph-volume/ceph_volume/tests/util/test_device.py index 3a098d7ed2d41..7477777bc8d57 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_device.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_device.py @@ -32,19 +32,19 @@ class TestDevice(object): disk = device.Device("vg/lv") assert disk.is_lv - def test_vgs_is_empty(self, device_info, pvolumes, monkeypatch): + def test_vgs_is_empty(self, device_info, pvolumes, pvolumes_empty, monkeypatch): BarPVolume = api.PVolume(pv_name='/dev/sda', pv_uuid="0000", pv_tags={}) pvolumes.append(BarPVolume) - monkeypatch.setattr(api, 'PVolumes', lambda: pvolumes) + monkeypatch.setattr(api, 'PVolumes', lambda populate=True: pvolumes if populate else pvolumes_empty) lsblk = {"TYPE": "disk"} device_info(lsblk=lsblk) disk = device.Device("/dev/nvme0n1") assert disk.vgs == [] - def test_vgs_is_not_empty(self, device_info, pvolumes, monkeypatch): + def test_vgs_is_not_empty(self, device_info, pvolumes, pvolumes_empty, monkeypatch): BarPVolume = api.PVolume(vg_name='foo', lv_uuid='111', pv_name='/dev/nvme0n1', pv_uuid="0000", pv_tags={}) pvolumes.append(BarPVolume) - monkeypatch.setattr(api, 'PVolumes', lambda: pvolumes) + monkeypatch.setattr(api, 'PVolumes', lambda populate=True: pvolumes if populate else pvolumes_empty) lsblk = {"TYPE": "disk"} device_info(lsblk=lsblk) disk = device.Device("/dev/nvme0n1") @@ -179,10 +179,10 @@ class TestDevice(object): disk = device.Device("/dev/sda") assert disk.is_ceph_disk_member is False - def test_pv_api(self, device_info, pvolumes, monkeypatch): + def test_pv_api(self, device_info, pvolumes, pvolumes_empty, monkeypatch): FooPVolume = api.PVolume(pv_name='/dev/sda', pv_uuid="0000", lv_uuid="0000", pv_tags={}, vg_name="vg") pvolumes.append(FooPVolume) - monkeypatch.setattr(api, 'PVolumes', lambda: pvolumes) + monkeypatch.setattr(api, 'PVolumes', lambda populate=True: pvolumes if populate else pvolumes_empty) data = {"/dev/sda": {"foo": "bar"}} lsblk = {"TYPE": "part"} device_info(devices=data, lsblk=lsblk) @@ -190,10 +190,10 @@ class TestDevice(object): assert disk.pvs_api @pytest.mark.parametrize("ceph_type", ["data", "block"]) - def test_used_by_ceph(self, device_info, pvolumes, monkeypatch, ceph_type): + def test_used_by_ceph(self, device_info, pvolumes, pvolumes_empty, monkeypatch, ceph_type): FooPVolume = api.PVolume(pv_name='/dev/sda', pv_uuid="0000", lv_uuid="0000", pv_tags={}, vg_name="vg") pvolumes.append(FooPVolume) - monkeypatch.setattr(api, 'PVolumes', lambda: pvolumes) + monkeypatch.setattr(api, 'PVolumes', lambda populate=True: pvolumes if populate else pvolumes_empty) data = {"/dev/sda": {"foo": "bar"}} lsblk = {"TYPE": "part"} lv_data = {"lv_path": "vg/lv", "vg_name": "vg", "lv_uuid": "0000", "tags": {"ceph.osd_id": 0, "ceph.type": ceph_type}} @@ -201,10 +201,10 @@ class TestDevice(object): disk = device.Device("/dev/sda") assert disk.used_by_ceph - def test_not_used_by_ceph(self, device_info, pvolumes, monkeypatch): + def test_not_used_by_ceph(self, device_info, pvolumes, pvolumes_empty, monkeypatch): FooPVolume = api.PVolume(pv_name='/dev/sda', pv_uuid="0000", lv_uuid="0000", pv_tags={}, vg_name="vg") pvolumes.append(FooPVolume) - monkeypatch.setattr(api, 'PVolumes', lambda: pvolumes) + monkeypatch.setattr(api, 'PVolumes', lambda populate=True: pvolumes if populate else pvolumes_empty) data = {"/dev/sda": {"foo": "bar"}} lsblk = {"TYPE": "part"} lv_data = {"lv_path": "vg/lv", "vg_name": "vg", "lv_uuid": "0000", "tags": {"ceph.osd_id": 0, "ceph.type": "journal"}} @@ -248,7 +248,7 @@ class TestDeviceEncryption(object): disk = device.Device("/dev/sda") assert disk.is_encrypted is True - def test_mapper_is_encrypted_luks1(self, device_info, pvolumes, monkeypatch): + def test_mapper_is_encrypted_luks1(self, device_info, pvolumes, pvolumes_empty, monkeypatch): status = {'type': 'LUKS1'} monkeypatch.setattr(device, 'encryption_status', lambda x: status) lsblk = {'FSTYPE': 'xfs', 'TYPE': 'lvm'} @@ -257,7 +257,7 @@ class TestDeviceEncryption(object): disk = device.Device("/dev/mapper/uuid") assert disk.is_encrypted is True - def test_mapper_is_encrypted_luks2(self, device_info, pvolumes, monkeypatch): + def test_mapper_is_encrypted_luks2(self, device_info, pvolumes, pvolumes_empty, monkeypatch): status = {'type': 'LUKS2'} monkeypatch.setattr(device, 'encryption_status', lambda x: status) lsblk = {'FSTYPE': 'xfs', 'TYPE': 'lvm'} @@ -266,7 +266,7 @@ class TestDeviceEncryption(object): disk = device.Device("/dev/mapper/uuid") assert disk.is_encrypted is True - def test_mapper_is_encrypted_plain(self, device_info, pvolumes, monkeypatch): + def test_mapper_is_encrypted_plain(self, device_info, pvolumes, pvolumes_empty, monkeypatch): status = {'type': 'PLAIN'} monkeypatch.setattr(device, 'encryption_status', lambda x: status) lsblk = {'FSTYPE': 'xfs', 'TYPE': 'lvm'} @@ -275,7 +275,7 @@ class TestDeviceEncryption(object): disk = device.Device("/dev/mapper/uuid") assert disk.is_encrypted is True - def test_mapper_is_not_encrypted_plain(self, device_info, pvolumes, monkeypatch): + def test_mapper_is_not_encrypted_plain(self, device_info, pvolumes, pvolumes_empty, monkeypatch): monkeypatch.setattr(device, 'encryption_status', lambda x: {}) lsblk = {'FSTYPE': 'xfs', 'TYPE': 'lvm'} blkid = {'TYPE': 'mapper'}