Merge "Handle unicode characters in migration params"

This commit is contained in:
Zuul 2018-08-13 04:05:25 +00:00 committed by Gerrit Code Review
commit 54043dad7e
2 changed files with 8 additions and 4 deletions

View File

@ -646,15 +646,19 @@ class GuestTestCase(test.NoDBTestCase):
@testtools.skipIf(not six.PY2, 'libvirt python3 bindings accept unicode')
def test_migrate_v3_unicode(self):
dest_xml_template = "<domain type='qemu'><name>%s</name></domain>"
name = u'\u00CD\u00F1st\u00E1\u00F1c\u00E9'
dest_xml = dest_xml_template % name
expect_dest_xml = dest_xml_template % encodeutils.to_utf8(name)
self.guest.migrate('an-uri', flags=1, migrate_uri='dest-uri',
migrate_disks=[u"disk1", u"disk2"],
destination_xml='</xml>',
destination_xml=dest_xml,
bandwidth=2)
self.domain.migrateToURI3.assert_called_once_with(
'an-uri', flags=1, params={'migrate_uri': 'dest-uri',
'migrate_disks': ['disk1',
'disk2'],
'destination_xml': '</xml>',
'destination_xml': expect_dest_xml,
'bandwidth': 2})
def test_abort_job(self):

View File

@ -665,8 +665,8 @@ class Guest(object):
# In the Python2 libvirt bindings, strings passed to
# migrateToURI3 via params must not be unicode.
if six.PY2:
params = {key: str(value) if isinstance(value, unicode) # noqa
else value
params = {key: encodeutils.to_utf8(value)
if isinstance(value, six.text_type) else value
for key, value in params.items()}
self._domain.migrateToURI3(