Commit Graph

75 Commits

Author SHA1 Message Date
Stephen Finucane 307adc5e08 db: Normalize migrations tests
We're going to be extensively reworking these to handle the alembic
switchover in a future change. Ahead of this rework, rework things
somewhat to simplify things and remove unnecessary noise.

Change-Id: Ie9d00e25b7e99104155466060a2b6f8a884a5e0a
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-08-09 15:34:40 +01:00
Stephen Finucane c3e113eb31 db: Trivial style changes
Rewrap some code just to make it a little less fugly to read.

Change-Id: If78bbd578bbba73fc85446ad55d34d3addd6c4af
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-08-09 15:34:40 +01:00
Stephen Finucane bf8b5fc7d0 db: Move remaining 'nova.db.sqlalchemy' modules
The two remaining modules, 'api_models' and 'api_migrations', are
moved to the new 'nova.db.api' module.

Change-Id: I138670fe36b07546db5518f78c657197780c5040
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-08-09 15:34:40 +01:00
Stephen Finucane 4bbea58cbb db: Move db.sqalchemy.migration to db.migration
At this point is nova's lifecycle, we're not going to change our ORM,
making the layer of indirection that is 'nova.db.sqlalchemy' is a
useless one. Start removing it with the 'migration' module.

Change-Id: I5fd6c6f74b7de2b422359cbe72defb07252e6b1e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-07-05 11:05:04 +01:00
Zuul 4f25a37bfa Merge "Placeholders for DB migration backports to Wallaby" 2021-04-15 20:21:41 +00:00
Sylvain Bauza 4dda84eb03 Placeholders for DB migration backports to Wallaby
We somehow need to reserve some migration numbers for any possible
backports down to Wallaby.

Change-Id: Ibda1b6ebdd4786e97686b523a23476a5b5caaa30
2021-03-05 14:53:08 +01:00
Stephen Finucane df89596edb apidb: Compact Train database migrations
Nothing but placeholders to be removed here.

Change-Id: I065e3a950e79b0754a2589232ef8a46bb4e83e7f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-03-03 16:05:04 +00:00
Stephen Finucane dae3c89874 apidb: Compact Stein database migrations
Specific changes include:

- Add 'user_id' column to 'instance_mappings' table (062)
- Add index covering 'user_id' and 'project_id' columns to
  'instance_mappings' table (062)

Note that we forgot to add placeholder migrations in Rocky, meaning
there is significantly less to clean up here.

Change-Id: I38a6f4d1c3d2a9797ba543694401b7b821a79805
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-03-03 16:03:09 +00:00
Stephen Finucane 6665bd8cb9 apidb: Compact Rocky database migrations
Specific changes include:

- Add 'disabled' column to 'cell_mappings' table (058)
- Add 'generation' column to 'consumers' table (059)
- Add 'rules' column to 'instance_group_policy' table (060)
- Add 'queued_for_delete' column to 'instance_mappings' table (061)

Note that we need to explicitly disable constraints for 'Boolean' fields
sqlalchemy since these weren't added by sqlachemy-migrate.

Change-Id: Id1c970c3d52c7cc672d00cb0486bfe49d69531b7
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-03-03 16:01:42 +00:00
Stephen Finucane 86b423f9f3 apidb: Compact Queens database migrations
Specific changes include:

- Add 'description' column to 'flavors' table (050)
- Add 'root_provider_id' and 'parent_provider_id' columns to
  'resource_providers' table (051)
- Add indexes covering 'root_provider_id' and 'parent_provider_id'
  columns of 'resource_providers' table (051)
- Alter type of 'spec' column of 'request_specs' table to MediumText
  (052)

Change-Id: Iafccbb52cba0c45b5159984d6560b822d9405d5f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-03-03 15:17:34 +00:00
Stephen Finucane 31f01aa44f apidb: Compact Pike database migrations
Specific changes include:

- Add 'traits' and 'resource_provider_traits' tables (041)
- Add 'tags' column to 'build_requests' table (042)
- Add 'consumers' table (043)
- Add 'projects', 'users' tables (044)
- Change type of 'project_id' and 'user_id' columns of 'consumers' table to 'Integer' (044)

