Commit Graph

363 Commits

Author SHA1 Message Date
Slawek Kaplonski a644b3c62b [S-RBAC] Change policies for port's binding:profile field
According to the neutron API-REF [1] port's "binding:profile" field is
intended to be used for the "machine-machine communication for compute
services like Nova, Ironic or Zun to pass information to a Neutron
back-end." so it should be by allowed only for the users with the
SERVICE role granted, not even for ADMIN.
This patch updates that policies to be available only for SERVICE role
when new, secure RBAC policies are enabled.

Additionally this patch updates some policies for create, update and get
port APIs to make them all work in the same way and allow them for the
SERVICE users too.

Finally this new policy for create/update_port:binding:profile have to
be overwritten in the fullstack tests to be allowed also for admin user.
It is done by adding custom policy file for the fullstack tests only.

[1] https://docs.openstack.org/api-ref/network/v2/index.html#create-port

Closes-Bug: #2052937
Change-Id: I5c0094ff21439fe8977cfc623789a09067e6a895
2024-02-16 16:10:43 +01:00
Brian Haley 542c2ff463 Update hacking version
Update hacking to a more recent version, along with
flake8-import-order.

Remove N347 (import mock library) check as that is the
default with later hacking versions.

Update the builtins override of '_' to be the neutron.i18n
version due to the code triggering a false positive. This
is done in a couple of other projects as well.

Fix a number of new warnings it found.

Added some ignore directives for new whitespace issues
found in the test tree, can fix later.

TrivialFix

Change-Id: I5923255af86cf1fa11ab8e3b03bb9efac7dd7b58
2024-02-08 10:34:10 -05:00
Miguel Lavalle 49366ecada Router flavors and service type for OVN
Support is added to the OVN L3 service plugin for the router
flavors and service type framework

Partial-Bug: #2020823
Change-Id: If40d7b39e7b59a39ff7622bd823dbdb14bfc69d2
2024-01-17 09:33:07 -06:00
Brian Haley eddde3522b Remove deprected and unused argument from update_port_status()
The optional network argument was deprecated in
update_port_status() in Pike. Let's remove it as there
are are only in-tree callers passing it anymore.

TrivialFix

Change-Id: Iab8d3dada2e147da009e195700e64b072e5bfabb
2023-11-20 21:59:45 -05:00
Zuul 9694c64bf0 Merge "Forbid updating vnic type on a bound port" 2023-11-20 15:25:41 +00:00
Jakub Libosvar 354205a423 Forbid updating vnic type on a bound port
The vnic type should not be changed once the port is bound since it's
related to the actual port binding. The patch validates the port update
operation and fails the update if the vnic type is attempted to be
changed on a bound port.

Closes-bug: #2033090
Change-Id: I5cb79d9da96ba41a7787083c81f522c328fae049
Signed-off-by: Jakub Libosvar <libosvar@redhat.com>
2023-11-15 13:59:46 +00:00
Rodolfo Alonso Hernandez 71a7abb498 Remove any IPAM allocation if port bulk creation fails
During the port bulk creation, if an IPAM allocation fails (for
example, if the IP address is outside of the subnet CIDR), the
other IPAM allocations already created are deleted before raising
the exception.

Closes-Bug: #2039550
Change-Id: I7fd6e38016d099c03f80874bfa1fb8bdaff8bd2c
2023-10-14 18:37:43 +00:00
zhouhenglc 35cb164ea5 [ovn]disable security group notifier
When we use the ovn driver, the security group is implemented
by the ACL of ovn. There is no need to send rpc messages.

Closes-Bug: #2007327

Change-Id: I4b486c910ed298633ac6f60fd93f695c6c3bfef2
2023-05-24 14:15:33 +08:00
Zuul 232a67f444 Merge "[S-RBAC] Switch to new policies by default" 2023-05-05 11:10:24 +00:00
Slawek Kaplonski 670cc383e0 [S-RBAC] Switch to new policies by default
As part of the Secure RBAC community goal, we should switch options
"enforce_new_defaults" and "enforce_scope" to be True by default.
It will be still possible to fallback to old policy rules by configuring
those config options to False in Neutron config.

