Merge "Prevent race during instance deletion"
This commit is contained in:
commit
89056e38ee
|
@ -562,7 +562,14 @@ class VirtualInstancePlugin(base.BasePlugin, nova.NovaClientWrapper):
|
||||||
for server in self.nova.servers.list(search_opts={
|
for server in self.nova.servers.list(search_opts={
|
||||||
'flavor': reservation_id,
|
'flavor': reservation_id,
|
||||||
'all_tenants': 1}, detailed=False):
|
'all_tenants': 1}, detailed=False):
|
||||||
server.delete()
|
try:
|
||||||
|
self.nova.servers.delete(server=server)
|
||||||
|
except nova_exceptions.NotFound:
|
||||||
|
LOG.info("Could not find server '%s', may have been deleted "
|
||||||
|
"concurrently.", server.id)
|
||||||
|
except Exception as e:
|
||||||
|
LOG.exception("Failed to delete server '%s': %s.", server.id,
|
||||||
|
str(e))
|
||||||
|
|
||||||
# We need to check the deletion is complete before deleting the
|
# We need to check the deletion is complete before deleting the
|
||||||
# reservation inventory. See the bug #1813252 for details.
|
# reservation inventory. See the bug #1813252 for details.
|
||||||
|
|
|
@ -17,6 +17,7 @@ import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
from novaclient import exceptions as nova_exceptions
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from blazar import context
|
from blazar import context
|
||||||
|
@ -1116,7 +1117,7 @@ class TestVirtualInstancePlugin(tests.TestCase):
|
||||||
|
|
||||||
self.patch(db_api, 'host_allocation_destroy')
|
self.patch(db_api, 'host_allocation_destroy')
|
||||||
|
|
||||||
fake_servers = [mock.MagicMock(method='delete') for i in range(5)]
|
fake_servers = [mock.MagicMock() for i in range(5)]
|
||||||
mock_nova = mock.MagicMock()
|
mock_nova = mock.MagicMock()
|
||||||
type(plugin).nova = mock_nova
|
type(plugin).nova = mock_nova
|
||||||
# First, we return the fake servers to delete. Second, on the check in
|
# First, we return the fake servers to delete. Second, on the check in
|
||||||
|
@ -1126,6 +1127,11 @@ class TestVirtualInstancePlugin(tests.TestCase):
|
||||||
|
|
||||||
mock_cleanup_resources = self.patch(plugin, 'cleanup_resources')
|
mock_cleanup_resources = self.patch(plugin, 'cleanup_resources')
|
||||||
|
|
||||||
|
mock_log = self.patch(instance_plugin, 'LOG')
|
||||||
|
mock_nova.servers.delete.side_effect = [nova_exceptions.NotFound(
|
||||||
|
404, "The server doesn't exist in Nova"), Exception('Unknown'),
|
||||||
|
None, None, None]
|
||||||
|
|
||||||
plugin.on_end('resource-id1')
|
plugin.on_end('resource-id1')
|
||||||
|
|
||||||
mock_nova.flavor_access.remove_tenant_access.assert_called_once_with(
|
mock_nova.flavor_access.remove_tenant_access.assert_called_once_with(
|
||||||
|
@ -1135,8 +1141,12 @@ class TestVirtualInstancePlugin(tests.TestCase):
|
||||||
search_opts={'flavor': 'reservation-id1', 'all_tenants': 1},
|
search_opts={'flavor': 'reservation-id1', 'all_tenants': 1},
|
||||||
detailed=False)
|
detailed=False)
|
||||||
mock_nova.servers.list.call_count = 3
|
mock_nova.servers.list.call_count = 3
|
||||||
for fake in fake_servers:
|
self.assertEqual(5, mock_nova.servers.delete.call_count)
|
||||||
fake.delete.assert_called_once()
|
mock_log.info.assert_any_call(
|
||||||
|
"Could not find server '%s', may have been deleted concurrently.",
|
||||||
|
fake_servers[0].id)
|
||||||
|
mock_log.exception.assert_called_with(
|
||||||
|
"Failed to delete server '%s': %s.", fake_servers[1].id, 'Unknown')
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
mock_delete_reservation_inventory.assert_any_call(
|
mock_delete_reservation_inventory.assert_any_call(
|
||||||
'host' + str(i + 1), 'reservation-id1')
|
'host' + str(i + 1), 'reservation-id1')
|
||||||
|
|
Loading…
Reference in New Issue