Commit 3ed6dbde authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Split file-quota semantics for account and contner

kamaki file quota --> only for account
kamaki file quota <container> --> kamaki file containerlimit get [container]

Support #3541
parent 326a79b9
......@@ -329,12 +329,13 @@ file (Storage/Pithos+)
permissions : Get object read/write permissions
publish : Publish an object
purge : Purge a container
quota : Get quota for account [or container]
quota : Get quota for account
setgroup : Create/update a new user group
setmeta : Set a new metadatum for account [, container [or object]]
setpermissions: Set sharing permissions
containerlimit: Container size limit commands
set : Set copntainer data limit
set : Set container data limit
get : Get container data limit
setversioning : Set new versioning (auto, none) for account [or container]
sharers : List the accounts that share objects with default account
touch : Create an empty object (file)
......
......@@ -203,7 +203,8 @@ file commands
* setgroup Set a user group
* setmeta Set a piece of metadata for account, container or object
* setpermissions Set permissions for an object
* containerlimit set Set new quota (in KB) for account or container
* containerlimit set Set new limit for container
* containerlimit get Get container limit
* setversioning Set versioning mode (auto, none) for account or container
* sharers List the accounts that share objects with current user
* touch Create an empty object (file)
......
......@@ -198,9 +198,11 @@ class _file_account_command(_pithos_init):
'Set user account (not permanent)',
('-A', '--account'))
def _run(self):
def _run(self, custom_account=None):
super(_file_account_command, self)._run()
if self['account']:
if custom_account:
self.client.account = custom_account
elif self['account']:
self.client.account = self['account']
@errors.generic.all
......@@ -484,7 +486,7 @@ class file_create(_file_container_command):
versioning=ValueArgument(
'set container versioning (auto/none)',
'--versioning'),
quota=IntArgument('set default container quota', '--quota'),
limit=IntArgument('set default container limit', '--limit'),
meta=KeyValueArgument(
'set container metadata (can be repeated)',
'--meta')
......@@ -495,7 +497,7 @@ class file_create(_file_container_command):
@errors.pithos.container
def _run(self):
self.client.container_put(
quota=self['quota'],
limit=self['limit'],
versioning=self['versioning'],
metadata=self['meta'])
......@@ -1745,7 +1747,7 @@ class file_delmeta(_file_container_command):
@command(pithos_cmds)
class file_quota(_file_account_command):
"""Get quota for account or container"""
"""Get account quota"""
arguments = dict(
in_bytes=FlagArgument('Show result in bytes', ('-b', '--bytes'))
......@@ -1753,20 +1755,15 @@ class file_quota(_file_account_command):
@errors.generic.all
@errors.pithos.connection
@errors.pithos.container
def _run(self):
if self.container:
reply = self.client.get_container_quota(self.container)
else:
reply = self.client.get_account_quota()
reply = self.client.get_account_quota()
if not self['in_bytes']:
for k in reply:
reply[k] = format_size(reply[k])
print_dict(pretty_keys(reply, '-'))
def main(self, container=None):
super(self.__class__, self)._run()
self.container = container
def main(self, custom_uuid=None):
super(self.__class__, self)._run(custom_account=custom_uuid)
self._run()
......@@ -1775,13 +1772,36 @@ class file_containerlimit(_pithos_init):
"""Container size limit commands"""
@command(pithos_cmds)
class file_containerlimit_get(_file_container_command):
"""Get container size limit"""
arguments = dict(
in_bytes=FlagArgument('Show result in bytes', ('-b', '--bytes'))
)
@errors.generic.all
@errors.pithos.container
def _run(self):
reply = self.client.get_container_limit(self.container)
if not self['in_bytes']:
for k in reply:
reply[k] = format_size(reply[k])
print_dict(pretty_keys(reply, '-'))
def main(self, container=None):
super(self.__class__, self)._run()
self.container = container
self._run()
@command(pithos_cmds)
class file_containerlimit_set(_file_account_command):
"""Set new storage limit for a container
By default, the limit is set in bytes
Users may specify a different unit, e.g:
/file containerlimit set 2.3GB mycontainer
Valide units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
Valid units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
"""
@errors.generic.all
......
......@@ -286,8 +286,8 @@ class Pithos(livetest.Generic):
you don't have permissions to modify those at account level
"""
newquota = 1000000
self.client.set_account_quota(newquota)
#newquota = 1000000
#self.client.set_account_quota(newquota)
#r = self.client.get_account_info()
#print(unicode(r))
#r = self.client.get_account_quota()
......@@ -396,14 +396,14 @@ class Pithos(livetest.Generic):
r = self.client.container_put()
self.assertEqual(r.status_code, 202)
r = self.client.get_container_quota(self.client.container)
r = self.client.get_container_limit(self.client.container)
cquota = r.values()[0]
newquota = 2 * int(cquota)
r = self.client.container_put(quota=newquota)
self.assertEqual(r.status_code, 202)
r = self.client.get_container_quota(self.client.container)
r = self.client.get_container_limit(self.client.container)
xquota = int(r.values()[0])
self.assertEqual(newquota, xquota)
......@@ -468,15 +468,15 @@ class Pithos(livetest.Generic):
self.assertEqual(r['x-container-meta-m2'], 'v2a')
"""check quota"""
r = self.client.get_container_quota(self.client.container)
r = self.client.get_container_limit(self.client.container)
cquota = r.values()[0]
newquota = 2 * int(cquota)
r = self.client.set_container_quota(newquota)
r = self.client.get_container_quota(self.client.container)
r = self.client.set_container_limit(newquota)
r = self.client.get_container_limit(self.client.container)
xquota = int(r.values()[0])
self.assertEqual(newquota, xquota)
r = self.client.set_container_quota(cquota)
r = self.client.get_container_quota(self.client.container)
r = self.client.set_container_limit(cquota)
r = self.client.get_container_limit(self.client.container)
xquota = r.values()[0]
self.assertEqual(cquota, xquota)
......
......@@ -716,11 +716,13 @@ class PithosClient(PithosRestClient):
"""
self.account_post(update=True, metadata={metakey: ''})
"""
def set_account_quota(self, quota):
"""
""
:param quota: (int)
"""
""
self.account_post(update=True, quota=quota)
"""
def set_account_versioning(self, versioning):
"""
......@@ -774,7 +776,7 @@ class PithosClient(PithosRestClient):
finally:
self.container = cnt_back_up
def get_container_quota(self, container=None):
def get_container_limit(self, container=None):
"""
:param container: (str)
......
......@@ -1277,11 +1277,13 @@ class PithosClient(TestCase):
self.client.set_account_meta(metas)
post.assert_called_once_with(update=True, metadata=metas)
"""
@patch('%s.account_post' % pithos_pkg, return_value=FR())
def test_set_account_quota(self, post):
qu = 1024
self.client.set_account_quota(qu)
post.assert_called_once_with(update=True, quota=qu)
"""
@patch('%s.account_post' % pithos_pkg, return_value=FR())
def test_set_account_versioning(self, post):
......@@ -1314,12 +1316,12 @@ class PithosClient(TestCase):
self.assertEqual(bu_cnt, self.client.container)
@patch('%s.get_container_info' % pithos_pkg, return_value=container_info)
def test_get_container_quota(self, GCI):
def test_get_container_limit(self, GCI):
key = 'x-container-policy-quota'
cont = 'c0n7-417'
bu_cnt = self.client.container
for container in (None, cont):
r = self.client.get_container_quota(container=container)
r = self.client.get_container_limit(container=container)
self.assertEqual(r[key], container_info[key])
self.assertEqual(GCI.mock_calls[-1], call())
self.assertEqual(bu_cnt, self.client.container)
......
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