Fix [H405] pep rule in heat/engine/clients

Implements bp docstring-improvements

Change-Id: I789a99e48b61f60dd53e82c59467befbac054deb
This commit is contained in:
Peter Razumovsky 2015-09-18 09:33:08 +03:00
parent 2da170c435
commit 4138090afd
8 changed files with 61 additions and 74 deletions

View File

@ -35,9 +35,7 @@ cfg.CONF.register_opts(cloud_opts)
class OpenStackClients(object):
'''
Convenience class to create and cache client instances.
'''
"""Convenience class to create and cache client instances."""
def __init__(self, context):
self.context = context
@ -79,9 +77,11 @@ class OpenStackClients(object):
class ClientBackend(object):
'''Delay choosing the backend client module until the client's class needs
"""Class for delaying choosing the backend client module.
Delay choosing the backend client module until the client's class needs
to be initialized.
'''
"""
def __new__(cls, context):
if cfg.CONF.cloud_backend == _default_backend:
return OpenStackClients(context)

View File

@ -66,7 +66,7 @@ class ClientPlugin(object):
@abc.abstractmethod
def _create(self):
'''Return a newly created client.'''
"""Return a newly created client."""
pass
@property
@ -148,7 +148,7 @@ class ClientPlugin(object):
return getattr(cfg.CONF.clients, option)
def is_client_exception(self, ex):
'''Returns True if the current exception comes from the client.'''
"""Returns True if the current exception comes from the client."""
if self.exceptions_module:
if isinstance(self.exceptions_module, list):
for m in self.exceptions_module:
@ -160,11 +160,11 @@ class ClientPlugin(object):
return False
def is_not_found(self, ex):
'''Returns True if the exception is a not-found.'''
"""Returns True if the exception is a not-found."""
return False
def is_over_limit(self, ex):
'''Returns True if the exception is an over-limit.'''
"""Returns True if the exception is an over-limit."""
return False
def is_conflict(self, ex):
@ -172,7 +172,7 @@ class ClientPlugin(object):
return False
def ignore_not_found(self, ex):
'''Raises the exception unless it is a not-found.'''
"""Raises the exception unless it is a not-found."""
if not self.is_not_found(ex):
exc_info = sys.exc_info()
six.reraise(*exc_info)

View File

@ -61,14 +61,13 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
return isinstance(ex, exc.HTTPConflict)
def get_image_id(self, image_identifier):
'''
Return an id for the specified image name or identifier.
"""Return the ID for the specified image name or identifier.
:param image_identifier: image name or a UUID-like identifier
:returns: the id of the requested :image_identifier:
:raises: exception.EntityNotFound,
exception.PhysicalResourceNameAmbiguity
'''
"""
if uuidutils.is_uuid_like(image_identifier):
try:
image_id = self.client().images.get(image_identifier).id
@ -79,14 +78,13 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
return image_id
def get_image_id_by_name(self, image_identifier):
'''
Return an id for the specified image name.
"""Return the ID for the specified image name.
:param image_identifier: image name
:returns: the id of the requested :image_identifier:
:raises: exception.EntityNotFound,
exception.PhysicalResourceNameAmbiguity
'''
"""
try:
filters = {'name': image_identifier}
image_list = list(self.client().images.list(filters=filters))

View File

