Commit Graph

306 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
Zuul 2d74a93d68 Merge "Disallow subnet cidr of :: without PD" 2024-02-13 21:48:00 +00: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 2f00111940 Disallow subnet cidr of :: without PD
Do not allow the subnet cidr of :: to be used when
creating a subnet, except in the case IPv6 prefix
delegation has been specified in the request.

Closes-bug: #2028159
Change-Id: I480e9a117513996f3c070acd4ba39c2b9fe9c0f1
2024-01-08 17:06:49 -05:00
Brian Haley 2f91d330da Correctly validate subnet arguments when using a subnetpool
When creating a subnet using a subnetpool, we were
failing to validate all the passed API arguments in
the dictionary, leading to a case where you could
specify an invalid DNS nameserver. For example,
using an IPv4 nameserver on an IPv6 subnet. This
could cause daemons the l3-agent starts, like radvd,
to fail to start correctly, leading to a loss of
connectivity.

Specifying a subnet by cidr without a subnetpool
did already correctly fail with an IP version
mismatch error, this is just an edge case that
was never tested.

Since _validate_subnet() was called in so many places
it was moved to a common location and is only not
called for IPv6 prefix-delegation subnets.

Closes-bug: #2036877
Change-Id: I6302e9a373cf93e706cec10f87c3beaf632a0391
2023-11-15 17:01:04 -05:00
Slawek Kaplonski 428f7a8418 [S-RBAC] Add service role in neutron policy
RBAC community wide goal phase-2[1] is to add service
role for the service APIs policy rule.
This patch adds new "service_api" role in policies, deprecates old rule
"context_is_advsvc" as this had basically same goal but for consistency
reasons we want now to have it named "service_api" as in other policies
for other projects.
This patch also adds unit tests to ensure what is allowed and what is
forbidden for the service role user.

[1] https://governance.openstack.org/tc/goals/selected/consistent-and-secure-rbac.html#phase-2

Closes-Bug: #2026182

Change-Id: Iaa1a3a491d310c2304f6500c6e5d2b9c31a72fa8
2023-10-06 07:55:05 +00:00
Rodolfo Alonso Hernandez 80f547ad1d Add a "port" child table "porthardwareoffloadtype"
This table has a 1:1 relationship with the "port" table, providing
the "hardware_offload_type" field (string).

The "neutron-lib" library minimum version is 3.8.0, that contains
[1].

NOTE: once the OSC patch is merged [2], the documentation will be
updated to reflect how to create a hardware offloaded port without
manually defining the port binding profile,

[1]https://review.opendev.org/c/openstack/neutron-lib/+/882726
[2]https://review.opendev.org/c/openstack/python-openstackclient/+/892792

Partial-Bug: #2013228
Change-Id: I04f232d6c43e39f254c4559caf041dcf05acec21
2023-08-19 06:08:51 +00:00
Rodolfo Alonso Hernandez 670675dd17 [sqlalchemy-20] Network "repr" should be tested with any order
The "repr" method of Network does not have an order enforced. The
elements of the DB model can be printed in the representation string
in any order.

Closes-Bug: #2027595
Change-Id: I763ee916eaf4dd9f3906bd20595f0533d25e356d
2023-07-07 03:13:17 +00:00
Zuul daa24b9492 Merge "port-hints: api extension" 2023-05-11 10:43:21 +00:00
Bence Romsics 0390ada97c port-hints: api extension
api extension
db model
db migration
ovo (including changes affecting push rpc)
extension driver
policies

To enable this:

* neutron-db-manage upgrade 6f1145bff34c
* ml2_conf.ini:
  [ml2]
  extension_drivers += port_hints

This patch also bumps neutron-lib requirement to 3.5.0.

Change-Id: I80816618285d742775bc0534510c0f874f84ed2e
Partial-Bug: #1990842
Related-Change (spec): https://review.opendev.org/c/openstack/neutron-specs/+/862133
Related-Change (n-lib api-def): https://review.opendev.org/c/openstack/neutron-lib/+/870080
2023-05-09 11:49:17 +02: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
Zuul 232a67f444 Merge "[S-RBAC] Switch to new policies by default" 2023-05-05 11:10:24 +00:00
Brian Haley 88ce859b56 Change API to validate network MTU minimums
A network's MTU is now only valid if it is the minimum value
allowed based on the IP version of the associated subnets,
68 for IPv4 and 1280 for IPv6.

