Convert ovirt url to a str

Older versions if pyculr.Curl.setopt don't accept unicode
string values.

Change-Id: I4fca91228435a1a652b98db69aa2a92ffbaa47e7
Closes-Bug: #1761724
This commit is contained in:
Derek Higgins 2018-04-09 11:21:15 +01:00
parent d27bcf030e
commit b7a5234057
2 changed files with 38 additions and 0 deletions

View File

@ -131,6 +131,16 @@ def _getvm(driver_info):
ca_file = driver_info['ovirt_ca_file']
name = driver_info['ovirt_vm_name'].encode('ascii', 'ignore')
url = "https://%s/ovirt-engine/api" % address
try:
# pycurl.Curl.setopt doesn't support unicode stings
# convert them to a acsii str
url = url.encode('ascii', 'strict')
except UnicodeEncodeError:
# url contains unicode characters that can't be converted, attempt to
# use it, if we have a version of pycurl that rejects it then a
# sdk.Error will be thrown below
pass
try:
connection = sdk.Connection(url=url, username=username,
password=password, insecure=insecure,

View File

@ -58,6 +58,34 @@ class oVirtDriverTestCase(db_base.DbTestCase):
self.assertEqual('changeme', params['ovirt_password'])
self.assertEqual('jimi', params['ovirt_vm_name'])
@mock.patch.object(ovirt_power, "sdk", create=True)
def test_getvm_nounicode(self, sdk):
self.node['driver_info']['ovirt_address'] = u'127.0.0.1'
driver_info = ovirt_power._parse_driver_info(self.node)
ovirt_power._getvm(driver_info)
ovirt_power.sdk.Connection.assert_called_with(
ca_file=None, insecure='False', password='changeme',
url=b'https://127.0.0.1/ovirt-engine/api',
username='jhendrix@internal'
)
url = ovirt_power.sdk.Connection.mock_calls[0][-1]['url']
self.assertEqual(type(b''), type(url))
@mock.patch.object(ovirt_power, "sdk", create=True)
def test_getvm_unicode(self, sdk):
self.node['driver_info']['ovirt_address'] = u'host\u20141'
driver_info = ovirt_power._parse_driver_info(self.node)
ovirt_power._getvm(driver_info)
ovirt_power.sdk.Connection.assert_called_with(
ca_file=None, insecure='False', password='changeme',
url=u'https://host\u20141/ovirt-engine/api',
username='jhendrix@internal'
)
url = ovirt_power.sdk.Connection.mock_calls[0][-1]['url']
self.assertEqual(type(u''), type(url))
def test_get_properties(self):
expected = list(ovirt_power.PROPERTIES.keys())
with task_manager.acquire(