Merge "Use objects through the run_instance() path"

This commit is contained in:
Jenkins
2014-05-30 16:23:05 +00:00
committed by Gerrit Code Review
4 changed files with 20 additions and 8 deletions

View File

@@ -562,7 +562,7 @@ class ComputeVirtAPI(virtapi.VirtAPI):
class ComputeManager(manager.Manager):
"""Manages the running instances from creation to destruction."""
target = messaging.Target(version='3.26')
target = messaging.Target(version='3.27')
def __init__(self, compute_driver=None, *args, **kwargs):
"""Load configuration options and connect to the hypervisor."""
@@ -2095,6 +2095,7 @@ class ComputeManager(manager.Manager):
' not rescheduling')
LOG.exception(msg, instance=instance)
@object_compat
@messaging.expected_exceptions(exception.BuildAbortException,
exception.UnexpectedTaskStateError,
exception.VirtualInterfaceCreateException,
@@ -2114,7 +2115,7 @@ class ComputeManager(manager.Manager):
if filter_properties is None:
filter_properties = {}
@utils.synchronized(instance['uuid'])
@utils.synchronized(instance.uuid)
def do_run_instance():
self._run_instance(context, request_spec,
filter_properties, requested_networks, injected_files,

View File

@@ -252,6 +252,8 @@ class ComputeAPI(object):
3.25 - Make detach_volume take an object
3.26 - Make live_migration() and
rollback_live_migration_at_destination() take an object
... - Removed run_instance()
3.27 - Make run_instance() accept a new-world object
'''
VERSION_ALIASES = {

View File

@@ -3630,7 +3630,8 @@ class ComputeTestCase(BaseTestCase):
fake_network.fake_get_instance_nw_info(self.stubs, 1, 1))
self.mox.StubOutWithMock(self.compute.driver, "macs_for_instance")
self.compute.driver.macs_for_instance(instance).AndReturn(macs)
self.compute.driver.macs_for_instance(
mox.IsA(instance_obj.Instance)).AndReturn(macs)
self.mox.ReplayAll()
self.compute.run_instance(self.context, instance, {}, {}, None, None,
None, True, None, False)

View File

@@ -11,6 +11,7 @@
# under the License.
import iso8601
import mock
import mox
from oslo.config import cfg
@@ -199,6 +200,10 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
def fake_delete(self2, ctxt, image_id):
self.deleted_image_id = image_id
def fake_claim(context, instance, limits):
instance.host = self.compute.host
return claims.Claim(db_instance, self.rt, _fake_resources())
fake_image.stub_out_image_service(self.stubs)
self.stubs.Set(fake_image._FakeImageService, 'delete', fake_delete)
@@ -213,8 +218,6 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
mox.IgnoreArg()).AndReturn('fake_bdm')
db_instance['key_data'] = None
db_instance['auto_disk_config'] = None
self.rt.instance_claim(self.context, instance, limits).AndReturn(
claims.Claim(db_instance, self.rt, _fake_resources()))
self.compute.driver.spawn(self.context, instance, image,
injected_files=[], admin_password=None,
network_info=[],
@@ -226,18 +229,23 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
'task_state': None,
'image_ref': instance['image_ref'],
'key_data': None,
'host': self.compute.host, # rt.instance_claim set this
'auto_disk_config': False,
'expected_task_state': task_states.SPAWNING,
'launched_at': cur_time_tz},
update_cells=False,
columns_to_join=['metadata', 'system_metadata']
).AndReturn((db_instance, db_instance))
).AndReturn((db_instance,
dict(db_instance,
host=self.compute.host)))
self.compute._notify_about_instance_usage(self.context, instance,
'unshelve.end')
self.mox.ReplayAll()
self.compute.unshelve_instance(self.context, instance, image=image,
filter_properties=filter_properties, node=node)
with mock.patch.object(self.rt, 'instance_claim',
side_effect=fake_claim):
self.compute.unshelve_instance(self.context, instance, image=image,
filter_properties=filter_properties, node=node)
self.assertEqual(image['id'], self.deleted_image_id)
self.assertEqual(instance.host, self.compute.host)