Commit Graph

435 Commits (15b9e81d37d1adaf5a13be68d12c1544405488e3)

Author SHA1 Message Date
Matt Riedemann 0b92c7e741 Fix hard-delete of instance with soft-deleted referential constraints
When hard-deleting an instance we first delete related records
but the code was not taking into account soft-deleted related
records which will result in the instance delete failing due to
a referential constraint because soft-deleted records are not
really deleted when it comes to table constraints.

This fixes the issue by simply passing read_deleted='yes' to the
related record model query in the hard delete path.

The related unit test is updated to cover this scenario and a
typo in that same test is also fixed here.

Change-Id: I9fc5a9cc40ceffc450c1fde1df7fb36581e9cc94
Closes-Bug: #1830438
4 years ago
Zuul ee9bfb5219 Merge "Stop handling 'update_cells' on 'BandwidthUsage.create'" 4 years ago
Jake Yip e822360b66 Add --before to nova-manage db archive_deleted_rows
Add a parameter to limit the archival of deleted rows by date. That is,
only rows related to instances deleted before provided date will be
archived.

This option works together with --max_rows, if both are specified both
will take effect.

Closes-Bug: #1751192
Change-Id: I408c22d8eada0518ec5d685213f250e8e3dae76e
Implements: blueprint nova-archive-before
4 years ago
Stephen Finucane 14cc25552a Stop handling 'update_cells' on 'BandwidthUsage.create'
Part of blueprint remove-cells-v1

Change-Id: I27719a2c44ebea90161c3032485581a6d8e4ba68
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
4 years ago
Matthew Booth aae5c7aa38 Fix retry of instance_update_and_get_original
_instance_update modifies its 'values' argument. Consequently if it is
retried due to an update conflict, the second invocation has the wrong
arguments.

A specific issue this causes is that if we called it with
expected_task_state a concurrent modification to task_state will cause
us to fail and retry. However, expected_task_state will have been popped
from values on the first invocation and will not be present for the
second. Consequently the second invocation will fail to perform the
task_state check and therefore succeed, resulting in a race.

We rewrite the old race unit test which wasn't testing the correct
thing for 2 reasons:

1. Due to the bug fixed in this patch, although we were calling
   update_on_match() twice, the second call didn't check the task state.
2. side_effect=iterable returns function items without executing them,
   but we weren't hitting this due to the bug fixed in this patch.

Closes-Bug: #1821373
Change-Id: I01c63e685113bf30e687ccb14a4d18e344b306f6
4 years ago
Surya Seetharaman c541ace518 Microversion 2.73: Support adding the reason behind a server lock
This patch adds a new parameter ``locked_reason`` to
``POST /servers/{server_id}/action`` request where the
action is lock. It enables the user to specify a reason when locking
a server.

The locked_reason will be exposed through ``GET servers/{server_id}``,
``GET /servers/detail``, ``POST /servers/{server_id}/action``  where
the action is rebuild and ``PUT servers/{server_id}`` requests' responses.

The InstanceActionNotification will emit the locked_reason
along with the other instance details. This patch hence changes the
payload object to include the "locked_reason" field.

Note that "locked" will be allowed as a valid filtering/sorting parameter
for ``GET /servers/detail`` and ``GET /servers`` from this new microversion.

Implements blueprint add-locked-reason

Change-Id: I46edd595e7417c584106487123774a73c6dbe65e
4 years ago
Zuul 5efce384fc Merge "Add get_compute_nodes_by_host_or_node()" 4 years ago
Tetsuro Nakamura 57465aae77 Add get_compute_nodes_by_host_or_node()
This patch adds a function, get_compute_nodes_by_host_or_node() to
the host manager to get ComputeNode objects by the given host name
and/or by the given node name.

Change-Id: Ic492766691741e3a8e4938ad90307cb2fe484cc5
Blueprint: use-placement-in-tree
4 years ago
Theodoros Tsioutsias 9760b5b7dc Add instance hard delete
In order to avoid a situation where an instance is both in cell0
and rebuilt *out of* cell0, we need to first hard delete the instance
in cell0. This change adds the ability to hard delete an instance from
a cell DB.

Change-Id: Ibf257276d879bfb409c00577607ae3b9712133fa
Implements: blueprint enable-rebuild-for-instances-in-cell0
4 years ago
Matt Riedemann 1af9de4e6e Soft delete virtual_interfaces when instance is destroyed
Like the other reference table entries for an instance,
we should soft_delete virtual_interfaces when destroying
an instance. Failing to do so can lead to archive issues
due to the referential constraint.

Change-Id: I04355bdec5477b4c144105fea130089fe1ae6772
Closes-Bug: #1823781
4 years ago
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
5 years ago
melanie witt 020651ad3d Replace usage of get_legacy_facade() with get_engine()
We've been seeing warnings emitted to the python 3 unit tests:

  OsloDBDeprecationWarning: EngineFacade is deprecated; please use
  oslo_db.sqlalchemy.enginefacade

which stem from our use of the get_legacy_facade() oslo.db method.

