Commit Graph

100 Commits

Author SHA1 Message Date
Zuul d32c5f8f32 Merge "Fix some new pylint "R" warnings" 2023-07-28 06:58:46 +00:00
Brian Haley 929b383743 Fix some new pylint "R" warnings
After updating pylint, it started emitting additional "R"
warnings in some cases, fix some of them.

  use-a-generator,
  unnecessary-lambda-assignment,
  consider-using-max-builtin,
  consider-using-generator,
  consider-using-in,
  use-list-literal,
  consider-using-from-import

Trivialfix

Change-Id: Ife6565cefcc30b4e8a0df9121c9454cf744225df
2023-07-18 18:06:51 -04:00
Sahid Orentino Ferdjaoui 256297fc7f rbacs: clean-up to use defined constants ACCESS_*
Some files are using strings access_as_shared or access_as_external
instead of using defined constants ACCESS_SHARED and ACCESS_EXTERNAL.

This commit is doing the cleaning it does not bring any functional
change.

Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@industrialdiscipline.com>
Change-Id: Ib75326c762776c5259740cb2f0abc1163842f95d
2023-05-05 16:08:20 +02:00
Brian Haley 55b16d7b7c Fix some pylint indentation warnings
Running with a stricter .pylintrc generates a lot of
C0330 warnings (hanging/continued indentation). Fix
the ones in neutron/db.

Trivialfix

Change-Id: I9311cfe5efc51552008072d84aa238e5d0c9de60
2022-11-03 19:50:54 -04:00
Zuul 430abde13e Merge "Add the corresponding DB context to all SQL transactions" 2022-04-08 13:08:32 +00:00
Rodolfo Alonso Hernandez eeb918e1b9 Add the corresponding DB context to all SQL transactions
The goal of this patch is to make the Neutron code compliant
with SQLAlchemy 2.0.

All SQL transactions must be executed inside an explicit
writer/reader context. SQLAlchemy no longer will create an
implicit transaction if the session has no active transaction.

A warning message, only available in debug mode, is added. When
an ORM session calls "do_orm_execute", if there is no active
transaction, a warning message with a traceback will be logged
to help to debug the regression introduced.

Related-Bug: #1964575

Change-Id: I3da37fee205b8d67d10673075b9130147d9eab5f
2022-04-08 09:09:54 +00:00
yatinkarel 820b2e2665 Ensure gateway is set for prefix delegated subnets
With [1] gateway is no longer set for subnet created
with prefix delegation, but when adding the subnet
to the router it fails as it expects gateway to be
set.

This patch ensures gateway is set temporary to the first IP
of the subnet as it used to be just like the temporary CIDR.
Also need to ensure dhcp configuration is skipped to avoid the
original issue[2].

[1] https://review.opendev.org/c/openstack/neutron/+/699465
[2] https://bugs.launchpad.net/neutron/+bug/1856675

Closes-Bug: #1962306
Related-Bug: #1856675
Change-Id: I512f7d98ac99bb0ef06fd2acba09482e3436d18d
2022-03-03 11:10:54 +05:30
Rodolfo Alonso Hernandez 8813b0ed2d Replace "target_tenant" with "target_project" in RBAC OVOs and models
This is part of the remaining technical debt of the specs
https://specs.openstack.org/openstack/neutron-specs/specs/newton/moving-to-keystone-v3.html

Blueprint: https://blueprints.launchpad.net/neutron/+spec/keystone-v3

Change-Id: I2d2fd4d1802c9dfe0778ac8fdddc7b9a8afe7d25
2021-12-03 10:48:57 +00:00
Oleg Bondarev 0af8497076 Improve Port list and show
Don't eagerly load several fields which are not used in
port list and show.

Port list and show speed-up is ~10-25%.

Depends on neutron-lib change:
https://review.opendev.org/c/openstack/neutron-lib/+/788729

Change-Id: I4bfcac16a54b766e0dc97f58ba4048eb709fa88f
2021-06-24 06:19:07 +00:00
Oleg Bondarev 4bb3c92917 Check for existence instead of fetching the whole net object
There is no need to fetch the whole net object
(which leads to several heavy DB requests according
to OSProfiler stats) when only need to check net existence

