Commit Graph

32 Commits (99f4495c940011293e3cabbb590770dc1e7b6900)

Author SHA1 Message Date
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 9662e2b170 Use context interface for constraint
Use the new constraint interface on the context rather than
setting an ugly attribute.

Depends-On: I6bc2539a1ddbf7990164abeb8bb951ddcb45c993

Related-Bug: #1493714
Change-Id: I9142ca96a40092b2a4c94920c4ded9bbc3a0b35b
2017-07-18 23:00:00 -07:00
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
2017-06-29 22:50:12 +00:00
Ihar Hrachyshka 527468be33 api: work around Routes cutting off suffix from resource id
Routes allows for auxiliary format suffix. Sadly it doesn't distinguish
between an actual format suffix (.json) and any other suffix that may be
part of the id. (like for first.second resource tag). To work this
behavior around, we will reattach the 'format' suffix if it is not of a
supported format (json only at the time of writing).

This of course leaves a corner case where there is a tag where .json is
a part of its id. This seems to be a reasonable balance to leave it
unfixed, because an alternative would probably be not backwards

Closes-Bug: #1694897
Change-Id: I271107150166f0ee680faaa2e3ca6044cf4e8d4f
2017-06-01 14:13:39 -07:00
Brandon Logan 96a45cadcc Pecan: Fix tags handling for pecan
Tags controller was not being picked up from the extension.  This also
allows the usage of collection_methods that tags uses.  Also, the tags
extension made use of action_status on a resource, which allowed
overriding the default status codes, so this patch handles action_status
as well.

Change-Id: Ic7f5cfddd30f26737469516235053656f1ba6a24
2017-02-02 19:02:13 +00:00
Ihar Hrachyshka f3816cb8bd ml2: postpone exception logs to when retry mechanism fails to recover
Since Ia2d911a6a90b1baba1d5cc36f7c625e156a2bc33, we use version_id_col
SQLAlchemy feature to routinely bump revision numbers for resources.  By
doing so, SQLAlchemy also enforces the expected number on any UPDATE and
DELETE, which may not be valid when the transaction is actually applied.
In that case, the library will raise StaleDataError:

The exception is then logged by ml2 and bubbles up to API layer where
retry mechanism will correctly catch it and issue another attempt.

If API layer does not retry on exception, it already logs the error,
including the traceback.

In ml2, it's too early to decide if an exception is worth being logged.
Plugin instead should just silently allow all unexpected exceptions to
bubble up and be dealt by API layer.

At the same time, there are some details that are known at the plugin
level only, that are not easily deducible from the API request details.
That's why we save details about the error on the exception object that
bubbles up into API layer, where we are ready to decide if those details
are worth being logged.

Change-Id: I848df0aef5381e50dfb58e46d7a652113ac27a49
Closes-Bug: #1593719
2016-07-01 09:38:38 +00:00
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
2016-05-13 20:23:43 -07:00
Henry Gessau ae5bad49cc Use exceptions from neutron-lib
Related-Blueprint: neutron-lib

Change-Id: Ia014468bd621c4ee6aea95bf19328c61070174c4
2016-04-21 21:29:44 -04: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 <>
Change-Id: Icec56676d83b604c3db3377838076d6429d61e48
2016-03-08 06:35:49 +00:00
Hirofumi Ichihara 0ae3c172ae Make API framework more flexible for various extensions
This patch adds a function to Neutron extension mechanism
so that we can add API methods to "/resources" path rather than
"/resources/action" path.

This patch also allow extentions to control correspondences
between action and status in API request.

Change-Id: I862086f7528583e65d7bee794f011ddff6ae8901
Partial-Implements: blueprint add-tags-to-core-resources
Related-Bug: #1489291
2016-03-02 05:39:04 +09:00
Akihiro Motoki 2d8632e412 Use _ from neutron._i18n
Partial-Bug: #1520094
Change-Id: I874a4aa1d71d1f7034a1ff0b7450b419ef5c6864
2015-12-06 19:39:04 +09:00
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
2015-12-01 19:29:10 -07:00
Akihiro Motoki 2d390876b9 Lower log level of errors caused by user requests to INFO
When webob exception is returned, error level log is
always recorded even though we return 4xx (client error)
to users. 4xx error in response code means errors due to
user requests, so error level log is not appropriate.
This commit lowers the log level to INFO for such events.

