Commit Graph

49 Commits

Author SHA1 Message Date
Boden R 957eca96f4 delete common_db_mixin
The functionality within neutron.db.common_db_mixin is available via
neutron-lib APIs. This patch removes common_db_mixin and updates any
uses of it to use neutron-lib instead.

Depends-On: https://review.openstack.org/#/c/636159/

NeutronLibImpact

Change-Id: I2388f90b37abb09408809dda8c21da551bcd94bb
2019-04-17 11:25:41 -06:00
Boden R 08bca27b93 remove unused methods in common_db_mixin
The following methods are no longer used in CommonDbMixin:
- register_dict_extend_funcs
- _apply_filters_to_query
- _filter_non_model_columns

This patch removes them from neutron.

NeutronLibImpact

Change-Id: Ic7042cdcb29e95cc3a13292819d77abc3971fe8a
2019-01-30 11:22:43 -07:00
Boden R 1382bf9a32 remove the neutron.db._model_query module
The functionality from model_query is already in neutron-lib and
consumers are using it. This patch removes the _model_query module
from neutron and updates all imports to use neutron-lib's version of
it instead.

NeutronLibImpact

Change-Id: Ib2eae9edb009a93e60b3b0d63ca365056138566b
2019-01-25 08:55:25 -07:00
Boden R 29f56478d1 remove the neutron.db._resource_extend module
The _resource_extend module is already rehomed into neutron-lib and is
shimmed in neutron. This patch removes the module as no active
consumers are using it.

NeutronLibImpact

Change-Id: I1550075fa5fa2aa2f1a88ee7189d311a1fe78391
2019-01-02 13:02:06 -07:00
Boden R a73deb9909 remove unused methods from CommonDbMixin
The register_model_query_hook and _apply_dict_extend_functions methods
from CommonDbMixin is not being used by consumers today. This patch
removes them and updates any doc references as well.

NeutronLibImpact

Change-Id: I3e72d7f33f5a7b0c9c023295302929410f94eefb
2018-11-20 06:55:13 -07:00
Boden R 6a89dd2feb use db utils from lib
The APIs our consumers are using from neutron.db_utils were rehomed into
neutron-lib with https://review.openstack.org/#/c/540161/

This patch consumes them by removing the rehomed APIs and using lib's
implementation where applicable.

NeutronLibImpact

Change-Id: I7ee53bce917feae8e37bf278eb3121a5af47131c
2018-07-02 08:24:36 -06:00
Boden R e65767034e remove model_query_scope from common db mixin
The model_query_scope method is not used from common db mixin [1]. This
patch removes it on the path to eventually removing common db mixin
all together.

NeutronLibImpact

[1] http://codesearch.openstack.org/?q=%5C.model_query_scope%5C(

Change-Id: Ib8ce6e9f6000e9c01d28c1471b885b0f3c8a041b
2018-06-12 08:04:57 -06:00
Boden R 14301613e6 remove safe_reference from common db mixin
The safe_reference property in common db mixin is only used by
vmware-nsx and they can use weakref directly (see depends on patch).
This patch removes safe_reference as we're working towards removing
common db mixin all together.

Depends-On: https://review.openstack.org/#/c/571221/

[1] http://codesearch.openstack.org/?q=%5C.safe_reference

Change-Id: I77f9561139fd88eff51638f6f41cf79f0b876dc1
2018-06-08 07:05:57 -06:00
Boden R d034df15a1 remove common db alaises to db utils
A handful of the functions implemented in neutron.db._utils are exposed
in common_db_mixin as aliases. These are unneeded as they're already
defined elsewhere.

This patch removes the following aliases in common_db_mixin:
- safe_creation
- model_query_scope
- model_query
- resource_fields

It also renames the UT for common db mixin to
test__utils to reflect the fact that its testing functions
from the _utils db module.

NeutronLibImpact

Change-Id: I53cd533f107d950f163ad5b19b47097546a4691d
2018-05-01 14:13:24 -06:00
Henry Gessau bb49c4f682 Move _get_marker_obj() out of CommonDbMixin.
This refactoring is a step towards the goal of removing the
CommonDbMixin mixin class.

Related-Blueprint: neutron-lib