Change-Id: I4abee9b93fe3840e463325c6cf7b2b52448bfca4
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-03-03 15:10:54 +00:00
Stephen Finucane 743693c740 apidb: Compact Ocata database migrations
Specific changes include:

- Add 'resource_classes' table (026)
- Add 'quota_classes', 'quota_usages', 'quotas', 'project_user_quotas',
  'reservations' and 'resource_classes' tables (027)
- Alter type of 'instance' column of 'build_requests' table to
  'MediumText' (028)
- Add 'placement_aggregates' table (029)

Note that migration 030 included a check to ensure cell mappings were
created when upgrading existing deployments. Since users will now be
required to upgrade to at Ocata before running migrations, this is no
longer necessary. The check was never executed for new deployments,
as noted in the migration itself:

  NOTE(danms): We need to be careful here if this is a new
  installation, which can't possibly have any mappings. Check
  to see if any flavors are defined to determine if we are
  upgrading an existing system. If not, then don't obsess over
  the lack of mappings.

Change-Id: Ibf82b5e8f46b89f8c7dcdc1925bf48d581cdc3f6
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-03-03 14:28:54 +00:00
Stephen Finucane 302f2bc4f7 apidb: Compact Newton database migrations
Specific changes include:

- Add 'instance_uuid' and 'instance' columns to 'build_requests' table
  (013)
- Add index covering 'instance_uuid' column of 'build_requests' table
  (013)
- Add unique constraint covering 'instance_uuid' column of
  'build_requests' table (013)
- Add 'keypairs' table (014)
- Drop foreign key constraint covering 'request_spec_id' of
  'build_requests' table (015)
- Drop unique constraint covering 'request_spec_id' of 'build_requests'
  table (015)
- Alter 'request_spec_id', 'user_id', 'security_groups' and
  'config_drive' columns of 'build_requests' table to be nullable (015)
- Add 'resource_providers', 'inventories', 'allocations', and
  'resource_provider_aggregates' tables (016)
- Add 'aggregate', 'aggregate_hosts' and 'aggregate_metadata' tables
  (017)
- Add 'groups', 'group_policy' and 'group_member' tables (018)
- Add 'block_device_mappings' column to 'build_requests' table (019)
- Alter 'block_device_mappings' column of 'build_requests' table to be
  'MediumText' (020)

Change-Id: I944a0ed33d9ac8bda81a4e09a33e8fd768b6f95d
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-02-10 15:42:51 +00:00
Stephen Finucane d2449232bd apidb: Compact Mitaka database migrations
Specific changes include:

- Add 'request_specs' table (004)
- Add 'flavors', 'flavor_extra_specs' and 'flavor_projects' tables (005)
- Add 'build_requests' table (006)
- Alter 'cell_id' column of 'instance_mappings' table to be nullable
  (007)

Change-Id: I1b6be3eb61f3e21da69a42ea32a19ce373b0a898
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-02-10 15:42:51 +00:00
Stephen Finucane d97fd31131 apidb: Compact Liberty database migrations
Specific changes include:

- Add 'cell_mappings' table (001)
- Add 'host_mappings' table (002)
- Add 'instance_mappings' table (003)

Change-Id: I5708442336cd9cea43bfbf32292475e52872ca3d
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-02-10 15:40:05 +00:00
Takashi Natsume 78ad4a4efd Add placeholder migrations for Victoria backports
Change-Id: I3f9c9deb11c45e6a252effa3c82951e02d9f4334
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2020-10-17 07:53:08 +00:00
Takashi Natsume 75a2d600fc Add placeholder migrations for Ussuri backports
Change-Id: Ie6090f1d0e5eb5c6f2d9be122435c2ee274398cd
2020-04-24 09:26:42 +09:00
Dan Smith 04e79b5b7e Add reserved schema migrations for Ussuri
Change-Id: Idb28bcae55db19a62b5e8b6dfcfc9fd5b8839e41
2019-10-03 08:47:36 -07:00
Balazs Gibizer 15b9e81d37 Simplfy test setup for TestNovaMigrations* tests
The NoDBTestCase base class does a lot of env setup that is not needed
for these tests. As we have issues with these tests (see bug 1823251)
this patch tries to decrease the complexity of them to help the
troubleshooting.