Change-Id: I09c0026ccf87e6c0bb1fa59165c03dc508fba6fa
2023-04-21 16:22:42 +02:00
Slawek Kaplonski a5e26408d2 Fix dns_integration and ml2 plugin unit tests modules
Those modules needs to ensure that common config options
are registered.
Otherwise it can't be successfully run without other tests as it was
then failing due to unregistered config option.

Trivial-fix

Change-Id: Ifa348218229b6be64bb7403d933df82f03afafdf
2023-04-19 16:56:22 +02:00
Slawek Kaplonski 8eecccfeae [S-RBAC] Allow network owners to get ports from that network
It was somehow missed initially when we wrote new Secure RBAC policies
but network owner should be able to see all ports created on the
network.

Additionally this patch adds mock of the neutron.policy.check function
in TestMl2DbOperationBounds class as this class is expected to check
DbOperators made by ML2 plugin while listing ports so there's no need to
include policy checks there too.

Change-Id: I2560edb915f7393fcda50dd4a37a1d366bd0ce59
2023-04-12 10:11:38 +02:00
Zuul f8121ee981 Merge "allow manila ports to do multiple port binding for ML2" 2023-02-09 17:14:03 +00:00
Maurice Escher 5c697b8d60
allow manila ports to do multiple port binding for ML2
Similar to Nova live migration
(see https://review.opendev.org/c/openstack/neutron/+/414251/74/neutron/plugins/ml2/plugin.py#2005)
Manila wants to do share live migration, and needs to modify its ports in a
similar way: issue port binding upfront to determine the segmentation id in
the target network segment.

Closes-Bug: #2003095
Change-Id: I647d00a30564ade246e704ff199b6aceafdc4c50
2023-02-06 09:20:55 +01:00
Bence Romsics ed68ba4a4c Do not ignore attributes in bulk port create
With unit tests that would have caught the bug.

Change-Id: Ia4a68bdccecfbcb9d1aa49e2b14e06d139891c0f
Closes-Bug: #2003553
2023-01-23 16:23:30 +01:00
Zuul e14a39e2f3 Merge "Fix bulk create without mac" 2022-12-12 22:06:05 +00:00
elajkat f7dd7790f5 Fix bulk create without mac
Bulk port create without mac address fails as when Neutron calls
oslo_utils.netutils.get_ipv6_addr_by_EUI64, as the mac field of the port
is an ATTR_NOT_SPECIFIED Sentinel() object.
With some reshuffling of the code to fill the mac field this can be
fixed.

Closes-Bug: #1995732
Related-Bug: #1954763

Change-Id: Id594003681f4755d8fd1af3b98e281c3109420f6
2022-11-30 11:47:28 +01:00
Sahid Orentino Ferdjaoui eeff5b3c81 db: add segment_index to the unique constraint
For multi segments support we have update the unique contraint so
`segment_index` will be part of it.

Related-Bug: #1791233
Partial-Bug: #1956435
Partial-Bug: #1764738
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@industrialdiscipline.com>
Change-Id: Ic564131dcd7525fc5f24c3282688e3584cd2e2e0
2022-11-23 08:43:21 +01:00
Rodolfo Alonso Hernandez 21491efd9f Port provisioning should retry only for VM ports
The port provisioning method ``Ml2Plugin._port_provisioned`` creates
an active wait to provision a port if the port is unbound since [1].
But this active wait should consider only VM ports in the case of
live migration, as described in the LP bug [2]. This wait should
not consider auxiliary Neutron ports or baremetal ports (we don't
live-migrate then).

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

Closes-Bug: #1991092
Change-Id: Ic8891e2deef4bb5e72cf7d7f37b043e936adbc00
2022-09-29 00:41:01 +02:00
Rodolfo Alonso Hernandez 91f0864dc0 Add an active wait during the port provisioning event
In ML2/OVN, during a live-migration process, it could
happend that the port provisioning event is received before
the port binding has been updated. That means the port has
been created in the destination host and the event received
(this event will remove any pending provisioning block). But
the Nova port binding request has not arrived yet, updating
the port binding registers. Because the port is considered
"not bound" (yet), the port provisioning doesn't set the port
status to ACTIVE.

This patch creates an active wait during the port provisioning
event method. If the port binding is still "unbound", the method
retries the port retrieval several times, giving some time to the
port binding request from Nova to arrive.

Closes-Bug: #1988199
Change-Id: I50091c84e67c172c94ce9140f23235421599185c
2022-08-31 23:20:37 +02:00
Nurmatov Mamatisa 655001594b Use neutron-lib method is_session_active
In patch [1] temporary was added is_session_active
method before n-lib patch [2] release. Now modified to
n-lib method

1) https://review.opendev.org/c/openstack/neutron/+/828739
2) https://review.opendev.org/c/openstack/neutron-lib/+/828738