This minimum is now enforced in the following ways:

1) When a subnet is associated with a network, validate
   the MTU is large enough for the IP version. Not only
   would the subnet be unusable if it was allowed, but the
   Linux kernel can fail adding addresses and configuring
   network settings like the MTU.

2) When a network MTU is changed, validate the MTU is large
   enough for any currently associated subnets. Allowing a
   smaller MTU would render any existing subnets unusable.

Closes-bug: #1988069
Change-Id: Ia4017a8737f9a7c63945df546c8a7243b2673ceb
2023-04-26 12:22:30 -04: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
Brian Haley c2a02d3c69 Remove two duplicated unit tests
Change b6126bc0f1 added two subnet unit tests that were
already covered in code right below them, remove them.

Trivialfix

Change-Id: Ic89df2d4e124e61fb36add0edbb9baebb139c9bc
2023-02-27 16:43:38 -05:00
Rajesh Tailor 8ab5ee1d17 Fix remaining typos in comments and tests
Change-Id: I872422cffd1f9a2e59b5e18a86695e5cb6edc2cd
2022-07-06 21:20:27 +05:30
Rodolfo Alonso Hernandez 5cc7175659 [UT] Reduce the port binding retries to 1 in ``TestPortsV2``
In ``TestPortsV2`` tests, set the
``neutron.plugins.ml2.plugin.MAX_BIND_TRIES`` to 1 to minimize the
number of retries during a failed port binding. That shortens all
test cases execution time if a port binding is executed.

Trivial-Fix

Change-Id: If0473031797984aab5b36c479fcb774e57ff5624
2022-06-13 08:21:09 +00:00
Rodolfo Alonso Hernandez 3c93da7bdf Set "type=virtual" for OVN LSP with parent ports
This is a follow-up of [1]. Before this patch, any virtual logical
switch port that was updated and the "device_owner" was not and empty
string, had its type set to '' (empty string).

This maintenance task, that is executed only once, lists all logical
switch ports, checks the presence or not of virtual parents and
sets the type to "virtual" if needed.

Related-Bug: #1973276

[1]https://review.opendev.org/c/openstack/neutron/+/841711

Change-Id: I6cf1167d556f0c2c2aa2013f05c809648020b377
2022-05-17 05:34:29 +00:00
Slawek Kaplonski fde91e8059 Remove "allow_overlapping_ips" config option
It was deprecated in Yoga by patch [1]. Now it's time to remove it.

[1] https://review.opendev.org/c/openstack/neutron/+/807848

Closes-Bug: #1942294
Change-Id: I95555395c8adcec70459d5f438e1080da358c4d4
2022-04-12 16:29:21 +02:00
zhouhenglc cc50b45ca3 [test][unit]creating resources support set project_id
To write a new unit test, need to set "project_id", and then
use the discarded "tenant_id" is not appropriate.

this patch updated creating resources method, both "project_id"
and "tenant_id" are acceptable. of course, "project_id" priority.

Closes-bug: #1966354

Change-Id: Ic24f03da169dd3d1549b05b35ec77d3e9a25f17b
2022-03-28 05:41:48 +00:00
Rodolfo Alonso Hernandez 83b6ce9e9e Remove exception ``IpAddressAllocationNotFound``
This patch removes the ``IpAddressAllocationNotFound`` exception. This
exception was raised when a IPAM register was called to be deleted
but not found.

As reported in the LP bug, this IPAM register deletion can be called
several times if a port fails during the creation. The IPAM register
deletion calls the DB deletion but doesn't raise any exception if the
register does not exist. The code ensures the IPAM register is
deleted and there is no need to fail if it is not present anymore.

This patch also removes the exception catch and try in "update_port",
that was added in [0] as a fix for [1]. That was added because the
subnet deletion code involved a port update call [2] during the
IP allocation deletion, if any port was still present in the subnet.
Since [3], this code is not needed because the subnet deletion does
not call a port update anymore.

