Skip to content

Commit

Permalink
Use oslo_serialization.base64 to follow OpenStack Python3
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TuanLAF committed Dec 15, 2016
1 parent 9af663b commit f6d02e1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ironic_inspector/process.py
Expand Up @@ -13,7 +13,6 @@

"""Handling introspection data from the ramdisk."""

import base64
import copy
import datetime
import os
Expand All @@ -22,6 +21,7 @@
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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ironic_inspector/test/unit/test_process.py
Expand Up @@ -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
Expand All @@ -25,6 +24,7 @@
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
Expand Down Expand Up @@ -256,7 +256,7 @@ def setUp(self):
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)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -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
Expand Down

0 comments on commit f6d02e1

Please sign in to comment.