Add functional recreate test of deleting a BFV server pre-scheduling

This is another wrinkle for bug 1404867 where we create a
volume-backed server, create an attachment on the volume which
puts the volume in 'attaching' status, and then delete the server
before it's actually created in a cell.

In this case, the _delete_while_booting code in the compute API
finds and deletes the BuildRequest before the instance was ever
created in a cell.

The bug is that _delete_while_booting in the API doesn't also
process block device mappings and unreserve/delete attachments
on the volume, which orphans the volume and can only be fixed
with admin intervention in the block storage service.

Change-Id: Ib65acc671711eae7aee65df9cd5c6b2ccb559f5c
Related-Bug: #1404867
This commit is contained in:
Matt Riedemann 2018-02-15 16:01:14 -05:00
parent b3f39244a3
commit 08f0f71a83
1 changed files with 44 additions and 1 deletions

View File

@ -12,11 +12,13 @@
from nova import test
from nova.tests import fixtures as nova_fixtures
from nova.tests.functional import integrated_helpers
from nova.tests.unit.image import fake as fake_image
from nova.tests.unit import policy_fixture
class ServersPreSchedulingTestCase(test.TestCase):
class ServersPreSchedulingTestCase(test.TestCase,
integrated_helpers.InstanceHelperMixin):
"""Tests for the servers API with unscheduled instances.
With cellsv2 an instance is not written to an instance table in the cell
@ -237,3 +239,44 @@ class ServersPreSchedulingTestCase(test.TestCase):
'servers/detail?not-tags-any=tag1,tag3')
list_resp = list_resp.body['servers']
self.assertEqual(0, len(list_resp))
def test_boot_from_volume_delete_build_request_pre_scheduling(self):
cinder = self.useFixture(
nova_fixtures.CinderFixtureNewAttachFlow(self))
# This makes the get_minimum_version_all_cells check say we're running
# the latest of everything.
self.useFixture(nova_fixtures.AllServicesCurrent())
volume_id = nova_fixtures.CinderFixtureNewAttachFlow.IMAGE_BACKED_VOL
server = self.api.post_server({
'server': {
'flavorRef': '1',
'name': 'test_bfv_delete_build_request_pre_scheduling',
'networks': 'none',
'block_device_mapping_v2': [
{
'boot_index': 0,
'uuid': volume_id,
'source_type': 'volume',
'destination_type': 'volume'
},
]
}
})
# Since _IntegratedTestBase uses the CastAsCall fixture, when we
# get the server back we know all of the volume stuff should be done.
self.assertIn(volume_id, cinder.attachments[server['id']])
# Now delete the server, which should go through the "local delete"
# code in the API, find the build request and delete it along with
# detaching the volume from the instance.
self.api.delete_server(server['id'])
# The volume should no longer have any attachments as instance delete
# should have removed them.
# self.assertNotIn(volume_id, cinder.attachments[server['id']])
# FIXME(mriedem): This is part of bug 1404867 where the BDMs aren't
# processed when the build request is deleted. Uncomment the above
# and remove the below when this is fixed.
self.assertIn(volume_id, cinder.attachments[server['id']])