Merge "Honor shared storage on resize revert" into stable/juno

This commit is contained in:
Jenkins
2015-04-30 12:49:16 +00:00
committed by Gerrit Code Review
4 changed files with 74 additions and 6 deletions

View File

@@ -784,7 +784,7 @@ class ComputeManager(manager.Manager):
network_info,
bdi, destroy_disks)
def _is_instance_storage_shared(self, context, instance):
def _is_instance_storage_shared(self, context, instance, host=None):
shared_storage = True
data = None
try:
@@ -793,7 +793,7 @@ class ComputeManager(manager.Manager):
if data:
shared_storage = (self.compute_rpcapi.
check_instance_shared_storage(context,
instance, data))
instance, data, host=host))
except NotImplementedError:
LOG.warning(_('Hypervisor driver does not support '
'instance shared storage check, '
@@ -3525,8 +3525,10 @@ class ComputeManager(manager.Manager):
block_device_info = self._get_instance_block_device_info(
context, instance, bdms=bdms)
destroy_disks = not self._is_instance_storage_shared(
context, instance, host=migration.source_compute)
self.driver.destroy(context, instance, network_info,
block_device_info)
block_device_info, destroy_disks)
self._terminate_volume_connections(context, instance, bdms)

View File

@@ -398,13 +398,13 @@ class ComputeAPI(object):
instance=instance,
dest_check_data=dest_check_data)
def check_instance_shared_storage(self, ctxt, instance, data):
def check_instance_shared_storage(self, ctxt, instance, data, host=None):
if self.client.can_send_version('3.29'):
version = '3.29'
else:
version = '3.0'
instance = jsonutils.to_primitive(instance)
cctxt = self.client.prepare(server=_compute_host(None, instance),
cctxt = self.client.prepare(server=_compute_host(host, instance),
version=version)
return cctxt.call(ctxt, 'check_instance_shared_storage',
instance=instance,

View File

@@ -4241,6 +4241,8 @@ class ComputeTestCase(BaseTestCase):
self.context, objects.Instance(), instance,
expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS)
for operation in actions:
if 'revert_resize' in operation:
migration.source_compute = 'fake-mini'
if operation[0] in want_objects:
self._test_state_revert(inst_obj, *operation)
else:
@@ -6597,7 +6599,7 @@ class ComputeTestCase(BaseTestCase):
evacuated_instance).AndReturn({'filename': 'tmpfilename'})
self.compute.compute_rpcapi.check_instance_shared_storage(fake_context,
evacuated_instance,
{'filename': 'tmpfilename'}).AndReturn(False)
{'filename': 'tmpfilename'}, host=None).AndReturn(False)
self.compute.driver.check_instance_shared_storage_cleanup(fake_context,
{'filename': 'tmpfilename'})
self.compute.driver.destroy(fake_context, evacuated_instance,

View File

@@ -3104,3 +3104,67 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
)
self.assertEqual("error", self.migration.status)
migration_save.assert_has_calls([mock.call(elevated_context)])
@mock.patch.object(objects.InstanceActionEvent,
'event_start')
@mock.patch.object(objects.InstanceActionEvent,
'event_finish_with_failure')
def _test_revert_resize_instance_destroy_disks(self,
event_finish,
event_start,
is_shared=False,):
# This test asserts that _is_instance_storage_shared() is called from
# revert_resize() and the return value is passed to driver.destroy().
# Otherwise we could regress this.
@mock.patch.object(self.compute, '_get_instance_nw_info')
@mock.patch.object(self.compute, '_is_instance_storage_shared')
@mock.patch.object(self.compute, 'finish_revert_resize')
@mock.patch.object(self.compute, '_instance_update')
@mock.patch.object(self.compute, '_get_resource_tracker')
@mock.patch.object(self.compute.driver, 'destroy')
@mock.patch.object(self.compute.network_api, 'setup_networks_on_host')
@mock.patch.object(self.compute.network_api, 'migrate_instance_start')
@mock.patch.object(self.compute.conductor_api, 'notify_usage_exists')
@mock.patch.object(self.migration, 'save')
@mock.patch.object(objects.BlockDeviceMappingList,
'get_by_instance_uuid')
def do_test(get_by_instance_uuid,
migration_save,
notify_usage_exists,
migrate_instance_start,
setup_networks_on_host,
destroy,
_get_resource_tracker,
_instance_update,
finish_revert_resize,
_is_instance_storage_shared,
_get_instance_nw_info):
self.migration.source_compute = self.instance['host']
# Inform compute that instance uses non-shared or shared storage
_is_instance_storage_shared.return_value = is_shared
self.compute.revert_resize(context=self.context,
migration=self.migration,
instance=self.instance,
reservations=None)
_is_instance_storage_shared.assert_called_once_with(
self.context, self.instance,
host=self.migration.source_compute)
# If instance storage is shared, driver destroy method
# should not destroy disks otherwise it should destroy disks.
destroy.assert_called_once_with(self.context, self.instance,
mock.ANY, mock.ANY, not is_shared)
do_test()
def test_revert_resize_instance_destroy_disks_shared_storage(self):
self._test_revert_resize_instance_destroy_disks(is_shared=True)
def test_revert_resize_instance_destroy_disks_non_shared_storage(self):
self._test_revert_resize_instance_destroy_disks(is_shared=False)