Change-Id: I1e2da0687310cc2da767dc2a6d13500307bba1ee
2017-05-02 16:47:42 +00:00
Henry Gessau ef471a652b Refactor CommonDbMixin for removal
Move the CommonDbMixin methods to model_query.py and
resource_extend.py

This leaves CommonDbMixin as just a shim, and it should be easy
to remove once subprojects have stopped depending on it.

Related-Blueprint: neutron-lib

Change-Id: I5b804e09e630d88d551271d9731cc1f65c065259
2017-04-25 14:13:30 -04:00
Henry Gessau b3c0d5f239 Eliminate lookup of "resource extend" funcs by name
By registering functions directly we cut off the dependency of the
"resource extend" functions on the plugin. This is a step towards
the goal of removing the CommonDbMixin mixin class.

Also, we register all "resource extend" functions at plugin create
(in __new__) instead of in the class definition (which caused the
hooks to be registered on import). This ensures the "resource
extend" functions are only registered for the plugins/mixins that
are actually used.

Note that decorators are used to register "resource extend" methods,
similar to the callback receiver decorators.

Related-Blueprint: neutron-lib

Change-Id: I128cfda773d5f9597df9cd61261fdc05f2a174aa
2017-04-21 14:48:42 -04:00
fpxie 574312165b Replace six.iteritems with dict.items(Part-2)
according to https://wiki.openstack.org/wiki/Python3, now we should avoid
using six.iteritems and replace it with dict.items.

Change-Id: I58a399baa2275f280acc0e6d649f81838648ce5c
Closes-Bug: #1680761
2017-04-18 18:56:46 +08:00
Manjeet Singh Bhatia 0387c6181a Removing workaround for bug 1656947
paginate_query was exploding when sort_keys had a
boolean column, since it was fixed in 4.18.0 of
oslo.db. This workaround is no longer needed.

Change-Id: Ie8df9c91c2828bb8886f9b175f06966fe9dd962c
2017-04-03 20:00:31 +00:00
Henry Gessau e7cd868c20 Decouple hook and func registration from CommonDbMixin
Move the model query hook registration and resource extend funcs
registration methods out of the CommonDbMixin class and make them
regular utility functions.

This is a step in refactoring the CommonDbMixin class.

Change-Id: Iec1bb7f7098c83640ae695fd7cf2f4736f414ad2
2017-03-11 18:04:11 -05:00
Ihar Hrachyshka 19307f6edf Avoid applying noop lambdas per object in db_api.get_objects
It's a waste of cpu time, and I hate grep catching my name in tree. ;)

TrivialFix

Change-Id: I6fad4a4413e41f1fdb434e800e135f6cbe93ffda
2017-02-22 06:11:40 +00:00
Jenkins 74fcf15631 Merge "Use weakrefs for common_db_mixin callbacks" 2017-01-28 00:24:50 +00:00
Kevin Benton faf80b950f Use weakrefs for common_db_mixin callbacks
This will prevent the common_db_mixin dictionary
extension functions and query hooks from stopping
the GC of plugins in tests and causing resource leaks.

Change-Id: I7576851a44abd14cbc337a3d3e28690c7316ec81
2017-01-26 07:10:06 -08:00
Kevin Benton 519d7ccc2c Always add unique sort keys when sorting
This avoids the logs being filled with warnings from
the sort utils about unstable sorting order.

"Unique keys not in sort_keys. The sorting order may be unstable."

Change-Id: I5cba69eb87abf1bec15fcc675369a725d67e23ce
2017-01-23 20:28:19 +00:00
Kevin Benton 393a3bd947 Protect against non-determinstic sort
This reverts commit e74b45d0eb.

This re-adds the non-deterministic sort logic but avoids using
boolean columns to work around the related bug.

Original commit msg:

With the switch to subquery loading, we need to eliminate the
possibility for non-deterministic results in the event of LIMIT
queries caused by non-unique SORT BY parameters.

This always adds on a set of unique keys to sort by when sorting
params are present. By placing them at the end, they take the lower
priority over the user-provided sort strings.

1. http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html#subqueryload-ordering
2. http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#faq-subqueryload-limit-sort

Related-Bug: #1656947
Change-Id: I503c65560d970427be93b39898f4e7acfc4d3e1f
2017-01-16 14:35:20 -08:00
YAMAMOTO Takashi e74b45d0eb Revert "Protect against non-determinstic sort"
This reverts commit 175bfe0482.

The change causes the following error if you're
unlucky enough to have such a marker column.

   ArgumentError: Only '=', '!=', 'is_()', 'isnot()' operators can be used with None/True/False

I saw test_floatingip_list_with_pagination failing,
where fixed_port_id of the marker was None.

Closes-Bug: #1656262
Change-Id: I6c32949d789f25d877d329ef0ae9d8650cb81acf
2017-01-16 07:39:38 +09:00
Kevin Benton 175bfe0482 Protect against non-determinstic sort
With the switch to subquery loading, we need to eliminate the
possibility for non-deterministic results in the event of LIMIT
queries caused by non-unique SORT BY parameters.

This always adds on a set of unique keys to sort by when sorting
params are present. By placing them at the end, they take the lower
priority over the user-provided sort strings.

1. http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html#subqueryload-ordering
2. http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#faq-subqueryload-limit-sort

Change-Id: I5abb1c7e2710af0be9dbd757608574945a26637e
2017-01-12 10:43:50 +00:00
Li-zhigang 846cad8c75 Remove unused LOG
Change-Id: I829429d698522a862f1ae0819d6b6583f6216e76
2016-11-21 11:22:47 +08:00
Henry Gessau 8f80a52b01 Refactor/prepare db common utils for neutron-lib
Extract all the common utils from common_db_mixin.py in preparation
for moving them to neutron-lib.

This is a preliminary step in preparation for refactoring the
CommonDbMixin class and moving it to neutron-lib also.

Partial Blueprint: neutron-lib

Change-Id: I3cba375a8162cb68e8f988f22f5c8b1ce7915180
2016-10-28 10:53:11 -04:00
Kevin Benton 145dbaab21 Get rid of double-join to rbac_entries without filter
apply_filters_to_query was performing an outerjoin to rbac_entries
unconditionally when model_query could have already performed an
outerjoin (if the request was from an unprivileged user) and/or when
the join wasn't even necessary (the '?shared=False' query that uses
a subquery and not a join). This resulted in terrible performance
because of cartesian products of rbac entries with themselves.

This fixes the issue by ensuring there is only an outerjoin to the
rbac table if it's going to be used for a filter condition and it's
not already joined because of a query scope imposed due to the user
not being privileged.

Unfortunately this doesn't include tests to prevent regressions because
we don't have any methods for testing the performance of individual
queries.

Closes-Bug: #1630939
Change-Id: I4364f4a97a29041e86b2fbd8aa895578153f4cf9
2016-10-07 00:42:02 -07:00
Dariusz Smigiel dd5976b7ab Accept and return project_id for API calls
Update the API to accept project_id in requests and return
project_id in responses.

For now, the API treats tenant_id and project_id equivalently.
It accepts either or both in requests.
It returns both in responses, depending on filters.

We include an extension to indicate that support for project_id
is enabled in the API.

Completes: blueprint keystone-v3

APIImpact: Describe how the Networking API supports Keystone V3.

Co-Authored-By: Henry Gessau <HenryG@gessau.net>
Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>

Change-Id: I8775aa8a477191ef21e7c3c6da31d098befefc3c
2016-09-12 19:23:53 +00:00
Henry Gessau 2f767839c9 Use paginate_query from oslo_db
The paginate_query method was copied from nova which was copied
from glance. Now it is available in oslo_db.

Check and convert the sort keys and sort directions for
consumption by the oslo_db version of the method, and fix up
some grammar in the exception messages.

This work is related to the neutron-lib effort. The lib should
not propagate neutron's copy of paginate_query().

Related-Blueprint: neutron-lib

Change-Id: Ie7da16b94fa2023c9c3d84d96d55f33d0f76903f
2016-04-27 03:12:24 +00:00
Gary Kotton 8e15824359 DB: remove method _get_tenant_id_for_create
This method was marked as deprecated in commit 584d960a93.

TrivialFix

Change-Id: Id753df324eb2df938fbce5a0e033768f3a11de11
2016-03-22 06:50:27 -07:00
Kevin Benton d1c501cd1d L3HA: Do not wrap create/delete in transaction
This is unsafe when calling ML2 because ML2 assumes that its
functions will not be called inside of a transaction. This is
not only an issue for drivers that try to do DB lookups using
a different session in the post commit operation, but it's a
big issue for the delete methods.