This speeds up port creation up to 15%

Closes-Bug: #1917866
Change-Id: I75db7c713a17a0f1b1b5aecc6eec93e636a71827
2021-03-10 11:06:29 +04:00
Oleg Bondarev e007349d47 Optimize get_ports with trunk extension
Use case: many trunk ports (300+) each with many subports.
Issue: get_ports takes much time.
Solution: apply trunk resource extend func for a full list of ports,
not for each port individually, thus avoiding a DB query for each
trunk port.

The approach will be extended for other resource extenders, like QoS,
and probably for other resources as well.
QoS: https://review.opendev.org/c/openstack/neutron/+/764454

Change-Id: Ic08e4049f6156c0700ca3c7aee251b6eb0eb97da
Closes-Bug: #1905268
2021-01-12 07:33:06 +00:00
Rodolfo Alonso Hernandez 78858e6719 Add "standard_attr_id" to some OVO dictionaries
Included standard attributes ID in some OVO dictionaries to improve
the OVN revision numbers operation. Having this ID, there is no need
to retrieve it from the database.

The following OVOs have been updated:
- port
- network
- subnet
- security group
- security group rule
- router

Closes-Bug: #1904188

Change-Id: Ia16335a2fc8f9324b9489692c76a73e4ef5bef96
2020-11-16 13:56:39 +00:00
Zuul 08863de754 Merge "Remove "six" library" 2020-07-30 00:35:59 +00:00
Rodolfo Alonso Hernandez ddd5832323 Remove "six" library
Last step to remove "six" library usage in Neutron.

Change-Id: Idd42e0c51c8c3bd598c9cf91602596be238bccae
2020-07-28 16:55:52 +00:00
Rodolfo Alonso Hernandez d0c9cc4c8f Remove DbBasePluginCommon._get_subnet unused method
Change-Id: I57a4508f42820db7876a9a8a63bb4d46e7b7ac28
2020-07-24 17:05:22 +00:00
Rodolfo Alonso Hernandez f8718e9b23 Remove unused method "_make_fixed_ip_dict"
Change-Id: I085a1fac9b2710d864d9be15e472a9e0ee14fc75
2020-05-01 08:35:34 +00:00
Igor Malinovskiy 56b971bb42 Allow sharing of subnet pools via RBAC mechanism
Neutron-lib api ref: https://review.opendev.org/705998/
Client: https://review.opendev.org/#/c/712705/
Tempest tests: https://review.opendev.org/#/c/711656/

Change-Id: I1d6125513cd8cb088b84c92497866f78955019a9
Partial-Bug: #1862032
Depends-On: https://review.opendev.org/709122
2020-04-09 19:02:47 +03:00
zhanghao af274fa826 Switch to reader context
Since the mtu is already non-nullable, the writer context
can be switched to a reader context. In addition, the redundant
reader context can be removed.

Change-Id: I482a3892dee8ee94ab70142cf734f71e766178ed
Closes-Bug: #1859258
2020-01-07 20:24:14 -05:00
zhouhenglc 39255f3e7e Parameter 'fileds' value is not used in _get_subnets
this patch remove it.

Change-Id: I20409d99c1906cbddede2f799cab5350eb290f5c
2019-11-19 11:21:40 +08:00
Zuul 9c00658a10 Merge "Optimize DVR related port DB query" 2019-08-30 19:42:26 +00:00
Harald Jensås 16679e9700 Conntrack Helper - Plugin
Implements Conntrack Helper service plugin for conntrack
helper resources. Supports create, update and delete
conntrack helper for l3 routers.

A new configuration option:
  [l3-conntrack-helpers]/allowed_conntrack_helpers
introduced to allow the operator to configure CT
helpers, and the helper protocol constraints.

Related-Bug: #1823633
Depends-On: https://review.opendev.org/663446
Change-Id: I58193955261f50b18b1946261fe662da6b20f0f5
2019-08-29 10:41:04 +02:00
LIU Yulong dd96f37759 Optimize DVR related port DB query
Save order by in port query when not require fixed_ips,
and save some useless query for dvr subnet mac.

