Merge "py3: adapt account/backend.py and utils.py"
This commit is contained in:
commit
56c06557ac
@ -20,6 +20,8 @@ from uuid import uuid4
|
|||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from swift.common.utils import Timestamp
|
from swift.common.utils import Timestamp
|
||||||
from swift.common.db import DatabaseBroker, utf8encode, zero_like
|
from swift.common.db import DatabaseBroker, utf8encode, zero_like
|
||||||
|
|
||||||
@ -244,7 +246,7 @@ class AccountBroker(DatabaseBroker):
|
|||||||
"""
|
"""
|
||||||
Create a container with the given attributes.
|
Create a container with the given attributes.
|
||||||
|
|
||||||
:param name: name of the container to create
|
:param name: name of the container to create (a native string)
|
||||||
:param put_timestamp: put_timestamp of the container to create
|
:param put_timestamp: put_timestamp of the container to create
|
||||||
:param delete_timestamp: delete_timestamp of the container to create
|
:param delete_timestamp: delete_timestamp of the container to create
|
||||||
:param object_count: number of objects in the container
|
:param object_count: number of objects in the container
|
||||||
@ -384,8 +386,9 @@ class AccountBroker(DatabaseBroker):
|
|||||||
put_timestamp, 0)
|
put_timestamp, 0)
|
||||||
"""
|
"""
|
||||||
delim_force_gte = False
|
delim_force_gte = False
|
||||||
(marker, end_marker, prefix, delimiter) = utf8encode(
|
if six.PY2:
|
||||||
marker, end_marker, prefix, delimiter)
|
(marker, end_marker, prefix, delimiter) = utf8encode(
|
||||||
|
marker, end_marker, prefix, delimiter)
|
||||||
if reverse:
|
if reverse:
|
||||||
# Reverse the markers if we are reversing the listing.
|
# Reverse the markers if we are reversing the listing.
|
||||||
marker, end_marker = end_marker, marker
|
marker, end_marker = end_marker, marker
|
||||||
@ -415,7 +418,7 @@ class AccountBroker(DatabaseBroker):
|
|||||||
query_args.append(marker)
|
query_args.append(marker)
|
||||||
# Always set back to False
|
# Always set back to False
|
||||||
delim_force_gte = False
|
delim_force_gte = False
|
||||||
elif marker and marker >= prefix:
|
elif marker and (not prefix or marker >= prefix):
|
||||||
query += ' name > ? AND'
|
query += ' name > ? AND'
|
||||||
query_args.append(marker)
|
query_args.append(marker)
|
||||||
elif prefix:
|
elif prefix:
|
||||||
|
@ -32,6 +32,8 @@ import random
|
|||||||
import mock
|
import mock
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from swift.account.backend import AccountBroker
|
from swift.account.backend import AccountBroker
|
||||||
from swift.common.utils import Timestamp
|
from swift.common.utils import Timestamp
|
||||||
from test.unit import patch_policies, with_tempdir, make_timestamp_iter
|
from test.unit import patch_policies, with_tempdir, make_timestamp_iter
|
||||||
@ -720,26 +722,23 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
broker.put_container('b', Timestamp(2).internal,
|
broker.put_container('b', Timestamp(2).internal,
|
||||||
Timestamp(0).internal, 0, 0,
|
Timestamp(0).internal, 0, 0,
|
||||||
POLICIES.default.idx)
|
POLICIES.default.idx)
|
||||||
hasha = hashlib.md5(
|
text = '%s-%s' % ('a', "%s-%s-%s-%s" % (
|
||||||
'%s-%s' % ('a', "%s-%s-%s-%s" % (
|
Timestamp(1).internal, Timestamp(0).internal, 0, 0))
|
||||||
Timestamp(1).internal, Timestamp(0).internal, 0, 0))
|
hasha = hashlib.md5(text.encode('ascii')).digest()
|
||||||
).digest()
|
text = '%s-%s' % ('b', "%s-%s-%s-%s" % (
|
||||||
hashb = hashlib.md5(
|
Timestamp(2).internal, Timestamp(0).internal, 0, 0))
|
||||||
'%s-%s' % ('b', "%s-%s-%s-%s" % (
|
hashb = hashlib.md5(text.encode('ascii')).digest()
|
||||||
Timestamp(2).internal, Timestamp(0).internal, 0, 0))
|
hashc = ''.join(('%02x' % (ord(a) ^ ord(b) if six.PY2 else a ^ b)
|
||||||
).digest()
|
for a, b in zip(hasha, hashb)))
|
||||||
hashc = \
|
|
||||||
''.join(('%02x' % (ord(a) ^ ord(b)) for a, b in zip(hasha, hashb)))
|
|
||||||
self.assertEqual(broker.get_info()['hash'], hashc)
|
self.assertEqual(broker.get_info()['hash'], hashc)
|
||||||
broker.put_container('b', Timestamp(3).internal,
|
broker.put_container('b', Timestamp(3).internal,
|
||||||
Timestamp(0).internal, 0, 0,
|
Timestamp(0).internal, 0, 0,
|
||||||
POLICIES.default.idx)
|
POLICIES.default.idx)
|
||||||
hashb = hashlib.md5(
|
text = '%s-%s' % ('b', "%s-%s-%s-%s" % (
|
||||||
'%s-%s' % ('b', "%s-%s-%s-%s" % (
|
Timestamp(3).internal, Timestamp(0).internal, 0, 0))
|
||||||
Timestamp(3).internal, Timestamp(0).internal, 0, 0))
|
hashb = hashlib.md5(text.encode('ascii')).digest()
|
||||||
).digest()
|
hashc = ''.join(('%02x' % (ord(a) ^ ord(b) if six.PY2 else a ^ b)
|
||||||
hashc = \
|
for a, b in zip(hasha, hashb)))
|
||||||
''.join(('%02x' % (ord(a) ^ ord(b)) for a, b in zip(hasha, hashb)))
|
|
||||||
self.assertEqual(broker.get_info()['hash'], hashc)
|
self.assertEqual(broker.get_info()['hash'], hashc)
|
||||||
|
|
||||||
def test_merge_items(self):
|
def test_merge_items(self):
|
||||||
@ -767,7 +766,9 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
sorted([rec['name'] for rec in items]))
|
sorted([rec['name'] for rec in items]))
|
||||||
|
|
||||||
def test_merge_items_overwrite_unicode(self):
|
def test_merge_items_overwrite_unicode(self):
|
||||||
snowman = u'\N{SNOWMAN}'.encode('utf-8')
|
snowman = u'\N{SNOWMAN}'
|
||||||
|
if six.PY2:
|
||||||
|
snowman = snowman.encode('utf-8')
|
||||||
broker1 = AccountBroker(':memory:', account='a')
|
broker1 = AccountBroker(':memory:', account='a')
|
||||||
broker1.initialize(Timestamp('1').internal, 0)
|
broker1.initialize(Timestamp('1').internal, 0)
|
||||||
id1 = broker1.get_info()['id']
|
id1 = broker1.get_info()['id']
|
||||||
@ -1729,7 +1730,7 @@ class TestAccountBrokerBeforePerPolicyContainerTrack(
|
|||||||
0, 0, int(policy))
|
0, 0, int(policy))
|
||||||
|
|
||||||
total_container_count = self.broker.get_info()['container_count']
|
total_container_count = self.broker.get_info()['container_count']
|
||||||
self.assertEqual(total_container_count, num_containers / 2)
|
self.assertEqual(total_container_count, num_containers // 2)
|
||||||
|
|
||||||
# trigger migration
|
# trigger migration
|
||||||
policy_info = self.broker.get_policy_stats(do_migrations=True)
|
policy_info = self.broker.get_policy_stats(do_migrations=True)
|
||||||
|
2
tox.ini
2
tox.ini
@ -29,6 +29,8 @@ setenv = VIRTUAL_ENV={envdir}
|
|||||||
[testenv:py35]
|
[testenv:py35]
|
||||||
commands =
|
commands =
|
||||||
nosetests {posargs:\
|
nosetests {posargs:\
|
||||||
|
test/unit/account/test_backend.py \
|
||||||
|
test/unit/account/test_utils.py \
|
||||||
test/unit/cli/test_dispersion_report.py \
|
test/unit/cli/test_dispersion_report.py \
|
||||||
test/unit/cli/test_form_signature.py \
|
test/unit/cli/test_form_signature.py \
|
||||||
test/unit/cli/test_info.py \
|
test/unit/cli/test_info.py \
|
||||||
|
Loading…
Reference in New Issue
Block a user