[0]https://review.opendev.org/c/openstack/neutron/+/373536
[1]https://bugs.launchpad.net/neutron/+bug/1622616
[2]https://github.com/openstack/neutron/blob/pike-em/neutron/db/db_base_plugin_v2.py#L1017-L1018
[3]https://review.opendev.org/c/openstack/neutron/+/713045

Closes-Bug: #1965807
Related-Bug: #1954763
Related-Bug: #1622616

Change-Id: I5b96b3a91aacffe118ddbb91a75c4892818ba97a
2022-03-16 16:48:06 +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 cde5657a50 [OVN] Sync QoS policies
The tool "neutron-ovn-db-sync-util" now syncs the Neutron QoS policies
with the OVN NB database. The tools reads the port and the floaiting IP
QoS policies and creates the corresponding OVN QoS rules.

The ovsdbapp library is bumped to version 1.15.0. This version updates
the "QoSAddCommand" to allow register updates. If the OVN NB QoS
register to be created is present in the DB and all parameters match,
no transaction is commited to the DB.

Depends-On: https://review.opendev.org/c/openstack/ovsdbapp/+/822138
Closes-Bug: #1947334

Change-Id: Ib597b62017b56b41009dd4d7359e169f424272b0
2022-02-02 19:21:21 +00:00
Rodolfo Alonso Hernandez 58feb88853 [OVN] Check if OVN SB supports virtual ports
Added a check for OVN SB schema, looking for "virtual_parent" in
"Port_Binding" table (added in OVN SB schema 2.5).

This patch removes the code to support OVN without virtual ports.
It is assumed that "virtual_parent" field is present in "Port_Binding"
table.

Closes-Bug: #1949496
Change-Id: I3d01f58dca570537b5e754b331ca4809a7161ae2
2022-01-13 04:08:18 +00:00
Zuul 3bd68be547 Merge "Don't fail subnet validation if gw_ip is actually not changed" 2021-12-21 13:32:36 +00:00
Slawek Kaplonski 6809bed632 Don't fail subnet validation if gw_ip is actually not changed
In subnet update API call Neutron checks if gateway_ip was send to be
updated and if so, it checkes if old gateway_ip isn't already allocated
to some router port. If it's already used, Neutron returns 409 response.
This is valid behaviour but sometimes, some automation tools may do
subnet update request and pass the same gateway ip as already used by
the subnet. In such case, as gateway_ip is actually not changed Neutron
should not raise exception in that validation.

Closes-Bug: #1955121
Change-Id: Iba90b44331fdc63273fd3d19c583a24b5295c0ac
2021-12-20 10:08:37 +01:00
yatinkarel 7b61adbb4a List ports when attempt to delete network with ports
When there is attempt to delete network with ports,
a general error message is displayed that one or more
ports are in use on the network. This patch proposes
to also return the ports which are in use as part of
the message.

Also modify test_delete_network_if_port_exists unit
test to check for port id and network id in Error
message.

Also bump required version of neutron-lib to 2.18.0
as that's needed for custom message in NetworkInUse
Exception.

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

Closes-Bug: #1953716
Change-Id: Ib0b40402746c6a487a226b238907142384608d3c
2021-12-16 16:31:44 +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
Zuul b4dd7003db Merge "Add Local IP Extension and DB" 2021-11-17 20:50:43 +00:00
Oleg Bondarev cd1d96863e Add Local IP Extension and DB
This adds Local IP API extension, DB and OVO models, DB mixin,
migration and service plugin.

Partial-Bug: #1930200
Change-Id: I0ab7c5e9bc918f7fad282673ac6e32e1b01985c5
2021-11-11 10:08:23 +03: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
Nurmatov Mamatisa ce3b86eef3 Use neutron-lib standard_attr
Now only neutron uses neutron/db/standard_attr.py
Shim can be removed

Change-Id: I980265335c5f3f6b5ee2e5fbcad9491aad91defe
2021-09-15 09:19:26 +00:00
Rodolfo Alonso Hernandez ad31c58d60 Remove ``ConfDriver`` code
The quota driver ``ConfDriver`` was deprecated in Liberty release.