Closes-Bug: #1834308
Change-Id: I6836840edcaa5a21fd2ba9f65ffd24f7e5038fa3
2019-08-25 01:24:03 +08:00
Nate Johnston d0c172afa6 Fix bulk port binding
Bulk ports were not binding correctly when they were created.  This is
due to a few inconsistencies between the create_port code and the
create_port_bulk code, mostly a result of the use of the Port object in
the bulk code.

Change-Id: I3bcd3cec12b1b6f6a568cda4bfeb569f636efb98
Closes-Bug: #1835209
2019-07-05 13:50:31 -04:00
Harald Jensås af77355732 Turn CIDR in query filter into proper subnet
Use netaddr.IPNetwork to convert CIDRs in a query
into proper subnets.

When creating subnets the CIDR is converted into
a proper subnet. i.e a subnet can be created with
cidr=10.0.0.11/24 in the create request. On create
the cidr is turned into a proper subnet resulting
in a subnet with cidr=10.0.0.0/24.

This change does the same to CIDRs when used as
query filters during a list subnet request, so
that the same value that was used to create the
subnet can be used to find the subnet.

Closes-Bug: #1831811
Change-Id: I8ae478a03ceedc6c3b1ae1d40081b5e5158813e6
2019-06-06 17:43:10 +02:00
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
Zuul f8b990736b Merge "remove neutron.common.constants" 2019-04-11 18:33:05 +00:00
Boden R 9bbe9911c4 remove neutron.common.constants
All of the externally consumed variables from neutron.common.constants
now live in neutron-lib. This patch removes neutron.common.constants
and switches all uses over to lib.

NeutronLibImpact

Depends-On: https://review.openstack.org/#/c/647836/
Change-Id: I3c2f28ecd18996a1cee1ae3af399166defe9da87
2019-04-04 14:10:26 -06:00
Nate Johnston dd95246fbe Ensure that bulk port dicts have unix-style MAC addresses
The bulk port code uses the Port OVO object, which encodes MAC address
as a netaddr.EUI object.  The default string representation for a
netaddr.EUI object is the standard IEEE EUI-48 format
("XX-XX-XX-XX-XX-XX") [1].  Having MAC addresses in that format breaks
the midonet gate, so revert to UNIX standard mac addresses
("xx:xx:xx:xx:xx:xx").

[1] https://netaddr.readthedocs.io/en/latest/tutorial_02.html#formatting

Change-Id: I2d2727335c347accdeb39cbac5151722e8a3339c
Closes-Bug: #1822999
2019-04-03 16:35:10 -04:00
Nate Johnston 2dc61dfbcc Utilize bulk port creation ops in ml2 plugin
Rather than iterating through all ports and leveraging the heavyweight
ml2 method, use a set of optimized functions that attempts to make bulk
port operations as speedy as possible.

The test test_bulk_ports_before_and_after_events_outside_of_txn is
deleted because with the change to using port OVO, the session will
not be closed, and it is not correct to check for it.

Change-Id: Ieea0e6074cd31a2d09ae92f1f3c8d375c6d8ecc2
Implements: blueprint speed-up-neutron-bulk-creation
2019-03-21 11:31:36 +00:00
Brian Haley eaf990b2bc Fix pep8 E128 warnings in non-test code
Reduces E128 warnings by ~260 to just ~900,
no way we're getting rid of all of them at once (or ever).
Files under neutron/tests still have a ton of E128 warnings.

Change-Id: I9137150ccf129bf443e33428267cd4bc9c323b54
Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
2019-03-12 21:22:33 +00:00
Boden R 68fd13af40 remove neutron.common.exceptions
Today the neutron common exceptions already live in neutron-lib and are
shimmed from neutron. This patch removes the neutron.common.exceptions
module and changes neutron's imports over to use their respective
neutron-lib exception module instead.

NeutronLibImpact

Change-Id: I9704f20eb21da85d2cf024d83338b3d94593671e
2019-02-01 14:35:00 -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
Nate Johnston 6098fc7430 Incorporate capability for multiple mac generation
The bulk port creation scenario requires the ability to generate
multiple MAC addresses for the bulk added ports.  This change leverages
the code added in [1] to make bulk MAC creation available.

[1] https://review.openstack.org/510830

Implements: blueprint speed-up-neutron-bulk-creation
Depends-On: https://review.openstack.org/613149
Change-Id: Ia769dadf69781ba511a19c52998949b668963a19
2018-11-08 09:43:33 -05:00
Boden R e4aa5902f7 use context manager from neutron-lib
The neutron.db.api.context_manager already references neutron-lib's
context manager; so consumers of it are already using neutron-lib. This
patch switches neutron's references to the context_manager over to
use neutron-lib's directly rather than that in neutron.db.api.

NeutronLibImpact

Change-Id: I97120faeec73690592ed21a5ec3c6202f61e1429
2018-10-24 07:18:46 -06: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
Ihar Hrachyshka f69389004a Revert "Revert "Automatically expire obsolete relationships""
This reverts commit a75014792a.

This is the second attempt to merge the patch after the previous one resulted
in revert due to multiple gate breakages in dependent projects (neutron-lbaas,
vmware-nsx, heat, networking-odl). This second attempt is validated with a set
of depends-on patches for all projects that were affected during the first
failed attempt.

The original commit message for the patch is included below for context.

===

Listen for foreign key changes and expire related relationships.

With this, we can remove OVO code that refreshes / detaches models on
each fetch. The patch also removes a bunch of expunge calls in plugin
code.

writer.using context manager is added to _get_subnets so that segment
plugin's _notify_subnet_updated handler that calls to _get_subnets
doesn't use the facade-less context.session that in specific cases may
cache old models from previous sessions when used in mixed
facade/facade-less environment.

This patch bumps SQLAlchemy minimal requirement to >= 1.2.0 because
pending_to_persistent event didn't exist before this version. It could be >=
1.1.0 if not for the fact that all 1.1.x releases have a bug that results in
breakage of test_update_with_none_and_own_mac_for_duplicate_ip due to obscure
import ordering issue in the library.

(The issue is fixed by https://github.com/zzzeek/sqlalchemy/commit/
63ff0140705207198545e3a0d7868a5ba8486e93)

Partially-Implements: blueprint enginefacade-switch
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db

Co-Authored-By: Michael Bayer <mike_mp@zzzcomputing.com>
Depends-On: If4b28110f460f6ac77ace1bbb02967ea986d4cab
Depends-On: I9f1e76cb24838533572b5fbe269ff96a24ce4af1
Change-Id: I0d65d19204da8ce30addfa5faff68544534b7853
2018-04-26 22:04:07 +00:00
Rabi Mishra a75014792a Revert "Automatically expire obsolete relationships"
This reverts commit 90ede813b0.

Closes-Bug: #1766267
Change-Id: Ia491a2a404bcbd9e108d20b2d9393aff1bb48c8e
2018-04-23 14:30:32 +00:00
Ihar Hrachyshka 90ede813b0 Automatically expire obsolete relationships
Listen for foreign key changes and expire related relationships.

With this, we can remove OVO code that refreshes / detaches models on
each fetch. The patch also removes a bunch of expunge calls in plugin
code.

writer.using context manager is added to _get_subnets so that segment
plugin's _notify_subnet_updated handler that calls to _get_subnets
doesn't use the facade-less context.session that in specific cases may
cache old models from previous sessions when used in mixed
facade/facade-less environment.

This patch bumps SQLAlchemy minimal requirement to >= 1.2.0 because
pending_to_persistent event didn't exist before this version. It could be >=
1.1.0 if not for the fact that all 1.1.x releases have a bug that results in
breakage of test_update_with_none_and_own_mac_for_duplicate_ip due to obscure
import ordering issue in the library.

(The issue is fixed by https://github.com/zzzeek/sqlalchemy/commit/
63ff0140705207198545e3a0d7868a5ba8486e93)

