py3: Fixes encoding and type error

Fixes encoding bytes to base64.
Fixes unorderedtype int() and str()
for python3.
Fixes encoding issues.

Change-Id: I6e7aaf21e080078d4b36562e41129804d71df2fc
This commit is contained in:
Lokesh S 2016-07-21 15:41:58 +00:00 committed by Alistair Coles
parent 45080a5177
commit 1fc46a0e13
3 changed files with 17 additions and 14 deletions

View File

@ -254,7 +254,7 @@ class AccountBroker(DatabaseBroker):
:param bytes_used: number of bytes used by the container
:param storage_policy_index: the storage policy for this container
"""
if delete_timestamp > put_timestamp and \
if Timestamp(delete_timestamp) > Timestamp(put_timestamp) and \
object_count in (None, '', 0, '0'):
deleted = 1
else:
@ -501,12 +501,14 @@ class AccountBroker(DatabaseBroker):
for i in range(5):
if record[i] is None and row[i] is not None:
record[i] = row[i]
if row[1] > record[1]: # Keep newest put_timestamp
if Timestamp(row[1]) > \
Timestamp(record[1]): # Keep newest put_timestamp
record[1] = row[1]
if row[2] > record[2]: # Keep newest delete_timestamp
if Timestamp(row[2]) > \
Timestamp(record[2]): # Keep newest delete_timestamp
record[2] = row[2]
# If deleted, mark as such
if record[2] > record[1] and \
if Timestamp(record[2]) > Timestamp(record[1]) and \
record[3] in (None, '', 0, '0'):
record[5] = 1
else:

View File

@ -142,7 +142,7 @@ def format_acl_v1(groups=None, referrers=None, header_name=None):
def format_acl_v2(acl_dict):
"""
r"""
Returns a version-2 Swift ACL JSON string.
HTTP headers for Version 2 ACLs have the following form:

View File

@ -30,6 +30,7 @@ import itertools
from contextlib import contextmanager
import random
import mock
import base64
from swift.account.backend import AccountBroker
from swift.common.utils import Timestamp
@ -801,13 +802,13 @@ class TestAccountBroker(unittest.TestCase):
broker = AccountBroker(broker_path, account='real')
broker.initialize(Timestamp(1).internal)
with open(broker.pending_file, 'a+b') as pending:
pending.write(':')
pending.write(pickle.dumps(
pending.write(b':')
pending.write(base64.b64encode(pickle.dumps(
# name, put_timestamp, delete_timestamp, object_count,
# bytes_used, deleted
('oldcon', Timestamp(200).internal,
Timestamp(0).internal,
896, 9216695, 0)).encode('base64'))
896, 9216695, 0))))
broker._commit_puts()
with broker.get() as conn:
@ -830,13 +831,13 @@ class TestAccountBroker(unittest.TestCase):
stale_reads_ok=True)
broker.initialize(Timestamp(1).internal)
with open(broker.pending_file, 'a+b') as pending:
pending.write(':')
pending.write(pickle.dumps(
pending.write(b':')
pending.write(base64.b64encode(pickle.dumps(
# name, put_timestamp, delete_timestamp, object_count,
# bytes_used, deleted
('oldcon', Timestamp(200).internal,
Timestamp(0).internal,
896, 9216695, 0)).encode('base64'))
896, 9216695, 0))))
broker._commit_puts = mock_commit_puts
broker.get_info()
@ -852,13 +853,13 @@ class TestAccountBroker(unittest.TestCase):
stale_reads_ok=False)
broker.initialize(Timestamp(1).internal)
with open(broker.pending_file, 'a+b') as pending:
pending.write(':')
pending.write(pickle.dumps(
pending.write(b':')
pending.write(base64.b64encode(pickle.dumps(
# name, put_timestamp, delete_timestamp, object_count,
# bytes_used, deleted
('oldcon', Timestamp(200).internal,
Timestamp(0).internal,
896, 9216695, 0)).encode('base64'))
896, 9216695, 0))))
broker._commit_puts = mock_commit_puts