summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2020-11-10 15:49:24 -0500
committerCole Robinson <crobinso@redhat.com>2020-11-11 19:06:32 -0500
commit6a6c1c13d74cc31e9d581b74bd7101c141a94a02 (patch)
treefe1643c2a6fca35ca7912741818ab22d94475ee0
parent3d07b28a360eb1ba1507c5713b99954eb226751f (diff)
downloadvirt-manager-6a6c1c13d74cc31e9d581b74bd7101c141a94a02.tar.gz
diskbackend: Fix volume lookup for existing rbd disk
Signed-off-by: Cole Robinson <crobinso@redhat.com>
-rw-r--r--tests/test_disk.py18
-rw-r--r--tests/uitests/test_addhardware.py2
-rw-r--r--virtinst/diskbackend.py15
3 files changed, 33 insertions, 2 deletions
diff --git a/tests/test_disk.py b/tests/test_disk.py
index 6e6c0b43..c5d2c3c3 100644
--- a/tests/test_disk.py
+++ b/tests/test_disk.py
@@ -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"
diff --git a/tests/uitests/test_addhardware.py b/tests/uitests/test_addhardware.py
index c1b02ee2..22852601 100644
--- a/tests/uitests/test_addhardware.py
+++ b/tests/uitests/test_addhardware.py
@@ -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):
diff --git a/virtinst/diskbackend.py b/virtinst/diskbackend.py
index 4a944b49..9a807561 100644
--- a/virtinst/diskbackend.py
+++ b/virtinst/diskbackend.py
@@ -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