Commit 66fa6e34 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

pithos-sh support for policies options & additional tests for testing policies & object update

parent 919232f8
......@@ -294,10 +294,11 @@ class OOS_Client(Client):
l = self._filter_trashed(l)
return l
def create_container(self, container, account=None, **meta):
def create_container(self, container, account=None, meta={}, **headers):
"""creates a container"""
account = account or self.account
headers = {}
if not headers:
headers = {}
for k,v in meta.items():
headers['x-container-meta-%s' %k.strip().upper()] = v.strip()
status, header, data = self.put('/%s/%s' % (account, container),
......@@ -632,6 +633,12 @@ class Pithos_Client(OOS_Client):
return self.post(path, headers=headers)
# Storage Container Services
def create_container(self, container, account=None, meta={}, policies={}):
"""creates a container"""
args = {}
for k, v in policies.items():
args['X-Container-Policy-%s' % k.capitalize()] = v
return OOS_Client.create_container(self, container, account, meta, **args)
def list_objects(self, container, format='text',
limit=None, marker=None, prefix=None, delimiter=None,
......
......@@ -225,13 +225,20 @@ class Meta(Command):
class CreateContainer(Command):
syntax = '<container> [key=val] [...]'
description = 'create a container'
policy={}
def add_options(self, parser):
parser.add_option('--versioning', action='store', dest=policy['versioning'],
default=None, help='set container versioning (auto/none)')
parser.add_option('--quota', action='store', dest=policy['quota'],
default=None, help='set default container quota')
def execute(self, container, *args):
meta = {}
for arg in args:
key, sep, val = arg.partition('=')
meta[key] = val
ret = self.client.create_container(container, **meta)
ret = self.client.create_container(container, meta=meta, policies=policy)
if not ret:
print 'Container already exists'
......
......@@ -1452,9 +1452,10 @@ class ObjectPost(BaseTestCase):
if content_length:
args['content_length'] = content_length
status = self.client.update_object(self.containers[0], self.obj[0]['name'],
StringIO(data), **args)[0]
r = self.client.update_object(self.containers[0], self.obj[0]['name'],
StringIO(data), **args)
status = r[0]
etag = r[1]['etag']
if partial < 0 or (instance_length and l <= last_byte_pos):
self.assertEqual(status, 202)
else:
......@@ -1465,6 +1466,7 @@ class ObjectPost(BaseTestCase):
self.assertEqual(content[:first_byte_pos], self.obj[0]['data'][:first_byte_pos])
self.assertEqual(content[first_byte_pos:last_byte_pos+1], data)
self.assertEqual(content[last_byte_pos+1:], self.obj[0]['data'][last_byte_pos+1:])
self.assertEqual(etag, compute_md5_hash(content))
def test_update_object_lt_blocksize(self):
self.test_update_object(10, 20, content_length=None)
......@@ -2074,6 +2076,36 @@ class TestPublish(BaseTestCase):
data = resp.read(length)
self.assertEqual(o_data, data)
class TestPolicies(BaseTestCase):
def test_none_versioning(self):
self.client.create_container('c', policies={'versioning':'none'})
o = self.upload_random_data('c', 'o')
meta = self.client.retrieve_object_metadata('c', 'o')
v = meta['x-object-version']
more_data = get_random_data()
self.client.update_object('c', 'o', StringIO(more_data))
vlist = self.client.retrieve_object_versionlist('c', 'o')
self.assert_raises_fault(404, self.client.retrieve_object_version,
'c', 'o', v)
data = self.client.retrieve_object('c', 'o')
end = len(o['data'])
self.assertEqual(data[:end], o['data'])
self.assertEqual(data[end:], more_data)
def test_quota(self):
self.client.create_container('c', policies={'quota':'1'})
meta = self.client.retrieve_container_metadata('c')
self.assertEqual(meta['x-container-policy-quota'], '1')
self.assert_raises_fault(413, self.upload_random_data, 'c', 'o',
length=1024*1024+1)
def test_quota_none(self):
self.client.create_container('c', policies={'quota':'0'})
meta = self.client.retrieve_container_metadata('c')
self.assertEqual(meta['x-container-policy-quota'], '0')
self.assert_not_raises_fault(413, self.upload_random_data, 'c', 'o',
length=1024*1024+1)
class AssertUUidInvariant(object):
def __init__(self, callable, *args, **kwargs):
self.callable = callable
......@@ -2142,7 +2174,7 @@ def compute_block_hash(data, algorithm):
def get_random_data(length=500):
char_set = string.ascii_uppercase + string.digits
return ''.join(random.choice(char_set) for x in range(length))
return ''.join(random.choice(char_set) for x in xrange(length))
def is_date(date):
MONTHS = 'jan feb mar apr may jun jul aug sep oct nov dec'.split()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment