Commit Graph

40 Commits (99f4495c940011293e3cabbb590770dc1e7b6900)

Author SHA1 Message Date
Doug Hellmann 2530ccff8f Upgrade pylint to a version that works with python3
Also fixed some six.moves errors as well.

Change-Id: I9783ee588de1ec4b91a665b9dc89fdba3e2d90df
Signed-off-by: Doug Hellmann <>
5 years ago
Zuul 88741f1547 Merge "Generate correct url in api pagination" 5 years ago
Hongbin Lu 2b1d8ea4a2 Implement filter validation
Enforce validation on filter parameters on list requests.
If an API request contains an unknown or unsupported parameter,
the server will return a 400 response instead of silently ignoring
the invalid input.

In resource attributes map, all filter parameters are annotated by
the ``is_filter`` keyword. Attributes with is_filter set to True
are candidates for validation.

Enabling filter validation requires support from core plugin and
all service plugins so each plugin need to indicate if it supports
the validation by setting ``__filter_validation_support`` to True.
If this field is not set, the default is False and validation is
turned off. Right now, the ML2 plugin and all the in-tree service
plugin support filter validation. Out-of-tree plugins will have
filter validation disabled by default.

An API extension is introduced to allow API users to discover this
new API behavior. This feature can be disabled by cloud operators
if they choose to do that. If it is disabled, the extension won't
be presented.

Depends-On: Ic3ab5b3ffdc378d570678b9c967cb42b0c7a8a9b
Depends-On: I4397df1c35463a8b532afdc9c5d28b37224a37b4
Depends-On: I3f2e6e861adaeef81a1a5819a57b28f5c6281d80
Depends-On: I1189bc9a50308df5c7e18c329f3a1262c90b9e12
Depends-On: I057cd917628c77dd20c0ff7747936c3fec7b4844
Depends-On: I0b24a304cc3466a2c05426cdbb6f9d99f1797edd

Change-Id: I21bf8a752813802822fd9966dda6ab3b6c4abfdc
Partial-Bug: #1749820
5 years ago
Mykola Yakovliev d62d82b0fe Generate correct url in api pagination
Use protocol from X-Forwarded-Proto, and not from current endpoint.

Change-Id: I3fafc4ef1cf56cb8f1cddc1a003a755e3f93c75c
Closes-Bug: 1774460
5 years ago
Hongbin Lu f213ba487b Populate project info before using it
Sorting and filtering will rely on the attributes information. It is
necessary to populate project info before using it to sort/filter.

Closes-Bug: #1765452
Change-Id: Ife90268530b6e86a0b0d213e4742a2ef81cb2395
5 years ago
Zuul d1a580541a Merge "Support filter attribute with empty string" 5 years ago
Brian Haley 7cfdf4aa81 Fix all pep8 E129 errors
Fixed all pep8 E129 errors and changed tox.ini to no longer
ignore them.

Change-Id: I0b06d99ce1d473b79a4cfdd173baa4f02e653847
5 years ago
Hongbin Lu a732bbf19e Support filter attribute with empty string
This will enable users to filter list of results with attributes
with empty value. For example, the request below will list
all unbound ports (unbound ports have blank device_id).

  GET "/ports?device_id="

