Fix pycurl args types in ovirt driver

Ensure passing text-typed parameters to `ovirtsdk4` calls. Otherwise
`ovirtsdk4` blows up Python 3.

This change prompts `six` version bump.

Change-Id: I3bbbb6b786d7007e0dd0a45de1b21be909ee588b
Story: 2006170
Task: 35681
This commit is contained in:
Ilya Etingof 2019-07-03 13:51:22 +02:00
parent d500b4b013
commit 935ec1ac69
5 changed files with 21 additions and 14 deletions

View File

@ -19,7 +19,6 @@ via oVirt sdk API.
For use in dev and test environments.
"""
from ironic.common import boot_devices
from ironic.common import exception
from ironic.common.i18n import _
@ -29,6 +28,7 @@ from ironic.drivers import base
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import importutils
import six
from ironic_staging_drivers.common import exception as staging_exception
@ -130,17 +130,18 @@ def _getvm(driver_info):
password = driver_info['ovirt_password']
insecure = driver_info['ovirt_insecure']
ca_file = driver_info['ovirt_ca_file']
name = driver_info['ovirt_vm_name'].encode('ascii', 'ignore')
name = six.ensure_str(
driver_info['ovirt_vm_name'], encoding='ascii', errors='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')
# pycurl.Curl.setopt doesn't support unicode strings,
# attempt to turn `url` into an all-ASCII string
url = six.ensure_str(url, encoding='ascii', errors='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
LOG.warning("oVirt URL '%(url)s' contains non-ascii characters, "
"that might cause pycurl to explode "
"momentarily", {'url': url})
try:
connection = sdk.Connection(url=url, username=username,

View File

@ -21,6 +21,7 @@ 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 mock
import six
from ironic_staging_drivers.ovirt import ovirt as ovirt_power
@ -64,11 +65,11 @@ class OVirtDriverTestCase(db_base.DbTestCase):
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.assertEqual(type(b''), type(url))
self.assertIsInstance(url, six.string_types)
@mock.patch.object(ovirt_power, "sdk", create=True)
def test_getvm_unicode(self, sdk):
@ -82,7 +83,7 @@ class OVirtDriverTestCase(db_base.DbTestCase):
username='jhendrix@internal'
)
url = ovirt_power.sdk.Connection.mock_calls[0][-1]['url']
self.assertEqual(type(u''), type(url))
self.assertIsInstance(url, six.text_type)
def test_get_properties(self):
expected = list(ovirt_power.PROPERTIES.keys())

View File

@ -70,7 +70,7 @@ requestsexceptions==1.4.0
restructuredtext-lint==1.1.3
rfc3986==1.1.0
Routes==2.4.1
six==1.10.0
six==1.12.0
snowballstemmer==1.2.1
Sphinx==1.6.2
sphinxcontrib-websupport==1.0.1

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fixed parameters types used to call ``ovirtsdk4`` package services in
``ovirt`` driver to make it operational under Python 3 as well.

View File

@ -9,6 +9,6 @@ oslo.config>=5.2.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0
oslo.log>=3.36.0 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0
six>=1.10.0 # MIT
six>=1.12.0 # MIT
jsonschema>=2.6.0 # MIT
oslo.service!=1.28.1,>=1.24.0 # Apache-2.0