The delete subnet and network methods in ML2 have 'while True'
loops that catch concurrency errors and retry the operation after
looking up info. If these are called inside a transaction, the
lookups will contain stale information and it can lead to the
while True loop never terminating!

Closes-Bug: #1551958
Change-Id: I33dc084ed15e5491fdda19da712a746ca87fbc8c
2016-03-11 23:59:10 +00:00
Kevin Benton 5dacbba701 Add a description field to all standard resources
In order to give users and operators more flexibility in
annotating the purpose of various Neutron resources, this patch
adds a description field limited to 255 chars to all of the
Neutron resources that reference the standard attribute table.
The resource that reference the table are the following:
security_group_rules, security_groups, ports, subnets,
networks, routers, floatingips, subnetpools

This patch adds a description table related to standard attributes
and migrates over the existing security group description to the new
table as well.

Co-Authored-By: James Dempsey <jamesd@catalyst.net.nz>

APIImpact
DocImpact: Adds a description field to all resources outline in
           commit message.
Closes-Bug: #1483480
Change-Id: I6e1ef53d7aae7d04a5485810cc1db0a8eb125953
2016-03-05 02:29:35 +00:00
Kevin Benton 957c21113f Get rid of UnionModel for RBAC
The union model approach was completely broken because it
didn't keep track of which model each result actually was.

This patch just strips it out and replaces get_rbac_policies
with queries to each model. This will mean pagination is broken
once multiple rbac types are in place, but everything else should
work fine.

Co-Authored-By: Haim Daniel <hdaniel@redhat.com>

Closes-Bug: #1542815
Change-Id: I1e91aa22d093d50e5a9d318f24d09bb65e072246
2016-02-15 08:18:01 +00:00
Ann Kamyshnikova 924f19e8f1 Make object creation methods in l3_hamode_db atomic
Methods _create_ha_network, add_ha_port don't have wrapping
transaction in them, so they are prone to race conditions.
This commit adds a transaction to them. To avoid problem with
rolling back outmost transaction during exception handling,
internal methods have been wrapped in nested transaction.

Nested transaction is required in places like this:

def create():
      create_something()
      try:
            _do_other_thing()
      except Exception:
             with excutils.save_and_reraise_exception():
                     delete_something()

def _do_other_thing():
     with context.session.begin(subtransactions=True):
         ....

When exception is raised in _do_other_thing it
is caught in except block, but the object cannot be deleted in
except section because internal transaction has been rolled back.

A new method safe_creation and has been added
that provides a common way of handling such situations.

Closes-bug: #1501686

Change-Id: I952f6f7f8684743aa7f829bd92b1dc41b2c6aecf
2016-01-18 13:36:39 +03:00
Gary Kotton 584d960a93 Ensure that decomposed plugins do not break
Commit 5d53dfb8d6 removed the
method _get_tenant_id_for_create. This is used by various plugins
and the *aaS libaries.

Change-Id: I6d5e2555d6c198102a3d5400609f1d671e0d388d
2016-01-09 00:15:22 -08:00
Mathieu Rohon 5d53dfb8d6 Avoid duplicating tenant check when creating resources
The check of the tenant done in the method _get_tenant_id_for_create()
is already did by the Neutron Controller in prepare_request_body(),
with a call to attributes.populate_tenant_id().
Moreover, when the Controller processes a "create" requests, it
will add the 'tenant_id' to the resource dict.
Thus, _get_tenant_id_for_create() can be deleted.
Calls to this method are replaced by the res['tenant_id'].

Changes have to be done in UT to explicitly add the tenant_id while
creating resources, since the UT framework is bypassing the controller code
that automatically adds the tenant_id to the resource.

Co-Authored-By: Hong Hui Xiao <xiaohhui@cn.ibm.com>
Closes-Bug: #1513825
Change-Id: Icea06dc81344e1120bdf986a97a6b1094bbb765e
Depends-On: I31022e9230fc5404c6a94edabbb08d2b079c3a09
Depends-On: Iea3f014ef17a1e1b755cd2efe99afd1a36ebbc6a
Depends-On: I604602d023e0cbf7f6591149f914d73217d7a574
2016-01-05 14:18:41 +00:00
Akihiro Motoki 2d8632e412 Use _ from neutron._i18n
Partial-Bug: #1520094
Change-Id: I874a4aa1d71d1f7034a1ff0b7450b419ef5c6864
2015-12-06 19:39:04 +09:00
Kevin Benton 35beca5327 Add UnionModel support to filter query generator
The _apply_filters_to_query method did not handle UnionModels
so objects leveraging it (i.e. RBAC policies) did not have
queries applied to them.

This patch corrects it by iterating through the component models
of the UnionModel and applying the filters to each component model.
It also adds an API test on RBAC that exercises the filtering.

Change-Id: I449acf359dd61189bbdacd200d7c41a4a88d3de8
Closes-Bug: #1517818
2015-11-24 10:23:57 +00:00
Kevin Benton 14c47284f6 Simplify join to rbac_entries for subnets
The subnet table was joined to the rbac table via an association proxy
which required a bunch of hacking in the model_query setup to get it
to work right.

This patch simplifies it quiet a bit by just using a direct relationship
between the subnets and networkrbacs tables joined via the subnet's
networkid.

It also unrolls an API test that was really difficult to debug because
it was hard to tell which iteration it was on.

Change-Id: I4da85218158aae624835b97053da9fbb6fb154ef
2015-09-18 10:36:52 -07:00
Kevin Benton ad9aaa63e5 Fix RBAC filter query for negative case
The query to find networks that aren't shared to the querier was
broken. It was querying for the inverse of RBAC entries that shared
to the querier, so it would return the network for each other tenant
it was shared to. This meant that if a network had multiple RBAC
entries, a shared=False filter wouldn't work in the API.

This patch corrects the behavior by adjusting the query that looks
for objects not shared to the caller to make sure the object ID doesn't
appear in the shared subquery.

This patch also adds a test that reliably reproduces the original issue.
The sporadically failing filter test that revealed this issue depended
on a race to have a network be shared to another tenant and to the wildcard
at the same time.

Change-Id: I9dcd869c1640b223221ba12e97284bbfcabbeb2b
Closes-Bug: #1495040
2015-09-04 18:27:42 -07:00
Kevin Benton 4595899f7f Neutron RBAC API and network support
This adds the new API endpoint to create, update, and delete
role-based access control entries. These entries enable tenants
to grant access to other tenants to perform an action on an object
they do not own.

This was previously done using a single 'shared' flag; however, this
was too coarse because an object would either be private to a tenant
or it would be shared with every tenant.

In addition to introducing the API, this patch also adds support to
for the new entries in Neutron networks. This means tenants can now
share their networks with specific tenants as long as they know the
tenant ID.

This feature is backwards-compatible with the previous 'shared'
attribute in the API. So if a deployer doesn't want this new feature
enabled, all of the RBAC operations can be blocked in policy.json and
networks can still be globally shared in the legacy manner.

Even though this feature is referred to as role-based access control,
this first version only supports sharing networks with specific
tenant IDs because Neutron currently doesn't have integration with
Keystone to handle changes in a tenant's roles/groups/etc.

DocImpact
APIImpact

Change-Id: Ib90e2a931df068f417faf26e9c3780dc3c468867
Partially-Implements: blueprint rbac-networks
2015-08-20 20:00:17 -07:00
Kevin Benton 3e0328b992 Network RBAC DB setup and legacy migration
This patch implements the database model required for the network
RBAC work. In addition it migrates the current network and subnet
'shared' attributes to leverage the new table.

'shared' is no longer a property of the DB model because its status
is based on the tenant ID of the API caller. From an API perspective
this is the same (tenants will see networks as 'shared=True' if the
network is shared with them). However, internal callers (e.g. plugins,
drivers, services) will not be able to check for the 'shared' attribute
on network and subnet db objects any more.

This patch just achieves parity with the current shared behavior so it
doesn't add the ability to manipulate the RBAC entries directly. The
RBAC API is in the following patch.

