Enable H202, H402, H404 rules
* H202 assertRaises Exception too broad * H402 one line docstring needs punctuation * H404 multi line docstring should start without a leading new line Change-Id: I2f662b8b97d14daa501620c8237bf93bd2251243
This commit is contained in:
parent
864df5b69d
commit
d6a3a2b2e6
@ -41,7 +41,7 @@ class VersionNegotiationFilter(wsgi.Middleware):
|
|||||||
super(VersionNegotiationFilter, self).__init__(app)
|
super(VersionNegotiationFilter, self).__init__(app)
|
||||||
|
|
||||||
def process_request(self, req):
|
def process_request(self, req):
|
||||||
"""Try to find a version first in the accept header, then the URL"""
|
"""Try to find a version first in the accept header, then the URL."""
|
||||||
msg = _("Determining version of request: %(method)s %(path)s"
|
msg = _("Determining version of request: %(method)s %(path)s"
|
||||||
" Accept: %(accept)s")
|
" Accept: %(accept)s")
|
||||||
args = {'method': req.method, 'path': req.path, 'accept': req.accept}
|
args = {'method': req.method, 'path': req.path, 'accept': req.accept}
|
||||||
@ -64,8 +64,7 @@ class VersionNegotiationFilter(wsgi.Middleware):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _match_version_string(self, subject):
|
def _match_version_string(self, subject):
|
||||||
"""
|
"""Given a string, tries to match a major and/or
|
||||||
Given a string, tries to match a major and/or
|
|
||||||
minor version number.
|
minor version number.
|
||||||
|
|
||||||
:param subject: The string to check
|
:param subject: The string to check
|
||||||
@ -79,8 +78,7 @@ class VersionNegotiationFilter(wsgi.Middleware):
|
|||||||
return major_version
|
return major_version
|
||||||
|
|
||||||
def _pop_path_info(self, req):
|
def _pop_path_info(self, req):
|
||||||
"""
|
"""'Pops' off the next segment of PATH_INFO, returns the popped
|
||||||
'Pops' off the next segment of PATH_INFO, returns the popped
|
|
||||||
segment. Do NOT push it onto SCRIPT_NAME.
|
segment. Do NOT push it onto SCRIPT_NAME.
|
||||||
"""
|
"""
|
||||||
path = req.path_info
|
path = req.path_info
|
||||||
|
@ -75,8 +75,7 @@ def _get_filters(query_params):
|
|||||||
|
|
||||||
|
|
||||||
def _validate_body(body):
|
def _validate_body(body):
|
||||||
"""
|
"""Check multipart/form-data has two parts: text (which is json string and
|
||||||
Check multipart/form-data has two parts: text (which is json string and
|
|
||||||
should parsed into dictionary in serializer) and file, which stores as
|
should parsed into dictionary in serializer) and file, which stores as
|
||||||
cgi.FieldStorage instance. Also validate file size doesn't exceed
|
cgi.FieldStorage instance. Also validate file size doesn't exceed
|
||||||
the limit: seek to the end of the file, get the position of EOF and
|
the limit: seek to the end of the file, get the position of EOF and
|
||||||
@ -116,13 +115,10 @@ def _validate_body(body):
|
|||||||
|
|
||||||
|
|
||||||
class Controller(object):
|
class Controller(object):
|
||||||
"""
|
"""WSGI controller for application catalog resource in Murano v1 API."""
|
||||||
WSGI controller for application catalog resource in Murano v1 API
|
|
||||||
"""
|
|
||||||
|
|
||||||
def update(self, req, body, package_id):
|
def update(self, req, body, package_id):
|
||||||
"""
|
"""List of allowed changes:
|
||||||
List of allowed changes:
|
|
||||||
{ "op": "add", "path": "/tags", "value": [ "foo", "bar" ] }
|
{ "op": "add", "path": "/tags", "value": [ "foo", "bar" ] }
|
||||||
{ "op": "add", "path": "/categories", "value": [ "foo", "bar" ] }
|
{ "op": "add", "path": "/categories", "value": [ "foo", "bar" ] }
|
||||||
{ "op": "remove", "path": "/tags" }
|
{ "op": "remove", "path": "/tags" }
|
||||||
@ -184,9 +180,8 @@ class Controller(object):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def upload(self, req, body=None):
|
def upload(self, req, body=None):
|
||||||
"""
|
"""Upload new file archive for the new package
|
||||||
Upload new file archive for the new package
|
together with package metadata.
|
||||||
together with package metadata
|
|
||||||
"""
|
"""
|
||||||
policy.check("upload_package", req.context)
|
policy.check("upload_package", req.context)
|
||||||
|
|
||||||
|
@ -87,9 +87,7 @@ def _do_import_package(_dir, categories, update=False):
|
|||||||
|
|
||||||
# TODO(ruhe): proper error handling
|
# TODO(ruhe): proper error handling
|
||||||
def do_import_package():
|
def do_import_package():
|
||||||
"""
|
"""Import Murano package from local directory."""
|
||||||
Import Murano package from local directory.
|
|
||||||
"""
|
|
||||||
_do_import_package(
|
_do_import_package(
|
||||||
CONF.command.directory,
|
CONF.command.directory,
|
||||||
CONF.command.categories,
|
CONF.command.categories,
|
||||||
|
@ -220,9 +220,7 @@ def parse_args(args=None, usage=None, default_config_files=None):
|
|||||||
|
|
||||||
|
|
||||||
def setup_logging():
|
def setup_logging():
|
||||||
"""
|
"""Sets up the logging options for a log with supplied name."""
|
||||||
Sets up the logging options for a log with supplied name
|
|
||||||
"""
|
|
||||||
|
|
||||||
if CONF.log_config:
|
if CONF.log_config:
|
||||||
# Use a logging configuration file for all settings...
|
# Use a logging configuration file for all settings...
|
||||||
@ -265,8 +263,7 @@ def setup_logging():
|
|||||||
|
|
||||||
|
|
||||||
def _get_deployment_flavor():
|
def _get_deployment_flavor():
|
||||||
"""
|
"""Retrieve the paste_deploy.flavor config item, formatted appropriately
|
||||||
Retrieve the paste_deploy.flavor config item, formatted appropriately
|
|
||||||
for appending to the application name.
|
for appending to the application name.
|
||||||
"""
|
"""
|
||||||
flavor = CONF.paste_deploy.flavor
|
flavor = CONF.paste_deploy.flavor
|
||||||
@ -286,8 +283,7 @@ def _get_paste_config_path():
|
|||||||
|
|
||||||
|
|
||||||
def _get_deployment_config_file():
|
def _get_deployment_config_file():
|
||||||
"""
|
"""Retrieve the deployment_config_file config item, formatted as an
|
||||||
Retrieve the deployment_config_file config item, formatted as an
|
|
||||||
absolute pathname.
|
absolute pathname.
|
||||||
"""
|
"""
|
||||||
path = CONF.paste_deploy.config_file
|
path = CONF.paste_deploy.config_file
|
||||||
@ -300,8 +296,7 @@ def _get_deployment_config_file():
|
|||||||
|
|
||||||
|
|
||||||
def load_paste_app(app_name=None):
|
def load_paste_app(app_name=None):
|
||||||
"""
|
"""Builds and returns a WSGI app from a paste config file.
|
||||||
Builds and returns a WSGI app from a paste config file.
|
|
||||||
|
|
||||||
We assume the last config file specified in the supplied ConfigOpts
|
We assume the last config file specified in the supplied ConfigOpts
|
||||||
object is the paste config file.
|
object is the paste config file.
|
||||||
|
@ -17,13 +17,12 @@ import types
|
|||||||
|
|
||||||
|
|
||||||
class TokenSanitizer():
|
class TokenSanitizer():
|
||||||
"""
|
"""Helper class for cleaning some object from different passwords/tokens.
|
||||||
Helper class for cleaning some object from different passwords/tokens.
|
|
||||||
Simply searches attribute with `look a like` name as one of
|
Simply searches attribute with `look a like` name as one of
|
||||||
the token and replace it value with message.
|
the token and replace it value with message.
|
||||||
"""
|
"""
|
||||||
def __init__(self, tokens=('token', 'pass'), message='*** SANITIZED ***'):
|
def __init__(self, tokens=('token', 'pass'), message='*** SANITIZED ***'):
|
||||||
"""
|
"""Init method of TokenSanitizer.
|
||||||
:param tokens: iterable with tokens
|
:param tokens: iterable with tokens
|
||||||
:param message: string by which each token going to be replaced
|
:param message: string by which each token going to be replaced
|
||||||
"""
|
"""
|
||||||
@ -32,16 +31,12 @@ class TokenSanitizer():
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def tokens(self):
|
def tokens(self):
|
||||||
"""
|
"""Iterable with tokens that should be sanitized."""
|
||||||
Iterable with tokens that should be sanitized
|
|
||||||
"""
|
|
||||||
return self._tokens
|
return self._tokens
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def message(self):
|
def message(self):
|
||||||
"""
|
"""String by which each token going to be replaced."""
|
||||||
String by which each token going to be replaced
|
|
||||||
"""
|
|
||||||
return self._message
|
return self._message
|
||||||
|
|
||||||
def _contains_token(self, value):
|
def _contains_token(self, value):
|
||||||
@ -51,8 +46,7 @@ class TokenSanitizer():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def sanitize(self, obj):
|
def sanitize(self, obj):
|
||||||
"""
|
"""Replaces each token found in object by message.
|
||||||
Replaces each token found in object by message
|
|
||||||
:param obj: types.DictType, types.ListType, types.Tuple, object
|
:param obj: types.DictType, types.ListType, types.Tuple, object
|
||||||
:return: Sanitized object
|
:return: Sanitized object
|
||||||
"""
|
"""
|
||||||
|
@ -32,8 +32,7 @@ class TraverseHelper(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(path, source):
|
def get(path, source):
|
||||||
"""
|
"""Provides the ability to traverse a data source made up of any
|
||||||
Provides the ability to traverse a data source made up of any
|
|
||||||
combination of lists and dicts. Has simple rules for selecting item of
|
combination of lists and dicts. Has simple rules for selecting item of
|
||||||
the list:
|
the list:
|
||||||
|
|
||||||
@ -81,8 +80,7 @@ class TraverseHelper(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update(path, value, source):
|
def update(path, value, source):
|
||||||
"""
|
"""Updates value selected with specified path.
|
||||||
Updates value selected with specified path.
|
|
||||||
|
|
||||||
Warning: Root object could not be updated
|
Warning: Root object could not be updated
|
||||||
|
|
||||||
@ -97,8 +95,7 @@ class TraverseHelper(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def insert(path, value, source):
|
def insert(path, value, source):
|
||||||
"""
|
"""Inserts new item to selected list.
|
||||||
Inserts new item to selected list.
|
|
||||||
|
|
||||||
:param path: string with path to desired value
|
:param path: string with path to desired value
|
||||||
:param value: value
|
:param value: value
|
||||||
@ -109,8 +106,7 @@ class TraverseHelper(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def extend(path, value, source):
|
def extend(path, value, source):
|
||||||
"""
|
"""Extend list by appending elements from the iterable.
|
||||||
Extend list by appending elements from the iterable.
|
|
||||||
|
|
||||||
:param path: string with path to desired value
|
:param path: string with path to desired value
|
||||||
:param value: value
|
:param value: value
|
||||||
@ -121,8 +117,7 @@ class TraverseHelper(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove(path, source):
|
def remove(path, source):
|
||||||
"""
|
"""Removes selected item from source.
|
||||||
Removes selected item from source.
|
|
||||||
|
|
||||||
:param path: string with path to desired value
|
:param path: string with path to desired value
|
||||||
:param source: python object (list or dict)
|
:param source: python object (list or dict)
|
||||||
@ -145,8 +140,7 @@ class TraverseHelper(object):
|
|||||||
|
|
||||||
|
|
||||||
def is_different(obj1, obj2):
|
def is_different(obj1, obj2):
|
||||||
"""
|
"""Stripped-down version of deep.diff comparator
|
||||||
Stripped-down version of deep.diff comparator
|
|
||||||
|
|
||||||
Compares arbitrary nested objects, handles circular links, but doesn't
|
Compares arbitrary nested objects, handles circular links, but doesn't
|
||||||
point to the first difference as deep.diff does.
|
point to the first difference as deep.diff does.
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class RequestContext(object):
|
class RequestContext(object):
|
||||||
"""
|
"""Stores information about the security context under which the user
|
||||||
Stores information about the security context under which the user
|
|
||||||
accesses the system, as well as additional request information.
|
accesses the system, as well as additional request information.
|
||||||
|
|
||||||
TODO: (sjmc7) - extend openstack.common.context
|
TODO: (sjmc7) - extend openstack.common.context
|
||||||
|
@ -77,8 +77,7 @@ def _authorize_package(package, context, allow_public=False):
|
|||||||
|
|
||||||
|
|
||||||
def package_get(package_id_or_name, context):
|
def package_get(package_id_or_name, context):
|
||||||
"""
|
"""Return package details
|
||||||
Return package details
|
|
||||||
:param package_id: ID or name of a package, string
|
:param package_id: ID or name of a package, string
|
||||||
:returns: detailed information about package, dict
|
:returns: detailed information about package, dict
|
||||||
"""
|
"""
|
||||||
@ -89,9 +88,10 @@ def package_get(package_id_or_name, context):
|
|||||||
|
|
||||||
|
|
||||||
def _get_categories(category_names, session=None):
|
def _get_categories(category_names, session=None):
|
||||||
"""
|
"""Return existing category objects or raise an exception.
|
||||||
Return existing category objects or raise an exception
|
|
||||||
:param category_names: name of categories to associate with package, list
|
:param category_names: name of categories
|
||||||
|
to associate with package, list
|
||||||
:returns: list of Category objects to associate with package, list
|
:returns: list of Category objects to associate with package, list
|
||||||
"""
|
"""
|
||||||
if session is None:
|
if session is None:
|
||||||
@ -111,8 +111,7 @@ def _get_categories(category_names, session=None):
|
|||||||
|
|
||||||
|
|
||||||
def _get_tags(tag_names, session=None):
|
def _get_tags(tag_names, session=None):
|
||||||
"""
|
"""Return existing tags object or create new ones
|
||||||
Return existing tags object or create new ones
|
|
||||||
:param tag_names: name of tags to associate with package, list
|
:param tag_names: name of tags to associate with package, list
|
||||||
:returns: list of Tag objects to associate with package, list
|
:returns: list of Tag objects to associate with package, list
|
||||||
"""
|
"""
|
||||||
@ -204,8 +203,7 @@ def _do_remove(package, change):
|
|||||||
|
|
||||||
|
|
||||||
def package_update(pkg_id_or_name, changes, context):
|
def package_update(pkg_id_or_name, changes, context):
|
||||||
"""
|
"""Update package information
|
||||||
Update package information
|
|
||||||
:param changes: parameters to update
|
:param changes: parameters to update
|
||||||
:returns: detailed information about new package, dict
|
:returns: detailed information about new package, dict
|
||||||
"""
|
"""
|
||||||
@ -225,8 +223,7 @@ def package_update(pkg_id_or_name, changes, context):
|
|||||||
|
|
||||||
|
|
||||||
def package_search(filters, context, limit=None):
|
def package_search(filters, context, limit=None):
|
||||||
"""
|
"""Search packages with different filters
|
||||||
Search packages with different filters
|
|
||||||
* Admin is allowed to browse all the packages
|
* Admin is allowed to browse all the packages
|
||||||
* Regular user is allowed to browse all packages belongs to user tenant
|
* Regular user is allowed to browse all packages belongs to user tenant
|
||||||
and all other packages marked is_public.
|
and all other packages marked is_public.
|
||||||
@ -328,8 +325,7 @@ def package_search(filters, context, limit=None):
|
|||||||
|
|
||||||
|
|
||||||
def package_upload(values, tenant_id):
|
def package_upload(values, tenant_id):
|
||||||
"""
|
"""Upload a package with new application
|
||||||
Upload a package with new application
|
|
||||||
:param values: parameters describing the new package
|
:param values: parameters describing the new package
|
||||||
:returns: detailed information about new package, dict
|
:returns: detailed information about new package, dict
|
||||||
"""
|
"""
|
||||||
@ -353,7 +349,7 @@ def package_upload(values, tenant_id):
|
|||||||
|
|
||||||
|
|
||||||
def package_delete(package_id_or_name, context):
|
def package_delete(package_id_or_name, context):
|
||||||
"""Delete a package by name or by ID"""
|
"""Delete a package by name or by ID."""
|
||||||
session = db_session.get_session()
|
session = db_session.get_session()
|
||||||
|
|
||||||
with session.begin():
|
with session.begin():
|
||||||
|
@ -54,7 +54,7 @@ Base = declarative.declarative_base(cls=_MuranoBase)
|
|||||||
|
|
||||||
|
|
||||||
class Environment(Base, TimestampMixin):
|
class Environment(Base, TimestampMixin):
|
||||||
"""Represents a Environment in the metadata-store"""
|
"""Represents a Environment in the metadata-store."""
|
||||||
__tablename__ = 'environment'
|
__tablename__ = 'environment'
|
||||||
|
|
||||||
id = sa.Column(sa.String(255),
|
id = sa.Column(sa.String(255),
|
||||||
@ -204,9 +204,7 @@ class Instance(Base):
|
|||||||
|
|
||||||
|
|
||||||
class Package(Base, TimestampMixin):
|
class Package(Base, TimestampMixin):
|
||||||
"""
|
"""Represents a meta information about application package."""
|
||||||
Represents a meta information about application package.
|
|
||||||
"""
|
|
||||||
__tablename__ = 'package'
|
__tablename__ = 'package'
|
||||||
|
|
||||||
id = sa.Column(sa.String(36),
|
id = sa.Column(sa.String(36),
|
||||||
@ -258,9 +256,7 @@ class Package(Base, TimestampMixin):
|
|||||||
|
|
||||||
|
|
||||||
class Category(Base, TimestampMixin):
|
class Category(Base, TimestampMixin):
|
||||||
"""
|
"""Represents an application categories in the datastore."""
|
||||||
Represents an application categories in the datastore.
|
|
||||||
"""
|
|
||||||
__tablename__ = 'category'
|
__tablename__ = 'category'
|
||||||
|
|
||||||
id = sa.Column(sa.String(36),
|
id = sa.Column(sa.String(36),
|
||||||
@ -270,9 +266,7 @@ class Category(Base, TimestampMixin):
|
|||||||
|
|
||||||
|
|
||||||
class Tag(Base, TimestampMixin):
|
class Tag(Base, TimestampMixin):
|
||||||
"""
|
"""Represents tags in the datastore."""
|
||||||
Represents tags in the datastore.
|
|
||||||
"""
|
|
||||||
__tablename__ = 'tag'
|
__tablename__ = 'tag'
|
||||||
|
|
||||||
id = sa.Column(sa.String(36),
|
id = sa.Column(sa.String(36),
|
||||||
@ -282,9 +276,7 @@ class Tag(Base, TimestampMixin):
|
|||||||
|
|
||||||
|
|
||||||
class Class(Base, TimestampMixin):
|
class Class(Base, TimestampMixin):
|
||||||
"""
|
"""Represents a class definition in the datastore."""
|
||||||
Represents a class definition in the datastore.
|
|
||||||
"""
|
|
||||||
__tablename__ = 'class_definition'
|
__tablename__ = 'class_definition'
|
||||||
|
|
||||||
id = sa.Column(sa.String(36),
|
id = sa.Column(sa.String(36),
|
||||||
@ -295,9 +287,7 @@ class Class(Base, TimestampMixin):
|
|||||||
|
|
||||||
|
|
||||||
def register_models(engine):
|
def register_models(engine):
|
||||||
"""
|
"""Creates database tables for all models with the given engine."""
|
||||||
Creates database tables for all models with the given engine
|
|
||||||
"""
|
|
||||||
models = (Environment, Status, Session, Task,
|
models = (Environment, Status, Session, Task,
|
||||||
ApiStats, Package, Category, Class, Instance)
|
ApiStats, Package, Category, Class, Instance)
|
||||||
for model in models:
|
for model in models:
|
||||||
@ -305,9 +295,7 @@ def register_models(engine):
|
|||||||
|
|
||||||
|
|
||||||
def unregister_models(engine):
|
def unregister_models(engine):
|
||||||
"""
|
"""Drops database tables for all models with the given engine."""
|
||||||
Drops database tables for all models with the given engine
|
|
||||||
"""
|
|
||||||
models = (Environment, Status, Session, Task,
|
models = (Environment, Status, Session, Task,
|
||||||
ApiStats, Package, Category, Class)
|
ApiStats, Package, Category, Class)
|
||||||
for model in models:
|
for model in models:
|
||||||
|
@ -22,8 +22,7 @@ from murano.openstack.common import timeutils
|
|||||||
class CoreServices(object):
|
class CoreServices(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_service_status(environment_id, service_id):
|
def get_service_status(environment_id, service_id):
|
||||||
"""
|
"""Service can have one of three distinguished statuses:
|
||||||
Service can have one of three distinguished statuses:
|
|
||||||
|
|
||||||
- Deploying: if environment has status deploying and there is at least
|
- Deploying: if environment has status deploying and there is at least
|
||||||
one orchestration engine report for this service;
|
one orchestration engine report for this service;
|
||||||
|
@ -43,8 +43,7 @@ DEFAULT_NETWORKS = {
|
|||||||
class EnvironmentServices(object):
|
class EnvironmentServices(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_environments_by(filters):
|
def get_environments_by(filters):
|
||||||
"""
|
"""Returns list of environments
|
||||||
Returns list of environments
|
|
||||||
:param filters: property filters
|
:param filters: property filters
|
||||||
:return: Returns list of environments
|
:return: Returns list of environments
|
||||||
"""
|
"""
|
||||||
@ -59,8 +58,7 @@ class EnvironmentServices(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status(environment_id):
|
def get_status(environment_id):
|
||||||
"""
|
"""Environment can have one of the following statuses:
|
||||||
Environment can have one of the following statuses:
|
|
||||||
|
|
||||||
- deploying: there is ongoing deployment for environment
|
- deploying: there is ongoing deployment for environment
|
||||||
- deleting: environment is currently being deleted
|
- deleting: environment is currently being deleted
|
||||||
@ -95,8 +93,8 @@ class EnvironmentServices(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def create(environment_params, tenant_id):
|
def create(environment_params, tenant_id):
|
||||||
#tagging environment by tenant_id for later checks
|
#tagging environment by tenant_id for later checks
|
||||||
"""
|
"""Creates environment with specified params, in particular - name
|
||||||
Creates environment with specified params, in particular - name
|
|
||||||
:param environment_params: Dict, e.g. {'name': 'env-name'}
|
:param environment_params: Dict, e.g. {'name': 'env-name'}
|
||||||
:param tenant_id: Tenant Id
|
:param tenant_id: Tenant Id
|
||||||
:return: Created Environment
|
:return: Created Environment
|
||||||
@ -131,8 +129,7 @@ class EnvironmentServices(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delete(environment_id, session_id):
|
def delete(environment_id, session_id):
|
||||||
"""
|
"""Deletes environment and notify orchestration engine about deletion
|
||||||
Deletes environment and notify orchestration engine about deletion
|
|
||||||
|
|
||||||
:param environment_id: Environment that is going to be deleted
|
:param environment_id: Environment that is going to be deleted
|
||||||
:param token: OpenStack auth token
|
:param token: OpenStack auth token
|
||||||
@ -155,10 +152,11 @@ class EnvironmentServices(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_environment_description(environment_id, session_id=None,
|
def get_environment_description(environment_id, session_id=None,
|
||||||
inner=True):
|
inner=True):
|
||||||
"""
|
"""Returns environment description for specified environment.
|
||||||
Returns environment description for specified environment. If session
|
|
||||||
is specified and not in deploying state function returns modified
|
If session is specified and not in deploying state function
|
||||||
environment description, otherwise returns actual environment desc.
|
returns modified environment description,
|
||||||
|
otherwise returns actual environment desc.
|
||||||
|
|
||||||
:param environment_id: Environment Id
|
:param environment_id: Environment Id
|
||||||
:param session_id: Session Id
|
:param session_id: Session Id
|
||||||
@ -192,8 +190,7 @@ class EnvironmentServices(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def save_environment_description(session_id, environment, inner=True):
|
def save_environment_description(session_id, environment, inner=True):
|
||||||
"""
|
"""Saves environment description to specified session.
|
||||||
Saves environment description to specified session
|
|
||||||
|
|
||||||
:param session_id: Session Id
|
:param session_id: Session Id
|
||||||
:param environment: Environment Description
|
:param environment: Environment Description
|
||||||
|
@ -35,8 +35,7 @@ SessionState = collections.namedtuple('SessionState', [
|
|||||||
class SessionServices(object):
|
class SessionServices(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_sessions(environment_id, state=None):
|
def get_sessions(environment_id, state=None):
|
||||||
"""
|
"""Get list of sessions for specified environment.
|
||||||
Get list of sessions for specified environment
|
|
||||||
|
|
||||||
:param environment_id: Environment Id
|
:param environment_id: Environment Id
|
||||||
:param state: glazierapi.db.services.environments.EnvironmentStatus
|
:param state: glazierapi.db.services.environments.EnvironmentStatus
|
||||||
@ -62,8 +61,7 @@ class SessionServices(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(environment_id, user_id):
|
def create(environment_id, user_id):
|
||||||
"""
|
"""Creates session object for specific environment for specified user.
|
||||||
Creates session object for specific environment for specified user.
|
|
||||||
|
|
||||||
:param environment_id: Environment Id
|
:param environment_id: Environment Id
|
||||||
:param user_id: User Id
|
:param user_id: User Id
|
||||||
@ -89,8 +87,7 @@ class SessionServices(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate(session):
|
def validate(session):
|
||||||
"""
|
"""Session is valid only if no other session for same.
|
||||||
Session is valid only if no other session for same
|
|
||||||
environment was already deployed on in deploying state,
|
environment was already deployed on in deploying state,
|
||||||
|
|
||||||
:param session: Session for validation
|
:param session: Session for validation
|
||||||
@ -117,8 +114,7 @@ class SessionServices(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def deploy(session, environment, unit, token):
|
def deploy(session, environment, unit, token):
|
||||||
"""
|
"""Prepares environment for deployment and send deployment command to
|
||||||
Prepares environment for deployment and send deployment command to
|
|
||||||
orchestration engine
|
orchestration engine
|
||||||
|
|
||||||
:param session: session that is going to be deployed
|
:param session: session that is going to be deployed
|
||||||
|
@ -78,7 +78,7 @@ class Agent(murano_object.MuranoObject):
|
|||||||
"by the server configuration")
|
"by the server configuration")
|
||||||
|
|
||||||
def _send(self, template, wait_results):
|
def _send(self, template, wait_results):
|
||||||
"""Send a message over the MQ interface"""
|
"""Send a message over the MQ interface."""
|
||||||
msg_id = template.get('ID', uuid.uuid4().hex)
|
msg_id = template.get('ID', uuid.uuid4().hex)
|
||||||
if wait_results:
|
if wait_results:
|
||||||
event = eventlet.event.Event()
|
event = eventlet.event.Event()
|
||||||
|
@ -79,8 +79,7 @@ class NetworkExplorer(murano_object.MuranoObject):
|
|||||||
|
|
||||||
# noinspection PyPep8Naming
|
# noinspection PyPep8Naming
|
||||||
def getAvailableCidr(self, routerId, netId):
|
def getAvailableCidr(self, routerId, netId):
|
||||||
"""
|
"""Uses hash of network IDs to minimize the collisions:
|
||||||
Uses hash of network IDs to minimize the collisions:
|
|
||||||
different nets will attempt to pick different cidrs out of available
|
different nets will attempt to pick different cidrs out of available
|
||||||
range.
|
range.
|
||||||
If the cidr is taken will pick another one
|
If the cidr is taken will pick another one
|
||||||
|
@ -79,8 +79,7 @@ class ActionServices(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_action(model, action_id):
|
def find_action(model, action_id):
|
||||||
"""
|
"""Traverses object model looking for an object definition
|
||||||
Traverses object model looking for an object definition
|
|
||||||
containing specified action
|
containing specified action
|
||||||
|
|
||||||
:param model: object model
|
:param model: object model
|
||||||
|
@ -97,9 +97,7 @@ class MuranoApiTestCase(base.MuranoWithDBTestCase, FakeLogMixin):
|
|||||||
|
|
||||||
|
|
||||||
class ControllerTest(object):
|
class ControllerTest(object):
|
||||||
"""
|
"""Common utilities for testing API Controllers."""
|
||||||
Common utilities for testing API Controllers.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(ControllerTest, self).__init__(*args, **kwargs)
|
super(ControllerTest, self).__init__(*args, **kwargs)
|
||||||
|
@ -32,7 +32,7 @@ class TestActionsApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
self.controller = actions.Controller()
|
self.controller = actions.Controller()
|
||||||
|
|
||||||
def test_execute_action(self, mock_policy_check):
|
def test_execute_action(self, mock_policy_check):
|
||||||
"""Test that action execution results in the correct rpc call"""
|
"""Test that action execution results in the correct rpc call."""
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'execute_action': '@'}
|
{'execute_action': '@'}
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,7 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
self.controller = environments.Controller()
|
self.controller = environments.Controller()
|
||||||
|
|
||||||
def test_list_empty_environments(self):
|
def test_list_empty_environments(self):
|
||||||
"""Check that with no environments an empty list is returned"""
|
"""Check that with no environments an empty list is returned."""
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'list_environments': '@'}
|
{'list_environments': '@'}
|
||||||
)
|
)
|
||||||
@ -39,7 +39,7 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
self.assertEqual({'environments': []}, json.loads(result.body))
|
self.assertEqual({'environments': []}, json.loads(result.body))
|
||||||
|
|
||||||
def test_create_environment(self):
|
def test_create_environment(self):
|
||||||
"""Create an environment, test environment.show()"""
|
"""Create an environment, test environment.show()."""
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'list_environments': '@',
|
{'list_environments': '@',
|
||||||
'create_environment': '@',
|
'create_environment': '@',
|
||||||
@ -90,7 +90,7 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
self.assertEqual(3, mock_uuid.call_count)
|
self.assertEqual(3, mock_uuid.call_count)
|
||||||
|
|
||||||
def test_missing_environment(self):
|
def test_missing_environment(self):
|
||||||
"""Check that a missing environment results in an HTTPNotFound"""
|
"""Check that a missing environment results in an HTTPNotFound."""
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'show_environment': '@'}
|
{'show_environment': '@'}
|
||||||
)
|
)
|
||||||
@ -102,7 +102,7 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
self.assertEqual(404, result.status_code)
|
self.assertEqual(404, result.status_code)
|
||||||
|
|
||||||
def test_update_environment(self):
|
def test_update_environment(self):
|
||||||
"""Check that environment rename works"""
|
"""Check that environment rename works."""
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'show_environment': '@',
|
{'show_environment': '@',
|
||||||
'update_environment': '@'}
|
'update_environment': '@'}
|
||||||
@ -159,7 +159,7 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
self.assertEqual(expected, json.loads(result.body))
|
self.assertEqual(expected, json.loads(result.body))
|
||||||
|
|
||||||
def test_delete_environment(self):
|
def test_delete_environment(self):
|
||||||
"""Test that environment deletion results in the correct rpc call"""
|
"""Test that environment deletion results in the correct rpc call."""
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'delete_environment': '@'}
|
{'delete_environment': '@'}
|
||||||
)
|
)
|
||||||
|
@ -20,7 +20,7 @@ from murano.tests.unit import base
|
|||||||
|
|
||||||
class TestModels(base.MuranoWithDBTestCase):
|
class TestModels(base.MuranoWithDBTestCase):
|
||||||
def test_missing_blob(self):
|
def test_missing_blob(self):
|
||||||
"""Fake a package with NULL supplier JSON blob to test bug 1342306"""
|
"""Fake a package with NULL supplier JSON blob to test bug 1342306."""
|
||||||
con = session.get_session().connection()
|
con = session.get_session().connection()
|
||||||
con.execute("INSERT INTO package(id, fully_qualified_name, "
|
con.execute("INSERT INTO package(id, fully_qualified_name, "
|
||||||
"owner_id, name, description, created, updated, type, "
|
"owner_id, name, description, created, updated, type, "
|
||||||
|
@ -38,8 +38,7 @@ class TestResultsSerializer(test_case.DslTestCase):
|
|||||||
self._runner = self.new_runner(self._root_class)
|
self._runner = self.new_runner(self._root_class)
|
||||||
|
|
||||||
def _test_data_in_section(self, name, serialized):
|
def _test_data_in_section(self, name, serialized):
|
||||||
"""
|
"""Test that a section of Object Model has expected structure and
|
||||||
Test that a section of Object Model has expected structure and
|
|
||||||
property values that are equal to those originally loaded
|
property values that are equal to those originally loaded
|
||||||
(e.g. that Model -> Load -> Serialize = Model)
|
(e.g. that Model -> Load -> Serialize = Model)
|
||||||
|
|
||||||
@ -63,8 +62,7 @@ class TestResultsSerializer(test_case.DslTestCase):
|
|||||||
'sampleClass']['stringProperty'])
|
'sampleClass']['stringProperty'])
|
||||||
|
|
||||||
def test_results_serialize(self):
|
def test_results_serialize(self):
|
||||||
"""
|
"""Test that serialized Object Model has both Objects and ObjectsCopy
|
||||||
Test that serialized Object Model has both Objects and ObjectsCopy
|
|
||||||
sections and they both contain the same property values and object
|
sections and they both contain the same property values and object
|
||||||
headers. Note, that Objects section may contain additional designer
|
headers. Note, that Objects section may contain additional designer
|
||||||
metadata and information on available actions that is not needed in
|
metadata and information on available actions that is not needed in
|
||||||
@ -79,8 +77,7 @@ class TestResultsSerializer(test_case.DslTestCase):
|
|||||||
self._test_data_in_section('ObjectsCopy', serialized)
|
self._test_data_in_section('ObjectsCopy', serialized)
|
||||||
|
|
||||||
def test_actions(self):
|
def test_actions(self):
|
||||||
"""
|
"""Test that information on actions can be invoked on each MuranoPL
|
||||||
Test that information on actions that can be invoked on each MuranoPL
|
|
||||||
object are persisted into object header ('?' key) during serialization
|
object are persisted into object header ('?' key) during serialization
|
||||||
of Objects section of Object Model
|
of Objects section of Object Model
|
||||||
|
|
||||||
@ -96,8 +93,7 @@ class TestResultsSerializer(test_case.DslTestCase):
|
|||||||
matchers.StartsWith('test'))
|
matchers.StartsWith('test'))
|
||||||
|
|
||||||
def test_attribute_serialization(self):
|
def test_attribute_serialization(self):
|
||||||
"""
|
"""Test that attributes produced by MuranoPL code are persisted in
|
||||||
Test that attributes produced by MuranoPL code are persisted in
|
|
||||||
dedicated section of Object Model. Attributes are values that are
|
dedicated section of Object Model. Attributes are values that are
|
||||||
stored in special key-value storage that is private to each class.
|
stored in special key-value storage that is private to each class.
|
||||||
Classes can store state data there. Attributes are persisted across
|
Classes can store state data there. Attributes are persisted across
|
||||||
@ -116,8 +112,7 @@ class TestResultsSerializer(test_case.DslTestCase):
|
|||||||
serialized['Attributes'][0])
|
serialized['Attributes'][0])
|
||||||
|
|
||||||
def test_attribute_deserialization(self):
|
def test_attribute_deserialization(self):
|
||||||
"""
|
"""Test that attributes that are put into Attributes section of
|
||||||
Test that attributes that are put into Attributes section of
|
|
||||||
Object Model become available to appropriate MuranoPL classes
|
Object Model become available to appropriate MuranoPL classes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class TestHeatStack(base.MuranoTestCase):
|
|||||||
|
|
||||||
@mock.patch('heatclient.client.Client')
|
@mock.patch('heatclient.client.Client')
|
||||||
def test_push_adds_version(self, mock_heat_client):
|
def test_push_adds_version(self, mock_heat_client):
|
||||||
"""Assert that if heat_template_version is omitted, it's added"""
|
"""Assert that if heat_template_version is omitted, it's added."""
|
||||||
# Note that the 'with x as y, a as b:' syntax was introduced in
|
# Note that the 'with x as y, a as b:' syntax was introduced in
|
||||||
# python 2.7, and contextlib.nested was deprecated in py2.7
|
# python 2.7, and contextlib.nested was deprecated in py2.7
|
||||||
with mock.patch(MOD_NAME + '.HeatStack._get_status') as status_get:
|
with mock.patch(MOD_NAME + '.HeatStack._get_status') as status_get:
|
||||||
@ -66,7 +66,7 @@ class TestHeatStack(base.MuranoTestCase):
|
|||||||
|
|
||||||
@mock.patch('heatclient.client.Client')
|
@mock.patch('heatclient.client.Client')
|
||||||
def test_description_is_optional(self, mock_heat_client):
|
def test_description_is_optional(self, mock_heat_client):
|
||||||
"""Assert that if heat_template_version is omitted, it's added"""
|
"""Assert that if heat_template_version is omitted, it's added."""
|
||||||
# Note that the 'with x as y, a as b:' syntax was introduced in
|
# Note that the 'with x as y, a as b:' syntax was introduced in
|
||||||
# python 2.7, and contextlib.nested was deprecated in py2.7
|
# python 2.7, and contextlib.nested was deprecated in py2.7
|
||||||
with mock.patch(MOD_NAME + '.HeatStack._get_status') as status_get:
|
with mock.patch(MOD_NAME + '.HeatStack._get_status') as status_get:
|
||||||
@ -98,7 +98,7 @@ class TestHeatStack(base.MuranoTestCase):
|
|||||||
self.assertTrue(hs._applied)
|
self.assertTrue(hs._applied)
|
||||||
|
|
||||||
def test_update_wrong_template_version(self):
|
def test_update_wrong_template_version(self):
|
||||||
"""Template version other than expected should cause error"""
|
"""Template version other than expected should cause error."""
|
||||||
|
|
||||||
hs = heat_stack.HeatStack(self.mock_murano_obj,
|
hs = heat_stack.HeatStack(self.mock_murano_obj,
|
||||||
None, None, None)
|
None, None, None)
|
||||||
|
5
tox.ini
5
tox.ini
@ -36,13 +36,10 @@ deps = flake8
|
|||||||
commands = flake8
|
commands = flake8
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# H202 assertRaises Exception too broad
|
|
||||||
# H402 one line docstring needs punctuation
|
|
||||||
# H404 multi line docstring should start without a leading new line
|
|
||||||
# H501 Do not use locals() for string formatting
|
# H501 Do not use locals() for string formatting
|
||||||
# H702 Argument to _ must be just a string
|
# H702 Argument to _ must be just a string
|
||||||
# H902 Use the 'not in' operator for collection membership evaluation
|
# H902 Use the 'not in' operator for collection membership evaluation
|
||||||
ignore = H202,H402,H404,H501,H702,H902
|
ignore =H501,H702,H902
|
||||||
show-source = true
|
show-source = true
|
||||||
builtins = _
|
builtins = _
|
||||||
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools
|
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools
|
||||||
|
Loading…
x
Reference in New Issue
Block a user