Change-Id: I46fafa470b9d378d96c0f364e9b487742bf58cb2
Related-Bug: #1823251
2019-06-03 14:02:34 +02:00
Stephen Finucane 4aa989f471 Add placeholder migrations for Stein backports
Seeing as these were missed for Rocky, we really ought to get them in
for Stein.

Change-Id: I29401773a0686e7be5d7d1cbb5ec82ffbb16fb4a
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2019-04-08 18:08:40 +01:00
melanie witt 9073445b38 Add user_id column to the instance_mappings table
The instance_mappings table already contains the project_id for an
instance. This adds the corresponding user_id. This also adds an index
on (user_id, project_id) because later patches in this series will be
using these columns for quota counting.

Part of blueprint count-quota-usage-from-placement

Change-Id: Id9eef7a58f66c73cd638c6c3e228447b7ab81e34
2019-03-07 16:33:58 -05:00
Takashi NATSUME 7748c754b9 Use oslo_db.sqlalchemy.test_fixtures
Make use of the newer fixtures in oslo_db.sqlalchemy.test_fixtures
which is what was intended to supersede fixtures
in oslo_db.sqlalchemy.test_base.

Change-Id: Icb88c13336fffb499083197ed864b8e4e45dc241
Closes-Bug: #1797102
2018-12-25 02:39:48 +00:00
Surya Seetharaman ea1c2b1662 Add queued for delete to instance_mappings table.
This column is being added to have information regarding an instance
being active/deleted in the nova-api database as a part of the handling
a down cell spec.

Related to blueprint handling-down-cell

Change-Id: Ic6253acab2ae08025d65add9a5be9ed463457290
2018-07-10 10:55:49 +02:00
Yikun Jiang 57b0bb3749 Add rules column to instance_group_policy table.
This adds the rules column to instance_group_policy table.

The ''Text'' column "rules" which is a dict, it can be
applied to the policy, and represents the rules for
specific policy.

Related to blueprint complex-anti-affinity-policies

Change-Id: I61ffb5ddb2d808bfef4e60088f4524bd98e0474e
2018-07-09 10:15:47 -07:00
Ed Leafe 1c36b645e1 add consumers generation field
In order to prevent races where two different processes can try to write
the allocations for a consumer, we are adding a 'generation' column to
the consumers table. This will be incremented each time a consumer's
allocations change, and allocation requests whose generation doesn't
match the current value will be rejected.

Blueprint: add-consumer-generation
Change-Id: Ia247f0783c5bbd172aafbfd86372fabeeef557c3
2018-06-12 15:27:57 -04:00
Surya Seetharaman f9743f0c2a Add disabled column to cell_mappings table.
This column has been added to the cell_mappings table since it is
required to represent if a cell is enabled or disabled as a part of the
cell-disable spec.

Related to blueprint cell-disable

Change-Id: Ibeddcb9a93c180f74727431b0579308c400436db
2018-03-17 23:12:31 +01:00
Dan Smith 9e745f401e Add placeholder migrations for Queens backports
Change-Id: Idf18f189ecc5c99c1a5b19a308764378a1b82447
2018-03-17 23:08:58 +01:00
Artom Lifshitz 40d7433908 Make request_spec.spec MediumText
request_spec.instance_group.members is a list of instance UUIDs. It
can get so long that it overflows its TEXT column. This patch changes
request_spec.spec to MEDIUMTEXT.

Change-Id: I6bf0fa19b72887803e77b66698587c2108c9372a
Closes-bug: 1738094
2017-12-14 21:28:18 -05:00
Jay Pipes b10f11d7e8 placement: add nested resource providers
Adds initial support for storing the relationship between parent and
child resource providers. Nested resource providers are essential for
expressing certain types of resources -- in particular SR-IOV physical
functions and certain SR-IOV fully-programmable gate arrays. The
resources that these providers expose are of resource class
SRIOV_NET_VF and we will need a way of indicating that the physical
function providing these virtual function resources is tagged with
certain traits (representing vendor_id, product_id or the physical
network the PF is attached to).

