Adding Auth, Compute and Blockstorage composites
* Composites aggregate the various clients, behaviors and configs for service subpackages into standalone classes for use in tests, data generators, fixtures, etc. * Cleans up import clutter by providing a single import for the entirety of a service's functionality. * Self-authing composites pull the data they need (as defined by their configs) from the access data usng the AuthProvider * Memoized auth method means that a composite will only ever auth once no matter how many times it's instantiated, so logs aren't cluttered with multiple, superfluous auth attempts. Change-Id: I347048f3f5d2f7153181df978f0afa3e65a4f145
This commit is contained in:
70
cloudcafe/blockstorage/composites.py
Normal file
70
cloudcafe/blockstorage/composites.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from cloudcafe.auth.provider import MemoizedAuthServiceComposite
|
||||
from cloudcafe.blockstorage.config import BlockStorageConfig
|
||||
from cloudcafe.blockstorage.volumes_api.common.config import VolumesAPIConfig
|
||||
|
||||
from cloudcafe.blockstorage.volumes_api.v1.config import \
|
||||
VolumesAPIConfig as v1Config
|
||||
from cloudcafe.blockstorage.volumes_api.v1.client import \
|
||||
VolumesClient as v1Client
|
||||
from cloudcafe.blockstorage.volumes_api.v1.behaviors import \
|
||||
VolumesAPI_Behaviors as v1Behaviors
|
||||
|
||||
from cloudcafe.blockstorage.volumes_api.v2.config import \
|
||||
VolumesAPIConfig as v2Config
|
||||
from cloudcafe.blockstorage.volumes_api.v2.client import \
|
||||
VolumesClient as v2Client
|
||||
from cloudcafe.blockstorage.volumes_api.v2.behaviors import \
|
||||
VolumesAPI_Behaviors as v2Behaviors
|
||||
|
||||
|
||||
class _BlockstorageAuthComposite(MemoizedAuthServiceComposite):
|
||||
def __init__(self):
|
||||
self.config = BlockStorageConfig()
|
||||
self.availability_zone = \
|
||||
self.config.availability_zone
|
||||
super(_BlockstorageAuthComposite, self).__init__(
|
||||
self.config.identity_service_name, self.config.region)
|
||||
|
||||
|
||||
class _BaseVolumesComposite(object):
|
||||
_config = None
|
||||
_client = None
|
||||
_behaviors = None
|
||||
|
||||
def __init__(self):
|
||||
self.blockstorage_auth = _BlockstorageAuthComposite()
|
||||
self.config = self._config()
|
||||
self.client = self._client(
|
||||
url=self.blockstorage_auth.public_url,
|
||||
auth_token=self.blockstorage_auth.token_id,
|
||||
serialize_format=self.config.serialize_format,
|
||||
deserialize_format=self.config.deserialize_format)
|
||||
self.behaviors = self._behaviors(self.client)
|
||||
|
||||
|
||||
#For version specific tests
|
||||
class VolumesV1Composite(_BaseVolumesComposite):
|
||||
_config = v1Config
|
||||
_client = v1Client
|
||||
_behaviors = v1Behaviors
|
||||
|
||||
|
||||
class VolumesV2Composite(_BaseVolumesComposite):
|
||||
_config = v2Config
|
||||
_client = v2Client
|
||||
_behaviors = v2Behaviors
|
||||
|
||||
|
||||
#For version agnostic tests
|
||||
class VolumesAutoComposite(object):
|
||||
def __new__(cls):
|
||||
config = VolumesAPIConfig()
|
||||
if config.version_under_test == "1":
|
||||
return VolumesV1Composite()
|
||||
if config.version_under_test == "2":
|
||||
return VolumesV2Composite()
|
||||
else:
|
||||
raise Exception(
|
||||
"VolumesAutoComposite cannot be used unless the "
|
||||
"'version_under_test' attribute of the VolumesAPIConfig"
|
||||
" is set to either '1' or '2'")
|
||||
Reference in New Issue
Block a user