Cleanup server before image at test level

test_attach_scsi_disk_with_config_drive test
create the server via self.create_test_server which
delete the server at class level cleanup and created
image cleanup happen at test level so throw error.

We need to delete the server at test level cleanup and before
image.

This is required as when both Glance and Nova use a shared RBD backend
Nova will clone an instance disk directly from the Glance RBD volume.
This results in any attempt to delete the Glance image to fail while the
server is still provisioned as it still references the Glance RBD volume.

Closes-Bug: #1905725
Change-Id: I1aa6a161d3821470fe282914929ebdc93dd5e802
This commit is contained in:
Ghanshyam Mann 2020-11-26 22:49:10 -06:00
parent 05628f2e91
commit 7d9b50a810
1 changed files with 13 additions and 4 deletions

View File

@ -61,6 +61,9 @@ class BaseAttachSCSIVolumeTest(base.BaseV2ComputeAdminTest):
}
create_dict.update(kwargs)
new_image = self.image_client.create_image(**create_dict)
self.addCleanup(self.image_client.wait_for_resource_deletion,
new_image['id'])
self.addCleanup(self.image_client.delete_image, new_image['id'])
self.image_client.store_image_file(new_image['id'], image_file)
return new_image['id']
@ -86,10 +89,16 @@ class AttachSCSIVolumeTestJSON(BaseAttachSCSIVolumeTest):
config_drive=True,
wait_until='ACTIVE')
# NOTE(lyarwood): Add image cleanup *after* creating the instance to
# ensure the instance is deleted first. This avoids failures when using
# the rbd backend is used for both Glance and Nova ephemeral storage.
self.addCleanup(self.image_client.delete_image, custom_img)
# NOTE(lyarwood): self.create_test_server delete the server
# at class level cleanup so add server cleanup to ensure that
# the instance is deleted first before created image. This
# avoids failures when using the rbd backend is used for both
# Glance and Nova ephemeral storage. Also wait until server is
# deleted otherwise image deletion can start before server is
# deleted.
self.addCleanup(waiters.wait_for_server_termination,
self.servers_client, server['id'])
self.addCleanup(self.servers_client.delete_server, server['id'])
volume = self.create_volume()
attachment = self.attach_volume(server, volume)