Fix issues with byte encoded strings
If byte encoded strings are passed to the ovirt SDK. We get the error outlined here: https://bugzilla.redhat.com/show_bug.cgi?id=1924928 This change leaves the string validation in place, but passes while raising a warning. Ultimately, non-encoded strings are provided to ovirt SDK to prevent the mentioned issue. Change-Id: I8e62a650ebae974017e17342ec17aa61ba67eed9
This commit is contained in:
parent
34f96a4a53
commit
594cb9ad98
@ -133,20 +133,21 @@ def _getvm(driver_info):
|
||||
password = driver_info['ovirt_password']
|
||||
insecure = driver_info['ovirt_insecure']
|
||||
ca_file = driver_info['ovirt_ca_file']
|
||||
name = str.encode(
|
||||
driver_info['ovirt_vm_name'], encoding='ascii', errors='ignore')
|
||||
name = driver_info['ovirt_vm_name']
|
||||
url = "https://%s/ovirt-engine/api" % address
|
||||
|
||||
try:
|
||||
# pycurl.Curl.setopt doesn't support unicode strings,
|
||||
# attempt to turn `url` into an all-ASCII string;
|
||||
# attempt to turn variables into an all-ASCII string;
|
||||
# in Python 3.x setopt accepts bytes as it should.
|
||||
url = str.encode(url, encoding='ascii', errors='strict')
|
||||
str.encode(url, encoding='ascii', errors='strict')
|
||||
|
||||
except UnicodeEncodeError:
|
||||
LOG.warning("oVirt URL '%(url)s' contains non-ascii characters, "
|
||||
"that might cause pycurl to explode "
|
||||
"momentarily", {'url': url})
|
||||
|
||||
LOG.exception("oVirt SDK does not accept non-ascii "
|
||||
"characters. A non-ascii character has "
|
||||
"been provided for: {}".format(url))
|
||||
raise staging_exception.OVirtError("Unicode values "
|
||||
"are not valid")
|
||||
try:
|
||||
connection = sdk.Connection(url=url, username=username,
|
||||
password=password, insecure=insecure,
|
||||
|
@ -21,7 +21,9 @@ from ironic.common import states
|
||||
from ironic.conductor import task_manager
|
||||
from ironic.tests.unit.db import base as db_base
|
||||
from ironic.tests.unit.objects import utils as obj_utils
|
||||
import testtools
|
||||
|
||||
from ironic_staging_drivers.common import exception as staging_exception
|
||||
from ironic_staging_drivers.ovirt import ovirt as ovirt_power
|
||||
|
||||
|
||||
@ -64,11 +66,11 @@ class OVirtDriverTestCase(db_base.DbTestCase):
|
||||
with 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',
|
||||
url='https://127.0.0.1/ovirt-engine/api',
|
||||
username='jhendrix@internal'
|
||||
)
|
||||
url = ovirt_power.sdk.Connection.mock_calls[0][-1]['url']
|
||||
self.assertIsInstance(url, bytes)
|
||||
self.assertIsInstance(url, str)
|
||||
|
||||
ovirt_power.sdk.Connection.return_value.close.assert_called()
|
||||
|
||||
@ -77,15 +79,10 @@ class OVirtDriverTestCase(db_base.DbTestCase):
|
||||
self.node['driver_info']['ovirt_address'] = u'host\u20141'
|
||||
driver_info = ovirt_power._parse_driver_info(self.node)
|
||||
|
||||
with 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.assertIsInstance(url, str)
|
||||
ovirt_power.sdk.Connection.return_value.close.assert_called()
|
||||
with testtools.ExpectedException(staging_exception.OVirtError):
|
||||
with ovirt_power._getvm(driver_info):
|
||||
pass
|
||||
ovirt_power.sdk.Connection.call_count = 0
|
||||
|
||||
def test_get_properties(self):
|
||||
expected = list(ovirt_power.PROPERTIES.keys())
|
||||
|
Loading…
x
Reference in New Issue
Block a user