Change-Id: I1144215b72f7c435e1949b2d66f8bbb268b08c98
2022-08-11 05:58:44 +02:00
Zuul d0ab555329 Merge "``Session.autocommit`` parameter is removed" 2022-08-17 15:48:53 +00:00
Rodolfo Alonso Hernandez 812ef0306f ``Session.autocommit`` parameter is removed
Since [1] (in oslo.db>9.1.0), the ``Session.autocommit`` member
is removed and should not be considered. This patch removes this
dependency while keeping backwards compatibility. This code will
be removed in future releases.

Due to the neutron-lib dependency, this patch bumps the needed
library version to 3.1.0.

[1]https://review.opendev.org/c/openstack/oslo.db/+/804775

Depends-On: https://review.opendev.org/c/openstack/neutron-lib/+/851193

Closes-Bug: #1982818
Change-Id: Ibfcf9d5f6cd805f2d64fcd88049e2b43fedc3497
2022-08-10 17:15:04 +02:00
Lucas Alvares Gomes 982c22dd46 [OVN] Fix updating network segmentation ID
The ML2/OVN driver wasn't handling updates to the segmentation ID for a
given network. This patch fixes this problem.

This patch extends the _update_segmentation_id() method to check on
drivers which does not inherits from AgentMechanismDriverBase, which
is the case of OVN (which inherits from MechanismDriver). A new method
is now called for those drivers to get a list of supported VIF types,
called get_supported_vif_types().

Closes-Bug: #1944708
Change-Id: Ibe08bfbc2efc55b9d628cdd0605941b7486186b6
Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
2022-08-10 09:44:55 +01:00
Rodolfo Alonso Hernandez f3b84ed099 Remove unneeded contexts in ``_create_port_security_group_binding``
Removed unneeded database context in
``_create_port_security_group_binding``. This method is called always
from inside an active database transaction, when the port is udpated
or created.

The retry context only makes sense when a method is called outside
an active database transaction. It doesn't retry the command if the
context passed has an active transaction.

Trivial-Fix

Change-Id: I8f84c1bce0d1ce2538789e3511fd8f7b64fcd41a
2022-05-20 09:07:02 +00:00
Miro Tomaska 0fba55cc26 Address small nitpick from patch 840146
Very minor changes to address nitpick from patch 840146

Change-Id: I582b94f3da4cb51364f122510371b2a792f8ec3e
2022-05-27 21:44:42 -05:00
Miro Tomaska d1fe14d366 Notify mech drivers with original and modified network.
Include original and modified network when notifying mechanism drivers in PRECOMMIT event. PRECOMMIT_CREATE modified network includes new segment, while original does not. Exact opposite for PRECOMMIT_DELETE

Closes-Bug: #1967742
Change-Id: I364fc7981458374ed25eb8837d1ed3afff046b95
2022-05-24 21:56:47 -05:00
Zuul cab15b15e2 Merge "Update port MAC from binding profile for PFs" 2022-04-25 12:54:29 +00:00
Balazs Gibizer 4e78aaa694 Update port MAC from binding profile for PFs
Today Nova updates the mac_address of a direct-physical port to reflect
the MAC address of the physical device the port is bound to. But this
can only be done before the port is bound. However during migration Nova
is not able to update the MAC when the port is bound to a different
physical device on the destination host.

