Use oslo_serialization.base64 to follow OpenStack Python3
This patch replaces python standard base64 library call to oslo_serialization.base64 to follow OpenStack Python3 porting standard [1]. Use base64 encoding takes 8-bit binary byte data and encodes it. On Python3, A string is a sequence of Unicode characters thus base64 has no idea what to do with Unicode data, it's not 8-bit[2]. We use oslo_serialization.base64 for python2 and python3. [1] https://wiki.openstack.org/wiki/Python3 [2] http://stackoverflow.com/questions/8908287/base64-encoding-in-python-3 Change-Id: I9d453ab6ebc826cad60c89d2a74c5764626eba01
This commit is contained in:
parent
5bd0172fb6
commit
2a3288c69c
|
@ -13,7 +13,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import base64
|
||||
import gzip
|
||||
import logging
|
||||
import math
|
||||
|
@ -28,6 +27,7 @@ import time
|
|||
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import base64
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import imageutils
|
||||
from oslo_utils import units
|
||||
|
@ -396,7 +396,7 @@ def _get_configdrive(configdrive, node_uuid, tempdir=None):
|
|||
data = configdrive
|
||||
|
||||
try:
|
||||
data = six.BytesIO(base64.b64decode(data))
|
||||
data = six.BytesIO(base64.decode_as_bytes(data))
|
||||
except TypeError:
|
||||
error_msg = (_('Config drive for node %s is not base64 encoded '
|
||||
'or the content is malformed.') % node_uuid)
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import base64
|
||||
import gzip
|
||||
import mock
|
||||
import os
|
||||
|
@ -23,6 +22,7 @@ import tempfile
|
|||
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import base64
|
||||
from oslo_service import loopingcall
|
||||
from oslo_utils import imageutils
|
||||
from oslotest import base as test_base
|
||||
|
@ -639,7 +639,7 @@ class GetConfigdriveTestCase(test_base.BaseTestCase):
|
|||
'http://1.2.3.4/cd', 'fake-node-uuid')
|
||||
self.assertFalse(mock_copy.called)
|
||||
|
||||
@mock.patch.object(base64, 'b64decode', autospec=True)
|
||||
@mock.patch.object(base64, 'decode_as_bytes', autospec=True)
|
||||
def test_get_configdrive_base64_error(self, mock_b64, mock_requests,
|
||||
mock_copy):
|
||||
mock_b64.side_effect = TypeError
|
||||
|
|
|
@ -6,6 +6,7 @@ pbr>=1.8 # Apache-2.0
|
|||
oslo.concurrency>=3.8.0 # Apache-2.0
|
||||
oslo.config!=3.18.0,>=3.14.0 # Apache-2.0
|
||||
oslo.i18n>=2.1.0 # Apache-2.0
|
||||
oslo.serialization>=1.10.0 # Apache-2.0
|
||||
oslo.service>=1.10.0 # Apache-2.0
|
||||
oslo.utils>=3.18.0 # Apache-2.0
|
||||
requests!=2.12.2,>=2.10.0 # Apache-2.0
|
||||
|
|
Loading…
Reference in New Issue