Change-Id: I9001214de126eb888c2425b6a6275f59ec8478e7
Closes-Bug: #1749304
5 years ago
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
6 years ago
Gary Kotton 5f972ef406 Ensure that fault map translations work correctly
The patch does two things:
1. make the code validation of the code checks more generic
2. enables a extended fault map to be treated correctly (for example

Change-Id: Idc89c0ece2e6ff3b0368f431fea098128bd68c34
6 years ago
Kevin Benton 7f17b4759e API compare-and-swap updates based on revision_number
Allows posting revision number matching in the If-Match header
so updates/deletes will only be satisfied if the current revision
number of the object matches.

DocImpact: The Neutron API now supports conditional updates to resources
           that contain the standard 'revision_number' attribute by
           setting the revision_number in an HTTP If-Match header.

Partial-Bug: #1493714
Partially-Implements: blueprint push-notifications
Change-Id: I7d97d6044378eb59cb2c7bdc788dc6c174783299
6 years ago
Mark Doffman f45957a67f Add a new configuration variable for api links.
Currently we use WebOb.request.application_url to return a link to the
neutron api. This may not be the correct link in the case where
'X-Forwarded-Proto' is used. Nova provides the osapi_compute_link_prefix
variable for providing custom links to the api. This does the same
for Neutron.

Co-Authored-By: Kevin Benton <>
Change-Id: I92227803b1bc2fec10ee168a0285f2f6f09f55b0
6 years ago
ZhaoBo 22707fb3d2 Add filter check for quering
Neutron rasises 500 error if the filter is the resources'
object property.

This patch add the check to prevent querying with base_db property.

Change-Id: I1aec4c1537e687e9087c468a592802779f370cb3
Closes-Bug: #1654195
6 years ago
Brian Haley e45d2a904d Correctly print --limit value passed via API
Passing an invalid limit value, for example '--limit -1'
in neutronclient, generates this error from the API:

  Bad limit request: Limit must be an integer 0 or
  greater and not '%d'.

It should print what was passed.

Closes-bug: #1649665

Change-Id: I9b8bd67d344cd91e008f7c897f1ea6a020a9c30b
7 years ago
Gary Kotton 49609f36f5 Remove deprecated class NeutronController
Commit 9b8bf7d25c marked
NeutronController as deprecated.

This code is no longer used in Neutron and there is no need for
the class nor the unit tests for it.


Closes-bug: #1625140

Change-Id: Ie02b6f1a45c3ea32a1116a48946c59673e2d2472
7 years ago
Gary Kotton 9f09f27c5d Fix deprecation warnings
Remove deprecation warnings for various constants
and exceptions that have moved to neutron_lib.

Fix miscellaneous other deprecations.

Uses constants instead of l3_constants when importing
neutron-lib constants.

Co-Authored By: Henry Gessau <>
Co-Authored By: Gary Kotton <>

Change-Id: Ib0e8ff5c3e23677c1009241a1818cbc8a3430c38
7 years ago
Jenkins 2f29a5db3c Merge "Pecan: Implement pagination" 7 years ago
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
7 years ago
Ihar Hrachyshka ce0981fa20 Don't return marker item when paginating backwards
In emulated pagination mode, we should not return the marker when
paginating backwards (page_reverse), same as we do when we paginate
forward, or when we paginate backwards with a plugin that supports
native pagination.

Closes-Bug: #1591981
Change-Id: I8b553ab22846122dde22372f9901e46a5276ee8e
7 years ago
Kevin Benton f7a0c0b044 Convert multiple exception types in the API
The callback framework will collect all exceptions that occur
during the notification loop and raise a single exception
containing all of them. The issue with this is that the code
that notifies has to manually unpack the exceptions and choose
what to reraise for the API layer even if it has no other reason
to catch the exception (i.e. any encountered exceptions should be
fatal). If it doesn't, the server will just return a generic HTTP
500 error to the user even if the internal exception is a normal
error that would convert to a 404, 409, etc.

This patch makes the API exception conversion layer aware of
exceptions containing other exceptions so code no longer has to
catch callback failures if it has no specific error-handling logic.

Multiple exceptions that translate to the same HTTP error code will
be converted into one exception of the same error code with the
details of each exception line-separated in the exception message.

Multiple exceptions that translate to different HTTP error codes will
be concatenated together line-separated with their HTTP error prefixes
into an HTTP Conflict exception.

If there is only a single exception in the multi exception type, the
inner exception is used directly.

Partially-Implements: bp/multi-l3-backends
Change-Id: I528de088079b68cf284ef361fee9bd195125e0d8
7 years ago
Henry Gessau 9b8bf7d25c [TrivialFix] Deprecate unused NeutronController class
Change-Id: I2bb527c7833a50642ff517adb926f5d274e3d302
7 years ago
Kevin Benton a1c194cf06 Make exception translation common and add to pecan
This moves the exception translation logic from the
legacy api.v2.resource module to a common module and
re-uses it from pecan to bring consistency to the
way language and exception translation is handled
between the two.

This also adjusts the policy enforcement hook to correctly
handle the unsupported method case since 'after' hooks
are executed after 'on_error' hooks that return an exception.

Closes-Bug: #1583844
Change-Id: If3c2d8c94ca6c1615f3b909accf0f718e320d1c2
7 years ago
Henry Gessau ae5bad49cc Use exceptions from neutron-lib
Related-Blueprint: neutron-lib

Change-Id: Ia014468bd621c4ee6aea95bf19328c61070174c4
7 years ago
LiuNanke 83ef6b5677 Using LOG.warning replace LOG.warn
Python 3 deprecated the logger.warn method, see:
so we prefer to use warning to avoid DeprecationWarning.

Closes-Bugs: #1529913

Change-Id: Icc01ce5fbd10880440cf75a2e0833394783464a0
Co-Authored-By: Gary Kotton <>
7 years ago
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

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
7 years ago
Hirofumi Ichihara 8daf493a7d Remove unnecessary argument in limit manage
Change-Id: I2a7a99c72f24cafef848806620667c14b655f83e
7 years ago
Akihiro Motoki 2d8632e412 Use _ from neutron._i18n
Partial-Bug: #1520094
Change-Id: I874a4aa1d71d1f7034a1ff0b7450b419ef5c6864
8 years ago
Doug Wiegley dd726ed494 Move i18n to _i18n, as per oslo_i18n guidelines
- This does NOT break other projects that rely on neutron.i18n,
  as this change includes a debtcollector shim to maintain those
  older entry points, until they can migrate.
- Also updates to the latest pattern defined by oslo_i18n
- Guidance and template are from the reference:

Partially-Closes-Bug: #1519493
Change-Id: I1aa3a5fd837d9156da4643a367013c869ed8bf9d
8 years ago
Gary Kotton 2b7fb6ff08 Removes the use of mutables as default args
Passing mutable objects as default args is a known Python pitfall.
We'd better avoid this. This commit changes mutable default args with
None, then use 'arg = arg or {}', 'arg = arg or []'. For unit code which
doesn't use the args , just set with None. This commit also adds hacking

This code was taken from commit 0bea84ac20fe498bd08f7212a0017196c8cb0812
in Nova.

Change-Id: I36d07cade687690dc02a8f6cc3d70f5d00caf112
Co-Authored-By: ChangBo Guo(gcb) <>
8 years ago
Cyril Roelandt a0b2c0f9d1 Python 3: do not compare int and NoneType
This is an invalid operation in Python 3, even though it works in Python 2.

Change-Id: I89d654c6acea10b53d19e50199565badf011e705
8 years ago
Cyril Roelandt a863342caf Python3: cast the result of zip() to list
The result of get_sorts was a 'zip object' in Python 3, and it was later used
as a list, which fails. Just cast the result to a list to fix this issue.

Change-Id: I12017f79cad92b1da4fe5f9939b38436db7219eb
Blueprint: neutron-python3
8 years ago
Cyril Roelandt 1e5ef92f6a Python3: do not use urllib.urlencode
It has been moved in Python3. Use six.moves to have code that works with both
Python 2 and 3.

Change-Id: I5f286b1f784b3b7bb37852b00169a6c1227eb74b
Blueprint: neutron-python3
8 years ago
Cyril Roelandt 53209ca19a Python 3: do not use cmp(), nor sorted(..., cmp=...)
* The "cmp" function has been removed, so we must not use it any more;
* The "cmp" keyword argument of the "sorted" function has been removed, so
  replace it with "key=functool.cmp_to_key".

Change-Id: Ic39d29dc1002a68f36f04c32e53a36bc826dce78
Blueprint: neutron-python3
8 years ago
Cyril Roelandt 3751f9ab34 Python3: use six.iteritems() instead of dict.iteritems()
This also adds a check to neutron/hacking/ that should catch this
error in the future.

Blueprint: neutron-python3
Change-Id: Ie7b833ffa173772d39b85ee3ecaddace18e1274f
8 years ago
Ihar Hrachyshka 22328baf1f Migrate to oslo.log
It's mostly a matter of changing imports to a new location.

Non-obvious changes needed:
* pass overwrite= argument to oslo_context since oslo.log reads context
  from its thread local store and not from incubator
* don't store context at now that there is no code that
  would consume it
* LOG.deprecated() -> versionutils.report_deprecated_feature()
* dropped LOG.audit check from hacking rule since now the method does
  not exist
* WritableLogger is now located in oslo_log.loggers

Dropped log module from the tree. Also dropped local module that is now
of no use (and obsolete, as per oslo team).

Added versionutils back to openstack-common.conf since now we use the
module directly from neutron code and not just as a dependency of some
other oslo-incubator module.

Note: tempest tests are expected to be broken now, so instead of fixing
all the oslo.log related issues for the subtree in this patch, I only
added TODOs with directions for later fix.

Closes-Bug: #1425013
Change-Id: I310e059a815377579de6bb2aa204de168e72571e
8 years ago
Ihar Hrachyshka 7a2a85623d oslo: migrate to namespace-less import paths
Oslo project decided to move away from using oslo.* namespace for all their
libraries [1], so we should migrate to new import path.

This patch applies new paths for:
- oslo.config
- oslo.db
- oslo.i18n
- oslo.messaging
- oslo.middleware
- oslo.rootwrap
- oslo.serialization
- oslo.utils

Added hacking check to enforce new import paths for all oslo libraries.

Updated setup.cfg entry points.

We'll cleanup old imports from oslo-incubator modules on demand or
if/when oslo officially deprecates old namespace in one of the next



Closes-Bug: #1409733
Change-Id: If0dce29a0980206ace9866112be529436194d47e
8 years ago
Ihar Hrachyshka 3f44c9e278 Migrate to oslo.i18n
Mostly trivial import changes.

- oslo.i18n no longer provide install() method to inject _() into
  globals(), so removed all calls to it;
- removed Babel from dependencies (it will now be grabbed by oslo.i18n);
- updated tox.ini to ignore import violations for oslo.i18n.

Change-Id: I6623d551f512fb7fe9bf35ee734ed6d4c6cbc287
9 years ago
Gary Kotton b8930e8f92 Update i18n translation for neutron.api log msg's
Validate that hacking rules apply to directory neutron/api

Change-Id: Idd54964dbb3a48505c20117c79ce57913a7f1c12
Partial-bug: #1320867
9 years ago
Mohammad Banikazemi 5a701d730a Removing vim header lines
Simply removes the vim header line and the empty line
following it (when present) for files in the api, db, and
extenssions base directories. In one single _init_ file in
this patchset, all comment lines are removed.

Change-Id: I81b7168dc2ad74b8c30a87e50a531e157851499e
Partial-Bug: 1229324
9 years ago
Mark McClain ee3fe4e836 Rename Quantum to Neutron
This change renames everything to Neutron while providing backwards
compatible adjustments for Grizzly configuration files.

implements blueprint: remove-use-of-quantum

Change-Id: Ie7d07ba7c89857e13d4ddc8f0e9b68de020a3d19
10 years ago