This patch extends port binding logic for direct-physical ports to allow
providing the MAC address of the physical device via the binding profile.
If it is provided then Neutron overwrites the value of the mac_address
field of the port with the value from the active binding profile.

Also when the port is being unbound or the MAC address is removed from
the active binding porfile then neutron resets the mac_address field of
port to a generated MAC to avoid duplicated MAC issues when another port
is being bound to the same physical device.

The shim API extension for this change is being proposed in
I54b4c85ffc4856fba7ad5e9e29f77f74815e1275 in neutron-lib.

Depends-On: https://review.opendev.org/c/openstack/neutron-lib/+/831935

Closes-Bug: #1942329

Change-Id: Ib0638f5db69cb92daf6932890cb89e83cf84f295
2022-04-21 11:31:05 +02:00
Rodolfo Alonso Hernandez 9829865073 Refactor session "is_active" handling for sqlalchemy-20
Since sqlalchemy 1.4, "session.autocommit" is False by default; in
sqlalchemy 2.0 this will be the only value accepted.

The ``_orm.Session`` is considered active when [1]:
- there is a transaction and this transaction is active
- there is no transaction [2], the class ``_orm.Session`` will
   autobegin when it is first used.

The second one breaks the way Neutron considers a session is active:
only when a transaction is in place, Neutron considers a session is
active.

[1]https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_4/lib/sqlalchemy/orm/session.py#L3918-L3950
[2]https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_4/lib/sqlalchemy/orm/session.py#L3930-L3932

Partial-Bug: #1962153
Topic: sqlalchemy-20

Change-Id: Iabaee4e556afb3dc75a82d99dc4a597fe4d7dd21
2022-02-10 09:03:36 +00:00
Slawek Kaplonski 82aabb0aa9 Allocate IPs in bulk requests in separate transactions
In the ML2 plugin in create_port_bulk method, we are iterating over
list of the ports to be created and do everything for all ports in
single DB transaction (which makes totally sense as this is bulk
request).
But one of the things which was done during that huge transaction was
allocation of the IP addresses for all ports. That action is prone for
race conditions and can fail often, especially when there is no many IP
addresses available in the subnet(s) for the ports.
In case of the error while allocating IP address even for one port from
the whole bulk request, whole create_port_bulk method was retried so
allocations (and everything else) for all ports was reverted and started
from scratch. That takes a lot of time so some requests may be processed
very long time, like e.g. 2-3 minutes in my tests.

To reproduce that issue I did simple script which created network with
/24 subnet and then sent 24 requests to create 10 ports in bulk in each
request. That was in totall 240 ports created in that subnet.
I measured time of the creation of all those ports in the current master
branch (without this patch) and with the patch. Results are like below:

+-----+---------------+------------+---------------------------+
| Run | Master branch | This patch | Simulate bulk by creation |
|     | [mm:ss]       | [mm:ss]    | of 10 ports one by one    |
+-----+---------------+------------+---------------------------+
| 1   | 01:37         | 01:02      | 00:57                     |
| 2   | 02:06         | 00:40      | 01:03                     |
| 3   | 02:08         | 00:41      | 00:59                     |
| 4   | 02:14         | 00:45      | 00:55                     |
| 5   | 01:58         | 00:45      | 00:57                     |
| 6   | 02:37         | 00:53      | 01:05                     |
| 7   | 01:59         | 00:42      | 00:58                     |
| 8   | 02:01         | 00:41      | 00:57                     |
| 9   | 02:39         | 00:42      | 00:55                     |
| 10  | 01:59         | 00:41      | 00:56                     |
+-----+---------------+------------+---------------------------+
| AVG | 00:02:07      | 00:00:45   | 00:58                     |
+-----+---------------+------------+---------------------------+

Closes-Bug: #1954763
Change-Id: I8877c658446fed155130add6f1c69f2772113c27
2021-12-21 12:56:35 +01:00
Zuul d562866fd2 Merge "Deprecate 'allow_overlapping_ips' config option" 2021-11-04 14:20:17 +00:00
Slawek Kaplonski 042de7e6bb Deprecate 'allow_overlapping_ips' config option
Config option allow_overlapping_ips is deprecated to removal now and
will be removed in the Z cycle.
Default value for that option is now set to True as this is supported by
IPAM module in Neutron.

