Commit Graph

16 Commits

Author SHA1 Message Date
Takashi NATSUME 5c1d9dcbb2 Fix misuse of nova.objects.base.obj_equal_prims
The nova.objects.base.obj_equal_prims returns True or False.
It does not assert anything.
So the return value should be asserted in tests.

Add assertTrue where the nova.objects.base.obj_equal_prims is called.

Change-Id: I49460ec3b572ee14b32229e771a5499ff91e8722
Closes-Bug: #1839853
2019-08-13 09:38:54 +09:00
Matt Riedemann aaee893a5e Drop delete_build_requests_with_no_instance_uuid online migration
This migration was added in Ocata and backported to Newton in change
I8a05ee01ec7f6a6f88b896f78414fb5487e0071e to deal with Mitaka-era
build_requests records that would not have an instance_uuid value
and thus raise a ValueError in BuildRequest._from_db_object (because
BuildRequest.instance_uuid is not nullable).

This is essentially a revert of that change now since operators
have had long enough to run the migration. If anyone were to skip
level upgrade from Mitaka to Train (which we don't support, we require
you to roll through), and hit an issue with this they could simply
execute this on their nova_api DB:

  DELETE FROM build_requests WHERE instance_uuid IS NULL;

Change-Id: Ie9593657544b7aef1fd7a5c8f01e30e09e3fcce6
2019-04-08 17:48:14 -04:00
Andrey Volkov 2ef704cba6 Exclude build request marker from server listing
When listing "real" (already in cell) instances e.g. from
nova_cell1.instances table, a marker option means "start after the
instance with marker".

For VMs:

| uuid | name |
| 1    | vm1  |
| 2    | vm2  |

"openstack server list --marker 1" returns vm2 only.

But for VMs from nova_api.build_requests table it's different.

For VMs:

| uuid | name |
| 1    | vm1  |
| 2    | vm2  |

"openstack server list --marker 1" returns both vm1 and vm2.

This patch excludes instance with marker from listing for
instances from build_requests table.

Closes-Bug: #1808286
Change-Id: I5165b69f956fbf1904112a742698b2739f747e72
2018-12-19 16:29:27 -05:00
Matt Riedemann 1706e39891 Raise MarkerNotFound if BuildRequestList.get_by_filters doesn't find marker
For some reason, probably because build requests are meant to be short lived
and we don't get a lot of bugs about paging misbehavior, when paging instances
with a marker, we didn't raise MarkerNotFound if we didn't find the marker in
the list of build requests. Doing so would match what we do when paging over
cells and listing instances using a marker. Once we find the marker, be that
in build_requests, or one of the cells, we need to set the marker to None to
stop looking for it elsewhere if we have more space to fill our limit.

For example, see change I8a957bebfcecd6ac712103c346e028d80f1ecd7c.

This patch fixes the issue by raising MarkerNotFound from BuildRequestList
get_by_filters if there is a marker and we didn't find a build request for
it. The compute API get_all() method handles that as normal and continues
looking for the marker in one of the cells.

Change-Id: I1aa3ca6cc70cef65d24dec1e7db9491c9b73f7ab
Closes-Bug: #1737856
2017-12-12 21:27:28 -05:00
Kevin_Zheng 18c61263a3 Support tag instances when boot(2/4)
This is the second patch of the series,
this patch adds tags to build_request
object.

Change-Id: I1121eaf24856dcb74f07c224531a821b3cdc46fc
Part of blueprint support-tag-instance-when-boot
2017-06-06 06:16:41 +00:00
Matt Riedemann ab05b90295 Provide an online data migration to cleanup orphaned build requests
This exhibits the failure reported in bug 1633734 when upgrading
from mitaka to newton with some bad build request records that
weren't cleaned up, and were created before API DB migration
013_build_request_extended_attrs when we didn't have the
instance_uuid or instance records in the database.

After 013_build_request_extended_attrs and the object change to
BuildRequest in a5d3b57c3d if we try
loading up a 'dirty' build request DB record without the
instance_uuid it fails with a ValueError, as shown in the functional
test in this change.

This also provides an online data migration (which will be backported
to Newton for upgrades from Mitaka) that will query the API DB for
build requests where instance_uuid=NULL and delete them.

Change-Id: I8a05ee01ec7f6a6f88b896f78414fb5487e0071e
Related-Bug: #1633734
2016-12-09 15:33:19 -05:00
Sylvain Bauza 723ee0195f Update BuildRequest if instance currently being scheduled
There are some cases where the instance is still waiting to be scheduled and
consequently there is still a BuildRequest object where we would also like to
update the instance attributes, like the display name.

In that case, we need to update the nested instance field from the BuildRequest
instead of trying to update the instance object itself, which could be located
in a child cell.

Change-Id: I97cd6dbae10ca1a29f646b0b25bc08edd699edca
Closes-Bug: #1620248
2016-09-12 22:31:50 +02:00
Andrew Laski 5ba1ff9180 Add BuildRequestList object
The BuildRequestList object can be used to fetch a list of pre-scheduled
instances which have not been written to an instance table yet. The
get_by_filters method emulates the behavior of Instance.get_by_filters
and returns a BuildRequestList object with the contained BuildRequest
objects sorted and filtered on the Instance object contained within.