@ -117,8 +117,7 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
raise exception.EntityNotFound(entity='Server', name=server)
def fetch_server(self, server_id):
"""
Fetch fresh server object from Nova.
"""Fetch fresh server object from Nova.
Log warnings and return None for non-critical API errors.
Use this method in various ``check_*_complete`` resource methods,
@ -144,10 +143,10 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
return server
def refresh_server(self, server):
'''
Refresh server's attributes and log warnings for non-critical
API errors.
'''
"""Refresh server's attributes.
Also log warnings for non-critical API errors.
"""
try:
server.get()
except exceptions.OverLimit as exc:
@ -176,11 +175,11 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
return ip['addr']
def get_status(self, server):
'''
Return the server's status.
"""Return the server's status.
:param server: server object
:returns: status as a string
'''
"""
# Some clouds append extra (STATUS) strings to the status, strip it
return server.status.split('(')[0]
@ -226,14 +225,14 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
result=_('%s is not active') % res_name)
def get_flavor_id(self, flavor):
'''
Get the id for the specified flavor name.
"""Get the id for the specified flavor name.
If the specified value is flavor id, just return it.
:param flavor: the name of the flavor to find
:returns: the id of :flavor:
:raises: exception.FlavorMissing
'''
"""
flavor_id = None
flavor_list = self.client().flavors.list()
for o in flavor_list:
@ -248,13 +247,12 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
return flavor_id
def get_keypair(self, key_name):
'''
Get the public key specified by :key_name:
"""Get the public key specified by :key_name:
:param key_name: the name of the key to look for
:returns: the keypair (name, public_key) for :key_name:
:raises: exception.UserKeyPairMissing
'''
"""
try:
return self.client().keypairs.get(key_name)
except exceptions.NotFound:
@ -262,9 +260,10 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
def build_userdata(self, metadata, userdata=None, instance_user=None,
user_data_format='HEAT_CFNTOOLS'):
'''
Build multipart data blob for CloudInit which includes user-supplied
Metadata, user data, and the required Heat in-instance configuration.
"""Build multipart data blob for CloudInit.
Data blob includes user-supplied Metadata, user data, and the required
Heat in-instance configuration.
:param resource: the resource implementation
:type resource: heat.engine.Resource
@ -275,7 +274,7 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
:param user_data_format: Format of user data to return
:type user_data_format: string
:returns: multipart mime as a string
'''
"""
if user_data_format == 'RAW':
return userdata
@ -423,8 +422,8 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
return False
def check_resize(self, server_id, flavor_id, flavor):
"""
Verify that a resizing server is properly resized.
"""Verify that a resizing server is properly resized.
If that's the case, confirm the resize, if not raise an error.
"""
server = self.fetch_server(server_id)
@ -479,8 +478,8 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
return False
def check_rebuild(self, server_id):
"""
Verify that a rebuilding server is rebuilt.
"""Verify that a rebuilding server is rebuilt.
Raise error if it ends up in an ERROR state.
"""
server = self.fetch_server(server_id)
@ -493,10 +492,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
return True
def meta_serialize(self, metadata):
"""
Serialize non-string metadata values before sending them to
Nova.
"""
"""Serialize non-string metadata values before sending them to Nova."""
if not isinstance(metadata, collections.Mapping):
raise exception.StackValidationFailed(message=_(
"nova server metadata needs to be a Map."))
@ -519,9 +515,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
client.servers.set_meta(server, metadata)
def server_to_ipaddress(self, server):
'''
Return the server's IP address, fetching it from Nova.
'''
"""Return the server's IP address, fetching it from Nova."""
try:
server = self.client().servers.get(server)
except exceptions.NotFound as ex:
@ -542,7 +536,6 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
"""Return dict-like structure of server's console urls.
The actual console url is lazily resolved on access.
"""
class ConsoleUrls(collections.Mapping):

View File