Related-Bug: #1942294
Change-Id: I17bf5e4483025e9cc4ee04dd3e7c925f7bddc3db
2021-10-21 10:56:33 +00:00
Sebastian Lohff b993ebb407 Fix dynamic segment allocation race condition
When two segments are concurrently created this could have resulted in
both threads creating a segment, thus resulting in two segments with
different segmentation ids. To prevent this we now introduce a new
unique constraint onto the networksegments table, which requires
(network_id, network_type, physical_network) to be unique, which allows
only a single segment with a single segmentation id to exist per
combination of these three values.

With the constraint in place a DB error will be thrown, which will cause
allocate_dynamic_segment() to be executed again and this time it will
find the already existing segment. To make sure that no additional DB
objects are created when segment creation failed we need to put all of
the allocation code into a DB transaction.

Change-Id: I407ae88d69ed971bf8d9a9b79120366f33bb56fd
Closes-Bug: #1791233
2021-10-07 13:20:04 +02:00
Rodolfo Alonso Hernandez 603abeb977 Execute the quota reservation removal in an isolated DB txn
The goal of [1] is to, in case of failing when removing the quota
reservation, continue the operation. Any expired reservation will
be removed automatically in any driver.

If the DB transaction fails, it should affect only to the reservation
trying to be deleted. This is why this patch isolates the
"remove_reservation" method and guarantees it is called outside an
active DB session. That guarantees, in case of failure, no other DB
operation will be affected.

This patch also partially reverts [2] but still checks the security
group rule quota when a new security group is created. Instead of
creating and releasing a quota reservation for the security group
rules created, now only the available quota limit is checked before
creating them. That won't prevent another operation to create security
group rules in parallel, exceeding the available quota. However, this
is not even guaranteed with the current quota driver.

[1]https://review.opendev.org/c/openstack/neutron/+/805031
[2]https://review.opendev.org/c/openstack/neutron/+/701565

Closes-Bug: #1943714

Change-Id: Id73368576a948f78a043d7cf0be16661a65626a9
2021-09-30 13:53:23 +00:00
Zuul c23dd997a0 Merge "[L2] no provisioning block for internal service port" 2021-09-14 18:39:18 +00:00
Nurmatov Mamatisa 43871e0654 Rename notify to publish
Neutron-lib patch [1] neutron-functional-with-uwsgi test is
failing because missed some code with notify

1) https://review.opendev.org/c/openstack/neutron-lib/+/807869

Change-Id: I2b4048a6bbcb9d1a385702755810714db5ea2d94
2021-09-09 18:11:27 +03:00
Zuul 7c28f39287 Merge "Rename notify to publish in unit tests" 2021-09-06 14:24:34 +00:00
Zuul 99db0d79b9 Merge "Replace deprecated assertDictContainsSubset" 2021-09-06 11:48:18 +00:00
Takashi Kajinami 34acbd6ff8 Replace deprecated assertDictContainsSubset
The method is deprecated since Python 3.2[1] and shows the following
DeprecationWarning.

/usr/lib/python3.9/unittest/case.py:1134: DeprecationWarning:
assertDictContainsSubset is deprecated
  warnings.warn('assertDictContainsSubset is deprecated',

[1] https://docs.python.org/3/whatsnew/3.2.html#unittest

Closes-Bug: #1938103
Change-Id: Iab60f52ffbfb3668e9509ce86e105917c616b8a9
2021-09-05 01:01:35 +09:00
Nurmatov Mamatisa d0c871df19 Rename notify to publish in unit tests
After [1] patch merging all neutron code will be
switched to payload style callback[2].
Neutron-lib registry.notify can be depricated

1) https://review.opendev.org/c/openstack/neutron/+/806607
2)https://codesearch.openstack.org/?q=registry.notify&i=nope&literal=nope&files=&excludeFiles=&repos=