``NullQuotaDriver`` is created for testing although it could be used
in production if no quota enforcement is needed. However, because
the Quota engine is not plugable (is an extension always loaded), it
could be interesting to make it plugable as any other plugin.

This patch also creates a Quota engine driver API class that should be
used in any Quota engine driver. Currently it is used in the three
in-tree drivers implemented: ``NullQuotaDriver``, ``DbQuotaDriver``
and ``DbQuotaNoLockDriver``.

Change-Id: Ib4af80e18fac52b9f68f26c84a215415e63c2822
Closes-Bug: #1928211
2021-07-26 15:00:32 +00:00
Nurmatov Mamatisa 437a311eca Using 31-Bit and 32-Bit prefixes for IPv4 reasonably
When needing to create a point to point connection via a subnet,
generally and /31 is the recommended cidr. Neutron supports /31
disabling dhcp and gateway on a subnet. /32 is also supported in
openstack.

Closes-Bug: #1580927
Change-Id: I3bfa3efb9fb8076656b16c89d2f35d74efde12b7
2021-06-09 07:35:54 +00:00
Zuul afcaf6805d Merge "New Quota driver ``DbQuotaNoLockDriver``" 2021-06-04 23:19:37 +00:00
LIU Yulong 444ef49bea Add test cases for concurrently Object delete
Verify if concurrently delete neutron DB records will
encounter the StaleDataError which suggest us to add
"confirm_deleted_rows=False" to mapper configuration.

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

Change-Id: Ia8935d5dd87402bedfd7aa9df9dfcb0ce06f8e39
Related-Bug: #1916889
2021-05-24 07:11:58 +00:00
Rodolfo Alonso Hernandez e135a8221d New Quota driver ``DbQuotaNoLockDriver``
This new quota driver, ``DbQuotaNoLockDriver``, does not create a lock
per (resource, project_id) but retrieves the instant (resource,
project_id) usage and the current (resource, project_id) reservations.
If the requested number of resources fit the available quota, a new
``Reservation`` register is created with the amount of units requested.

All those operations are done inside a DB transaction context. That
means the amount of resources and reservations is guaranteed inside
this transaction (depending on the DB backend isolation level defined)
and the new reservation created will not clash with other DB transation.
That will guarantee the number of resources and instant reservations
never exceed the quota limits defined for this (resource, project_id).

NOTES:
- This change tries to be as unobtrusive as possible. The new driver
  uses the same ``DbQuotaDriver`` dabatase tables (except for
  ``QuotaUsage``) and the same Quota engine API, located in
  ``neutron.quota``. However, the Quota engine resources implements some
  particular API actions like "dirty", that are not used in the new
  driver.
- The Pecan Quota enforcement hooks,
  ``neutron.pecan_wgsi.hooks.quota_enforcement``, execute actions like
  "resync", "mark_resources_dirty" or "set_resources_dirty", that has
  no meaning in the new driver.
- The isolation between the Quota engine and the Pecan hook, and the
  driver itself is not clearly defined. A refactor of the Quota engine,
  Quota service, Quota drivers and a common API between the driver and
  the engine is needed.
- If ``DbQuotaDriver`` is deprecated, ``CountableResource`` and
  ``TrackedResource`` will be joined in a single class. This resource
  class will have a count method (countable) or a hard dependency on a
  database table (tracked resource). The only difference will be the
  "count" method implementation.

Closes-Bug: #1926787

Change-Id: I4f98c6fcd781459fd7150aff426d19c7fdfa98c1
2021-05-20 07:55:59 +00:00
Zuul 309639ca89 Merge "Replace assertItemsEqual with assertCountEqual" 2021-04-26 19:12:38 +00:00
Rodolfo Alonso Hernandez 303d24ab8a Allow to manually define the gateway IP when using subnet pools
Now is possible to define a gateway IP when creating a subnet using a
subnet pool. The IPAM subnet generator retrieves the available IP
ranges in the subnet pool and generates a list of candidate subnets
with the prefix lenght defined. If the gateway IP can be allocated in
one of those candidate subnets, the IPAM returns a valid IpamSubnet
that will be used to create a Neutron subnet.