@ -81,14 +81,13 @@ class SaharaClientPlugin(client_plugin.ClientPlugin):
ex.error_name == 'IMAGE_NOT_REGISTERED')
def get_image_id(self, image_identifier):
'''
Return an id for the specified image name or identifier.
"""Return the ID for the specified image name or identifier.
:param image_identifier: image name or a UUID-like identifier
:returns: the id of the requested :image_identifier:
:raises: exception.EntityNotFound,
exception.PhysicalResourceNameAmbiguity
'''
"""
if uuidutils.is_uuid_like(image_identifier):
try:
image_id = self.client().images.get(image_identifier).id
@ -100,14 +99,13 @@ class SaharaClientPlugin(client_plugin.ClientPlugin):
return image_id
def get_image_id_by_name(self, image_identifier):
'''
Return an id for the specified image name.
"""Return the ID for the specified image name.
:param image_identifier: image name
:returns: the id of the requested :image_identifier:
:raises: exception.EntityNotFound,
exception.PhysicalResourceNameAmbiguity
'''
"""
try:
filters = {'name': image_identifier}
image_list = self.client().images.find(**filters)

View File

@ -71,7 +71,7 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
ex.http_status == 409)
def is_valid_temp_url_path(self, path):
'''Return True if path is a valid Swift TempURL path, False otherwise.
"""Return True if path is a valid Swift TempURL path, False otherwise.
A Swift TempURL path must:
- Be five parts, ['', 'v1', 'account', 'container', 'object']
@ -81,7 +81,7 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
:param path: The TempURL path
:type path: string
'''
"""
parts = path.split('/', 4)
return bool(len(parts) == 5 and
not parts[0] and
@ -92,9 +92,7 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
def get_temp_url(self, container_name, obj_name, timeout=None,
method='PUT'):
'''
Return a Swift TempURL.
'''
"""Return a Swift TempURL."""
key_header = 'x-account-meta-temp-url-key'
if key_header not in self.client().head_account():
self.client().post_account({
@ -114,10 +112,11 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
return '%s://%s%s' % (sw_url.scheme, sw_url.netloc, tempurl)
def get_signal_url(self, container_name, obj_name, timeout=None):
'''
Turn on object versioning so we can use a single TempURL for
multiple signals and return a Swift TempURL.
'''
"""Turn on object versioning.
We can use a single TempURL for multiple signals and return a Swift
TempURL.
"""
self.client().put_container(
container_name, headers={'x-versions-location': container_name})
self.client().put_object(container_name, obj_name, IN_PROGRESS)
@ -125,14 +124,15 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
return self.get_temp_url(container_name, obj_name, timeout)
def parse_last_modified(self, lm):
'''
Parses the last-modified value, such as from a swift object header,
and returns the datetime.datetime of that value.
"""Parses the last-modified value.
For example, last-modified values from a swift object header.
Returns the datetime.datetime of that value.
:param lm: The last-modified value (or None)
:type lm: string
:returns: An offset-naive UTC datetime of the value (or None)
'''
"""
if not lm:
return None
pd = email.utils.parsedate(lm)[:6]

View File

@ -91,14 +91,14 @@ class TroveClientPlugin(client_plugin.ClientPlugin):
return isinstance(ex, exceptions.Conflict)
def get_flavor_id(self, flavor):
'''
Get the id for the specified flavor name.
"""Get the ID for the specified flavor name.
If the specified value is flavor id, just return it.
:param flavor: the name of the flavor to find
:returns: the id of :flavor:
:raises: exception.FlavorMissing
'''
"""
flavor_id = None
flavor_list = self.client().flavors.list()
for o in flavor_list:

View File

@ -28,7 +28,7 @@ class ServerCreateProgress(object):
class ServerUpdateProgress(ServerCreateProgress):
"""Keeps track on particular server update task
"""Keeps track on particular server update task.
``handler`` is a method of client plugin performing
required update operation.
@ -36,13 +36,13 @@ class ServerUpdateProgress(ServerCreateProgress):
and this method must be resilent to intermittent failures,
returning ``True`` if API was successfully called, ``False`` otherwise.
If result of API call is asyncronous, client plugin must have
If result of API call is asynchronous, client plugin must have
corresponding ``check_<handler>`` method.
Its first positional argument must be ``server_id``
and it must return ``True`` or ``False`` indicating completeness
of the update operation.
For syncronous API calls,
For synchronous API calls,
set ``complete`` attribute of this object to ``True``.
``[handler|checker]_extra`` arguments, if passed to constructor,
@ -56,8 +56,6 @@ class ServerUpdateProgress(ServerCreateProgress):
Missing ``args`` or ``kwargs`` are interpreted
as empty tuple/dict respectively.
Defaults are interpreted as both ``args`` and ``kwargs`` being empty.
"""
def __init__(self, server_id, handler, complete=False, called=False,
handler_extra=None, checker_extra=None):