Currently only case I see is webob.exc.HTTPNotFound returned
by the policy engine when a user requests an operation
prohibited by the policy, but I think there is no reason
we deal with 404 specially in neutron.api.v2.resource.

Change-Id: I9f042a90c9bf528be7cb835d7fe818ed1879054b
Closes-Bug: #1473556
2015-07-12 16:44:33 +09:00
Martin Roy fe6654b250 Use string exception casting everywhere
Instead of the deprecated "message" member access,
casting to a string invokes the __str__ method of the exception
that is wired to return the message

Added a test of the failure cases of IpRouteCommand::delete_gateway
because they were missing

Running unit and functional tests locally no longer shows the warning
reported in the bug.

Change-Id: Ia79f526aa973ece1145615d65349f860aa3fd465
Closes-Bug: #1466542
2015-06-22 09:13:56 -04:00
Ihar Hrachyshka 9143ce10e4 Consume oslo.policy
Some non intrusive changes to tests are needed, so that we don't rely on
library symbols that are now private (f.e. parse_rule).

Closes-Bug: #1458945
Change-Id: I90326479e908042fec9ecb25fa19a8dd5b15e7d8
2015-06-09 17:07:13 +00:00
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
2015-03-12 11:22:56 +01:00
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
2015-02-05 15:09:32 +01:00
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
2014-11-26 22:19:24 +01:00
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
2014-11-19 00:20:01 -08:00
Elena Ezhova d83731a96d Updated policy module from oslo-incubator
Common policy has not been synced with oslo-incubator for a
long time and is seriously outdated.

This change pulls in fresh code from oslo-incubator which
introduces the Enforcer class to replace the old check function.

Rewrite neutron.policy using naming conventions and approach
that was set in Nova and amend related unit tests.
Remove neutron.common.exceptions.PolicyNotAuthorized and switch
to neutron.openstack.common.policy.PolicyNotAuthorized.
Drop Neutron specific policy_file option since now it is defined
in oslo-incubator policy module.

Change log:
4ca5091 Fixes nits in module policy
262fc82 Correct default rule name for policy.Enforcer
9e8b9f6 Minor fixes in policy module
6c706c5 Delete graduated serialization files
5d40e14 Remove code that moved to oslo.i18n
aebb58f Fix typo to show correct log message
bb410d9 Use MultiStrOpt for policy_dirs
33f44bf Add support for policy configration directories
2b966f9 Fix deletion of cached file for policy enforcer
238e601 Make policy debug logging less verbose
fe3389e Improve help strings
15722f1 Adds a flag to determine whether to reload the rules in policy
5d1f15a Documenting policy.json syntax
fcf517d Update oslo log messages with translation domains
e038d89 Fix policy tests for parallel testing
0da5de6 Allow policy.json resource vs constant check
e4b2334 Replaces use of urlutils with six in policy module
8b2b0b7 Use hacking import_exceptions for gettextutils._
0d8f18b Use urlutils functions instead of urllib/urllib2
12bcdb7 Remove vim header
9ef9fec Use six.string_type instead of basestring
4bfb7a2 Apply six for metaclass
1538c80 ConfigFileNotFoundError with proper argument
33533b0 Keystone user can't perform revoke_token
64bb5e2 Fix wrong argument in openstack common policy
b7edc99 Fix missing argument bug in oslo common policy
3626b6d Fix policy default_rule issue
7bf8ee9 Allow use of hacking 0.6.0 and enable new checks
e4ac367 Fix missing argument bug in oslo common policy
1a2df89 Enable H302 hacking check
7119e29 Enable hacking H404 test.
6d27681 Enable H306 hacking check.
1091b4f Reduce duplicated code related to policies

Closes-Bug: #1288178
Change-Id: I87ee30e2b64ec6b07faa84a231fd5f7eb925d501
2014-11-13 13:55:19 +03:00
Mark McClain 1b4ad95758 Remove XML support
XML support in Neutron has always been a second class feature to the
JSON API and broken for many extensions and outputs. The XML API been marked as
deprecated for the Icehouse and Juno release and is ready for removal in