Partially-Implements: blueprint rbac-networks
Change-Id: I3426b13eede8bfa29729cf3efea3419fb91175c4
2015-07-16 05:48:10 -07:00
Jenkins 8d0c7fea03 Merge "Add a non-mixin function for model queries" 2015-06-05 13:02:35 +00:00
Cyril Roelandt 3751f9ab34 Python3: use six.iteritems() instead of dict.iteritems()
This also adds a check to neutron/hacking/checks.py that should catch this
error in the future.

Blueprint: neutron-python3
Change-Id: Ie7b833ffa173772d39b85ee3ecaddace18e1274f
2015-06-01 23:13:42 +02:00
Salvatore Orlando 70e07629bf Add a non-mixin function for model queries
This patch simply adds a version of model_query in
neutron.db.common_db_mixin which can be invoked without
having to declare a class which inherits the mixin.

To this aim, model_query_scope has been refactored as well.
As the model query function being introduced in this patch
cannot use model query hooks (and does not need to), the
method was re-implemented rather than bringing out of the
mixin as it has been done for model_query_scope.

This change will allow for developing DB APIs without
having to use the baseDB/mixin classes models used so far.

Related-Blueprint: better-quotas

Change-Id: I7a79980f626e9eaf2775711c8a25f508067e5716
2015-06-01 11:22:29 -07:00
Cyril Roelandt 6c1cb05302 Python 3: use six.string_types instead of basestring
In Python 3, there is no "basestring". In Python 3, "six.string_types" is
"basestring", and "str" in Python 3.

Change-Id: Ic22e932cbf3c4b75cd424f4b41428da869f197cf
Blueprint: neutron-python3
2015-05-21 04:03:17 +02:00
Sergey Belous 949256d3f7 Added check for emptyness where in_ is being used
All the Neutron code was scanned for places where in_ is being used
and added checks to ensure that the input is not an empty sequence.

Change-Id: I1e27f94ea350ce1dfabdd7eb14e4397ca29e8eb7
Closes-Bug:1264579
2015-03-10 11:31:29 +03:00
Isaku Yamahata 70236654b7 common_db_mixin.py: simplify CommonDbMixin
Simplfy register_model_query_hook() and register_dict_extend_funcs().
Move register_dict_extend_funcs() into CommonDbMixin attribute
because the related class attribute, _dict_extend_functions, is
defined in CommonDbMixin. They should be defined in same class.

Change-Id: Ib7b6df0c236f1d0804941147cc7cd7902a611311
2015-01-19 17:53:04 -08:00
Kyle Mestery d4f00659eb Add advsvc role to neutron policy file
Add in a default "advsvc" user and the logic in the Neutron policy
infrastructure which will allow this user to create/get/update/delete
ports on other tenants networks, as well as view other tenants
networks. This is for the use case of letting advanced services have
a user to put ports on other tenants networks. By default, we do not
define any roles for the policy "context_is_advsvc", but rely on
operators to specify the likely value of "role advsvc".

DocImpact

Closes-Bug: #1331836

Change-Id: I94cb3383eb1fed793934719603f888dbbdbbd85a
Co-Authored-By: Susanne Balle <sleipnir012@gmail.com>
2014-10-27 12:49:27 +00:00
Joe Gordon b74a38cb11 Revert "VPNaaS REST Client UT Broken"
I8badc249ad021fdbdb2367b5416c72435ed58994 causes anything importing
neutron/tests/unit/services/vpn/device_drivers/_test_cisco_csr_rest.py
to exit since httmock isn't a dependency.

Fix all hacking issues in addition to the revert, as this patch fixes 'tox -epep8'.
And just a reverting the patch will cause pep8 to fail.

Fixes-Bug: #1340881

This reverts commit 7f0a8f09ab.

Change-Id: I373a8c8ab16eb387be6a451b8146642389081afa
2014-07-11 11:21:14 -07:00
Eugene Nikanorov cbd89e75d3 Extract CommonDBMixin to a separate file
db_base_plugin_v2 imports too much modules that are not necessary
usually, so extract CommonDBMixin in different file.
Plus using db_base_plugin_v2 for some types of modules can lead to
cycles in imports, this refactoring should resolve the issue.

Closes-Bug: #1340145
Change-Id: Idb027d7c5cee2d5bc7598f805c56c55fd4aca048
2014-07-10 13:04:30 +04:00