Merge "Use calendar.timegm not time.mktime"

This commit is contained in:
Jenkins 2016-01-25 21:28:45 +00:00 committed by Gerrit Code Review
commit c97df893f1
2 changed files with 31 additions and 5 deletions

View File

@ -115,6 +115,7 @@ Disable versioning from a container (x is any value except empty)::
-H "X-Remove-Versions-Location: x" http://<storage_url>/container
"""
import calendar
import json
import six
from six.moves.urllib.parse import quote, unquote
@ -209,9 +210,9 @@ class VersionedWritesContext(WSGIContext):
lprefix = prefix_len + object_name + '/'
ts_source = hresp.environ.get('swift_x_timestamp')
if ts_source is None:
ts_source = time.mktime(time.strptime(
hresp.headers['last-modified'],
'%a, %d %b %Y %H:%M:%S GMT'))
ts_source = calendar.timegm(time.strptime(
hresp.headers['last-modified'],
'%a, %d %b %Y %H:%M:%S GMT'))
new_ts = Timestamp(ts_source).internal
vers_obj_name = lprefix + new_ts
copy_headers = {

View File

@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import functools
import os
import time
import unittest
from swift.common import swob
from swift.common.middleware import versioned_writes
@ -31,6 +34,26 @@ class FakeCache(object):
return self.val
def local_tz(func):
'''
Decorator to change the timezone when running a test.
This uses the Eastern Time Zone definition from the time module's docs.
Note that the timezone affects things like time.time() and time.mktime().
'''
@functools.wraps(func)
def wrapper(*args, **kwargs):
tz = os.environ.get('TZ', '')
try:
os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0'
time.tzset()
return func(*args, **kwargs)
finally:
os.environ['TZ'] = tz
time.tzset()
return wrapper
class VersionedWritesTestCase(unittest.TestCase):
def setUp(self):
self.app = FakeSwift()
@ -327,12 +350,13 @@ class VersionedWritesTestCase(unittest.TestCase):
self.assertEqual(len(self.authorized), 1)
self.assertRequestEqual(req, self.authorized[0])
@local_tz
def test_new_version_sysmeta_precedence(self):
self.app.register(
'PUT', '/v1/a/c/o', swob.HTTPOk, {}, 'passed')
self.app.register(
'HEAD', '/v1/a/c/o', swob.HTTPOk,
{'last-modified': 'Wed, 19 Nov 2014 18:19:02 GMT'}, 'passed')
{'last-modified': 'Thu, 1 Jan 1970 00:00:00 GMT'}, 'passed')
self.app.register(
'COPY', '/v1/a/c/o', swob.HTTPCreated, {}, None)
@ -354,7 +378,8 @@ class VersionedWritesTestCase(unittest.TestCase):
method, path, req_headers = calls[1]
self.assertEqual('COPY', method)
self.assertEqual('/v1/a/c/o', path)
self.assertTrue(req_headers['Destination'].startswith('ver_cont/'))
self.assertEqual('ver_cont/001o/0000000000.00000',
req_headers['Destination'])
def test_copy_first_version(self):
self.app.register(