This replaces the get_legacy_facade() usage with the get_engine()
method from the transaction context manager.

Closes-Bug: #1795078

Change-Id: If1e355d6174f15a1880e97115a2cf3f9f4be837e
5 years ago
Zuul 62bb8e2d06 Merge "Delete instance_id_mappings record in instance_destroy" 5 years ago
zhangbailin 28c1075b59 Resource retrieving: add changes-before filter
This adds the changes-before filter to the servers,
os-instance-actions and os-migrations APIs for
filtering resources which were last updated before
or equal to the given time. The changes-before filter,
like the changes-since filter, will return deleted
server resources.

Part of bp support-to-query-nova-resources-filter-by-changes-before
Change-Id: If91c179e3823c8b0da744a9363906b0f7b05c326
5 years ago
Zuul 5c528df45d Merge "Use six.string_types to improve python2/3 compatibility" 5 years ago
Chen a09ba76fe7 Use six.string_types to improve python2/3 compatibility
Change-Id: I336525cf1c49692b1bbd58e42c94dd1670cd071e
5 years ago
Eric Fried 8e1ca5bf34 Use uuidsentinel from oslo.utils
oslo.utils release 3.37.0 [1] introduced uuidsentinel [2]. This change
rips out nova's uuidsentinel and replaces it with the one from
oslo.utils.

[1] https://review.openstack.org/#/c/599754/
[2] https://review.openstack.org/#/c/594179/

Change-Id: I7f5f08691ca3f73073c66c29dddb996fb2c2b266
Depends-On: https://review.openstack.org/600041
5 years ago
Matt Riedemann 8a6b57cf74 Delete instance_id_mappings record in instance_destroy
The instance_create DB API creates an instance_id_mappings record
but instance_destroy was not cleaning it up when the instance is
deleted; this adds that delete code. Otherwise those records
never get moved to shadow tables so you can't archive and purge them.

Change-Id: Idfe52d3c2f987b9aac551f013a0990423d87fad3
Closes-Bug: #1786298
5 years ago
Chris Dent def4b17934 Use nova.db.api directly
nova/db/__init__.py was importing * from nova.db.api. This meant that
any time any code anywhere within the nova.db package was imported
then nova.db.api was too, leading to a cascade of imports that may
not have been desired. Also, in general, code in __init__.py is a pain.

Therefore, this change adjusts code that so that either:

* nova.db.api is used directly
* nova.db.api is imported as 'db'

In either case, the functionality remains the same.

The primary goal of this change was to make it possible to import the
model files without having to import the db api. Moving the model files
to a different place in the directory hierarchy was considered, but
given that "code in __init__.py is a pain" this mode was chosen.

This looks like a very large change, but it is essentially adjusting
package names, many in mocks.

Change-Id: Ic1fd7c87ceda05eeb96735da2a415ef37060bb1a
5 years ago
Matt Riedemann 683fbe3c84 Remove remaining legacy DB API instance_group* methods
Since Ifbd53b13fa0fef62e0329283b73d587f367e46c2 we no
longer have compat code in the InstanceGroup object
and everything is handled in the API database, so we can
drop the legacy DB API methods for instance groups.

Change-Id: I3816176ccd33995486a7cd19217bd76100f8bddf
5 years ago
Matt Riedemann 7a4c43d20b Remove unused DB API instance_group_member* methods
Since Ifbd53b13fa0fef62e0329283b73d587f367e46c2 we no
longer have compat code in the InstanceGroup object
and everything is handled in the API database, so we can
drop the legacy DB API methods for instance groups.

This is part of a series of cleanup changes.

Change-Id: Ic1da9e2c36297784ddc2e7dc9e1a83146fa2292c
5 years ago
Matt Riedemann 7f455490d3 Remove unused DB API instance_group_delete method
Since Ifbd53b13fa0fef62e0329283b73d587f367e46c2 we no
longer have compat code in the InstanceGroup object
and everything is handled in the API database, so we can
drop the legacy DB API methods for instance groups.

This is part of a series of cleanup changes.

Change-Id: I569ee5d582ce42d84afe2b4b6e702657abe8733b
5 years ago
Dan Smith 6cfcce0559 Expose instance_get_all_uuids_by_host() from DB API and use it
We've had a long-standing optimization point in the
InstanceList.get_uuids_by_host() method, where we pull the entire
list of instance objects only to strip and return the uuids. We
already had a query method for generating just the uuids in the
DB API, but it was not exposed as it was just a helper for another
method. This exposes it publicly and uses it in that InstanceList
method.

Change-Id: I35c05e78d59ec9b95c2a443979b8d66cd42ea043
5 years ago
dane-fichter e35e8d7f3f Add trusted_certs to instance_extra
This change adds a trusted_certs deferred-load column to
instance_extras, which stores a list of trusted x509 certificate
UUIDs for a given instance in the form of a JSON blob.

