diff --git a/bin/manila-manage b/bin/manila-manage index 295174d119..15e14d1633 100755 --- a/bin/manila-manage +++ b/bin/manila-manage @@ -95,6 +95,7 @@ def args(*args, **kwargs): def param2id(object_id): """Helper function to convert various id types to internal id. + args: [object_id], e.g. 'vol-0000000a' or 'volume-0000000a' or '10' """ if uuidutils.is_uuid_like(object_id): @@ -169,6 +170,7 @@ class ShellCommands(object): @args('--path', required=True, help='Script path') def script(self, path): """Runs the script from the specifed path with flags set properly. + arguments: path """ exec(compile(open(path).read(), path, 'exec'), locals(), globals()) @@ -189,6 +191,7 @@ class HostCommands(object): help='Availability Zone (default: %(default)s)') def list(self, zone=None): """Show a list of all physical hosts. Filter by zone. + args: [zone] """ print("%-25s\t%-15s" % (_('host'), _('zone'))) @@ -354,8 +357,9 @@ CATEGORIES = { def methods_of(obj): - """Get all callable methods of an object that don't start with underscore - returns a list of tuples of the form (method_name, method) + """Get all callable methods of an object that don't start with underscore. + + Returns a list of tuples of the form (method_name, method). """ result = [] for i in dir(obj): diff --git a/contrib/tempest/tempest/services/share/json/shares_client.py b/contrib/tempest/tempest/services/share/json/shares_client.py index ce9ded3427..95e4094e10 100644 --- a/contrib/tempest/tempest/services/share/json/shares_client.py +++ b/contrib/tempest/tempest/services/share/json/shares_client.py @@ -358,8 +358,8 @@ class SharesClient(rest_client.RestClient): return resp, self._parse_resp(body) def reset_state(self, s_id, status="error", s_type="shares"): - """ - Resets the state of a share or a snapshot + """Resets the state of a share or a snapshot. + status: available, error, creating, deleting, error_deleting s_type: shares, snapshots """ @@ -368,8 +368,8 @@ class SharesClient(rest_client.RestClient): return self.post("%s/%s/action" % (s_type, s_id), body) def force_delete(self, s_id, s_type="shares"): - """ - Force delete share or snapshot + """Force delete share or snapshot. + s_type: shares, snapshots """ body = {"os-force_delete": None} diff --git a/manila/api/middleware/sizelimit.py b/manila/api/middleware/sizelimit.py index c98eebb916..83f62f40be 100644 --- a/manila/api/middleware/sizelimit.py +++ b/manila/api/middleware/sizelimit.py @@ -39,7 +39,8 @@ LOG = logging.getLogger(__name__) class LimitingReader(object): """Reader to limit the size of an incoming request.""" def __init__(self, data, limit): - """ + """Initialize LimitingReader. + :param data: Underlying data object :param limit: maximum number of bytes the reader should allow """ diff --git a/manila/api/v1/limits.py b/manila/api/v1/limits.py index a4691fcab3..24d9f1e107 100644 --- a/manila/api/v1/limits.py +++ b/manila/api/v1/limits.py @@ -74,15 +74,11 @@ class LimitsTemplate(xmlutil.TemplateBuilder): class LimitsController(object): - """ - Controller for accessing limits in the OpenStack API. - """ + """Controller for accessing limits in the OpenStack API.""" @wsgi.serializers(xml=LimitsTemplate) def index(self, req): - """ - Return all global and rate limit information. - """ + """Return all global and rate limit information.""" context = req.environ['manila.context'] quotas = QUOTAS.get_project_quotas(context, context.project_id, usages=False) @@ -101,9 +97,7 @@ def create_resource(): class Limit(object): - """ - Stores information about a limit for HTTP requests. - """ + """Stores information about a limit for HTTP requests.""" UNITS = { 1: "SECOND", @@ -115,8 +109,7 @@ class Limit(object): UNIT_MAP = dict([(v, k) for k, v in UNITS.items()]) def __init__(self, verb, uri, regex, value, unit): - """ - Initialize a new `Limit`. + """Initialize a new `Limit`. @param verb: HTTP verb (POST, PUT, etc.) @param uri: Human-readable URI @@ -146,8 +139,7 @@ class Limit(object): self.error_message = msg % self.__dict__ def __call__(self, verb, url): - """ - Represents a call to this limit from a relevant request. + """Represents a call to this limit from a relevant request. @param verb: string http verb (POST, GET, etc.) @param url: string URL @@ -215,15 +207,16 @@ DEFAULT_LIMITS = [ class RateLimitingMiddleware(base_wsgi.Middleware): - """ - Rate-limits requests passing through this middleware. All limit information - is stored in memory for this implementation. + """Rate-limits requests passing through this middleware. + + All limit information is stored in memory for this implementation. """ def __init__(self, application, limits=None, limiter=None, **kwargs): - """ - Initialize new `RateLimitingMiddleware`, which wraps the given WSGI - application and sets up the given limits. + """Initialize new `RateLimitingMiddleware`. + + `RateLimitingMiddleware` wraps the given WSGI application and + sets up the given limits. @param application: WSGI application to wrap @param limits: String describing limits @@ -247,13 +240,13 @@ class RateLimitingMiddleware(base_wsgi.Middleware): @webob.dec.wsgify(RequestClass=wsgi.Request) def __call__(self, req): - """ - Represents a single call through this middleware. We should record the - request if we have a limit relevant to it. If no limit is relevant to - the request, ignore it. + """Represents a single call through this middleware. - If the request should be rate limited, return a fault telling the user - they are over the limit and need to retry later. + We should record the request if we have a limit relevant to + it. If no limit is relevant to the request, ignore it. + + If the request should be rate limited, return a fault telling + the user they are over the limit and need to retry later. """ verb = req.method url = req.url @@ -277,13 +270,10 @@ class RateLimitingMiddleware(base_wsgi.Middleware): class Limiter(object): - """ - Rate-limit checking class which handles limits in memory. - """ + """Rate-limit checking class which handles limits in memory.""" def __init__(self, limits, **kwargs): - """ - Initialize the new `Limiter`. + """Initialize the new `Limiter`. @param limits: List of `Limit` objects """ @@ -297,14 +287,11 @@ class Limiter(object): self.levels[username] = self.parse_limits(value) def get_limits(self, username=None): - """ - Return the limits for a given user. - """ + """Return the limits for a given user.""" return [limit.display() for limit in self.levels[username]] def check_for_delay(self, verb, url, username=None): - """ - Check the given verb/user/user triplet for limit. + """Check the given verb/user/user triplet for limit. @return: Tuple of delay (in seconds) and error message (or None, None) """ @@ -328,9 +315,9 @@ class Limiter(object): # default limit parsing. @staticmethod def parse_limits(limits): - """ - Convert a string into a list of Limit instances. This - implementation expects a semicolon-separated sequence of + """Convert a string into a list of Limit instances. + + This implementation expects a semicolon-separated sequence of parenthesized groups, where each group contains a comma-separated sequence consisting of HTTP method, user-readable URI, a URI reg-exp, an integer number of @@ -383,9 +370,9 @@ class Limiter(object): class WsgiLimiter(object): - """ - Rate-limit checking from a WSGI application. Uses an in-memory `Limiter`. + """Rate-limit checking from a WSGI application. + Uses an in-memory `Limiter`. To use, POST ``/`` with JSON data such as:: { @@ -399,8 +386,7 @@ class WsgiLimiter(object): """ def __init__(self, limits=None): - """ - Initialize the new `WsgiLimiter`. + """Initialize the new `WsgiLimiter`. @param limits: List of `Limit` objects """ @@ -408,10 +394,11 @@ class WsgiLimiter(object): @webob.dec.wsgify(RequestClass=wsgi.Request) def __call__(self, request): - """ - Handles a call to this application. Returns 204 if the request is - acceptable to the limiter, else a 403 is returned with a relevant - header indicating when the request *will* succeed. + """Handles a call to this application. + + Returns 204 if the request is acceptable to the limiter, else + a 403 is returned with a relevant header indicating when the + request *will* succeed. """ if request.method != "POST": raise webob.exc.HTTPMethodNotAllowed() @@ -435,13 +422,10 @@ class WsgiLimiter(object): class WsgiLimiterProxy(object): - """ - Rate-limit requests based on answers from a remote source. - """ + """Rate-limit requests based on answers from a remote source.""" def __init__(self, limiter_address): - """ - Initialize the new `WsgiLimiterProxy`. + """Initialize the new `WsgiLimiterProxy`. @param limiter_address: IP/port combination of where to request limit """ @@ -472,9 +456,9 @@ class WsgiLimiterProxy(object): # decisions are made by a remote server. @staticmethod def parse_limits(limits): - """ - Ignore a limits string--simply doesn't apply for the limit - proxy. + """Ignore a limits string. + + This simply doesn't apply for the limit proxy. @return: Empty list. """ diff --git a/manila/api/v1/router.py b/manila/api/v1/router.py index a722b4aedd..f8c0bed703 100644 --- a/manila/api/v1/router.py +++ b/manila/api/v1/router.py @@ -39,7 +39,8 @@ LOG = logging.getLogger(__name__) class APIRouter(manila.api.openstack.APIRouter): - """ + """Route API requests. + Routes requests on the OpenStack API to the appropriate controller and method. """ diff --git a/manila/api/views/versions.py b/manila/api/views/versions.py index 371033ded6..d04cc17d20 100644 --- a/manila/api/views/versions.py +++ b/manila/api/views/versions.py @@ -26,7 +26,8 @@ def get_view_builder(req): class ViewBuilder(object): def __init__(self, base_url): - """ + """Initialize ViewBuilder. + :param base_url: url of the root wsgi application """ self.base_url = base_url diff --git a/manila/api/xmlutil.py b/manila/api/xmlutil.py index b9d32a114c..99f08a1c5f 100644 --- a/manila/api/xmlutil.py +++ b/manila/api/xmlutil.py @@ -864,9 +864,7 @@ class TemplateBuilder(object): def make_links(parent, selector=None): - """ - Attach an Atom element to the parent. - """ + """Attach an Atom element to the parent.""" elem = SubTemplateElement(parent, '{%s}link' % XMLNS_ATOM, selector=selector) @@ -879,7 +877,8 @@ def make_links(parent, selector=None): def make_flat_dict(name, selector=None, subselector=None, ns=None): - """ + """Utility for simple XML templates. + Utility for simple XML templates that traditionally used XMLDictSerializer with no metadata. Returns a template element where the top-level element has the given tag name, and where diff --git a/manila/common/config.py b/manila/common/config.py index 81e7cd449f..c5d0f8dd8f 100644 --- a/manila/common/config.py +++ b/manila/common/config.py @@ -36,8 +36,7 @@ CONF = cfg.CONF def _get_my_ip(): - """ - Returns the actual ip of the local machine. + """Returns the actual ip of the local machine. This code figures out what source address would be used if some traffic were to be sent out to some well known address on the Internet. In this diff --git a/manila/context.py b/manila/context.py index 82e8b458c7..0bc6e9ce95 100644 --- a/manila/context.py +++ b/manila/context.py @@ -48,7 +48,8 @@ class RequestContext(object): roles=None, remote_address=None, timestamp=None, request_id=None, auth_token=None, overwrite=True, quota_class=None, service_catalog=None, **kwargs): - """ + """Initialize RequestContext. + :param read_deleted: 'no' indicates deleted records are hidden, 'yes' indicates deleted records are visible, 'only' indicates that *only* deleted records are visible. diff --git a/manila/network/linux/ip_lib.py b/manila/network/linux/ip_lib.py index fb2da66216..d8f5b01633 100644 --- a/manila/network/linux/ip_lib.py +++ b/manila/network/linux/ip_lib.py @@ -334,7 +334,9 @@ class IpRouteCommand(IpDeviceCommandBase): return retval def pullup_route(self, interface_name): - """Ensures that the route entry for the interface is before all + """Pullup route entry. + + Ensures that the route entry for the interface is before all others on the same subnet. """ device_list = [] diff --git a/manila/network/neutron/neutron_network_plugin.py b/manila/network/neutron/neutron_network_plugin.py index dfb01eca44..a3dec9e95e 100644 --- a/manila/network/neutron/neutron_network_plugin.py +++ b/manila/network/neutron/neutron_network_plugin.py @@ -34,9 +34,10 @@ class NeutronNetworkPlugin(manila_network.NetworkBaseAPI, db_base.Base): self.neutron_api = neutron_api.API() def allocate_network(self, context, share_server, share_network, **kwargs): - """Allocate network resources using given network information: create - neutron ports for a given neutron network and subnet, create manila db - records for allocated neutron ports. + """Allocate network resources using given network information. + + Create neutron ports for a given neutron network and subnet, + create manila db records for allocated neutron ports. :param context: RequestContext object :param share_network: share network data @@ -64,9 +65,10 @@ class NeutronNetworkPlugin(manila_network.NetworkBaseAPI, db_base.Base): return ports def deallocate_network(self, context, share_server): - """Deallocate neutron network resources for the given network info: - delete previously allocated neutron ports, delete manila db records for - deleted ports. + """Deallocate neutron network resources for the given network info. + + Delete previously allocated neutron ports, delete manila db + records for deleted ports. :param context: RequestContext object :param share_network: share network data diff --git a/manila/policy.py b/manila/policy.py index 7f9a6a68a5..8a9ac98fe6 100644 --- a/manila/policy.py +++ b/manila/policy.py @@ -84,8 +84,7 @@ def check_is_admin(roles): def wrap_check_policy(resource): - """Check policy corresponding to the wrapped methods prior to execution. - """ + """Check policy corresponding to the wrapped methods prior to execution.""" def check_policy_wraper(func): @functools.wraps(func) def wrapped(self, context, target_obj, *args, **kwargs): diff --git a/manila/quota.py b/manila/quota.py index c683babbfb..c0db7d2b2f 100644 --- a/manila/quota.py +++ b/manila/quota.py @@ -61,7 +61,8 @@ CONF.register_opts(quota_opts) class DbQuotaDriver(object): - """ + """Database Quota driver. + Driver to perform necessary checks to enforce quotas and obtain quota information. The default driver utilizes the local database. @@ -98,7 +99,8 @@ class DbQuotaDriver(object): def get_class_quotas(self, context, resources, quota_class, defaults=True): - """ + """Retrieve quotas for a quota class. + Given a list of resources, retrieve the quotas for the given quota class. @@ -172,7 +174,8 @@ class DbQuotaDriver(object): def get_project_quotas(self, context, resources, project_id, quota_class=None, defaults=True, usages=True, remains=False): - """ + """Retrieve quotas for project. + Given a list of resources, retrieve the quotas for the given project. @@ -206,7 +209,8 @@ class DbQuotaDriver(object): def get_user_quotas(self, context, resources, project_id, user_id, quota_class=None, defaults=True, usages=True): - """ + """Retrieve quotas for user and project. + Given a list of resources, retrieve the quotas for the given user and project. @@ -243,7 +247,8 @@ class DbQuotaDriver(object): def get_settable_quotas(self, context, resources, project_id, user_id=None): - """ + """Retrieve range of settable quotas. + Given a list of resources, retrieve the range of settable quotas for the given user or project. @@ -275,7 +280,8 @@ class DbQuotaDriver(object): def _get_quotas(self, context, resources, keys, has_sync, project_id=None, user_id=None): - """ + """Retrieve quotas for a resource. + A helper method which retrieves the quotas for the specific resources identified by keys, and which apply to the current context. @@ -503,7 +509,8 @@ class DbQuotaDriver(object): user_id=user_id) def usage_reset(self, context, resources): - """ + """Reset usage records. + Reset the usage records for a particular user on a list of resources. This will force that user's usage records to be refreshed the next time a reservation is made. @@ -533,7 +540,8 @@ class DbQuotaDriver(object): pass def destroy_all_by_project(self, context, project_id): - """ + """Destroy metadata associated with a project. + Destroy all quotas, usages, and reservations associated with a project. @@ -544,7 +552,8 @@ class DbQuotaDriver(object): db.quota_destroy_all_by_project(context, project_id) def destroy_all_by_project_and_user(self, context, project_id, user_id): - """ + """Destroy metadata associated with a project and user. + Destroy all quotas, usages, and reservations associated with a project and user. @@ -571,8 +580,7 @@ class BaseResource(object): """Describe a single resource for quota checking.""" def __init__(self, name, flag=None): - """ - Initializes a Resource. + """Initializes a Resource. :param name: The name of the resource, i.e., "shares". :param flag: The name of the flag or configuration option @@ -584,7 +592,8 @@ class BaseResource(object): self.flag = flag def quota(self, driver, context, **kwargs): - """ + """Obtain quota for a resource. + Given a driver and context, obtain the quota for this resource. @@ -641,8 +650,7 @@ class ReservableResource(BaseResource): """Describe a reservable resource.""" def __init__(self, name, sync, flag=None): - """ - Initializes a ReservableResource. + """Initializes a ReservableResource. Reservable resources are those resources which directly correspond to objects in the database, i.e., shares, gigabytes, @@ -680,14 +688,14 @@ class AbsoluteResource(BaseResource): class CountableResource(AbsoluteResource): - """ + """Describe a countable resource. + Describe a resource where the counts aren't based solely on the project ID. """ def __init__(self, name, count, flag=None): - """ - Initializes a CountableResource. + """Initializes a CountableResource. Countable resources are those resources which directly correspond to objects in the database, i.e., shares, gigabytes, @@ -1000,7 +1008,8 @@ class QuotaEngine(object): LOG.debug("Rolled back reservations %s", reservations) def usage_reset(self, context, resources): - """ + """Reset usage records. + Reset the usage records for a particular user on a list of resources. This will force that user's usage records to be refreshed the next time a reservation is made. @@ -1017,7 +1026,8 @@ class QuotaEngine(object): self._driver.usage_reset(context, resources) def destroy_all_by_project_and_user(self, context, project_id, user_id): - """ + """Destroy metadata associated with a project and user. + Destroy all quotas, usages, and reservations associated with a project and user. @@ -1030,7 +1040,8 @@ class QuotaEngine(object): project_id, user_id) def destroy_all_by_project(self, context, project_id): - """ + """Destroy metadate associated with a project. + Destroy all quotas, usages, and reservations associated with a project. diff --git a/manila/scheduler/scheduler_options.py b/manila/scheduler/scheduler_options.py index f01769b56c..8df1480b1d 100644 --- a/manila/scheduler/scheduler_options.py +++ b/manila/scheduler/scheduler_options.py @@ -43,7 +43,8 @@ LOG = logging.getLogger(__name__) class SchedulerOptions(object): - """ + """Monitor and load local .json file for filtering and weighing. + SchedulerOptions monitors a local .json file for changes and loads it if needed. This file is converted to a data structure and passed into the filtering and weighing functions which can use it for dynamic diff --git a/manila/tests/api/test_common.py b/manila/tests/api/test_common.py index 88f8038b67..925664789d 100644 --- a/manila/tests/api/test_common.py +++ b/manila/tests/api/test_common.py @@ -31,10 +31,11 @@ ATOMNS = "{http://www.w3.org/2005/Atom}" class LimiterTest(test.TestCase): - """ - Unit tests for the `manila.api.common.limited` method which takes - in a list of items and, depending on the 'offset' and 'limit' GET params, - returns a subset or complete set of the given items. + """Unit tests for the `manila.api.common.limited` method. + + Takes in a list of items and, depending on the 'offset' and + 'limit' GET params, returns a subset or complete set of the given + items. """ def setUp(self): @@ -155,10 +156,10 @@ class LimiterTest(test.TestCase): class PaginationParamsTest(test.TestCase): - """ - Unit tests for the `manila.api.common.get_pagination_params` - method which takes in a request object and returns 'marker' and 'limit' - GET params. + """Unit tests for the `manila.api.common.get_pagination_params` method. + + Takes in a request object and returns 'marker' and 'limit' GET + params. """ def test_no_params(self): diff --git a/manila/tests/api/v1/test_limits.py b/manila/tests/api/v1/test_limits.py index 8d76e2f67b..a48d83f8d3 100644 --- a/manila/tests/api/v1/test_limits.py +++ b/manila/tests/api/v1/test_limits.py @@ -330,7 +330,8 @@ class LimitTest(BaseLimitTestSuite): class ParseLimitsTest(BaseLimitTestSuite): - """ + """Test default limits parser. + Tests for the default limits parser in the in-memory `limits.Limiter` class. """ @@ -415,7 +416,8 @@ class LimiterTest(BaseLimitTestSuite): return sum(item for item in results if item) def test_no_delay_GET(self): - """ + """Test no delay on GET for single call. + Simple test to ensure no delay on a single call for a limit verb we didn"t set. """ @@ -423,14 +425,16 @@ class LimiterTest(BaseLimitTestSuite): self.assertEqual(delay, (None, None)) def test_no_delay_PUT(self): - """ + """Test no delay on single call. + Simple test to ensure no delay on a single call for a known limit. """ delay = self.limiter.check_for_delay("PUT", "/anything") self.assertEqual(delay, (None, None)) def test_delay_PUT(self): - """ + """Ensure 11th PUT will be delayed. + Ensure the 11th PUT will result in a delay of 6.0 seconds until the next request will be granced. """ @@ -440,7 +444,8 @@ class LimiterTest(BaseLimitTestSuite): self.assertEqual(expected, results) def test_delay_POST(self): - """ + """Ensure 8th POST will be delayed. + Ensure the 8th POST will result in a delay of 6.0 seconds until the next request will be granced. """ @@ -460,7 +465,8 @@ class LimiterTest(BaseLimitTestSuite): self.assertEqual(expected, results) def test_delay_PUT_volumes(self): - """ + """Ensure PUT limits. + Ensure PUT on /volumes limits at 5 requests, and PUT elsewhere is still OK after 5 requests...but then after 11 total requests, PUT limiting kicks in. @@ -476,7 +482,8 @@ class LimiterTest(BaseLimitTestSuite): self.assertEqual(expected, results) def test_delay_PUT_wait(self): - """ + """Test limit handling. + Ensure after hitting the limit and then waiting for the correct amount of time, the limit will be lifted. """ @@ -628,7 +635,8 @@ class FakeHttplibConnection(object): self.host = host def request(self, method, path, body="", headers=None): - """ + """Transalate request to WSGI app. + Requests made via this connection actually get translated and routed into our WSGI app, we then wait for the response and turn it back into an `httplib.HTTPResponse`. diff --git a/manila/tests/test_migrations.py b/manila/tests/test_migrations.py index 346c4f42d0..6a858e892a 100644 --- a/manila/tests/test_migrations.py +++ b/manila/tests/test_migrations.py @@ -141,9 +141,10 @@ class ManilaMigrationsCheckers(test_migrations.WalkVersionsMixin): raise def test_walk_versions(self): - """ - Walks all version scripts for each tested database, ensuring - that there are no errors in the version scripts for each engine + """Walks all version scripts for each tested database. + + While walking, ensur that there are no errors in the version + scripts for each engine. """ with mock.patch('manila.db.sqlalchemy.api.get_engine', return_value=self.engine): diff --git a/tools/lintstack.py b/tools/lintstack.py index 0406435d41..4162cac760 100755 --- a/tools/lintstack.py +++ b/tools/lintstack.py @@ -71,8 +71,10 @@ class LintOutput(object): @classmethod def from_msg_to_dict(cls, msg): - """From the output of pylint msg, to a dict, where each key - is a unique error identifier, value is a list of LintOutput + """From the output of pylint msg, to a dict. + + Each key is a unique error identifier, value is a list of + LintOutput. """ result = {} for line in msg.splitlines(): diff --git a/tox.ini b/tox.ini index 69ab625fee..83cee78e40 100644 --- a/tox.ini +++ b/tox.ini @@ -50,6 +50,6 @@ commands = bash tools/lintstack.sh # # H904 wrap long lines in parentheses instead of a backslash # reason: removed in hacking (https://review.openstack.org/#/c/101701/) -ignore = H404,H405,H501,H904 +ignore = H405,H501,H904 builtins = _ exclude = .venv,.tox,dist,doc,openstack,*egg