Commit Graph

21 Commits

Author SHA1 Message Date
Fernando Royo c25097b0b0 Optimize queries for port operations
Port create/update are most time-consuming operations
on subnet creation. As example, in those cases where
several subnets are created over the same network the
response time for those port operations is linearly
increased as the total subnets increases.

This patch improves the number of queries required on port
operations in order to reduce the response time.

Closes-Bug: #1977831
Change-Id: I0fccf36a2035e8f6c2fa8dab0307358da600c8f7
2022-06-13 10:30:11 +02:00
Rodolfo Alonso Hernandez 59b2ac0c2a Replace "tenant_id" with "project_id" in OVO base
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: I714d97449c41c9dd889d1842c0fa9b78ffa0f9f2
2021-10-28 15:37:07 +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
Rodolfo Alonso Hernandez 397eb2a2fe Serialize subnet creating depending on the network ID
Add a new DB table "network_subnet_lock". The primary key will be the
network_id. When a subnet is created, inside the write context during
the "subnet" object creation, a register in the mentioned table is
created or updated. This will enforce the serialization of the "subnet"
registers belonging to the same network, due to the write lock in the
DB.

This will solve the problem of attending several "subnet" creation
requests, described in the related bug. If several subnets with the
same CIDR are processed in parallel, the implemented logic won't reject
them because any of them will not contain the information of each other.

This DB lock will also work in case of distributed servers because the
lock is not enforced in the server logic but in the DB backend.

Change-Id: Iecbb096e0b7e080a3e0299ea340f8b03e87ddfd2
Closes-Bug: #1852777
2019-12-02 17:19:03 +00:00
Brian Haley b79842f289 Start enforcing E125 flake8 directive
Removed E125 (continuation line does not distinguish itself
from next logical line) from the ignore list and fixed all
the indentation issues.  Didn't think it was going to be
close to 100 files when I started.

Change-Id: I0a6f5efec4b7d8d3632dd9dbb43e0ab58af9dff3
2019-07-19 23:39:41 -04:00
Ihar Hrachyshka 5cf6663b9f tests: don't configure plugin for tests that don't need it
Except test_subnet, there are no more object tests that would require
the plugin configured, so let's not go through the hassle of setting it
up. (For the record, this setup was not needed since
If1252c42c49cd59dba7ec7c02c9b887fdc169f51).

Change-Id: Iafb886c17dbf9a91a3514b0caa1bcd14093a796c
2018-04-12 16:01:58 -07:00
Ihar Hrachyshka 6f83466307 Allow objects to opt in new engine facade
New facade is enabled by setting new_facade = True for the object of
interest. With new_facade on, all OVO actions will use the new reader /
writer decorator to activate sessions.

There are two new facade decorators added to OVO: db_context_reader and
db_context_write that should be used instead of explicit
autonested_transaction / reader.using / writer.using in OVO context.

All neutron.objects.db.api helpers now receive OVO classes / objects
instead of model classes, since they need to know which type of engine
facade to use for which object. While it means we change signatures for
those helper functions, they are not used anywhere outside neutron tree
except vmware-nsx unit tests, and the latter pass anyway because the
tests completely mock out them disregarding their signatures.

This patch also adds several new OVO objects to be able to continue
using neutron.objects.db.api helpers to persist models that previously
didn't have corresponding OVO classes.

Finally, the patch adds registration for missing options in
neutron/tests/unit/extensions/test_qos_fip.py to be able to debug
failures in those unit tests. Strictly speaking, this change doesn't
belong to the patch, but I include it nevertheless to speed up merge in
time close to release.

There are several non-obvious changes included, specifically:

- in neutron.objects.base, decorator() that refreshes / expunges models
from the active session now opens a subtransaction for the whole span of
call / refresh / expunge, so that we can safely refresh model regardless
of whether caller opened another parent subtransaction (it was not the
case for create_subnetpool in base db plugin code).

- in neutron.db.l3_fip_qos, removed code that updates obj.db_model
relationship directly after corresponding insertions for child policy
binding model. This code is not needed because the only caller to the
_process_extra_fip_qos_update method refetches latest state of floating
ip OVO object anyway, and this code triggers several unit test failures.

- unit tests checking that a single commit happens for get_object and
get_objects are no longer valid for new facade objects that use reader
decorator that doesn't commit but close. This change is as intended, so
unit tests were tweaked to check close for new facade objects.

Change-Id: I15ec238c18a464f977f7d1079605b82965052311
Related-Bug: #1746996
2018-02-09 04:07:34 +00:00
Ihar Hrachyshka b309e12a5d objects: added update_objects to OVO framework
This method allows to update matching resources with requested values
without doing full fetch/set/update cycle. This is also handy to "lock"
records in database with UPDATE WHERE.

Change-Id: I2347fedbecef823babe3d8038f5a74b21fc0a602
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2017-05-24 20:28:11 +00:00
Victor Morales 474bfe289a Refactoring _create_test methods for OVO UTs
Most of the _create_test methods create a property and only uses
its id during their execution.  This change pretends to simplify
the returned data and reduce the number of lines used for the
creation of test data used during the execution of Unit Tests for
Oslo-Versioned Objects.

