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: Ibf24df3a90ecbcdec400a0570f2818f89b78ea0a
This commit is contained in:
Luong Anh Tuan 2016-12-15 12:42:03 +07:00 committed by Tuan Luong-Anh
parent 9af663b59f
commit f6d02e1cb9
3 changed files with 5 additions and 4 deletions

View File

@ -13,7 +13,6 @@
"""Handling introspection data from the ramdisk."""
import base64
import copy
import datetime
import os
@ -22,6 +21,7 @@ import eventlet
import json
from oslo_config import cfg
from oslo_serialization import base64
from oslo_utils import excutils
from ironic_inspector.common.i18n import _, _LE, _LI, _LW
@ -73,7 +73,7 @@ def _store_logs(introspection_data, node_info):
os.makedirs(CONF.processing.ramdisk_logs_dir)
with open(os.path.join(CONF.processing.ramdisk_logs_dir, file_name),
'wb') as fp:
fp.write(base64.b64decode(logs))
fp.write(base64.decode_as_bytes(logs))
except EnvironmentError:
LOG.exception(_LE('Could not store the ramdisk logs'),
data=introspection_data, node_info=node_info)

View File

@ -11,7 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import base64
import copy
import functools
import json
@ -25,6 +24,7 @@ import fixtures
from ironicclient import exceptions
import mock
from oslo_config import cfg
from oslo_serialization import base64
from oslo_utils import uuidutils
from ironic_inspector.common import ironic as ir_utils
@ -256,7 +256,7 @@ class TestStoreLogs(BaseProcessTest):
CONF.set_override('ramdisk_logs_dir', self.tempdir, 'processing')
self.logs = b'test logs'
self.data['logs'] = base64.b64encode(self.logs)
self.data['logs'] = base64.encode_as_bytes(self.logs)
def _check_contents(self, name=None):
files = os.listdir(self.tempdir)

View File

@ -22,6 +22,7 @@ oslo.i18n>=2.1.0 # Apache-2.0
oslo.log>=3.11.0 # Apache-2.0
oslo.middleware>=3.0.0 # Apache-2.0
oslo.rootwrap>=5.0.0 # Apache-2.0
oslo.serialization>=1.10.0 # Apache-2.0
oslo.utils>=3.18.0 # Apache-2.0
six>=1.9.0 # MIT
stevedore>=1.17.1 # Apache-2.0