def test_build_filter(): mounts = [ MountInfo("/dev/mapper/vg0-lv_home", "/home", ["/dev/sda2", "/dev/sdb2"]), MountInfo("/dev/mapper/vg0-lv_root", "/", ["/dev/sda2"]), MountInfo("/dev/mapper/vg0-lv_swap", "[SWAP]", ["/dev/sda2"]), ] lvm_filter = lvmfilter.build_filter(mounts) assert lvm_filter == ["a|^/dev/sda2$|", "a|^/dev/sdb2$|", "r|.*|"]
def test_find_wwids(monkeypatch, fake_sys_block_info): disks = {'/dev/sda': {'name': '/dev/sda', 'type': 'disk'}} monkeypatch.setattr(lvmfilter, "find_disks", lambda x: disks) mounts = [ MountInfo("/dev/mapper/vg0-lv_root", "/", ["/dev/sda2"]), ] udevadm_info = """\ ID_PART_TABLE_TYPE=dos ID_PART_TABLE_UUID=a11738e9 ID_PATH=pci-0000:00:01.1-ata-2 ID_PATH_TAG=pci-0000_00_01_1-ata-2 ID_REVISION=2.5+ ID_SCSI=1 ID_SCSI_INQUIRY=1 ID_SERIAL=QEMU_HARDDISK_QM00003 ID_SERIAL_SHORT=QM00003 ID_TYPE=disk ID_VENDOR=ATA ID_VENDOR_ENC=ATA\x20\x20\x20\x20\x20 """ monkeypatch.setattr(udevadm, "info", lambda x: udevadm_info) assert lvmfilter.find_wwids(mounts) == {'QEMU_HARDDISK_QM00003'}
""" stable_name = "lvm-pv-uuid-{}".format(str(uuid.uuid4())) stable_link = str(tmpdir.join(stable_name)) unstable_link = str(tmpdir.join("mapped-device")) device = str(tmpdir.join("dm-1")) open(device, "w").close() os.symlink(device, stable_link) os.symlink(device, unstable_link) return FakeDevice(device, stable_link, unstable_link) @pytest.mark.parametrize("plat,expected", [ ("rhel74", [ MountInfo("/dev/mapper/vg0-lv_home", "/home", FAKE_DEVICES), MountInfo("/dev/mapper/vg0-lv_root", "/", FAKE_DEVICES), MountInfo("/dev/mapper/vg0-lv_swap", "[SWAP]", FAKE_DEVICES), ]), ("fedora", [ MountInfo("/dev/mapper/fedora-home", "/home", FAKE_DEVICES), MountInfo("/dev/mapper/fedora-root", "/", FAKE_DEVICES), MountInfo("/dev/mapper/fedora-swap", "[SWAP]", FAKE_DEVICES), ]), ]) def test_find_lvm_mounts(monkeypatch, plat, expected): # Monkeypatch the module to run the fake-lsblk returning data collected on # on real platform. monkeypatch.setattr(lvmfilter, "LSBLK", FAKE_LSBLK) monkeypatch.setenv("FAKE_STDOUT", FAKE_LSBLK + "." + plat + ".out")