def test_reattach_volume_ok_iscsi(monkeypatch, fake_os_brick, tmpdir, tmp_db, fake_lvm, fake_supervdsm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") monkeypatch.setattr(managedvolume, "DEV_MAPPER", str(tmpdir)) tmpdir.join("fakemultipathid").write("") connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } managedvolume.attach_volume("fake_sd_id", "fake_vol_id", connection_info) # Attaching invalidates the filter, reset. fake_lvm.devices_invalidated = False with pytest.raises(se.ManagedVolumeAlreadyAttached): managedvolume.attach_volume( "fake_sd_id", "fake_vol_id", connection_info) # Device still owned by managed volume. assert tmp_db.owns_multipath("fakemultipathid") entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # Volume already attached, no need to invalidated filter. assert not fake_lvm.devices_invalidated
def test_detach_volume_iscsi_attached(monkeypatch, fake_os_brick, tmpdir, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") monkeypatch.setattr(managedvolume, "DEV_MAPPER", str(tmpdir)) connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } managedvolume.attach_volume("fake_vol_id", connection_info) # Attaching invalidates the filter, reset. fake_lvm.filter_invalidated = False tmpdir.join("fakemultipathid").write("") managedvolume.detach_volume("fake_vol_id") entries = fake_os_brick.log() assert len(entries) == 2 assert entries[0]["action"] == "connect_volume" assert entries[1]["action"] == "disconnect_volume" with pytest.raises(managedvolumedb.NotFound): tmp_db.get_volume("fake_vol_id") # Device not owned by managed volume. assert not tmp_db.owns_multipath("fakemultipathid") # No multipath id added, no need to invalidated filter. assert not fake_lvm.filter_invalidated
def test_detach_volume_iscsi_not_attached(monkeypatch, fake_os_brick, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") connection_info = { "driver_volume_type": "iscsi", "data": { "some_info": 26 } } managedvolume.attach_volume("fake_vol_id", connection_info) # Attaching invalidates the filter, reset. fake_lvm.filter_invalidated = False managedvolume.detach_volume("fake_vol_id") with pytest.raises(managedvolumedb.NotFound): tmp_db.get_volume("fake_vol_id") entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # No multipath id added, no need to invalidated filter. assert not fake_lvm.filter_invalidated
def test_reattach_volume_other_connection(monkeypatch, fake_os_brick, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } managedvolume.attach_volume("fake_vol_id", connection_info) # Attaching invalidates the filter, reset. fake_lvm.filter_invalidated = False other_connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 99} } with pytest.raises(se.ManagedVolumeConnectionMismatch): managedvolume.attach_volume("fake_vol_id", other_connection_info) entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # No multipath id added, no need to invalidated filter. assert not fake_lvm.filter_invalidated
def test_attach_volume_fail_update(monkeypatch, fake_os_brick, tmpdir, tmp_db, fake_lvm, fake_supervdsm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") monkeypatch.setattr(managedvolume, "DEV_MAPPER", str(tmpdir)) tmpdir.join("fakemultipathid").write("") connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } def raise_error(*args, **kargs): raise RuntimeError monkeypatch.setattr(managedvolumedb.DB, "update_volume", raise_error) with pytest.raises(RuntimeError): managedvolume.attach_volume( "fake_sd_id", "fake_vol_id", connection_info) entries = fake_os_brick.log() assert len(entries) == 2 assert entries[0]["action"] == "connect_volume" assert entries[1]["action"] == "disconnect_volume" # Multipath id not added, no need to invalidated filter. assert not fake_lvm.devices_invalidated
def test_reattach_volume_ok_iscsi(monkeypatch, fake_os_brick, tmpdir, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") monkeypatch.setattr(managedvolume, "DEV_MAPPER", str(tmpdir)) tmpdir.join("fakemultipathid").write("") connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } managedvolume.attach_volume("fake_vol_id", connection_info) # Attaching invalidates the filter, reset. fake_lvm.filter_invalidated = False with pytest.raises(se.ManagedVolumeAlreadyAttached): managedvolume.attach_volume("fake_vol_id", connection_info) # Device still owned by managed volume. assert tmp_db.owns_multipath("fakemultipathid") entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # Volume already attached, no need to invalidated filter. assert not fake_lvm.filter_invalidated
def test_attach_volume_fail_update(monkeypatch, fake_os_brick, tmpdir, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") monkeypatch.setattr(managedvolume, "DEV_MAPPER", str(tmpdir)) tmpdir.join("fakemultipathid").write("") connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } def raise_error(*args, **kargs): raise RuntimeError monkeypatch.setattr(managedvolumedb.DB, "update_volume", raise_error) with pytest.raises(RuntimeError): managedvolume.attach_volume("fake_vol_id", connection_info) entries = fake_os_brick.log() assert len(entries) == 2 assert entries[0]["action"] == "connect_volume" assert entries[1]["action"] == "disconnect_volume" # Multipath id not added, no need to invalidated filter. assert not fake_lvm.filter_invalidated
def test_reattach_volume_other_connection(monkeypatch, fake_os_brick, tmp_db, fake_lvm, fake_supervdsm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } managedvolume.attach_volume("fake_sd_id", "fake_vol_id", connection_info) # Attaching invalidates the filter, reset. fake_lvm.devices_invalidated = False other_connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 99} } with pytest.raises(se.ManagedVolumeConnectionMismatch): managedvolume.attach_volume( "fake_sd_id", "fake_vol_id", other_connection_info) entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # No multipath id added, no need to invalidated filter. assert not fake_lvm.devices_invalidated
def test_attach_volume_no_multipath_id(monkeypatch, fake_os_brick, tmp_db, vol_type, fake_lvm, fake_supervdsm): # Simulate attaching iSCSI or FC device without multipath_id. monkeypatch.setenv("FAKE_ATTACH_RESULT", "NO_WWN") with pytest.raises(se.ManagedVolumeUnsupportedDevice): managedvolume.attach_volume( "sd_id", "vol_id", { "driver_volume_type": vol_type, "data": {"some_info": 26} }) # Verify that we deatch the unsupported device. entries = fake_os_brick.log() assert len(entries) == 2 assert entries[0]["action"] == "connect_volume" assert entries[1]["action"] == "disconnect_volume" # And remove the volume from the db. with pytest.raises(managedvolumedb.NotFound): tmp_db.get_volume("vol_id") # Multipath id was not added to database, so no invalidation is needed. assert not fake_lvm.devices_invalidated
def test_detach_volume_iscsi_attached(monkeypatch, fake_os_brick, tmpdir, tmp_db, fake_lvm, fake_supervdsm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") monkeypatch.setattr(managedvolume, "DEV_MAPPER", str(tmpdir)) connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } managedvolume.attach_volume("fake_sd_id", "fake_vol_id", connection_info) # Attaching invalidates the filter, reset. fake_lvm.devices_invalidated = False tmpdir.join("fakemultipathid").write("") managedvolume.detach_volume("fake_sd_id", "fake_vol_id") entries = fake_os_brick.log() assert len(entries) == 2 assert entries[0]["action"] == "connect_volume" assert entries[1]["action"] == "disconnect_volume" with pytest.raises(managedvolumedb.NotFound): tmp_db.get_volume("fake_vol_id") # Device not owned by managed volume. assert not tmp_db.owns_multipath("fakemultipathid") # No multipath id added, no need to invalidated filter. assert not fake_lvm.devices_invalidated
def test_attach_volume_ok_rbd(monkeypatch, fake_os_brick, tmp_db, fake_lvm, fake_supervdsm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK_RBD") connection_info = { "driver_volume_type": "rbd", "data": { "name": "volumes/volume-fake" }} ret = managedvolume.attach_volume( "fake_sd_id", "fake_vol_id", connection_info) path = "/dev/rbd/volumes/volume-fake" assert ret["result"]["path"] == path volume_info = { "connection_info": connection_info, "path": path, "attachment": { "path": "/dev/fakerbd" }, "vol_id": "fake_vol_id" } assert tmp_db.get_volume("fake_vol_id") == volume_info entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # RBD does not use multipath. assert not fake_lvm.devices_invalidated assert fake_supervdsm.udev_rules["fake_vol_id"]["triggered"]
def test_attach_volume_ok_other(monkeypatch, fake_os_brick, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "NO_WWN") connection_info = { "driver_volume_type": "other", "data": { "param1": "value1" } } ret = managedvolume.attach_volume("other_vol_id", connection_info) path = "/dev/fakesda" assert ret["result"]["path"] == path volume_info = { "connection_info": connection_info, "path": path, "attachment": { "path": "/dev/fakesda" } } assert tmp_db.get_volume("other_vol_id") == volume_info entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # Other devices do not use multipath. assert not fake_lvm.filter_invalidated
def test_attach_volume_ok_iscsi(monkeypatch, fake_os_brick, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } ret = managedvolume.attach_volume("fake_vol_id", connection_info) path = "/dev/mapper/fakemultipathid" assert ret["result"]["path"] == path volume_info = { "connection_info": connection_info, "path": path, "attachment": { "path": "/dev/fakesda", "scsi_wwn": "fakewwn", "multipath_id": "fakemultipathid" }, "multipath_id": "fakemultipathid", "vol_id": "fake_vol_id" } assert tmp_db.get_volume("fake_vol_id") == volume_info assert tmp_db.owns_multipath("fakemultipathid") entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # Adding new multipath id requires filter invalidation. assert fake_lvm.filter_invalidated
def test_attach_volume_ok_other(monkeypatch, fake_os_brick, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "NO_WWN") connection_info = { "driver_volume_type": "other", "data": { "param1": "value1" } } ret = managedvolume.attach_volume("other_vol_id", connection_info) path = "/dev/fakesda" assert ret["result"]["path"] == path volume_info = { "connection_info": connection_info, "path": path, "attachment": { "path": "/dev/fakesda" }, "vol_id": "other_vol_id" } assert tmp_db.get_volume("other_vol_id") == volume_info entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # Other devices do not use multipath. assert not fake_lvm.filter_invalidated
def test_attach_volume_ok_rbd(monkeypatch, fake_os_brick, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK_RBD") connection_info = { "driver_volume_type": "rbd", "data": { "name": "volumes/volume-fake" }} ret = managedvolume.attach_volume("fake_vol_id", connection_info) path = "/dev/rbd/volumes/volume-fake" assert ret["result"]["path"] == path volume_info = { "connection_info": connection_info, "path": path, "attachment": { "path": "/dev/fakerbd" }, "vol_id": "fake_vol_id" } assert tmp_db.get_volume("fake_vol_id") == volume_info entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # RBD does not use multipath. assert not fake_lvm.filter_invalidated
def test_attach_volume_ok_iscsi(monkeypatch, fake_os_brick, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") connection_info = { "driver_volume_type": "iscsi", "data": { "some_info": 26 } } ret = managedvolume.attach_volume("fake_vol_id", connection_info) path = "/dev/mapper/fakemultipathid" assert ret["result"]["path"] == path volume_info = { "connection_info": connection_info, "path": path, "attachment": { "path": "/dev/fakesda", "scsi_wwn": "fakewwn", "multipath_id": "fakemultipathid" }, "multipath_id": "fakemultipathid" } assert tmp_db.get_volume("fake_vol_id") == volume_info assert tmp_db.owns_multipath("fakemultipathid") entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # Adding new multipath id requires filter invalidation. assert fake_lvm.filter_invalidated
def test_attach_volume_no_multipath_id(monkeypatch, fake_os_brick, tmp_db, vol_type, fake_lvm): # Simulate attaching iSCSI or FC device without multipath_id. monkeypatch.setenv("FAKE_ATTACH_RESULT", "NO_WWN") with pytest.raises(se.ManagedVolumeUnsupportedDevice): managedvolume.attach_volume("vol_id", { "driver_volume_type": vol_type, "data": {"some_info": 26}}) # Verify that we deatch the unsupported device. entries = fake_os_brick.log() assert len(entries) == 2 assert entries[0]["action"] == "connect_volume" assert entries[1]["action"] == "disconnect_volume" # And remove the volume from the db. with pytest.raises(managedvolumedb.NotFound): tmp_db.get_volume("vol_id") # Multipath id was not added to database, so no invalidation is needed. assert not fake_lvm.filter_invalidated
def test_detach_volume_iscsi_not_attached(monkeypatch, fake_os_brick, tmp_db, fake_lvm): monkeypatch.setenv("FAKE_ATTACH_RESULT", "OK") connection_info = { "driver_volume_type": "iscsi", "data": {"some_info": 26} } managedvolume.attach_volume("fake_vol_id", connection_info) # Attaching invalidates the filter, reset. fake_lvm.filter_invalidated = False managedvolume.detach_volume("fake_vol_id") with pytest.raises(managedvolumedb.NotFound): tmp_db.get_volume("fake_vol_id") entries = fake_os_brick.log() assert len(entries) == 1 assert entries[0]["action"] == "connect_volume" # No multipath id added, no need to invalidated filter. assert not fake_lvm.filter_invalidated
def test_attach_volume_not_installed_attach(monkeypatch): # Simulate missing os_brick. monkeypatch.setattr(managedvolume, "os_brick", None) with pytest.raises(se.ManagedVolumeNotSupported): managedvolume.attach_volume("vol_id", {})
def test_attach_volume_not_installed_attach(monkeypatch): # Simulate missing os_brick. monkeypatch.setattr(managedvolume, "os_brick", None) with pytest.raises(se.ManagedVolumeNotSupported): managedvolume.attach_volume("sd_id", "vol_id", {})