diskbackend: Fix volume lookup for existing rbd disk

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-11-10 15:49:24 -05:00
parent 3d07b28a36
commit 6a6c1c13d7
3 changed files with 33 additions and 2 deletions

View File

@ -208,3 +208,21 @@ def test_disk_diskbackend_parse():
guest = virtinst.Guest(conn, parsexml=dom.XMLDesc(0))
for disk in guest.devices.disk:
disk.set_backend_for_existing_path()
def test_disk_rbd_path():
conn = utils.URIs.open_testdriver_cached()
diskxml1 = """
<disk type="network" device="disk">
<source protocol="rbd" name="rbd-sourcename/some-rbd-vol">
<host name="ceph-mon-1.example.com" port="6789"/>
<host name="ceph-mon-2.example.com" port="6789"/>
<host name="ceph-mon-3.example.com" port="6789"/>
</source>
<target dev="vdag" bus="virtio"/>
</disk>
"""
disk1 = virtinst.DeviceDisk(conn, parsexml=diskxml1)
disk1.set_backend_for_existing_path()
assert disk1.get_vol_object().name() == "some-rbd-vol"

View File

@ -130,7 +130,7 @@ def testAddCephDisk(app):
tab = details.find("disk-tab")
lib.utils.check(lambda: tab.showing)
disk_path = tab.find("disk-source-path")
lib.utils.check(lambda: "rbd://" in disk_path.text)
lib.utils.check(lambda: "rbd-sourcename/some-rbd-vol" in disk_path.text)
def testAddDisks(app):

View File

@ -125,6 +125,17 @@ def _can_auto_manage(path):
return True
def _get_storage_search_path(path):
# If the passed path is one of our artificial rbd:// style
# URIs, parse out the path component, since that is what is needed
# for looking up storage volumes by target path
from .uri import URI
uriobj = URI(path)
if uriobj.scheme == "rbd":
return uriobj.path.strip("/")
return path
def manage_path(conn, path):
"""
If path is not managed, try to create a storage pool to probe the path
@ -136,7 +147,9 @@ def manage_path(conn, path):
if not path_is_url(path) and not path_is_network_vol(conn, path):
path = os.path.abspath(path)
vol, pool = _check_if_path_managed(conn, path)
searchpath = _get_storage_search_path(path)
vol, pool = _check_if_path_managed(conn, searchpath)
if vol or pool or not _can_auto_manage(path):
return vol, pool