Commit 46786557 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Merge branch 'feature-pithos-astakosclient-instances' into develop

parents ca035503 2195b072
......@@ -56,7 +56,7 @@ from pithos.api.util import (
get_content_range, socket_read_iterator, SaveToBackendHandler,
object_data_response, put_object_block, hashmap_md5, simple_list_response,
api_method, is_uuid, retrieve_uuid, retrieve_uuids,
retrieve_displaynames, get_pithos_usage, Checksum, NoChecksum
retrieve_displaynames, Checksum, NoChecksum
)
from pithos.api.settings import (UPDATE_MD5, TRANSLATE_UUIDS,
......@@ -240,14 +240,12 @@ def account_list(request):
return response
account_meta = []
usage = get_pithos_usage(request.x_auth_token)
for x in accounts:
if x == request.user_uniq:
continue
try:
meta = request.backend.get_account_meta(
request.user_uniq, x, 'pithos', include_user_defined=False,
external_quota=usage)
request.user_uniq, x, 'pithos', include_user_defined=False)
groups = request.backend.get_account_groups(request.user_uniq, x)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
......@@ -284,11 +282,9 @@ def account_meta(request, v_account):
# badRequest (400)
until = get_int_parameter(request.GET.get('until'))
usage = get_pithos_usage(request.x_auth_token)
try:
meta = request.backend.get_account_meta(
request.user_uniq, v_account, 'pithos', until,
external_quota=usage)
request.user_uniq, v_account, 'pithos', until)
groups = request.backend.get_account_groups(
request.user_uniq, v_account)
......@@ -297,7 +293,7 @@ def account_meta(request, v_account):
groups[k] = retrieve_displaynames(
getattr(request, 'token', None), groups[k])
policy = request.backend.get_account_policy(
request.user_uniq, v_account, external_quota=usage)
request.user_uniq, v_account)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
......@@ -365,15 +361,13 @@ def container_list(request, v_account):
# badRequest (400)
until = get_int_parameter(request.GET.get('until'))
usage = get_pithos_usage(request.x_auth_token)
try:
meta = request.backend.get_account_meta(
request.user_uniq, v_account, 'pithos', until,
external_quota=usage)
request.user_uniq, v_account, 'pithos', until)
groups = request.backend.get_account_groups(
request.user_uniq, v_account)
policy = request.backend.get_account_policy(
request.user_uniq, v_account, external_quota=usage)
request.user_uniq, v_account)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
......
......@@ -239,6 +239,16 @@ class PithosAPITest(TestCase):
new_callable=PropertyMock)
mock_api_oauth2_auth.return_value = '/astakos/oauth2/'
mock_service_get_quotas = self.create_patch(
'astakosclient.AstakosClient.service_get_quotas')
mock_service_get_quotas.return_value = {
self.user: {
"system": {
"pithos.diskspace": {
"usage": 0,
"limit": 1073741824, # 1GB
"pending": 0}}}}
def tearDown(self):
#delete additionally created metadata
meta = self.get_account_meta()
......
......@@ -1068,17 +1068,6 @@ def update_response_headers(request, response):
response[quote(k)] = quote(v, safe='/=,:@; ')
def get_pithos_usage(token):
"""Get Pithos Usage from astakos."""
astakos = AstakosClient(token, ASTAKOS_AUTH_URL,
retry=2, use_pool=True,
logger=logger)
quotas = astakos.get_quotas()['system']
pithos_resources = [r['name'] for r in resources]
map(quotas.pop, filter(lambda k: k not in pithos_resources, quotas.keys()))
return quotas.popitem()[-1] # assume only one resource
def api_method(http_method=None, token_required=True, user_required=True,
logger=None, format_allowed=False, serializations=None,
strict_serlization=False, lock_container_path=False):
......
......@@ -120,6 +120,7 @@ inf = float('inf')
ULTIMATE_ANSWER = 42
DEFAULT_SOURCE = 'system'
DEFAULT_DISKSPACE_RESOURCE = 'pithos.diskspace'
logger = logging.getLogger(__name__)
......@@ -339,11 +340,17 @@ class ModularBackend(BaseBackend):
start, limit = self._list_limits(allowed, marker, limit)
return allowed[start:start + limit]
def _get_account_quotas(self, account):
"""Get account usage from astakos."""
quotas = self.astakosclient.service_get_quotas(account)[account]
return quotas.get(DEFAULT_SOURCE, {}).get(DEFAULT_DISKSPACE_RESOURCE,
{})
@debug_method
@backend_method
def get_account_meta(
self, user, account, domain, until=None, include_user_defined=True,
external_quota=None):
def get_account_meta(self, user, account, domain, until=None,
include_user_defined=True):
"""Return a dictionary with the account metadata for the domain."""
path, node = self._lookup_account(account, user == account)
......@@ -377,7 +384,7 @@ class ModularBackend(BaseBackend):
meta.update({'until_timestamp': tstamp})
meta.update({'name': account, 'count': count, 'bytes': bytes})
if self.using_external_quotaholder:
external_quota = external_quota or {}
external_quota = self._get_account_quotas(account)
meta['bytes'] = external_quota.get('usage', 0)
meta.update({'modified': modified})
return meta
......@@ -424,7 +431,7 @@ class ModularBackend(BaseBackend):
@debug_method
@backend_method
def get_account_policy(self, user, account, external_quota=None):
def get_account_policy(self, user, account):
"""Return a dictionary with the account policy."""
if user != account:
......@@ -434,7 +441,7 @@ class ModularBackend(BaseBackend):
path, node = self._lookup_account(account, True)
policy = self._get_policy(node, is_account_policy=True)
if self.using_external_quotaholder:
external_quota = external_quota or {}
external_quota = self._get_account_quotas(account)
policy['quota'] = external_quota.get('limit', 0)
return policy
......
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