Merge "Make on_shared_storage optional in compute manager"

This commit is contained in:
Jenkins 2015-07-14 17:46:58 +00:00 committed by Gerrit Code Review
commit 42d91ebee0
2 changed files with 46 additions and 5 deletions

View File

@ -2550,7 +2550,7 @@ class ComputeManager(manager.Manager):
@wrap_instance_fault @wrap_instance_fault
def rebuild_instance(self, context, instance, orig_image_ref, image_ref, def rebuild_instance(self, context, instance, orig_image_ref, image_ref,
injected_files, new_pass, orig_sys_metadata, injected_files, new_pass, orig_sys_metadata,
bdms, recreate, on_shared_storage, bdms, recreate, on_shared_storage=None,
preserve_ephemeral=False): preserve_ephemeral=False):
"""Destroy and re-make this instance. """Destroy and re-make this instance.
@ -2568,7 +2568,10 @@ class ComputeManager(manager.Manager):
:param recreate: True if the instance is being recreated (e.g. the :param recreate: True if the instance is being recreated (e.g. the
hypervisor it was on failed) - cleanup of old state will be hypervisor it was on failed) - cleanup of old state will be
skipped. skipped.
:param on_shared_storage: True if instance files on shared storage :param on_shared_storage: True if instance files on shared storage.
If not provided then information from the
driver will be used to decide if the instance
files are available or not on the target host
:param preserve_ephemeral: True if the default ephemeral storage :param preserve_ephemeral: True if the default ephemeral storage
partition must be preserved on rebuild partition must be preserved on rebuild
""" """
@ -2585,9 +2588,16 @@ class ComputeManager(manager.Manager):
self._check_instance_exists(context, instance) self._check_instance_exists(context, instance)
# To cover case when admin expects that instance files are on if on_shared_storage is None:
# shared storage, but not accessible and vice versa LOG.debug('on_shared_storage is not provided, using driver'
if on_shared_storage != self.driver.instance_on_disk(instance): 'information to decide if the instance needs to'
'be recreated')
on_shared_storage = self.driver.instance_on_disk(instance)
elif (on_shared_storage !=
self.driver.instance_on_disk(instance)):
# To cover case when admin expects that instance files are
# on shared storage, but not accessible and vice versa
raise exception.InvalidSharedStorage( raise exception.InvalidSharedStorage(
_("Invalid state of instance files on shared" _("Invalid state of instance files on shared"
" storage")) " storage"))

View File

@ -11280,6 +11280,37 @@ class EvacuateHostTestCase(BaseTestCase):
self.assertRaises(exception.InstanceRecreateNotSupported, self.assertRaises(exception.InstanceRecreateNotSupported,
lambda: self._rebuild(on_shared_storage=True)) lambda: self._rebuild(on_shared_storage=True))
def test_on_shared_storage_not_provided_host_without_shared_storage(self):
fake_image = {'id': 1,
'name': 'fake_name',
'properties': {'kernel_id': 'fake_kernel_id',
'ramdisk_id': 'fake_ramdisk_id'}}
self.mox.StubOutWithMock(self.compute.driver, 'spawn')
self.compute.driver.spawn(mox.IsA(self.context),
mox.IsA(objects.Instance), mox.IsA(fake_image),
mox.IgnoreArg(), mox.IsA('newpass'),
network_info=mox.IgnoreArg(),
block_device_info=mox.IgnoreArg())
self.stubs.Set(self.compute.driver, 'instance_on_disk',
lambda x: False)
self.mox.ReplayAll()
self._rebuild(on_shared_storage=None)
def test_on_shared_storage_not_provided_host_with_shared_storage(self):
self.mox.StubOutWithMock(self.compute.driver, 'spawn')
self.compute.driver.spawn(mox.IsA(self.context),
mox.IsA(objects.Instance), {}, mox.IgnoreArg(), 'newpass',
network_info=mox.IgnoreArg(),
block_device_info=mox.IgnoreArg())
self.stubs.Set(self.compute.driver, 'instance_on_disk', lambda x: True)
self.mox.ReplayAll()
self._rebuild(on_shared_storage=None)
class ComputeInjectedFilesTestCase(BaseTestCase): class ComputeInjectedFilesTestCase(BaseTestCase):
# Test that running instances with injected_files decodes files correctly # Test that running instances with injected_files decodes files correctly