Change-Id: If3638caba2c12d4c087a854bd8cbf4f79ef9652d
Partially-implements: bp add-buildrequest-obj
Partially-implements: bp cells-scheduling-interaction
2016-08-25 12:04:28 -04:00
Andrew Laski a0594c643a Create Instance from BuildRequest if not in a cell
This is preliminary work towards moving instance creation until after
scheduling. In order to do that we still need the ability to honor an
instance show request. This does a lookup to determine if an instance is
in a cell and if not it synthesizes an instance from the BuildRequest
object that has been stored.

If the instance is not mapped then the deployment has not migrated to
their first cell yet and the instance lookup proceeds as usual.

Until instance creation is moved to after scheduling this is mostly a
noop.

Honoring the instance list command will come later.

Change-Id: Ib984c30543acb3ca9cb95fb53d44d9ded0f5a5c8
Partially-implements: bp add-buildrequest-obj
Partially-implements: bp cells-scheduling-interaction
2016-08-22 16:52:53 -04:00
Andrew Laski d9d3b16527 Add block_device_mappings to BuildRequest
Due to the os-extended-volumes API it is necessary to be able to
retrieve block device mapping info for an instance at any time. In order
to do so it needs to be stored with the build request.

This also makes it available during instance deletion where it may be
useful to look up whether delete_on_termination is set on a bdm so that
it can be cleaned up.

Change-Id: Ib774a43e49b7153b3f7b099a59483c62003ee7a8
Partially-Implements: bp add-buildrequest-obj
2016-07-12 13:35:09 -04:00
Vladik Romanovsky 1aa494107e objects: Add devices_metadata to instance object
Loading the InstanceDeviceMetadata object into the
instance will avoid the need to make multiple calls
to the db from the metadata service.

Partially implements blueprint virt-device-role-tagging
Change-Id: Iea73c26e48d02c9fda9426c8603d1627c0e8e692
2016-06-24 04:30:51 -04:00
Andrew Laski 47d70deb35 Raise exception if BuildRequest deleted twice
After an instance has been scheduled to a cell and mapped to the
instance table there the BuildRequest for it will be destroyed.  An
instance delete that occurs before that remapping has happened will also
destroy the BuildRequest.

In order to know that a delete has happened, and stop the build, the
destroy method should raise an exception if it is already deleted.

Change-Id: Ib86ac14e2bd933bb9e76ea86b2a1ec4f40d204a3
2016-06-09 13:36:20 -04:00
Andrew Laski 98a05bc637 Drop fields from BuildRequest object and model
Now that there's a serialized instance object on the BuildRequest object
and in the build_requests table a lot of fields/columns are no longer
necessary. To prepare for removal of the columns from the db at a later
time references to them have been removed. This starts a deprecation
timer so that they can be removed in Ocata at the earliest.

Note that the BuildRequest object was never passed over the wire, and is
just created and immediately destroyed at this point so there is no need
to handle backwards compatibility for these changes.

Change-Id: Ie86ba66d5f73c153b68bef83661d4c8bdb0ae9dc
2016-05-18 16:54:27 -04:00
Andrew Laski a5d3b57c3d Change BuildRequest to contain a serialized instance
It turns out that BuildRequest was going to need to copy quite a bit of
the Instance fields and was starting to look very similar. Instead of
continuing to add fields to BuildRequest let's just store a serialized
Instance in there so everything is available.

Note that the BuildRequest object version is not being bumped because
this object is not yet passed over the wire anywhere or looked up
anywhere, so there are no backwards compatibility concerns.

Partially-implements: bp add-buildrequest-obj
Change-Id: I63023915b5b7907949e55d6fd2693fcbc7777511
2016-04-21 09:22:55 -04:00
Dan Smith 1906aa4214 Add a DatabasePoisonFixture
This is the beginning of a poison fixture for tests that don't use
the database. If they do, we interrupt them deep in oslo_db, log a
warning, and return a MagicMock. This keeps them from breaking
global database state, but doesn't actually poison them. This should
be followed-up with a patch to raise an exception, and fix the rest
of the tests that depend on the broken behavior.

Since some tests claim to not be DB test, but use the fixture
themselves anyway, this adds a USES_DB_SELF flag to help gate
the application of the poison.

Change-Id: If071a12a33aad86e918a9f441a246a930e921c8d
2016-03-23 06:55:06 -07:00
Andrew Laski 00d6561934 Add BuildRequest object
The BuildRequest object represents a boot request before an instance has
been created and written to the database. It will be required to respond
to API requests to list/show an instance in cellsv2 where the instance
is not written to the database immediately. An upcoming change will
modify the boot process to defer instance creation until after
scheduling has picked a cell/host and having this BuildRequest object is
a prerequisite for that work.

Change-Id: Ie9307388c2e068229177bcc4690cb834028c1481
Partially-implements: bp cells-scheduling-interaction
2016-03-02 21:31:45 -05:00