Commit d6634886 authored by Georgios D. Tsoukalas's avatar Georgios D. Tsoukalas
Browse files

pithos-backend: disable AstakosClient if no URL given

If the backend is initialized with astakos_url=None,
or AstakosClient cannot be imported,
a fake AstakosClient is instantiated which will raise
an AssertionError on any attempt to access it.

Read-only uses of pithos backend, as in pithcat,
should never have to access the astakosclient initialized.
The fake client is there to make an access raise an informative
error message instead of 'NoneType object has no attribute xxx'.
parent 512f8b2e
......@@ -37,13 +37,28 @@ import logging
import hashlib
import binascii
from astakosclient import AstakosClient
try:
from astakosclient import AstakosClient
except ImportError:
AstakosClient = None
from base import (DEFAULT_ACCOUNT_QUOTA, DEFAULT_CONTAINER_QUOTA,
DEFAULT_CONTAINER_VERSIONING, NotAllowedError, QuotaError,
BaseBackend, AccountExists, ContainerExists, AccountNotEmpty,
ContainerNotEmpty, ItemNotExists, VersionNotExists)
class DisabledAstakosClient(object):
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
def __getattr__(self, name):
m = ("AstakosClient has been disabled, "
"yet an attempt to access it was made")
raise AssertionError(m)
# Stripped-down version of the HashMap class found in tools.
class HashMap(list):
......@@ -237,10 +252,17 @@ class ModularBackend(BaseBackend):
self.astakos_url = astakos_url
self.service_token = service_token
self.astakosclient = AstakosClient(
astakos_url,
use_pool=True,
pool_size=astakosclient_poolsize)
if not astakos_url or not AstakosClient:
self.astakosclient = DisabledAstakosClient(
astakos_url,
use_pool=True,
pool_size=astakosclient_poolsize)
else:
self.astakosclient = AstakosClient(
astakos_url,
use_pool=True,
pool_size=astakosclient_poolsize)
self.serials = []
self.messages = []
......@@ -251,7 +273,7 @@ class ModularBackend(BaseBackend):
@property
def using_external_quotaholder(self):
return True
return not isinstance(self.astakosclient, DisabledAstakosClient)
@backend_method
def list_accounts(self, user, marker=None, limit=10000):
......
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