Change-Id: I611aa9382ba3bfb08b2970c63e83b0fdd3d2e8a4
Closes-Bug: #1380787
2014-10-24 15:18:49 +00:00
Elena Ezhova ea3c43a402 Send HTTP exceptions in the format expected by neutronclient
Neutron client for the v2 API expects exceptions to have 'type',
'message' and 'detail' attributes. That is why they need to be
included in the body of HTTP Exceptions.

Change-Id: I70bd47977e42ad7bac760600329e9440452b74bc
Closes-Bug: 1355902
2014-08-18 17:21:45 +04:00
Jenkins 3e1799d046 Merge "Remove unused 'as e' in exception blocks" 2014-03-04 03:57:24 +00:00
shihanzhang aa5ace6b75 Remove unused 'as e' in exception blocks
Change-Id: I0bd26e1657a4e0ec40405d03d43aee9e10a13636
Closes-bug: #1287031
2014-03-03 18:08:35 +08:00
Akihiro Motoki 6b13ee0c3b Avoid using "raise" to reraise with modified exception
The code changes the exception and reraises it.
This commit changes the code to use the same way as
excutils.save_and_reraise_exception does to ensure
the exception context.

This is the last patch of reraise clean up series.

Closes-Bug: #1279813
Change-Id: I8787dcbdc8321f75964de26e97cae395707aafc2
2014-03-02 09:03:19 +00:00
Akihiro Motoki 0dd0b6b5ee Lower log level of errors due to user requests to INFO
Errors due to bad client requests (e.g., NotFound, BadRequest)
are logged as exception/trace level and it is annoying
from the point of operators' view.
This commit changes the log level for errors due to
user requests (HTTP 4xx errors) to INFO.

Closes-Bug: #1282394
Change-Id: Ic5646333db88ce856f9366e914cf961890d30501
2014-02-25 19:43:14 +09:00
Gary Kotton 4dbb55cbb0 Update RPC code from oslo
The common RPC code has been updated to include the following:

Updated to include the following in modules in openstack-common.conf:
py3kcompat, sslutils, and versionutils.

The update also includes imports from the RPC code

Change-Id: I84c5b8e2b17da0018dd69ecb354d123a609afe98
2014-01-15 04:26:57 -08:00
Nachi Ueno 88148584f2 Fix misspells
Change-Id: I8be38727ca55ebbead9032cf69f10a1006fd004b
2013-12-03 15:03:47 -08:00
Oleg Bondarev 20b97388ef Send proper exception info as expected by the neutron client
The python neutron client for the V2 API expects the neutron API
to send information back such as the type and detail of the exception
in the body of the message

Change-Id: I9486d757258c4be72799c41102babe1f7923121c
Closes-bug: #1226400
2013-09-19 17:32:30 +04:00
Luis A. Garcia 7e2622c2fc Enhance exception translation to better handle NeutronExceptions
NeutronExceptions have a 'message' class attribute that holds the
generic error message template, e.g. "Network %(network)s not found",
unfortunately, because the names are the same, it was overshadowing the
actual exception instance 'message', e.g. "Network 1 not found", after
translation when the exception was serialized to JSON.

This patch puts the exception's actual message in a new field called
'msg' and overwrites NeutronException unicode() so that 'msg' is used
during serialization and we'll get the correct message on the REST API

Fixes bug: #1212882

Change-Id: I3965bffb1c2c2eee0af440d1ecd30ccb3bb958d5
2013-09-12 18:43:15 +00:00
Luis A. Garcia d12fcadaa0 Enable localizable REST API responses via the Accept-Language header
Add support for doing language resolution for a request, based on the
Accept-Language HTTP header. Using the lazy gettext functionality, from
oslo gettextutils, it is possible to use the resolved language to
translate exception messages to the user requested language and
return that translation from the API.

Partially implements bp user-locale-api.

Change-Id: I63edc8463836bfff257daa8a2c66ed5d3a444254
2013-08-07 21:19:25 +00:00
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
2013-07-06 15:02:43 -04:00