Merge "Make servers::update() use Instance.save() to do the work"

This commit is contained in:
Jenkins
2013-07-19 10:08:41 +00:00
committed by Gerrit Code Review
3 changed files with 22 additions and 7 deletions

View File

@@ -1020,16 +1020,12 @@ class Controller(wsgi.Controller):
instance = self.compute_api.get(ctxt, id,
want_objects=True)
req.cache_db_instance(instance)
self.compute_api.update(ctxt, instance, **update_dict)
instance.update(update_dict)
instance.save()
except exception.NotFound:
msg = _("Instance could not be found")
raise exc.HTTPNotFound(explanation=msg)
# FIXME(danms): Until compute_api.update() is object-aware,
# we need to apply the updates to the instance object so
# that views will return the new data
instance.update(update_dict)
return self._view_builder.show(req, instance)
@wsgi.response(202)

View File

@@ -89,6 +89,7 @@ def return_security_group(context, instance_id, security_group_id):
def instance_update(context, instance_uuid, values, update_cells=True):
inst = fakes.stub_instance(INSTANCE_IDS.get(instance_uuid),
name=values.get('display_name'))
inst = dict(inst, **values)
return (inst, inst)
@@ -1292,7 +1293,7 @@ class ServersControllerTest(test.TestCase):
def fake_update(*args, **kwargs):
raise exception.InstanceNotFound(instance_id='fake')
self.stubs.Set(compute_api.API, 'update', fake_update)
self.stubs.Set(db, 'instance_update_and_get_original', fake_update)
req = fakes.HTTPRequest.blank('/fake/servers/%s' % FAKE_UUID)
req.method = 'PUT'
req.content_type = 'application/json'

View File

@@ -428,6 +428,7 @@ def unset_stub_network_methods(stubs):
def stub_compute_with_ips(stubs):
orig_get = compute_api.API.get
orig_get_all = compute_api.API.get_all
orig_create = compute_api.API.create
def fake_get(*args, **kwargs):
return _get_instances_with_cached_ips(orig_get, *args, **kwargs)
@@ -435,8 +436,12 @@ def stub_compute_with_ips(stubs):
def fake_get_all(*args, **kwargs):
return _get_instances_with_cached_ips(orig_get_all, *args, **kwargs)
def fake_create(*args, **kwargs):
return _create_instances_with_cached_ips(orig_create, *args, **kwargs)
stubs.Set(compute_api.API, 'get', fake_get)
stubs.Set(compute_api.API, 'get_all', fake_get_all)
stubs.Set(compute_api.API, 'create', fake_create)
def _get_fake_cache():
@@ -486,3 +491,16 @@ def _get_instances_with_cached_ips(orig_func, *args, **kwargs):
else:
_info_cache_for(instances)
return instances
def _create_instances_with_cached_ips(orig_func, *args, **kwargs):
"""Kludge the above kludge so that the database doesn't get out
of sync with the actual instance.
"""
instances, reservation_id = orig_func(*args, **kwargs)
fake_cache = _get_fake_cache()
for instance in instances:
instance['info_cache']['network_info'] = fake_cache
db.instance_info_cache_update(args[1], instance['uuid'],
{'network_info': fake_cache})
return (instances, reservation_id)