Closes-Bug: #1904436

Change-Id: Ib1d1f591c4d0f59ebff3ddcb3be7b10b0b5e67dc
2021-02-27 10:06:35 +00:00
Rodolfo Alonso Hernandez 8912ea5575 Add port device profile extension
Added a new port extension: device profile (``port_device_profile``).
This extension adds the "device_profile" parameter to the "port" API
and specifies the device profile per port. This parameter is a
string.

This parameter is passed to Nova and Nova retrieves the requested
device profile from Cyborg. Reference:
  https://docs.openstack.org/api-ref/accelerator/v2/index.html#
    device-profiles

For backwards compatibility, this parameter will be "None" by
default.

Closes-Bug: #1906602
Depends-On: https://review.opendev.org/c/openstack/neutron-lib/+/767586

Change-Id: I1202a8388e64ae4270ef4ca118993504ae7c1731
2021-01-22 16:17:30 +00:00
gugug 62729d4e74 Replace assertItemsEqual with assertCountEqual
assertItemsEqual was removed from Python's unittest.TestCase in
Python 3.3 [1][2]. We have been able to use them since then, because
testtools required unittest2, which still included it. With testtools
removing Python 2.7 support [3][4], we will lose support for
assertItemsEqual, so we should switch to use assertCountEqual.

NOTE(dmllr): added hacking check

[1] - https://bugs.python.org/issue17866
[2] - https://hg.python.org/cpython/rev/d9921cb6e3cd
[3] - testing-cabal/testtools#286
[4] - testing-cabal/testtools#277

Change-Id: I7c20fec08e5dc9f67b34100c925ea6724bbd25f0
2020-11-30 10:21:57 +01:00
Zuul f96fc8f049 Merge "Auto-remove floating agent gw ports on net/subnet delete" 2020-11-23 15:43:45 +00:00
Rodolfo Alonso Hernandez a217a5d290 Add port NUMA affinity policy
Added a new port extension: NUMA affinity policy. This extension adds
the "numa_affinity_policy" parameter to the "port" API and specifies
the NUMA affinity policy per port.

This parameter is passed to Nova when a virtual machine is created.
Nova will use this information to schedule the virtual machine.

For backwards compatibility, this parameter will be "None" by default.

Depends-On: https://review.opendev.org/#/c/740058/
Closes-Bug: #1886798

Change-Id: Ie3d68c098ddb727ab8333aa1de4064e67a4f00a7
2020-11-13 15:49:34 +00:00
Oleg Bondarev b97a8eb488 Auto-remove floating agent gw ports on net/subnet delete
fip agent gw ports may be left in DB after router removal due to
race condition between l3 agent and server: when server processes
"router delete" - l3 agent is still processing "router add" and creates
fip agent gw port after server already removed the router.

The patch also adds handling of external network delete event
to cleanup fip namespaces left on agents due to same race condition.

Change-Id: Ib2f3aca08946e584156d092c37e1ea5ed5ca81a6
Closes-Bug: #1902998
2020-11-09 14:05:03 +04:00
zhanghao cc54a1c38e Fix port can not be created with the sg of other project
This patch adds the verification of whether admin context when
verifying the valid security groups of port.

Change-Id: I2674bdc448d9a091b9fe8c68f0866fd19141c6be
Closes-Bug: #1890539
2020-08-10 10:58:30 -04: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
Brian Haley 7594bb0627 Remove the dependency on the "mock" package
Now that we are python3 only, we should move to using the built
in version of mock that supports all of our testing needs and
remove the dependency on the "mock" package.

This patch moves all references to "import mock" to
"from unittest import mock". It also cleans up some new line
inconsistency.

Fixed an inconsistency in the OVSBridge.deferred() definition
as it needs to also have an *args argument.

Fixed an issue where an l3-agent test was mocking
functools.partial, causing a python3.8 failure.

Unit tests only, removing from tests/base.py affects
functional tests which need additional work.

Change-Id: I40e8a8410840c3774c72ae1a8054574445d66ece
2020-04-28 18:05:37 -04:00