Skip to content

Commit

Permalink
Merge "Follow up mem_server diskfile fixes"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Mar 7, 2016
2 parents 1a69b14 + f39cffb commit 35d62d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
30 changes: 25 additions & 5 deletions swift/obj/mem_diskfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,37 @@ def __init__(self):
self._filesystem = {}

def get_object(self, name):
"""
Return back an file-like object and its metadata
:param name: standard object name
:return (fp, metadata): fp is `StringIO` in-memory representation
object (or None). metadata is a dictionary
of metadata (or None)
"""
val = self._filesystem.get(name)
if val is None:
data, metadata = None, None
fp, metadata = None, None
else:
data, metadata = val
return data, metadata
fp, metadata = val
return fp, metadata

def put_object(self, name, fp, metadata):
"""
Store object into memory
def put_object(self, name, data, metadata):
self._filesystem[name] = (data, metadata)
:param name: standard object name
:param fp: `StringIO` in-memory representation object
:param metadata: dictionary of metadata to be written
"""
self._filesystem[name] = (fp, metadata)

def del_object(self, name):
"""
Delete object from memory
:param name: standard object name
"""
del self._filesystem[name]

def get_diskfile(self, account, container, obj, **kwargs):
Expand Down
9 changes: 9 additions & 0 deletions test/unit/proxy/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2970,6 +2970,10 @@ def _do_conditional_GET_checks(last_modified_time):

# now POST to the object using default object_post_as_copy setting
orig_post_as_copy = prosrv.object_post_as_copy

# last-modified rounded in sec so sleep a sec to increment
sleep(1)

sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile()
fd.write('POST /v1/a/c/o.last_modified HTTP/1.1\r\n'
Expand All @@ -2984,10 +2988,14 @@ def _do_conditional_GET_checks(last_modified_time):

# last modified time will have changed due to POST
last_modified_head = _do_HEAD()
self.assertNotEqual(last_modified_put, last_modified_head)
_do_conditional_GET_checks(last_modified_head)

# now POST using non-default object_post_as_copy setting
try:
# last-modified rounded in sec so sleep a sec to increment
last_modified_post = last_modified_head
sleep(1)
prosrv.object_post_as_copy = not orig_post_as_copy
sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile()
Expand All @@ -3005,6 +3013,7 @@ def _do_conditional_GET_checks(last_modified_time):

# last modified time will have changed due to POST
last_modified_head = _do_HEAD()
self.assertNotEqual(last_modified_post, last_modified_head)
_do_conditional_GET_checks(last_modified_head)

def test_PUT_auto_content_type(self):
Expand Down

0 comments on commit 35d62d0

Please sign in to comment.