The compute host is a resource provider which has an SR-IOV-enabled
physical function (NIC) as a child resource provider. The physical
function has an inventory containing some total amount of SRIOV_NET_VF
resources. These SRIOV_NET_VF resources are allocated to zero or more
consumers (instances) on the compute host.

                    compute host (parent resource provider)
                         |
                         |
                      SR-IOV PF  (child resource provider)
                         :
                        / \
                       /   \
                    VF1    VF2   (inventory of child provider)

The resource provider model gets two new fields:

 - root_provider_uuid: The "top" or "root" of the tree of nested
   providers
 - parent_provider_uuid: The immediate parent of the provider, or None
   if the provider is a root provider.

The database schema adds two new columns to the resource_providers
table that contain the internal integer IDs that correspond to the
user-facing UUID values:

 - root_provider_id
 - parent_provider_id

The root_provider_uuid field is non-nullable in the ResourceProvider
object definition, and this code includes an online data migration to
automatically populate the root_provider_id field with the value of the
resource_providers.id field for any resource providers already in the
DB.

The root_provider_id field value is populated automatically when a
provider is created. If the parent provider UUID is set, then the
root_provider_id is set to the root_provider_id value of the parent. If
parent is unset, root_provider_id is set to the value of the id
attribute of the provider being created. The corresponding UUID values
for root and parent provider are fetched in the queries that retrieves
resource provider data using two self-referential joins.

The root_provider_id column allows us to do extremely quick lookups of
an entire tree of providers without needing to perform any recursive
database queries.

Logic in this patch ensures that no resource provider can be deleted if
any of its children have any allocations active on them. We also check
to ensure that when created or updated, a resource provider's parent
provider UUID actually points to an existing provider.

It's important to point out that qualitative trait information is only
associated with a resource provider entity, not the resources that
resource provider has in its inventory. This is the reason why nested
resource providers are necessary. In the case of things like NUMA nodes
or SRIOV physical functions, if a compute host had multiple SRIOV
physical functions, each associated with a different network trait,
there would be no way to differentiate between the SRIOV_NET_VF
resources that those multiple SRIOV physical functions provided if the
containing compute host had a single inventory item containing the
total number of VFs exposed by both PFs.

Change-Id: I2d8df57f77a03cde898d9ec792c5d59b75f61204
blueprint: nested-resource-providers
Co-Authored-By: Moshe Levi <moshele@mellanox.com>
2017-11-28 15:29:28 -05:00
Matt Riedemann 3ca7eaab02 Add Flavor.description attribute
This adds the description attribute to the Flavor object
and the accompanying database schema upgrade.

This is the first field on a flavor that we've allowed
to be updated, so it requires some new plumbing for doing
an update on the flavor record itself during save(). The
updateable fields are whitelisted so we don't leak other
updates in here, like name, flavorid, vcpus, etc.

As part of this change, we also have to be sure to not
persist the description in the embedded instance.flavor
since (1) it's a large field and (2) we are not going
to expose the instance.flavor.description out of the
servers API.

Versioned notifications will be handled in a later change.

Part of blueprint flavor-description

Change-Id: I6db4eb46df0d7ec025b969a46621823957503958
2017-11-05 01:24:01 -05:00
Dan Smith b198ad349a Add placeholder migrations for Pike backports
Change-Id: I8fd8c75ddfac917777c466d1e5416a37a368a175
2017-08-28 13:24:09 -07:00
Jay Pipes f89909658a placement: use separate tables for projects/users
We were a bit naughty in Iecbe0eb5717afb0b13ca90d4868a3ca5f9e8902b in
that we didn't normalize the storage of Keystone project and user
identifiers in the API DB's new consumers table. This means that we
will use a whole lot more storage for what ends up being very
repetitive data.