Change-Id: I5a549c4d09822659f7e4cdd08b085d856f3b65ed
2021-09-02 14:41:18 +00:00
Oleg Bondarev 3640ffa0c6 Handle all portbinding attrs in case of bulk port creation
Bulk port creation should honor binding:vnic_type
and binding:profile attributes from request.

Closes-Bug: #1940074
Change-Id: I99d27d568f66c6330f6373843d096c6ee1b4ec54
2021-08-19 23:19:47 +08:00
Nurmatov Mamatisa e7c61d3eba use payloads for PORT and FLOATING_IP
This patch switches over to callback payloads for PORT
and FLOATING_IP PRECOMMIT_DELETE events.

Change-Id: I2b3dd3ac70bcdd51125650f0a997859316ff644a
2021-07-22 18:25:42 +03:00
LIU Yulong e0ea4a51ba [L2] no provisioning block for internal service port
Provisioning Blocks [1] was introduced to manage composite
object status. Port object is the one Neutron sets provisioning
block during the port processing life cycle. Here is the compute
port (VM's NIC port) processing procedure:
1. nova creates port
2. the 'openvswitch' mechinism driver inserts provisioning block
   for this port
3. nova calls related interface to plug the device
4. L2-agent sets the flows (or rules/devices) for the port and
   call update_device_list to neutron-server
5. neutron-server try to set port status to ACTIVE
6. neutron-server notify nova that "vif-plugged" success

This works fine for VM with its ports. But for neutron service port,
like router_gateway, router_interface and dhcp, it is unnecessary.
Because there is no dependency among neutron resources. Neutron
just knows that the ports had been set properly. And another thing
is, for most of these internal service port, there is no need of
DHCP, security group or port security.

So for neutron internal service ports, the procesure can be:
1. neutron L3/DHCP/X related service plugin creates port
2. no provisioning_block
3. L3/DHCP/X related agent plug the port
4. L2-agent sets the flows (or rules/devices) for the port and
   call update_device_list to neutron-server
5. neutron-server sets port status to ACTIVE directly, then done!

This patch will set neutron *AgentMechanismDrver (including built-in
drivers: linuxbridge, macvtap, sriov, openvswitch) to skip inserting
the provisioning_block for Neutron internal service ports.

[1] https://docs.openstack.org/neutron/latest/contributor/internals/provisioning_blocks.html

Closes-Bug: #1930432
Change-Id: Iaf7788bf0cba19a693cbf456f98e50d7b5de9e41
2021-07-13 08:23:01 +08:00
Nurmatov Mamatisa 3cae410b30 use payloads for PORT AFTER_DELETE events
This patch switches over to callback payloads for PORT
AFTER_DELETE events.
Some shims were removed.

Change-Id: If69e37b84fe1b027777b1d673b3d08a6651a979e
2021-07-11 06:00:08 +00:00
Nurmatov Mamatisa 129b823a8b use payloads for PORT AFTER_UPDATE events
This patch switches over to callback payloads for PORT
AFTER_UPDATE events.

Change-Id: I5c00eae155afa6c0fc8e3956bc39edbeca3ea1e7
2021-07-07 21:01:24 +00:00
Zuul 3127bd1d57 Merge "[ML2] Change way how list of supported API extensions is made" 2021-06-28 00:54:46 +00:00
Zuul 7fd6d169f5 Merge "use callback payloads for SUBNET" 2021-06-25 12:57:25 +00:00
Slawek Kaplonski db2207f32d [ML2] Change way how list of supported API extensions is made
Previously if extension was not supported by one of the mech drivers,
but it wasn't filtered out by next mech driver, it was available finally
in the list.
Now, this patch changes that so if extension is disabled by one of the
drivers it isn't available on the list at all.
This will work better e.g. with discoverability of what is available
e.g. when OVN backend is used by Neutron.

Closes-Bug: #1929676
Change-Id: I6a4ff42f47f7ee90365516d37472c09ac87773e5
2021-06-25 07:41:11 +00:00
Nurmatov Mamatisa cd8c4f7e30 use callback payloads for SUBNET
This patch switches over to callback payloads for
SUBNET events.

Change-Id: Ic4c3490aed4f899293be993d4663bb537c34ab8b
2021-06-24 00:14:52 +03:00