Partially-Implements: blueprint enginefacade-switch
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db

Co-Authored-By: Michael Bayer <mike_mp@zzzcomputing.com>
Change-Id: I18c6794f99d2847c208dfd6e9eb187d53b657a05
2018-04-20 15:33:59 -05:00
Sławek Kapłoński d795fc9471 Switch to Subnet OVO in ipam_backend_mixin _save_subnet method
This patch switch to use Subnet OVO in
ipam_backend_mixin.IpamBackendMixin._save_subnet
method.

To use Subnet OVO there, additional changes in _make_subnet_args()
method are also required. Now this method returns:
* 'project_id' instead of 'tenant_id',
* 'cidr' as instance of netaddr.IPNetwork,
* 'gateway_ip' as instance of netaddr.IPAddress

Change-Id: I9fb284e98394b1a41ec8af919b65dc512663ff6a
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2018-01-03 12:48:44 +01:00
Sławek Kapłoński 4d97dba20b Revert "Revert "objects: get, update and delete converted to Subnet OVO usage""
This reverts commit 1470baf02b.

As Neutron uses own objects registry this commit should be safe
to merge again and it shoudn't break projects like midonet.

Change-Id: I51833eebb4b24207f395e1d4095b1809f191a480
2017-12-01 16:45:50 +07:00
YAMAMOTO Takashi 1470baf02b Revert "objects: get, update and delete converted to Subnet OVO usage"
This reverts commit 32c757babd.

Closes-Bug: #1731623
Change-Id: Ie5c773165948d6db55f1b7ba3b7e312a5bb1318b
2017-11-12 09:33:20 +00:00
Artur Korzeniewski 32c757babd objects: get, update and delete converted to Subnet OVO usage
changes made in db_base_plugin _v2 and _common:
- _make_subnet_dict accepts both dict and Subnet object
- _delete_subnet uses Subnet object

added in db_base_plugin_common:
- _get_subnet_object* - returns Subnet object

Co-Authored-By: Slawek Kaplonski <slawek@kaplonski.pl>
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
Change-Id: I04e155cb92be65f4d5e8e9a4c21e6ca736aff82c
2017-11-03 21:14:06 +00:00
Lujin 019c7cebb3 Integration of Port OVO in db_base_plugin_common.py
This patch integrates Port OVO in db/db_base_plugin_common.py and
other two files, except for _get_port() which results in changes
in a large scale and will be taken care of in following patches.

Change-Id: Ia19996d7fb3f09a63ed0f392e013bed422b5eebe
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2017-08-29 13:21:36 +09:00
Ihar Hrachyshka d207fb9235 Fixed FlushError on subnet creation retry
Automatically allocated fixed IP addresses were not reflected on cached
port records, which triggered FlushError if the allocating method failed
and triggered a retry.

Change-Id: Ia7725094827b554aa6d928c7daa026959a237991
Closes-Bug: #1706750
2017-07-26 19:21:02 +00:00
Jenkins 3d4aee57db Merge "Integration of IPAllocation" 2017-07-10 04:17:15 +00:00
Boden R 62576cabf7 use core resource attribute constants from neutron-lib
neutron-lib now contains the API definitions for neutron's core
resources. This patch removes the constant core resource and collection
variables and uses them from lib. Subsequent patches will consume the
actual core resource attribute definitions.

NeutronLibImpact

Change-Id: Ia9afdf620cd538b2aa420593277d6403a45c996b
2017-06-30 06:25:36 -06:00
Victor Morales 6670954de3 Integration of IPAllocation
This patch integrates the Oslo-Versioned Object created for
IPAllocation model class.

Change-Id: Ibb731c4635d89c848081fac73f216d2ecf10b599
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2017-06-21 17:33:41 +09: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 d8c1e153f8 Stop using CommonDbMixin
Now that CommonDbMixin is just a shim we can stop using it.

Instead, use the model_query and resource_extend functions directly.

Related-Blueprint: neutron-lib

Change-Id: If1252c42c49cd59dba7ec7c02c9b887fdc169f51
2017-04-26 10:37:36 -04:00