Change-Id: Icfc251a7d460246e91e260a4ac503d10c4031170
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2017-04-17 12:05:19 -07:00
Armando Migliaccio ca751a1486 Spin off context module
NeutronLibImpact

Partially-implements: blueprint neutron-lib

Change-Id: I48cf45dc1b07035d952152eac2548a3bd9fc2832
2017-03-06 16:25:29 +00:00
Ihar Hrachyshka 79e62516af tests: introduce update_obj_fields method in base objects test class
This method can be used by subclasses to inject specific values into
randomly generated values for objects, for example, when we need to link
those automatic test objects to other objects through foreign keys.

Change-Id: Ic32ebf5ef055b25e4c765a9bf71ca4657d3b3d70
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2016-11-29 07:29:31 +00:00
Artur Korzeniewski a20eac787f OVO: add SubnetServiceType object and code integration.
Adding SubnetServiceType to Subnet OVO as synthetic field.
It is not required to change the Subnet version, since it is not used.

Change-Id: I0ccff39dcb5e41351b0a4aeba7c98cfba24a1689
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2016-11-28 14:54:06 +01:00
Ihar Hrachyshka 2676372f26 tests: don't override base object test class attributes
DNSNameServerDbObjectTestCase was overriding self.db_objs and
self.obj_fields if the attributes did not have unique order/address
fields generated by get_random_fields. But since
Id1ca4ce7b134d9729e68661cedb2f5556e58d6ff landed, we should have also
updated self.objs, otherwise test_filtering_by_fields will fail later
when it will try to find an object with attributes that were not used
when creating the object targeted by the filtering attempt.

Instead of adding the update for self.objs in the
DNSNameServerDbObjectTestCase test class, I went with an alternative
approach, getting rid of overriding logic completely. The rationale for
the path is that there is nothing wrong in duplicate address and order
field values (at least as per underlying model definition), and hence
our tests should be resilient against that kind of scenario.

So instead of comparing all fields for an object, just make sure that
the order monotonically goes up/down in the sorted result, and ignore
other fields to be strictly ordered.

Change-Id: Ic956072de5dab336f83b04bddfa9da967b2865b2
Closes-Bug: #1623425
2016-09-10 07:11:57 +00:00
Ihar Hrachyshka 9cd230397c tests: refactor objects test cases to use db models instead of dicts
This should reflect the code under test better, and is needed for one of
patches in the review queue (I130609194f15b89df89e5606fb8193849edd14d8)
to pass some of those test cases.

Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
Change-Id: Id1ca4ce7b134d9729e68661cedb2f5556e58d6ff
2016-09-06 13:44:12 +00:00
Artur Korzeniewski 394546743b objects: loading synthetic fields from defined ORM relationships.
Limit the SQL query number when loading the synthetic fields for Neutron
DB objects. If synthetic fields is defined in SQL model as orm.relationship,
the objects are loaded with main object. No need to query for those resources
once more.

It has impact on performance in scale, to have constant number of SQL queries
when number of resources stored in DB is increasing.

Change-Id: Ie54d9f51642edec1f4533062eb8306b78a1b6f20
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2016-07-27 14:15:39 +02:00
Jenkins de4e3cca77 Merge "objects: Adjust Subnet fields, add tenant_id and segment_id" 2016-07-23 00:54:08 +00:00
Artur Korzeniewski 313f48b413 objects: Adjust Subnet fields, add tenant_id and segment_id
Fields types and nullable parameters were adjusted according to usage model
and tests expectations.
Added segment_id as it was added in Subnet DB model in Newton.

Change-Id: I0d4a9934af9253321593a6bd64edfd6f660c26f1
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2016-07-21 15:33:45 +02:00
Artur Korzeniewski 81ff0ac527 objects: better apply filters for objects/db/api/get_object query.
Problem found when querying for shared subnet. Current implementation for
filtering is applying the filter_by(id=xxx) to NetworkRBAC id, not the
subnets.id field.

Change-Id: I9343ccbbb9723582db4365d671505d0bb6eba72d
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2016-07-18 11:03:18 +00:00
Artur Korzeniewski bd6d454154 objects: Add RBAC to Subnet OVO
Subnet 'shared' attribute is dependent from network 'shared' state.
Added helper methods in rbac_db to calculate the share state based on
rbac_entries.
Refactor existing RbacNeutronDbObjectMixin is_shared_with_tenant method
to be able to use it within already opened session.

Change-Id: I235cf3d37fefa27c005cff992a08fd324e910e75
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2016-07-14 09:26:11 +02:00
Artur Korzeniewski 61138bd905 objects: Introduce the DNSNameServer OVO in the code
Added sorting by 'order' field in DNSNameServer.get_objects()
Loading the synthetic fields for Subnet object, dns_nameservers needs
to be sorted by order.

Change-Id: Icd833eae062b23555d4e53cf2cbd5bcd17cf2108
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
2016-06-27 16:22:11 +02:00
Artur Korzeniewski 563fea3786 Introducing the Subnet OVO
This patch is introducing the following OVOs:
- DNSNameServer
- Route
- IPAllocation
- Subnet

Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
Change-Id: I3fca197098f24f68ea2b2915851c68dc170e781c
2016-05-21 13:56:16 +02:00