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 both python2 and python3. [1] https://wiki.openstack.org/wiki/Python3 [2] http://stackoverflow.com/questions/8908287/base64-encoding-in-python-3 Change-Id: I1dafe878a71f37d223eaf58ea8e2e8c6b4422a14
This commit is contained in:
parent
28da1ca05a
commit
81780adef8
@ -13,7 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import base64
|
||||
import errno
|
||||
import glob
|
||||
import io
|
||||
@ -27,6 +26,7 @@ import testtools
|
||||
from ironic_lib import utils as ironic_utils
|
||||
import mock
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_serialization import base64
|
||||
from oslotest import base as test_base
|
||||
|
||||
from ironic_python_agent import errors
|
||||
@ -386,7 +386,7 @@ class TestUtils(testtools.TestCase):
|
||||
io_dict = {'fake-name': io.BytesIO(bytes(contents))}
|
||||
data = utils.gzip_and_b64encode(io_dict=io_dict)
|
||||
|
||||
res = io.BytesIO(base64.b64decode(data))
|
||||
res = io.BytesIO(base64.decode_as_bytes(data))
|
||||
with tarfile.open(fileobj=res) as tar:
|
||||
members = [(m.name, m.size) for m in tar]
|
||||
self.assertEqual([('fake-name', len(contents))], members)
|
||||
|
@ -12,7 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import base64
|
||||
import copy
|
||||
import errno
|
||||
import glob
|
||||
@ -27,6 +26,7 @@ import time
|
||||
from ironic_lib import utils as ironic_utils
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import base64
|
||||
from oslo_utils import units
|
||||
from six.moves.urllib import parse
|
||||
|
||||
@ -383,7 +383,7 @@ def gzip_and_b64encode(io_dict=None, file_list=None):
|
||||
tar.add(f)
|
||||
|
||||
fp.seek(0)
|
||||
return base64.b64encode(fp.getvalue())
|
||||
return base64.encode_as_bytes(fp.getvalue())
|
||||
|
||||
|
||||
def collect_system_logs(journald_max_lines=None):
|
||||
|
Loading…
x
Reference in New Issue
Block a user