Skip to content

Commit e8b6b0b

Browse files
committed
Fix python3 compatibility of rbd get_fsid
In py3 librados's get_fsid() function returns a binary string which breaks comparison when compared with the same value as a string. This is currently breakin the logic that compares ceph cluster fsids when deciding whether the image used to boot an instance is cow-clonable. Change-Id: I79b40ca40400c67b0805926096317afd875ffabb Closes-Bug: #1816468
1 parent 1316c1c commit e8b6b0b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

nova/tests/unit/virt/libvirt/storage/test_rbd.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ def test_bad_locations(self):
119119
self.assertFalse(self.driver.is_cloneable({'url': loc},
120120
image_meta))
121121

122+
@mock.patch.object(rbd_utils, 'RADOSClient')
123+
def test_rbddriver(self, mock_client):
124+
client = mock_client.return_value
125+
client.__enter__.return_value = client
126+
client.cluster.get_fsid.side_effect = lambda: b'abc'
127+
self.assertEqual('abc', self.driver.get_fsid())
128+
122129
@mock.patch.object(rbd_utils.RBDDriver, 'get_fsid')
123130
def test_cloneable(self, mock_get_fsid):
124131
mock_get_fsid.return_value = 'abc'

nova/virt/libvirt/storage/rbd_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from oslo_log import log as logging
2929
from oslo_serialization import jsonutils
3030
from oslo_service import loopingcall
31+
from oslo_utils import encodeutils
3132
from oslo_utils import excutils
3233
from oslo_utils import units
3334

@@ -194,7 +195,7 @@ def parse_url(self, url):
194195

195196
def get_fsid(self):
196197
with RADOSClient(self) as client:
197-
return client.cluster.get_fsid()
198+
return encodeutils.safe_decode(client.cluster.get_fsid())
198199

199200
def is_cloneable(self, image_location, image_meta):
200201
url = image_location['url']
@@ -204,6 +205,7 @@ def is_cloneable(self, image_location, image_meta):
204205
LOG.debug('not cloneable: %s', e)
205206
return False
206207

208+
fsid = encodeutils.safe_decode(fsid)
207209
if self.get_fsid() != fsid:
208210
reason = '%s is in a different ceph cluster' % url
209211
LOG.debug(reason)

0 commit comments

Comments
 (0)