This patch changes the consumers DB table schema's project_id and
user_id columns from VARCHAR(255) to INT data type. This should result
in significantly faster queries for usage information since 9X the
index records can fit into a single index block in memory (36-byte
UUIDs stored in VARCHAR(255) versus 4-byte integers. The more index
records we can fit into a single page of memory, the faster both scans
and seeks will be.

Let's address this now before anything uses the consumers table.

Change-Id: I1b7357739f2a7e55c55d3acb9bd604731c4a2b32
blueprint: placement-project-user
2017-06-07 16:00:28 +00:00
melanie witt b9eed6a286 Add database migration and model for consumers
Part of blueprint placement-project-user

Change-Id: Iecbe0eb5717afb0b13ca90d4868a3ca5f9e8902b
2017-06-02 04:50:17 +00:00
Jenkins 0cc730f186 Merge "Remove the can_host column" 2017-05-26 14:30:13 +00:00
EdLeafe fcfe28192e Remove the can_host column
Originally it was felt that we would need this column to distinguish
between compute nodes and non-compute providers. With the advent of
traits, though, this column is no longer used or needed.

Closes-Bug: #1648197

Change-Id: I614db98727f4737deb6728ee874ab0f68024ebe5
2017-05-08 12:30:09 +00:00
Kevin_Zheng e0803fd60e Support tag instances when boot(1)
This is the first patch of the series,
this patch adds tags to build_request
table and corresponding db update
script.

Change-Id: I01e1973449a572ecd647ede0a70d274eac1583bd
Part of blueprint support-tag-instance-when-boot
2017-04-28 16:59:04 -04:00
He Jie Xu 7dafc66d5c [placement] Add Traits related table to the api database
This patch adds DB table `traits` and `resource_provider_traits` into
the api database.

The traits table is used to represent the trait. The resource_provider_traits
table is used to represent the relationship between trait and resource provider.

Part of implementation blueprint shared-resources-pike

Change-Id: I5c34bdd1423beab53cc4af45e016d9a9bba5ffda
2017-02-28 17:43:54 -05:00
Jenkins 139d85af56 Merge "Reserve migration placeholders for Ocata backports" 2017-02-10 18:47:35 +00:00
Dan Smith a5e051edd9 Reserve migration placeholders for Ocata backports
Normally we reserve five slots for the API database instead of the default
ten. However, given all the stuff that merged in Ocata related to API-level
services, I'm going to reserve ten here just so we have space if we need
it.

Change-Id: I57c2edcf1fb80e24017cb1b4be00065aa20b342c
2017-02-06 07:40:31 -08:00
Diana Clarke 2285b445b1 vomiting
Fixing this typo because it's Friday night, and it cracked me up ;)

Change-Id: I9324621b530dc0adfaf0524861900d975826a614
2017-02-03 18:55:49 -05:00
Davanum Srinivas 584969aff1 [py35] Fixes to get rally scenarios working
Get nova.boot_server, nova.attach_volume, nova.detach_volume and
nova.delete_server working. Please see the following cinder review
for the experiment (see gate-rally-dsvm-py35-cinder-nv):
Id78b136ad15ac77717711ebcbb671c2f1dd3a10c

nova/api/openstack/placement/handlers:
* make sure we convert to bytes before we set the response.body

nova/tests/functional/db/api/test_migrations.py:
* range is an iterator and must be converted to a list

nova/tests/unit/virt/libvirt/test_driver.py:
nova/tests/unit/virt/libvirt/test_fakelibvirt.py:
nova/virt/libvirt/config.py:
nova/virt/libvirt/guest.py:
nova/virt/libvirt/host.py:
* libvirt API expects strings, some of the code paths ended up
  being bytes, so convert them to strings before calling libvirt

Finally, eliminated the tests that now started to pass from
tests-functional-py3.txt

Change-Id: Ib721442e9d83a3b9a7fe597f3886430449a9e684
2017-01-13 15:44:00 +00:00
Dan Smith ff6b9998bb Require cellsv2 setup before migrating to Ocata
We have code going into Ocata that needs to be sure that cell and
host mappings are in place. Since this was required homework in
Newton, we can land a migration to intentionally fail if this was
not completed.

This is, however, a little difficult to require because a first-time
deployment will be initialized schema-wise with none of these records,
which is also sane. So, we look to see if any flavors are defined as
a sentinel to indicate that this is an upgrade of an existing
deployment instead of a first-time event. Not perfect, but since this
is really just a helper for the user, it seems like a reasonable
risk.

Depends-On: If1af9c478e8ea2420f2523a9bb8b70fafddc86b7
Change-Id: I72fb724dc13e1a5f4e97c58915b538ba761c582d
2016-12-05 19:51:36 -05:00
Chris Dent b761ea47b9 [placement] add a placement_aggregates table to api_db
In order to facilitate a future extraction of the placement service
we want to record the association between a resource provider and an
arbitrary aggregate uuid in its own table.

A PlacementAggregate model is joined from ResourceProvider via
ResourceProviderAggregate. Note that this structure is used so we can
join on ids instead of strings (the uuids). A direct mapping between
ResourceProvider uuid and Aggregate uuid was mooted earlier in the year
but was determined to be suboptimal.

The name 'placement_aggregates' is used as the least problematic of
several choices after discussion amongst several parties.

The data will be used by the forthcoming get_ and set_aggregates
methods on the ResourceProvider object.

Change-Id: Id0355cb022f68e962af306ff04cf724d22b68d19
Partially-Implements: blueprint generic-resource-pools-ocata
2016-11-08 16:09:56 +00:00
Matt Riedemann fd7b3d64c7 Make build_requests.instance MediumText
The build_requests.instance column is a serialized
instance object, and the instances.user_data column
is MediumText, so the build_requests.instance column
itself needs to be at least MediumText in size for MySQL.

Change-Id: I7d65df37c02750593037744543ad15e5bc64e913
Closes-Bug: #1635446
2016-10-26 06:27:07 -04:00
Mark Doffman c632c9342f Add quota related tables to the api database.
Quotas are required to exist in the API database as we need to enforce
quotas across cells.

blueprint cells-quota-api-db

Change-Id: I52fd680eaa4880b06f7f8d4bd1bb74920e73195d
2016-10-12 07:40:00 +00:00
Jay Pipes d79d6f665d placement: add new resource_classes table
We will store custom resource classes in the new resource_classes table.
These custom resource classes represent non-standardized resource
classes. Followup patches add the plumbing to handle existing
standardized classes currently using the fields.ResourceClass field type
and to perform CRUD operations against a /resource-classes REST API
endpoint.

Change-Id: I60ea0dcb392c1b82fead4b859fc7ed6b32d4bda0
blueprint: custom-resource-classes
2016-10-11 12:30:44 -04:00
Sean Dague f75c06aa8a properly capture logging during db functional tests
Much like in the unit tests, because these inherit from oslo_db they
don't correctly setup logging capture consistent with the rest of the
nova test suite. This adds the right fixture initialization before we
do setup to prevent corruption of the output stream.

Change-Id: I1243db75dd837b92c3b88df2064d4d9f74ed6058
2016-09-23 09:58:30 -04:00
Dan Smith 05304b5c73 Add placeholder DB migrations for Ocata
This adds placeholder migrations for potential backports of database
migrations to newton.

Change-Id: I3ead9c09fb033592f752b26cac7482cefaa5d12b
2016-09-22 07:42:57 -07:00
Ken Burger 80795f2dc5 Increase BDM column in build_requests table
When deploying with a very large number of volumes the
block_device_mappings column is not sufficient.  The column
needs to be increased to MEDIUMTEXT size to support this use case.

Change-Id: Ia34d06429c1f8f0a8259616bcba0c349c4c9aa33
Closes-Bug: #1621138
2016-09-08 20:22:20 -04:00
Mark Doffman 24f0c5b9d6 Manage db sync command for cell0
Add the ability to sync the cell0 database using nova-manage.
The `db sync` command will be used to sync the cell0 database.
This ensures that operators will only have two db sync commands to
perform in the single cell case.

blueprint cells-cell0

Change-Id: I21ae13a6c029e8ac89484faa212434911160fd51
2016-08-22 18:53:45 +03:00