Change-Id: I3fd4e395b31ff1b69f35242d559f8caa17c05a6a
Implements: blueprint nova-validate-certificates
5 years ago
Zuul 98e9b588e2 Merge "Remove old flavor_create db api method" 5 years ago
Zuul b35cb34faa Merge "Remove old flavor_get_all db api method" 5 years ago
Zuul af5e3eb610 Merge "Remove old flavor_get db api method" 5 years ago
Zuul b41a0f2031 Merge "Remove old flavor_get_by_name db api method" 5 years ago
Zuul a4e6e91b66 Merge "Remove old flavor_get_by_flavor_id db api method" 5 years ago
Zuul 600b694723 Merge "Remove old flavor_destroy db api method" 5 years ago
Zuul dd7d5a9c25 Merge "Remove old flavor_access_get_by_flavor_id db api method" 5 years ago
Zuul 2ec6b972d9 Merge "Remove old flavor_access_add db api methods" 5 years ago
Zuul b30fba37a8 Merge "Remove old flavor_access_remove db api method" 5 years ago
Zuul 51d4a537a5 Merge "Remove old flavor_extra_specs_get db api method" 5 years ago
Zuul b38a330256 Merge "Remove old flavor_extra_specs_delete db api method" 5 years ago
Zuul 7d33930ff5 Merge "Remove old flavor_access_get_by_flavor_id db api method" 5 years ago
Dan Smith 3a258ba927 Remove deprecated aggregate DB compatibility
We dropped support for aggregates in newton, so this compatibility code
should no longer be used or needed.

Related to blueprint placement-req-filter

Change-Id: Iec161b0b13b5d3fe655531eacad83193fea89fda
5 years ago
Matt Riedemann 9238711460 Remove old flavor_create db api method
We haven't used this since the flavor migration compat
code was removed: I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: I9f752fe01b0b1506691586e78f231b3dabe24698
5 years ago
Matt Riedemann 233cebc3ef Remove old flavor_get_all db api method
We haven't used this since the flavor migration compat
code was removed: I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: Ic167a6e7f1be7246ef57d157c2e485465902e512
5 years ago
Matt Riedemann 04f381ce79 Remove old flavor_get db api method
We haven't used this since the flavor migration compat
code was removed: I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: I1cb3b75e512b6766320ead2e5ff2595e7a485df9
5 years ago
Matt Riedemann 0a767277ff Remove old flavor_get_by_name db api method
We haven't used this since the flavor migration compat
code was removed: I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: I9da861b672da7ac45e5b2ca588942a55847f2d46
5 years ago
Matt Riedemann f74651e718 Remove old flavor_get_by_flavor_id db api method
We haven't used this since the flavor migration compat
code was removed:

I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: I7481e53edbbf2439e38c61f75bd71d381565636b
5 years ago
Matt Riedemann b0b2370893 Remove old flavor_destroy db api method
This hasn't been used since the flavor migration compat
code was removed:

I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: I77e23d6b52a81cf2835287fc69582559943ef31b
5 years ago
Matt Riedemann 4aedd5120b Remove old flavor_access_get_by_flavor_id db api method
This hasn't been used since the flavor migration compat
code was removed:

I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: Iff84a719f5297e570316d8f17ec6b720471d549d
5 years ago
Matt Riedemann 082191ec87 Remove old flavor_access_add db api methods
This hasn't been used since the flavor migration compat
code was removed:

I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: Ic5f62e7554cee059f579515b05224fecc11bd476
5 years ago
Matt Riedemann 39e54d5d44 Remove old flavor_access_remove db api method
We haven't used this since the flavor migration compat
code was removed:

I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: If0433c7a6d988165d854e965f3b7d498af3f952d
5 years ago
Matt Riedemann cf6a2688b9 Remove old flavor_extra_specs_get db api method
We haven't used this since the flavor migration compat
code was removed in:

I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: Ibbd620c5ebcfc7b923a20db9e0f74575f5335c36
5 years ago
Matt Riedemann 0eca044521 Remove old flavor_extra_specs_delete db api method
We haven't used this since the flavor migration compat
code was removed:

I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: Ic75e1a892ea5093175a8ac981249b56e5962a906
5 years ago
Matt Riedemann 27c7c88737 Remove old flavor_access_get_by_flavor_id db api method
We haven't used this since the flavor migration compat
code was removed:

I4107af592448e20fe929f8fa3112929e3685b581

Change-Id: I9d3220aaafaad754f0975cf4bf72e86b50253d15
5 years ago
Yikun Jiang b933847cbb Fix 500 in test_resize_server_negative_invalid_state
In some case(such as, delete a confirmResize server), the
actions maybe have same instance_uuid and request_id. When
we record the event we should get the last created action,
otherwise, we would find the wrong action, and we can't find
the specific event using this wrong action id. Finally, raise
a 500 error due to the error of InstanceActionEventNotFound.

So, if more than one actions with same instance uuid and request
id are exists. we should choice the last created action id as
event record action id.

This change fixes this by sorting action by desc(created_at, id)
and get back the last created action.

Change-Id: Ie6efee14d4b4d25a73dc23f0649a56bfa724c492
Closes-Bug: #1741220
5 years ago