Merge "Process config options via os-client-config"
This commit is contained in:
commit
d18f7d6988
@ -3,7 +3,7 @@ pbr>=0.11,<2.0
|
|||||||
bunch
|
bunch
|
||||||
decorator
|
decorator
|
||||||
jsonpatch
|
jsonpatch
|
||||||
os-client-config>=1.3.0
|
os-client-config>=1.6.0
|
||||||
six
|
six
|
||||||
|
|
||||||
python-novaclient>=2.21.0
|
python-novaclient>=2.21.0
|
||||||
|
@ -126,38 +126,28 @@ def openstack_clouds(config=None, debug=False):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def openstack_cloud(debug=False, **kwargs):
|
def openstack_cloud(config=None, **kwargs):
|
||||||
config = kwargs.get('config')
|
if not config:
|
||||||
if config is None:
|
|
||||||
config = os_client_config.OpenStackConfig()
|
config = os_client_config.OpenStackConfig()
|
||||||
cloud_config = config.get_one_cloud(**kwargs)
|
cloud_config = config.get_one_cloud(**kwargs)
|
||||||
return OpenStackCloud(
|
return OpenStackCloud(
|
||||||
cloud=cloud_config.name,
|
|
||||||
cache_interval=config.get_cache_max_age(),
|
cache_interval=config.get_cache_max_age(),
|
||||||
cache_class=config.get_cache_class(),
|
cache_class=config.get_cache_class(),
|
||||||
cache_arguments=config.get_cache_arguments(),
|
cache_arguments=config.get_cache_arguments(),
|
||||||
cloud_config=cloud_config,
|
cloud_config=cloud_config)
|
||||||
debug=debug, **cloud_config.config)
|
|
||||||
|
|
||||||
|
|
||||||
def operator_cloud(debug=False, **kwargs):
|
def operator_cloud(config=None, **kwargs):
|
||||||
|
if 'interface' not in kwargs:
|
||||||
|
kwargs['interface'] = 'admin'
|
||||||
|
if not config:
|
||||||
config = os_client_config.OpenStackConfig()
|
config = os_client_config.OpenStackConfig()
|
||||||
cloud_config = config.get_one_cloud(**kwargs)
|
cloud_config = config.get_one_cloud(**kwargs)
|
||||||
return OperatorCloud(
|
return OperatorCloud(
|
||||||
cloud_config.name, debug=debug,
|
|
||||||
cache_interval=config.get_cache_max_age(),
|
cache_interval=config.get_cache_max_age(),
|
||||||
cache_class=config.get_cache_class(),
|
cache_class=config.get_cache_class(),
|
||||||
cache_arguments=config.get_cache_arguments(),
|
cache_arguments=config.get_cache_arguments(),
|
||||||
cloud_config=cloud_config,
|
cloud_config=cloud_config)
|
||||||
**cloud_config.config)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_service_values(kwargs, service_key):
|
|
||||||
# get defauts returns a copy of the defaults dict
|
|
||||||
values = os_client_config.defaults.get_defaults()
|
|
||||||
values.update(kwargs)
|
|
||||||
return {k[:-(len(service_key) + 1)]: str(values[k])
|
|
||||||
for k in values.keys() if k.endswith(service_key)}
|
|
||||||
|
|
||||||
|
|
||||||
def _cache_on_arguments(*cache_on_args, **cache_on_kwargs):
|
def _cache_on_arguments(*cache_on_args, **cache_on_kwargs):
|
||||||
@ -204,32 +194,6 @@ class OpenStackCloud(object):
|
|||||||
and that Floating IP will be actualized either via neutron or via nova
|
and that Floating IP will be actualized either via neutron or via nova
|
||||||
depending on how this particular cloud has decided to arrange itself.
|
depending on how this particular cloud has decided to arrange itself.
|
||||||
|
|
||||||
:param string name: The name of the cloud
|
|
||||||
:param dict auth: Dictionary containing authentication information.
|
|
||||||
Depending on the value of auth_type, the contents
|
|
||||||
of this dict can vary wildly.
|
|
||||||
:param string region_name: The region of the cloud that all operations
|
|
||||||
should be performed against.
|
|
||||||
(optional, default '')
|
|
||||||
:param string auth_type: The name of the keystone auth_type to be used
|
|
||||||
:param string endpoint_type: The type of endpoint to get for services
|
|
||||||
from the service catalog. Valid types are
|
|
||||||
`public` ,`internal` or `admin`. (optional,
|
|
||||||
defaults to `public`)
|
|
||||||
:param bool private: Whether to return or use private IPs by default for
|
|
||||||
servers. (optional, defaults to False)
|
|
||||||
:param float api_timeout: A timeout to pass to REST client constructors
|
|
||||||
indicating network-level timeouts. (optional)
|
|
||||||
:param bool verify: The verification arguments to pass to requests. True
|
|
||||||
tells requests to verify SSL requests, False to not
|
|
||||||
verify. (optional, defaults to True)
|
|
||||||
:param string cacert: A path to a CA Cert bundle that can be used as part
|
|
||||||
of verifying SSL requests. If this is set, verify
|
|
||||||
is set to True. (optional)
|
|
||||||
:param string cert: A path to a client certificate to pass to requests.
|
|
||||||
(optional)
|
|
||||||
:param string key: A path to a client key to pass to requests. (optional)
|
|
||||||
:param bool debug: Deprecated and unused parameter.
|
|
||||||
:param int cache_interval: How long to cache items fetched from the cloud.
|
:param int cache_interval: How long to cache items fetched from the cloud.
|
||||||
Value will be passed to dogpile.cache. None
|
Value will be passed to dogpile.cache. None
|
||||||
means do not cache at all.
|
means do not cache at all.
|
||||||
@ -242,64 +206,41 @@ class OpenStackCloud(object):
|
|||||||
OpenStack API tasks. Unless you're doing
|
OpenStack API tasks. Unless you're doing
|
||||||
rate limiting client side, you almost
|
rate limiting client side, you almost
|
||||||
certainly don't need this. (optional)
|
certainly don't need this. (optional)
|
||||||
:param bool image_api_use_tasks: Whether or not this cloud needs to
|
|
||||||
use the glance task-create interface for
|
|
||||||
image upload activities instead of direct
|
|
||||||
calls. (optional, defaults to False)
|
|
||||||
:param CloudConfig cloud_config: Cloud config object from os-client-config
|
:param CloudConfig cloud_config: Cloud config object from os-client-config
|
||||||
In the future, this will be the only way
|
In the future, this will be the only way
|
||||||
to pass in cloud configuration, but is
|
to pass in cloud configuration, but is
|
||||||
being phased in currently.
|
being phased in currently.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, cloud, auth,
|
def __init__(
|
||||||
region_name='',
|
self,
|
||||||
auth_type='password',
|
cloud_config=None,
|
||||||
endpoint_type='public',
|
cache_interval=None,
|
||||||
private=False,
|
|
||||||
verify=True, cacert=None, cert=None, key=None,
|
|
||||||
api_timeout=None,
|
|
||||||
debug=False, cache_interval=None,
|
|
||||||
cache_class='dogpile.cache.null',
|
cache_class='dogpile.cache.null',
|
||||||
cache_arguments=None,
|
cache_arguments=None,
|
||||||
manager=None,
|
manager=None, **kwargs):
|
||||||
image_api_use_tasks=False,
|
|
||||||
cloud_config=None,
|
|
||||||
**kwargs):
|
|
||||||
|
|
||||||
self.log = logging.getLogger('shade')
|
self.log = logging.getLogger('shade')
|
||||||
|
if not cloud_config:
|
||||||
if cloud_config is None:
|
|
||||||
config = os_client_config.OpenStackConfig()
|
config = os_client_config.OpenStackConfig()
|
||||||
ssl_args = dict(
|
cloud_config = config.get_one_cloud(**kwargs)
|
||||||
verify=verify, cacert=cacert, cert=cert, key=key,
|
|
||||||
)
|
self.name = cloud_config.name
|
||||||
if cloud in config.get_cloud_names():
|
self.auth = cloud_config.get_auth_args()
|
||||||
cloud_config = config.get_one_cloud(cloud, **ssl_args)
|
self.region_name = cloud_config.region_name
|
||||||
else:
|
self.auth_type = cloud_config.config['auth_type']
|
||||||
cloud_config = config.get_one_cloud(**ssl_args)
|
self.default_interface = cloud_config.get_interface()
|
||||||
self._cloud_config = cloud_config
|
self.private = cloud_config.config.get('private', False)
|
||||||
self.name = cloud
|
self.api_timeout = cloud_config.config['api_timeout']
|
||||||
self.auth = auth
|
self.image_api_use_tasks = cloud_config.config['image_api_use_tasks']
|
||||||
self.region_name = region_name
|
self.secgroup_source = cloud_config.config['secgroup_source']
|
||||||
self.auth_type = auth_type
|
|
||||||
self.endpoint_type = endpoint_type
|
|
||||||
self.private = private
|
|
||||||
self.api_timeout = api_timeout
|
|
||||||
if manager is not None:
|
if manager is not None:
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
else:
|
else:
|
||||||
self.manager = task_manager.TaskManager(
|
self.manager = task_manager.TaskManager(
|
||||||
name=self.name, client=self)
|
name=self.name, client=self)
|
||||||
|
|
||||||
self.service_types = _get_service_values(kwargs, 'service_type')
|
|
||||||
self.service_names = _get_service_values(kwargs, 'service_name')
|
|
||||||
self.endpoints = _get_service_values(kwargs, 'endpoint')
|
|
||||||
self.api_versions = _get_service_values(kwargs, 'api_version')
|
|
||||||
self.image_api_use_tasks = image_api_use_tasks
|
|
||||||
|
|
||||||
self.secgroup_source = kwargs.get('secgroup_source', None)
|
|
||||||
|
|
||||||
(self.verify, self.cert) = cloud_config.get_requests_verify_args()
|
(self.verify, self.cert) = cloud_config.get_requests_verify_args()
|
||||||
|
|
||||||
self._cache = cache.make_region(
|
self._cache = cache.make_region(
|
||||||
@ -324,6 +265,8 @@ class OpenStackCloud(object):
|
|||||||
self._swift_service = None
|
self._swift_service = None
|
||||||
self._trove_client = None
|
self._trove_client = None
|
||||||
|
|
||||||
|
self.cloud_config = cloud_config
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def _neutron_exceptions(self, error_message):
|
def _neutron_exceptions(self, error_message):
|
||||||
try:
|
try:
|
||||||
@ -365,12 +308,6 @@ class OpenStackCloud(object):
|
|||||||
return ans
|
return ans
|
||||||
return generate_key
|
return generate_key
|
||||||
|
|
||||||
def get_service_type(self, service):
|
|
||||||
return self.service_types.get(service, service)
|
|
||||||
|
|
||||||
def get_service_name(self, service):
|
|
||||||
return self.service_names.get(service, None)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nova_client(self):
|
def nova_client(self):
|
||||||
if self._nova_client is None:
|
if self._nova_client is None:
|
||||||
@ -380,9 +317,9 @@ class OpenStackCloud(object):
|
|||||||
# trigger exception on lack of compute. (what?)
|
# trigger exception on lack of compute. (what?)
|
||||||
self.get_session_endpoint('compute')
|
self.get_session_endpoint('compute')
|
||||||
self._nova_client = nova_client.Client(
|
self._nova_client = nova_client.Client(
|
||||||
self.api_versions['compute'],
|
self.cloud_config.get_api_version('compute'),
|
||||||
session=self.keystone_session,
|
session=self.keystone_session,
|
||||||
service_name=self.get_service_name('compute'),
|
service_name=self.cloud_config.get_service_name('compute'),
|
||||||
region_name=self.region_name,
|
region_name=self.region_name,
|
||||||
timeout=self.api_timeout)
|
timeout=self.api_timeout)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -409,13 +346,13 @@ class OpenStackCloud(object):
|
|||||||
plugin=self.auth_type, error=str(e)))
|
plugin=self.auth_type, error=str(e)))
|
||||||
|
|
||||||
def _get_identity_client_class(self):
|
def _get_identity_client_class(self):
|
||||||
if self.api_versions['identity'] == '3':
|
if self.cloud_config.get_api_version('identity') == '3':
|
||||||
return k3_client.Client
|
return k3_client.Client
|
||||||
elif self.api_versions['identity'] in ('2', '2.0'):
|
elif self.cloud_config.get_api_version('identity') in ('2', '2.0'):
|
||||||
return k2_client.Client
|
return k2_client.Client
|
||||||
raise OpenStackCloudException(
|
raise OpenStackCloudException(
|
||||||
"Unknown identity API version: {version}".format(
|
"Unknown identity API version: {version}".format(
|
||||||
version=self.api_versions['identity']))
|
version=self.cloud_config.get_api_version('identity')))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def keystone_session(self):
|
def keystone_session(self):
|
||||||
@ -488,7 +425,7 @@ class OpenStackCloud(object):
|
|||||||
project_dict = dict()
|
project_dict = dict()
|
||||||
if name_or_id:
|
if name_or_id:
|
||||||
project_id = self._get_project(name_or_id).id
|
project_id = self._get_project(name_or_id).id
|
||||||
if self.api_versions['identity'] == '3':
|
if self.cloud_config.get_api_version('identity') == '3':
|
||||||
project_dict['default_project'] = project_id
|
project_dict['default_project'] = project_id
|
||||||
else:
|
else:
|
||||||
project_dict['tenant_id'] = project_id
|
project_dict['tenant_id'] = project_id
|
||||||
@ -501,7 +438,7 @@ class OpenStackCloud(object):
|
|||||||
# not. However, keystone v2 does not allow user creation by non-admin
|
# not. However, keystone v2 does not allow user creation by non-admin
|
||||||
# users, so we can throw an error to the user that does not need to
|
# users, so we can throw an error to the user that does not need to
|
||||||
# mention api versions
|
# mention api versions
|
||||||
if self.api_versions['identity'] == '3':
|
if self.cloud_config.get_api_version('identity') == '3':
|
||||||
if not domain_id:
|
if not domain_id:
|
||||||
raise OpenStackCloudException(
|
raise OpenStackCloudException(
|
||||||
"User creation requires an explicit domain_id argument.")
|
"User creation requires an explicit domain_id argument.")
|
||||||
@ -667,7 +604,8 @@ class OpenStackCloud(object):
|
|||||||
kwargs['timeout'] = self.api_timeout
|
kwargs['timeout'] = self.api_timeout
|
||||||
try:
|
try:
|
||||||
self._glance_client = glanceclient.Client(
|
self._glance_client = glanceclient.Client(
|
||||||
self.api_versions['image'], endpoint, token=token,
|
self.cloud_config.get_api_version('image'),
|
||||||
|
endpoint, token=token,
|
||||||
session=self.keystone_session, insecure=not self.verify,
|
session=self.keystone_session, insecure=not self.verify,
|
||||||
cacert=self.cert, **kwargs)
|
cacert=self.cert, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -689,7 +627,7 @@ class OpenStackCloud(object):
|
|||||||
self._swift_client = swift_client.Connection(
|
self._swift_client = swift_client.Connection(
|
||||||
preauthurl=endpoint,
|
preauthurl=endpoint,
|
||||||
preauthtoken=token,
|
preauthtoken=token,
|
||||||
auth_version=self.api_versions['identity'],
|
auth_version=self.cloud_config.get_api_version('identity'),
|
||||||
os_options=dict(
|
os_options=dict(
|
||||||
auth_token=token,
|
auth_token=token,
|
||||||
object_storage_url=endpoint,
|
object_storage_url=endpoint,
|
||||||
@ -751,10 +689,10 @@ class OpenStackCloud(object):
|
|||||||
# Make the connection - can't use keystone session until there
|
# Make the connection - can't use keystone session until there
|
||||||
# is one
|
# is one
|
||||||
self._trove_client = trove_client.Client(
|
self._trove_client = trove_client.Client(
|
||||||
self.api_versions['database'],
|
self.cloud_config.get_api_version('database'),
|
||||||
session=self.keystone_session,
|
session=self.keystone_session,
|
||||||
region_name=self.region_name,
|
region_name=self.region_name,
|
||||||
service_type=self.get_service_type('database'),
|
service_type=self.cloud_config.get_service_type('database'),
|
||||||
timeout=self.api_timeout,
|
timeout=self.api_timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -781,7 +719,7 @@ class OpenStackCloud(object):
|
|||||||
def designate_client(self):
|
def designate_client(self):
|
||||||
if self._designate_client is None:
|
if self._designate_client is None:
|
||||||
# get dns service type if defined in cloud config
|
# get dns service type if defined in cloud config
|
||||||
dns_service_type = self.get_service_type('dns')
|
dns_service_type = self.cloud_config.get_service_type('dns')
|
||||||
# trigger exception on lack of designate
|
# trigger exception on lack of designate
|
||||||
self.get_session_endpoint(dns_service_type)
|
self.get_session_endpoint(dns_service_type)
|
||||||
|
|
||||||
@ -830,8 +768,9 @@ class OpenStackCloud(object):
|
|||||||
ram=ram, include=include))
|
ram=ram, include=include))
|
||||||
|
|
||||||
def get_session_endpoint(self, service_key):
|
def get_session_endpoint(self, service_key):
|
||||||
if service_key in self.endpoints:
|
override_endpoint = self.cloud_config.get_endpoint(service_key)
|
||||||
return self.endpoints[service_key]
|
if override_endpoint:
|
||||||
|
return override_endpoint
|
||||||
try:
|
try:
|
||||||
# keystone is a special case in keystone, because what?
|
# keystone is a special case in keystone, because what?
|
||||||
if service_key == 'identity':
|
if service_key == 'identity':
|
||||||
@ -839,9 +778,11 @@ class OpenStackCloud(object):
|
|||||||
interface=ksc_auth.AUTH_INTERFACE)
|
interface=ksc_auth.AUTH_INTERFACE)
|
||||||
else:
|
else:
|
||||||
endpoint = self.keystone_session.get_endpoint(
|
endpoint = self.keystone_session.get_endpoint(
|
||||||
service_type=self.get_service_type(service_key),
|
service_type=self.cloud_config.get_service_type(
|
||||||
service_name=self.get_service_name(service_key),
|
service_key),
|
||||||
interface=self.endpoint_type,
|
service_name=self.cloud_config.get_service_name(
|
||||||
|
service_key),
|
||||||
|
interface=self.cloud_config.get_interface(service_key),
|
||||||
region_name=self.region_name)
|
region_name=self.region_name)
|
||||||
except keystone_exceptions.EndpointNotFound as e:
|
except keystone_exceptions.EndpointNotFound as e:
|
||||||
self.log.debug(
|
self.log.debug(
|
||||||
@ -1418,7 +1359,7 @@ class OpenStackCloud(object):
|
|||||||
try:
|
try:
|
||||||
# Note that in v1, the param name is image, but in v2,
|
# Note that in v1, the param name is image, but in v2,
|
||||||
# it's image_id
|
# it's image_id
|
||||||
glance_api_version = self.api_versions['image']
|
glance_api_version = self.cloud_config.get_api_version('image')
|
||||||
if glance_api_version == '2':
|
if glance_api_version == '2':
|
||||||
self.manager.submitTask(
|
self.manager.submitTask(
|
||||||
_tasks.ImageDelete(image_id=image.id))
|
_tasks.ImageDelete(image_id=image.id))
|
||||||
@ -1456,7 +1397,7 @@ class OpenStackCloud(object):
|
|||||||
kwargs[IMAGE_SHA256_KEY] = sha256
|
kwargs[IMAGE_SHA256_KEY] = sha256
|
||||||
|
|
||||||
if disable_vendor_agent:
|
if disable_vendor_agent:
|
||||||
kwargs.update(self._cloud_config.config['disable_vendor_agent'])
|
kwargs.update(self.cloud_config.config['disable_vendor_agent'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# This makes me want to die inside
|
# This makes me want to die inside
|
||||||
@ -1506,7 +1447,7 @@ class OpenStackCloud(object):
|
|||||||
def _upload_image_put(self, name, filename, **image_kwargs):
|
def _upload_image_put(self, name, filename, **image_kwargs):
|
||||||
image_data = open(filename, 'rb')
|
image_data = open(filename, 'rb')
|
||||||
# Because reasons and crying bunnies
|
# Because reasons and crying bunnies
|
||||||
if self.api_versions['image'] == '2':
|
if self.cloud_config.get_api_version('image') == '2':
|
||||||
image = self._upload_image_put_v2(name, image_data, **image_kwargs)
|
image = self._upload_image_put_v2(name, image_data, **image_kwargs)
|
||||||
else:
|
else:
|
||||||
image = self._upload_image_put_v1(name, image_data, **image_kwargs)
|
image = self._upload_image_put_v1(name, image_data, **image_kwargs)
|
||||||
@ -1587,7 +1528,7 @@ class OpenStackCloud(object):
|
|||||||
img_props[k] = v
|
img_props[k] = v
|
||||||
|
|
||||||
# This makes me want to die inside
|
# This makes me want to die inside
|
||||||
if self.api_versions['image'] == '2':
|
if self.cloud_config.get_api_version('image') == '2':
|
||||||
return self._update_image_properties_v2(image, img_props)
|
return self._update_image_properties_v2(image, img_props)
|
||||||
else:
|
else:
|
||||||
return self._update_image_properties_v1(image, img_props)
|
return self._update_image_properties_v1(image, img_props)
|
||||||
@ -3392,20 +3333,8 @@ class OperatorCloud(OpenStackCloud):
|
|||||||
of which OpenStack service those operations are for.
|
of which OpenStack service those operations are for.
|
||||||
|
|
||||||
See the :class:`OpenStackCloud` class for a description of most options.
|
See the :class:`OpenStackCloud` class for a description of most options.
|
||||||
`OperatorCloud` overrides the default value of `endpoint_type` from
|
|
||||||
`public` to `admin`.
|
|
||||||
|
|
||||||
:param string endpoint_type: The type of endpoint to get for services
|
|
||||||
from the service catalog. Valid types are
|
|
||||||
`public` ,`internal` or `admin`. (optional,
|
|
||||||
defaults to `admin`)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(OperatorCloud, self).__init__(*args, **kwargs)
|
|
||||||
if 'endpoint_type' not in kwargs:
|
|
||||||
self.endpoint_type = 'admin'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def auth_token(self):
|
def auth_token(self):
|
||||||
if self.auth_type in (None, "None", ''):
|
if self.auth_type in (None, "None", ''):
|
||||||
@ -3446,7 +3375,8 @@ class OperatorCloud(OpenStackCloud):
|
|||||||
endpoint = self.get_session_endpoint(service_key='baremetal')
|
endpoint = self.get_session_endpoint(service_key='baremetal')
|
||||||
try:
|
try:
|
||||||
self._ironic_client = ironic_client.Client(
|
self._ironic_client = ironic_client.Client(
|
||||||
self.api_versions['baremetal'], endpoint, token=token,
|
self.cloud_config.get_api_version('baremetal'),
|
||||||
|
endpoint, token=token,
|
||||||
timeout=self.api_timeout,
|
timeout=self.api_timeout,
|
||||||
os_ironic_api_version=ironic_api_microversion)
|
os_ironic_api_version=ironic_api_microversion)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -261,9 +261,10 @@ class TestMemoryCache(base.TestCase):
|
|||||||
self.cloud.create_image(
|
self.cloud.create_image(
|
||||||
name, imagefile.name, container=container, wait=True)
|
name, imagefile.name, container=container, wait=True)
|
||||||
|
|
||||||
|
@mock.patch.object(occ.cloud_config.CloudConfig, 'get_api_version')
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'glance_client')
|
@mock.patch.object(shade.OpenStackCloud, 'glance_client')
|
||||||
def test_create_image_put_v1(self, glance_mock):
|
def test_create_image_put_v1(self, glance_mock, mock_api_version):
|
||||||
self.cloud.api_versions['image'] = '1'
|
mock_api_version.return_value = '1'
|
||||||
glance_mock.images.list.return_value = []
|
glance_mock.images.list.return_value = []
|
||||||
self.assertEqual([], self.cloud.list_images())
|
self.assertEqual([], self.cloud.list_images())
|
||||||
|
|
||||||
@ -280,9 +281,10 @@ class TestMemoryCache(base.TestCase):
|
|||||||
fake_image_dict = meta.obj_to_dict(fake_image)
|
fake_image_dict = meta.obj_to_dict(fake_image)
|
||||||
self.assertEqual([fake_image_dict], self.cloud.list_images())
|
self.assertEqual([fake_image_dict], self.cloud.list_images())
|
||||||
|
|
||||||
|
@mock.patch.object(occ.cloud_config.CloudConfig, 'get_api_version')
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'glance_client')
|
@mock.patch.object(shade.OpenStackCloud, 'glance_client')
|
||||||
def test_create_image_put_v2(self, glance_mock):
|
def test_create_image_put_v2(self, glance_mock, mock_api_version):
|
||||||
self.cloud.api_versions['image'] = '2'
|
mock_api_version.return_value = '2'
|
||||||
self.cloud.image_api_use_tasks = False
|
self.cloud.image_api_use_tasks = False
|
||||||
|
|
||||||
glance_mock.images.list.return_value = []
|
glance_mock.images.list.return_value = []
|
||||||
@ -301,6 +303,7 @@ class TestMemoryCache(base.TestCase):
|
|||||||
fake_image_dict = meta.obj_to_dict(fake_image)
|
fake_image_dict = meta.obj_to_dict(fake_image)
|
||||||
self.assertEqual([fake_image_dict], self.cloud.list_images())
|
self.assertEqual([fake_image_dict], self.cloud.list_images())
|
||||||
|
|
||||||
|
@mock.patch.object(occ.cloud_config.CloudConfig, 'get_api_version')
|
||||||
@mock.patch.object(shade.OpenStackCloud, '_get_file_hashes')
|
@mock.patch.object(shade.OpenStackCloud, '_get_file_hashes')
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'glance_client')
|
@mock.patch.object(shade.OpenStackCloud, 'glance_client')
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'swift_client')
|
@mock.patch.object(shade.OpenStackCloud, 'swift_client')
|
||||||
@ -309,8 +312,9 @@ class TestMemoryCache(base.TestCase):
|
|||||||
swift_service_mock,
|
swift_service_mock,
|
||||||
swift_mock,
|
swift_mock,
|
||||||
glance_mock,
|
glance_mock,
|
||||||
get_file_hashes):
|
get_file_hashes,
|
||||||
self.cloud.api_versions['image'] = '2'
|
mock_api_version):
|
||||||
|
mock_api_version.return_value = '2'
|
||||||
self.cloud.image_api_use_tasks = True
|
self.cloud.image_api_use_tasks = True
|
||||||
|
|
||||||
class Container(object):
|
class Container(object):
|
||||||
|
@ -20,6 +20,7 @@ Tests for the `create_server` command.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mock import patch, Mock
|
from mock import patch, Mock
|
||||||
|
import os_client_config
|
||||||
from shade import meta
|
from shade import meta
|
||||||
from shade import OpenStackCloud
|
from shade import OpenStackCloud
|
||||||
from shade.exc import (OpenStackCloudException, OpenStackCloudTimeout)
|
from shade.exc import (OpenStackCloudException, OpenStackCloudTimeout)
|
||||||
@ -30,7 +31,8 @@ class TestCreateServer(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestCreateServer, self).setUp()
|
super(TestCreateServer, self).setUp()
|
||||||
self.client = OpenStackCloud("cloud", {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.client = OpenStackCloud(cloud_config=config.get_one_cloud())
|
||||||
|
|
||||||
def test_create_server_with_create_exception(self):
|
def test_create_server_with_create_exception(self):
|
||||||
"""
|
"""
|
||||||
|
@ -21,6 +21,7 @@ Tests for the `delete_server` command.
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
from novaclient import exceptions as nova_exc
|
from novaclient import exceptions as nova_exc
|
||||||
|
import os_client_config
|
||||||
|
|
||||||
from shade import OpenStackCloud
|
from shade import OpenStackCloud
|
||||||
from shade import exc as shade_exc
|
from shade import exc as shade_exc
|
||||||
@ -40,7 +41,8 @@ class TestDeleteServer(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestDeleteServer, self).setUp()
|
super(TestDeleteServer, self).setUp()
|
||||||
self.cloud = OpenStackCloud("cloud", {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.cloud = OpenStackCloud(cloud_config=config.get_one_cloud())
|
||||||
|
|
||||||
@mock.patch('shade.OpenStackCloud.nova_client')
|
@mock.patch('shade.OpenStackCloud.nova_client')
|
||||||
def test_delete_server(self, nova_mock):
|
def test_delete_server(self, nova_mock):
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import os_client_config as occ
|
||||||
|
|
||||||
import bunch
|
import bunch
|
||||||
|
|
||||||
@ -27,11 +28,11 @@ class TestDomainParams(base.TestCase):
|
|||||||
super(TestDomainParams, self).setUp()
|
super(TestDomainParams, self).setUp()
|
||||||
self.cloud = shade.openstack_cloud()
|
self.cloud = shade.openstack_cloud()
|
||||||
|
|
||||||
|
@mock.patch.object(occ.cloud_config.CloudConfig, 'get_api_version')
|
||||||
@mock.patch.object(shade.OpenStackCloud, '_get_project')
|
@mock.patch.object(shade.OpenStackCloud, '_get_project')
|
||||||
def test_identity_params_v3(self, mock_get_project):
|
def test_identity_params_v3(self, mock_get_project, mock_api_version):
|
||||||
mock_get_project.return_value = bunch.Bunch(id=1234)
|
mock_get_project.return_value = bunch.Bunch(id=1234)
|
||||||
|
mock_api_version.return_value = '3'
|
||||||
self.cloud.api_versions = dict(identity='3')
|
|
||||||
|
|
||||||
ret = self.cloud._get_identity_params(domain_id='5678', project='bar')
|
ret = self.cloud._get_identity_params(domain_id='5678', project='bar')
|
||||||
self.assertIn('default_project', ret)
|
self.assertIn('default_project', ret)
|
||||||
@ -39,22 +40,23 @@ class TestDomainParams(base.TestCase):
|
|||||||
self.assertIn('domain', ret)
|
self.assertIn('domain', ret)
|
||||||
self.assertEqual(ret['domain'], '5678')
|
self.assertEqual(ret['domain'], '5678')
|
||||||
|
|
||||||
|
@mock.patch.object(occ.cloud_config.CloudConfig, 'get_api_version')
|
||||||
@mock.patch.object(shade.OpenStackCloud, '_get_project')
|
@mock.patch.object(shade.OpenStackCloud, '_get_project')
|
||||||
def test_identity_params_v3_no_domain(self, mock_get_project):
|
def test_identity_params_v3_no_domain(
|
||||||
|
self, mock_get_project, mock_api_version):
|
||||||
mock_get_project.return_value = bunch.Bunch(id=1234)
|
mock_get_project.return_value = bunch.Bunch(id=1234)
|
||||||
|
mock_api_version.return_value = '3'
|
||||||
self.cloud.api_versions = dict(identity='3')
|
|
||||||
|
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exc.OpenStackCloudException,
|
exc.OpenStackCloudException,
|
||||||
self.cloud._get_identity_params,
|
self.cloud._get_identity_params,
|
||||||
domain_id=None, project='bar')
|
domain_id=None, project='bar')
|
||||||
|
|
||||||
|
@mock.patch.object(occ.cloud_config.CloudConfig, 'get_api_version')
|
||||||
@mock.patch.object(shade.OpenStackCloud, '_get_project')
|
@mock.patch.object(shade.OpenStackCloud, '_get_project')
|
||||||
def test_identity_params_v2(self, mock_get_project):
|
def test_identity_params_v2(self, mock_get_project, mock_api_version):
|
||||||
mock_get_project.return_value = bunch.Bunch(id=1234)
|
mock_get_project.return_value = bunch.Bunch(id=1234)
|
||||||
|
mock_api_version.return_value = '2'
|
||||||
self.cloud.api_versions = dict(identity='2')
|
|
||||||
|
|
||||||
ret = self.cloud._get_identity_params(domain_id='foo', project='bar')
|
ret = self.cloud._get_identity_params(domain_id='foo', project='bar')
|
||||||
self.assertIn('tenant_id', ret)
|
self.assertIn('tenant_id', ret)
|
||||||
|
@ -20,6 +20,7 @@ Tests Keystone endpoints commands.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
import os_client_config
|
||||||
from shade import OperatorCloud
|
from shade import OperatorCloud
|
||||||
from shade.tests.fakes import FakeEndpoint
|
from shade.tests.fakes import FakeEndpoint
|
||||||
from shade.tests.unit import base
|
from shade.tests.unit import base
|
||||||
@ -38,7 +39,8 @@ class TestCloudEndpoints(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestCloudEndpoints, self).setUp()
|
super(TestCloudEndpoints, self).setUp()
|
||||||
self.client = OperatorCloud("op_cloud", {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.client = OperatorCloud(cloud_config=config.get_one_cloud())
|
||||||
self.mock_ks_endpoints = \
|
self.mock_ks_endpoints = \
|
||||||
[FakeEndpoint(**kwa) for kwa in self.mock_endpoints]
|
[FakeEndpoint(**kwa) for kwa in self.mock_endpoints]
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ Tests floating IP resource methods for Neutron and Nova-network.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
import os_client_config
|
||||||
from shade import meta
|
from shade import meta
|
||||||
from shade import OpenStackCloud
|
from shade import OpenStackCloud
|
||||||
from shade.tests.fakes import FakeServer
|
from shade.tests.fakes import FakeServer
|
||||||
@ -29,7 +30,8 @@ from shade.tests.unit import base
|
|||||||
class TestFloatingIP(base.TestCase):
|
class TestFloatingIP(base.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestFloatingIP, self).setUp()
|
super(TestFloatingIP, self).setUp()
|
||||||
self.client = OpenStackCloud("cloud", {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.client = OpenStackCloud(cloud_config=config.get_one_cloud())
|
||||||
|
|
||||||
@patch.object(OpenStackCloud, 'get_floating_ip')
|
@patch.object(OpenStackCloud, 'get_floating_ip')
|
||||||
@patch.object(OpenStackCloud, 'attach_ip_to_server')
|
@patch.object(OpenStackCloud, 'attach_ip_to_server')
|
||||||
|
@ -20,6 +20,7 @@ Tests Floating IP resource methods for Neutron
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
import os_client_config
|
||||||
|
|
||||||
from neutronclient.common import exceptions as n_exc
|
from neutronclient.common import exceptions as n_exc
|
||||||
|
|
||||||
@ -121,7 +122,8 @@ class TestFloatingIP(base.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestFloatingIP, self).setUp()
|
super(TestFloatingIP, self).setUp()
|
||||||
# floating_ip_source='neutron' is default for OpenStackCloud()
|
# floating_ip_source='neutron' is default for OpenStackCloud()
|
||||||
self.client = OpenStackCloud("cloud", {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.client = OpenStackCloud(cloud_config=config.get_one_cloud())
|
||||||
|
|
||||||
@patch.object(OpenStackCloud, 'neutron_client')
|
@patch.object(OpenStackCloud, 'neutron_client')
|
||||||
@patch.object(OpenStackCloud, 'has_service')
|
@patch.object(OpenStackCloud, 'has_service')
|
||||||
|
@ -20,6 +20,7 @@ Tests Floating IP resource methods for nova-network
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
import os_client_config
|
||||||
|
|
||||||
from novaclient import exceptions as n_exc
|
from novaclient import exceptions as n_exc
|
||||||
|
|
||||||
@ -69,7 +70,8 @@ class TestFloatingIP(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestFloatingIP, self).setUp()
|
super(TestFloatingIP, self).setUp()
|
||||||
self.client = OpenStackCloud("cloud", {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.client = OpenStackCloud(cloud_config=config.get_one_cloud())
|
||||||
|
|
||||||
@patch.object(OpenStackCloud, 'nova_client')
|
@patch.object(OpenStackCloud, 'nova_client')
|
||||||
@patch.object(OpenStackCloud, 'has_service')
|
@patch.object(OpenStackCloud, 'has_service')
|
||||||
|
@ -20,6 +20,7 @@ Test floating IP pool resource (managed by nova)
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
import os_client_config
|
||||||
from shade import OpenStackCloud
|
from shade import OpenStackCloud
|
||||||
from shade import OpenStackCloudException
|
from shade import OpenStackCloudException
|
||||||
from shade.tests.unit import base
|
from shade.tests.unit import base
|
||||||
@ -33,7 +34,8 @@ class TestFloatingIPPool(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestFloatingIPPool, self).setUp()
|
super(TestFloatingIPPool, self).setUp()
|
||||||
self.client = OpenStackCloud('cloud', {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.client = OpenStackCloud(cloud_config=config.get_one_cloud())
|
||||||
|
|
||||||
@patch.object(OpenStackCloud, '_has_nova_extension')
|
@patch.object(OpenStackCloud, '_has_nova_extension')
|
||||||
@patch.object(OpenStackCloud, 'nova_client')
|
@patch.object(OpenStackCloud, 'nova_client')
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import os_client_config
|
||||||
from swiftclient import client as swift_client
|
from swiftclient import client as swift_client
|
||||||
from swiftclient import service as swift_service
|
from swiftclient import service as swift_service
|
||||||
from swiftclient import exceptions as swift_exc
|
from swiftclient import exceptions as swift_exc
|
||||||
@ -28,7 +29,8 @@ class TestObject(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestObject, self).setUp()
|
super(TestObject, self).setUp()
|
||||||
self.cloud = OpenStackCloud('cloud', {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.cloud = OpenStackCloud(cloud_config=config.get_one_cloud())
|
||||||
|
|
||||||
@mock.patch.object(swift_client, 'Connection')
|
@mock.patch.object(swift_client, 'Connection')
|
||||||
@mock.patch.object(shade.OpenStackCloud, 'auth_token',
|
@mock.patch.object(shade.OpenStackCloud, 'auth_token',
|
||||||
|
@ -20,6 +20,7 @@ Test port resource (managed by neutron)
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
import os_client_config
|
||||||
from shade import OpenStackCloud
|
from shade import OpenStackCloud
|
||||||
from shade.exc import OpenStackCloudException
|
from shade.exc import OpenStackCloudException
|
||||||
from shade.tests.unit import base
|
from shade.tests.unit import base
|
||||||
@ -143,7 +144,8 @@ class TestPort(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPort, self).setUp()
|
super(TestPort, self).setUp()
|
||||||
self.client = OpenStackCloud('cloud', {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.client = OpenStackCloud(cloud_config=config.get_one_cloud())
|
||||||
|
|
||||||
@patch.object(OpenStackCloud, 'neutron_client')
|
@patch.object(OpenStackCloud, 'neutron_client')
|
||||||
def test_create_port(self, mock_neutron_client):
|
def test_create_port(self, mock_neutron_client):
|
||||||
|
@ -20,6 +20,7 @@ Tests for the `rebuild_server` command.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mock import patch, Mock
|
from mock import patch, Mock
|
||||||
|
import os_client_config
|
||||||
from shade import meta
|
from shade import meta
|
||||||
from shade import OpenStackCloud
|
from shade import OpenStackCloud
|
||||||
from shade.exc import (OpenStackCloudException, OpenStackCloudTimeout)
|
from shade.exc import (OpenStackCloudException, OpenStackCloudTimeout)
|
||||||
@ -30,7 +31,8 @@ class TestRebuildServer(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestRebuildServer, self).setUp()
|
super(TestRebuildServer, self).setUp()
|
||||||
self.client = OpenStackCloud("cloud", {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.client = OpenStackCloud(cloud_config=config.get_one_cloud())
|
||||||
|
|
||||||
def test_rebuild_server_rebuild_exception(self):
|
def test_rebuild_server_rebuild_exception(self):
|
||||||
"""
|
"""
|
||||||
|
@ -20,6 +20,7 @@ Tests Keystone services commands.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
import os_client_config
|
||||||
from shade import OpenStackCloudException
|
from shade import OpenStackCloudException
|
||||||
from shade import OperatorCloud
|
from shade import OperatorCloud
|
||||||
from shade.tests.fakes import FakeService
|
from shade.tests.fakes import FakeService
|
||||||
@ -40,7 +41,8 @@ class CloudServices(base.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CloudServices, self).setUp()
|
super(CloudServices, self).setUp()
|
||||||
self.client = OperatorCloud("op_cloud", {})
|
config = os_client_config.OpenStackConfig()
|
||||||
|
self.client = OperatorCloud(cloud_config=config.get_one_cloud())
|
||||||
self.mock_ks_services = [FakeService(**kwa) for kwa in
|
self.mock_ks_services = [FakeService(**kwa) for kwa in
|
||||||
self.mock_services]
|
self.mock_services]
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ from keystoneclient.v2_0 import client as k2_client
|
|||||||
from keystoneclient.v3 import client as k3_client
|
from keystoneclient.v3 import client as k3_client
|
||||||
from neutronclient.common import exceptions as n_exc
|
from neutronclient.common import exceptions as n_exc
|
||||||
|
|
||||||
|
import os_client_config.cloud_config
|
||||||
import shade
|
import shade
|
||||||
from shade import exc
|
from shade import exc
|
||||||
from shade import meta
|
from shade import meta
|
||||||
@ -55,22 +56,28 @@ class TestShade(base.TestCase):
|
|||||||
plugin,
|
plugin,
|
||||||
keystoneclient.auth.identity.generic.password.Password)
|
keystoneclient.auth.identity.generic.password.Password)
|
||||||
|
|
||||||
def test_get_client_v2(self):
|
@mock.patch.object(
|
||||||
self.cloud.api_versions['identity'] = '2'
|
os_client_config.cloud_config.CloudConfig, 'get_api_version')
|
||||||
|
def test_get_client_v2(self, mock_api_version):
|
||||||
|
mock_api_version.return_value = '2'
|
||||||
|
|
||||||
self.assertIs(
|
self.assertIs(
|
||||||
self.cloud._get_identity_client_class(),
|
self.cloud._get_identity_client_class(),
|
||||||
k2_client.Client)
|
k2_client.Client)
|
||||||
|
|
||||||
def test_get_client_v3(self):
|
@mock.patch.object(
|
||||||
self.cloud.api_versions['identity'] = '3'
|
os_client_config.cloud_config.CloudConfig, 'get_api_version')
|
||||||
|
def test_get_client_v3(self, mock_api_version):
|
||||||
|
mock_api_version.return_value = '3'
|
||||||
|
|
||||||
self.assertIs(
|
self.assertIs(
|
||||||
self.cloud._get_identity_client_class(),
|
self.cloud._get_identity_client_class(),
|
||||||
k3_client.Client)
|
k3_client.Client)
|
||||||
|
|
||||||
def test_get_client_v4(self):
|
@mock.patch.object(
|
||||||
self.cloud.api_versions['identity'] = '4'
|
os_client_config.cloud_config.CloudConfig, 'get_api_version')
|
||||||
|
def test_get_client_v4(self, mock_api_version):
|
||||||
|
mock_api_version.return_value = '4'
|
||||||
|
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exc.OpenStackCloudException,
|
exc.OpenStackCloudException,
|
||||||
|
@ -17,6 +17,7 @@ from keystoneclient import auth as ksc_auth
|
|||||||
import mock
|
import mock
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
import os_client_config.cloud_config
|
||||||
import shade
|
import shade
|
||||||
from shade import exc
|
from shade import exc
|
||||||
from shade import meta
|
from shade import meta
|
||||||
@ -548,8 +549,10 @@ class TestShadeOperator(base.TestCase):
|
|||||||
self.assertEqual('22', self.cloud.get_image_id('22'))
|
self.assertEqual('22', self.cloud.get_image_id('22'))
|
||||||
self.assertEqual('22', self.cloud.get_image_id('22 name'))
|
self.assertEqual('22', self.cloud.get_image_id('22 name'))
|
||||||
|
|
||||||
def test_get_session_endpoint_provided(self):
|
@mock.patch.object(
|
||||||
self.cloud.endpoints['image'] = 'http://fake.url'
|
os_client_config.cloud_config.CloudConfig, 'get_endpoint')
|
||||||
|
def test_get_session_endpoint_provided(self, fake_get_endpoint):
|
||||||
|
fake_get_endpoint.return_value = 'http://fake.url'
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'http://fake.url', self.cloud.get_session_endpoint('image'))
|
'http://fake.url', self.cloud.get_session_endpoint('image'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user