Commit Graph

28 Commits

Author SHA1 Message Date
Brian Haley 86badcfe2d Fix some pylint indentation warnings
Running with a stricter .pylintrc generates a lot of
C0330 warnings (hanging/continued indentation). Fix
some remaining ones in miscellaneous directories.

Also cleanup any remaining code that I missed in this
series, or has changed since I started.

Trivialfix

Change-Id: I17b4779020a7bfb369c3e721ab6638cd4a6ab50c
2022-12-12 11:48:25 -05:00
zhouhenglc 45612ca52f fix update neutron resource with incorrect body key server return 500
In current neutron, when I update resource with incorrect body, neutron
server return 500 NeutronError. It should be fixed and BadRequest (400)
should be returned.
This patch fixed it.

Change-Id: I024b8ef73be69af069e4516dc501df3f5c145419
Partial-bug: #1838587
2019-08-09 08:53:28 +08:00
zhufl 65f1a7e521 Add missing ws seperator between words
This is to add missing ws seperator between words, usually
in log messages.

Change-Id: Ia975aba3883ce7b3be3cc22044a8cb33ee215f85
2018-11-19 13:57:05 +08:00
Jenkins 863fb129f9 Merge "Pecan: Add missing emulated bulk create method" 2017-09-12 01:01:44 +00:00
Kevin Benton 444f802012 Pecan: Add missing body validations
This changes the pecan body validation to bring parity with the
old legacy controller code.

* If a body is present on POST/PUT, it must be a JSON dict
* DELETEs to an item must not contain a body
* A POST request to the standard collection controller must have
  resources in the body.

Closes-Bug: #1714348
Change-Id: I1568285c28d227bacf038b3667466a20d3947ca9
2017-09-08 10:56:31 -07:00
Kevin Benton fb76c4f57d Pecan: Add missing emulated bulk create method
This adds the simple bulk emulation logic that was present
in the old legacy controller for plugins that do not support
bulk operations.

Closes-Bug: #1714355
Change-Id: I4ff02b9c5c007847edd18ec4ad6794257dd79576
2017-09-01 21:38:50 +00:00
Inessa Vasilevskaya 7322bd6efb Make code follow log translation guideline
Since Pike log messages should not be translated.
This patch removes calls to i18n _LC, _LI, _LE, _LW from
logging logic throughout the code. Translators definition
from neutron._i18n is removed as well.
This patch also removes log translation verification from
ignore directive in tox.ini.

Change-Id: If9aa76fcf121c0e61a7c08088006c5873faee56e
2017-08-14 02:01:48 +00:00
Kevin Benton d67a96664d Don't return content when we set HTTP 204
Pecan json renderer converts a None response from a controller
into a string 'null' in the HTTP response. This directly conflicts
with us setting an HTTP 204 in the response to HTTP DELETE calls.
The legacy API did not return data on HTTP DELETE calls.

The result of saying we were providing no content and then providing
content was strange behavior with Apache2 mod_proxy (the way devstack
deploys Neutron) where connections would be unusable after a DELETE
call. Since mod_proxy re-uses connections, this would cause long
pauses until connection timeouts occurred.

Change-Id: Ie2fd9108f7b8a60c2574dab31b586ee43fd2a789
2016-12-19 17:40:57 -08:00
Henry Gessau 4151486bd4 Remove REVERSED_PLURALS and get_resource_info()
By changing pecan to store plugins by collection (plural) instead of
resource (singular) we don't need REVERSED_PLURALS and
get_resource_info().

These are not used outside of neutron core.

Consequently, this exposed a bug with some controllers not honoring an
extension's intention of disallowing pagination and sorting.  This is
also fixed in this patch to get successful test runs.

Co-Authored-By: Brandon Logan <brandon.logan@rackspace.com>

Change-Id: I9d529d0a2ad369e2be0a8df3c6f06a6532e8b13d
2016-11-23 11:11:12 -05:00
Jenkins b474012731 Merge "Pecan: No fields to plugin on GET member actions" 2016-11-22 20:51:35 +00:00
Brandon Logan 3e44d75660 Pecan: Find subresource controllers by parent
Fix for finding subresource controller by parent and
added functional tests

Change-Id: I34bb1968fdc3daa75f8a60f5ad9aa68cc3414ad5
closes-Bug: #1633665
2016-11-07 15:07:43 -07:00
Brandon Logan 1392d37d3d Pecan: No fields to plugin on GET member actions
The legacy wsgi does not pass the fields query parameters down to the
plugin layer on GET member actions.  Pecan should follow suit to
maintain compatibility.

