diff --git a/nova/api/openstack/compute/contrib/multinic.py b/nova/api/openstack/compute/contrib/multinic.py index 8a47975bd9b8..774a7193bf05 100644 --- a/nova/api/openstack/compute/contrib/multinic.py +++ b/nova/api/openstack/compute/contrib/multinic.py @@ -35,9 +35,10 @@ class MultinicController(wsgi.Controller): super(MultinicController, self).__init__(*args, **kwargs) self.compute_api = compute.API() - def _get_instance(self, context, instance_id): + def _get_instance(self, context, instance_id, want_objects=False): try: - return self.compute_api.get(context, instance_id) + return self.compute_api.get(context, instance_id, + want_objects=want_objects) except exception.InstanceNotFound: msg = _("Server not found") raise exc.HTTPNotFound(msg) @@ -53,7 +54,7 @@ class MultinicController(wsgi.Controller): msg = _("Missing 'networkId' argument for addFixedIp") raise exc.HTTPUnprocessableEntity(explanation=msg) - instance = self._get_instance(context, id) + instance = self._get_instance(context, id, want_objects=True) network_id = body['addFixedIp']['networkId'] self.compute_api.add_fixed_ip(context, instance, network_id) return webob.Response(status_int=202) diff --git a/nova/api/openstack/compute/plugins/v3/multinic.py b/nova/api/openstack/compute/plugins/v3/multinic.py index 7931fe6c59d8..dcb98c403f5e 100644 --- a/nova/api/openstack/compute/plugins/v3/multinic.py +++ b/nova/api/openstack/compute/plugins/v3/multinic.py @@ -45,7 +45,8 @@ class MultinicController(wsgi.Controller): context = req.environ['nova.context'] authorize(context) - instance = common.get_instance(self.compute_api, context, id) + instance = common.get_instance(self.compute_api, context, id, + want_objects=True) network_id = body['add_fixed_ip']['network_id'] self.compute_api.add_fixed_ip(context, instance, network_id) return webob.Response(status_int=202) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index ce127463633d..6630482181b5 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -412,7 +412,7 @@ class ComputeVirtAPI(virtapi.VirtAPI): class ComputeManager(manager.Manager): """Manages the running instances from creation to destruction.""" - target = messaging.Target(version='3.11') + target = messaging.Target(version='3.12') def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -3321,6 +3321,7 @@ class ComputeManager(manager.Manager): qr_error, instance=instance) self._set_instance_error_state(context, instance['uuid']) + @object_compat @wrap_exception() @reverts_task_state @wrap_instance_fault @@ -3335,14 +3336,12 @@ class ComputeManager(manager.Manager): self.network_api.add_fixed_ip_to_instance(context, instance, network_id) - inst_obj = instance_obj.Instance._from_db_object( - context, instance_obj.Instance(), instance) - network_info = self._inject_network_info(context, inst_obj) - self.reset_network(context, inst_obj) + network_info = self._inject_network_info(context, instance) + self.reset_network(context, instance) # NOTE(russellb) We just want to bump updated_at. See bug 1143466. - self._instance_update(context, instance['uuid'], - updated_at=timeutils.utcnow()) + instance.updated_at = timeutils.utcnow() + instance.save() self._notify_about_instance_usage( context, instance, "create_ip.end", network_info=network_info) diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index 8ec1f2b76c5e..feadd4678fc2 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -225,6 +225,7 @@ class ComputeAPI(object): 3.9 - Update rescue_instance() to take an instance object 3.10 - Added get_rdp_console method 3.11 - Update unrescue_instance() to take an object + 3.12 - Update add_fixed_ip_to_instance() to take an object ''' VERSION_ALIASES = { @@ -280,13 +281,16 @@ class ComputeAPI(object): slave_info=slave_info) def add_fixed_ip_to_instance(self, ctxt, instance, network_id): - # NOTE(russellb) Havana compat - version = self._get_compat_version('3.0', '2.0') - instance_p = jsonutils.to_primitive(instance) + if self.client.can_send_version('3.12'): + version = '3.12' + else: + # NOTE(russellb) Havana compat + version = self._get_compat_version('3.0', '2.0') + instance = jsonutils.to_primitive(instance) cctxt = self.client.prepare(server=_compute_host(None, instance), version=version) cctxt.cast(ctxt, 'add_fixed_ip_to_instance', - instance=instance_p, network_id=network_id) + instance=instance, network_id=network_id) def attach_interface(self, ctxt, instance, network_id, port_id, requested_ip): diff --git a/nova/tests/api/openstack/compute/contrib/test_multinic_xs.py b/nova/tests/api/openstack/compute/contrib/test_multinic_xs.py index 6438eb872950..a188719136ae 100644 --- a/nova/tests/api/openstack/compute/contrib/test_multinic_xs.py +++ b/nova/tests/api/openstack/compute/contrib/test_multinic_xs.py @@ -16,6 +16,7 @@ import webob from nova import compute +from nova.objects import instance as instance_obj from nova.openstack.common import jsonutils from nova import test from nova.tests.api.openstack import fakes @@ -38,8 +39,14 @@ def compute_api_remove_fixed_ip(self, context, instance, address): last_remove_fixed_ip = (instance['uuid'], address) -def compute_api_get(self, context, instance_id): - return {'id': 1, 'uuid': instance_id} +def compute_api_get(self, context, instance_id, want_objects=False): + instance = instance_obj.Instance() + instance.uuid = instance_id + instance.id = 1 + instance.vm_state = 'fake' + instance.task_state = 'fake' + instance.obj_reset_changes() + return instance class FixedIpTest(test.NoDBTestCase): diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index c31d293df426..48fb89b00da8 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -3120,7 +3120,7 @@ class ComputeTestCase(BaseTestCase): self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0) self.compute.add_fixed_ip_to_instance(self.context, network_id=1, - instance=instance) + instance=self._objectify(instance)) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2) self.compute.terminate_instance(self.context, @@ -8043,7 +8043,8 @@ class ComputeAPITestCase(BaseTestCase): instance = self._create_fake_instance(params={'host': CONF.host}) self.stubs.Set(self.compute_api.network_api, 'deallocate_for_instance', lambda *a, **kw: None) - self.compute_api.add_fixed_ip(self.context, instance, '1') + self.compute_api.add_fixed_ip(self.context, self._objectify(instance), + '1') self.compute_api.remove_fixed_ip(self.context, instance, '192.168.1.1') self.compute_api.delete(self.context, self._objectify(instance)) diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py index 54ccd5932cac..892794a9089a 100644 --- a/nova/tests/compute/test_rpcapi.py +++ b/nova/tests/compute/test_rpcapi.py @@ -104,7 +104,7 @@ class ComputeRpcAPITestCase(test.TestCase): def test_add_fixed_ip_to_instance(self): self._test_compute_api('add_fixed_ip_to_instance', 'cast', - instance=self.fake_instance, network_id='id') + instance=self.fake_instance, network_id='id', version='3.12') # NOTE(russellb) Havana compat self.flags(compute='havana', group='upgrade_levels')