Change-Id: Ic9ef676b75464eaba58ff1403c8969610e9a9a6a
Closes-Bug: #1639109
2016-11-03 21:43:45 -05:00
Brandon Logan 64252405c4 Pecan: Bulk create with one item returns plural
If a bulk create happened with a single item, the pecan code would
return back to the user the singular version of the resource in the
body.  For example, to bulk create many security group rules, the user
would give in the body of the request the json with a parent key of
"security-group-rules" with a value of a list of json security group
rules.  If this list is of length one, then after the creation of the
one security group rule, the API would return back to the client
"security-group-rule" as the parent key.  This is not how the legacy
wsgi layer behaved.  The behavior is expected when nova creates security
group rules by calling the neutron API through its deprecated security
groups API.

Change-Id: I8757630403e4d486cd3c8dd6f041e9ee326ba3b4
Closes-Bug: #1633671
2016-10-20 19:03:08 -05:00
Brandon Logan 6e908dd417 Pecan: Handle member actions
The legacy pecan uri routing allowed the definition of member actions.
These are API resources that hang off a particular resource_id.  An
example of this is:

PUT /routers/{router_id}/add_router_interface

The legacy seemed to do only PUTs and GETs so that has been implemented
in Pecan.  Other methods can easily be added if needed.

Also, with the generic handling of this came the decision to remove the
specific pecan routers controller because it's only function was to
facilitate its member actions to work.  It is no longer needed.

Change-Id: If776476545edca0c4c43ce3969bb5d1af79f4382
2016-08-30 00:34:02 -05:00
tonytan4ever 9e87a70a1a Add subresources support for PECAN
Implements adding a subresource (of extensions) to its parents
A resource and a subresource has a parent-child relationship, for
example:
A qos resource has a subresource of bandwith_limit_rules. This patch
will allow urls like : /qos/policies/{policy_id}/bandwidth_limit_rules to
work.

Change-Id: Ib2288234710fd6eed7fb9f6b880f57c9dd3beade
2016-07-22 11:02:27 -04:00
Brandon Logan a2016a6211 Pecan: Define plugin crud methods in base class
Refactors the current pecan code to use predefined methods to get
the plugin methods the controllers will call.  This also adds in
parent resource information to build those method names, but parent
support will not be complete until a follow up patch.

Change-Id: I4e0e6ef96364991a9393bc5fba495e37dade68a1
Closes-Bug: #1596754
2016-07-15 11:49:54 -05:00
Brandon Logan 09a6a46e77 Pecan: Implement pagination
Implements pagination and sorting in the QueryParametersHook. Doing
this in a hook keeps the main controller code clean and also doesn't
require implementing pagination and sorting in every controller.

Change-Id: I5f439cf2457984d6b62ce5fed9d5d471aafbde81
Closes-Bug: #1591338
2016-06-24 21:42:17 -05:00
Brandon Logan 6019b163d6 Pecan: move fields and filters logic to hooks
The logic for massaging the fields and filters data was being done in
the controllers.  This change pulls that logic out of the controllers
and puts it in a generic hook so that it's done for all controllers.
This will later be used for pagination, but thats not the main
motivation of this patch.

Ideally, the filters and fields would be passed into the controller
methods themselves as kwargs, but that is not easily done due to pecan
not easily allowing overriding the args and kwargs passed to the
controller methods. For now, the fields and filters will have to be
pulled out of the request context.

Change-Id: Ibea9087c7036faa064b87acb52e09c9a3c74148a
2016-06-24 00:38:04 -05:00
Brandon Logan 8a6d22ccb5 Pecan: handle single fields query parameter
This also correctly handles the case where no fields are requested which seems
to have started to break.

Closes-Bug: #1590588
Change-Id: Ida1e3ff575c7fe6c3199c5f4393679bbf89c0fe1
2016-06-09 21:34:04 +00:00
Brandon Logan 093bd96b9f Pecan: bind attribute map to controllers
The legacy controllers used their own references to the resource
attribute info while pecan was looking for it in the
attributes.RESOURCE_ATTRIBUTE_MAP.  This aligns pecan controllers
with that of the legacy controllers, in that the pecan controllers
now store the their own resource attribute info.

This also fixes a bug that was unnoticed until the above change was
made.  The ItemController's index method was not passing the *args and
**kwargs to the get method.

Change-Id: I1cc85daecfb19f73092e52678fd19ff1a2912195
2016-05-26 06:13:53 +00:00
salvatore 80426cf620 Pecan: tell the plugin about field selection
Neutron plugin are able to do field selection on responses (for
instance only returning id & name for a resource). However,
Pecan does not leverage this capability and always tells the
plugin to fetch all fields, doing field selection while
processing the response.

This patch ensures that pecan send the field list down to the
plugin.

As a part of this patch TestRequestProcessing has been update
to inherit from TestRootController rather than
TestResourceController. Inheriting from the latter was causing
tests to be executed twice for no reason, beyong using
TestResourceController's 'port' attribute, which was however
unnecessary as this change proves.

Closes-Bug: #1570259

Change-Id: Iac930cd3bb14dfdda78e6a94d2c8bef2b5c4b9a5
2016-05-24 12:13:21 -05:00
Akihiro Motoki 44be13a2a6 Hacking rule to check i18n usage
* Detect neutron.i18n import (neutron._i18n is recommended)
* Check builtins _ usage
* 'builtins = _' in tox.ini is no longer required.
* Introduce hacking rule doctest framework.
  Newly added check_builtins_gettext() hacking check takes
  token as argument. It is not a good idea to pass a tokenized
  line manually. Instead it is reasonable to use docstring based
  tests used in hacking repo.

Change-Id: Ib7464658fc4c8a6f1b03af6ab46f0bd3ee0bfb18
2016-03-30 21:28:37 -04:00
LiuNanke 83ef6b5677 Using LOG.warning replace LOG.warn
Python 3 deprecated the logger.warn method, see:
https://docs.python.org/3/library/logging.html#logging.warning
so we prefer to use warning to avoid DeprecationWarning.

Closes-Bugs: #1529913

Change-Id: Icc01ce5fbd10880440cf75a2e0833394783464a0
Co-Authored-By: Gary Kotton <gkotton@vmware.com>
2016-03-10 11:02:45 -08:00
Brandon Logan 6659428669 Pecan routing for agent schedulers
For pecan to support existing agent scheduler controllers, a couple of shim
pecan controllers need to be added.  These shim controllers will be used if
there are extensions that have legacy controllers that have not been
registered.  The shim controller is just a passthrough to those legacy
controllers.  This may have the added benefit of support existing out of
tree extensions that have defined their legacy extension controllers the
same way.

Changes to how the router(s) controllers determines whether something
is a member action has been changed a bit to support this.

Closes-Bug: #1552978
Co-Authored-By: Kevin Benton <kevin@benton.pub>
Change-Id: Icec56676d83b604c3db3377838076d6429d61e48
2016-03-08 06:35:49 +00:00
Salvatore Orlando f392a04051 Pecan: filter items need type conversion
In order for filtering to work properly on GET requests, filter
values should be converted to the appropriate type specified in
neutron.api.v2.attributes.RESOURCE_ATTRIBUTE_MAP.

Without this change queries on boolean attributes, for instance,
won't work as the value to filter on will be passed to the plugin
as a string.

Closes Bug: #1537924

Change-Id: I0a697a01f272f94378928ecc099232e3b2d11f1f
2016-02-24 09:39:52 +00:00
Salvatore Orlando 12646fa68f Pecan: get rid of member action hook
The MemberAction hook, which parses the URL to find out if there is
anything beyond the resource identifier which might be interpreted as
an action to execute is an abomination and a horrible hack.
This patch does some justice by casting it into the abyss of git
history, hopefully forever.

As a matter of fact, the only Neutron API resource that uses this
capability is the router, with the actions 'add_router_interface' and
'remove_reouter_interface'. Therefore, not without a good deal of
deliberate opinionated thinking, this patch adds a specialiized Pecan
controller for the router resource rather than adding the abiity to
handle member actions in the generic resource controller.
The main driver behind this decision is that "member actions" should
be avoided as much as possile, and there is not yet an agreed-upon API
guideline on how they should be expressed in OpenStack APIs.

The 'router' extension (neutron/extensions/l3.py) has also been
"pecanized", by returning a RouterController for routers and an
instance of the generic ItemController for floating IPs.

Moreover, references to the 'member_action' parameter in the request
context are removed. The BodyValidation hook has been updated to
process the request body only if a resource or collection name can be
found in it (member actions don't have any according to the Neutron
API specification).

Finally, this patch adds functional tests specific for validating
member action processing in the router controller.

Related-Blueprint: wsgi-pecan-switch

Change-Id: Ib57472b38f5b1576387c8bf49c082ce25d3e5bd6
2016-02-19 04:30:08 -08:00
Salvatore Orlando 7c24fa111e Pecan: wrap PUT response with resource name
For no peculiar reason other than that's the way the API is
supposed to work.

Change-Id: Ifd6f8b492dfc86c069a4f33931235c7f3d8e7c2e
Closes-Bug: #1537929
2016-02-10 00:45:24 +00:00
Salvatore Orlando cf8f60e5f3 Pecan: Controller and test refactor
This patch refactors the pecan controllers and functional tests
by spliting the code in several modules in order to avoid excessive
growth and ensure some level of consistency as regards function
and classes defined in each module.

To this aim:
- The generic resource controllers are moved into their own module
- Other controllers, such as extension and quotas, are moved into
  their own module
- Functional tests are split into 3 modules: one for generic tests,
  one for request processing tests, and the latter for testing hooks.

Related blueprint wsgi-pecan-switch

Change-Id: Id76cd88208dfd273bccadc15a1c6febbcc4fc030
2016-02-09 23:27:25 +00:00