diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-12-04 06:01:37 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-12-04 06:01:37 +0000 |
commit | 7989f2d0f77304886914a5e4b642a92a5527f70f (patch) | |
tree | d55bf0a0724ff6e9167b605febc5066b1b2ea9f7 | |
parent | 209c45209fc866499d0682c1f9d0772252ff57de (diff) | |
parent | ccb7ef2b017edd1d192b597310c0688e690a9175 (diff) | |
download | nova-7989f2d0f77304886914a5e4b642a92a5527f70f.tar.gz |
Merge "Make Instance.save() update numa_topology" into stable/juno
-rw-r--r-- | nova/objects/instance.py | 8 | ||||
-rw-r--r-- | nova/objects/instance_numa_topology.py | 22 | ||||
-rw-r--r-- | nova/tests/objects/test_instance.py | 22 |
3 files changed, 50 insertions, 2 deletions
diff --git a/nova/objects/instance.py b/nova/objects/instance.py index 8ad6b2b1c9..6048dffaa2 100644 --- a/nova/objects/instance.py +++ b/nova/objects/instance.py @@ -398,8 +398,12 @@ class Instance(base.NovaPersistentObject, base.NovaObject): pass def _save_numa_topology(self, context): - # NOTE(ndipanov): No need for this yet. - pass + if self.numa_topology: + self.numa_topology.instance_uuid = self.uuid + self.numa_topology._save(context) + else: + objects.InstanceNUMATopology.delete_by_instance_uuid( + context, self.uuid) def _save_pci_devices(self, context): # NOTE(yjiang5): All devices held by PCI tracker, only PCI tracker diff --git a/nova/objects/instance_numa_topology.py b/nova/objects/instance_numa_topology.py index e1c0a4f07c..a1cffbf5fe 100644 --- a/nova/objects/instance_numa_topology.py +++ b/nova/objects/instance_numa_topology.py @@ -63,6 +63,7 @@ class InstanceNUMATopology(base.NovaObject): cells.append(cell) return hardware.VirtNUMAInstanceTopology(cells=cells) + # TODO(ndipanov) Remove this method on the major version bump to 2.0 @base.remotable def create(self, context): topology = self.topology_from_obj() @@ -73,6 +74,27 @@ class InstanceNUMATopology(base.NovaObject): values) self.obj_reset_changes() + # NOTE(ndipanov): We can't rename create and want to avoid version bump + # as this needs to be backported to stable so this is not a @remotable + # That's OK since we only call it from inside Instance.save() which is. + def _save(self, context): + topology = self.topology_from_obj() + if not topology: + return + values = {'numa_topology': topology.to_json()} + db.instance_extra_update_by_uuid(context, self.instance_uuid, + values) + self.obj_reset_changes() + + # NOTE(ndipanov): We want to avoid version bump + # as this needs to be backported to stable so this is not a @remotable + # That's OK since we only call it from inside Instance.save() which is. + @classmethod + def delete_by_instance_uuid(cls, context, instance_uuid): + values = {'numa_topology': None} + db.instance_extra_update_by_uuid(context, instance_uuid, + values) + @base.remotable_classmethod def get_by_instance_uuid(cls, context, instance_uuid): db_topology = db.instance_extra_get_by_instance_uuid( diff --git a/nova/tests/objects/test_instance.py b/nova/tests/objects/test_instance.py index d89c673fc5..d75452ae87 100644 --- a/nova/tests/objects/test_instance.py +++ b/nova/tests/objects/test_instance.py @@ -404,6 +404,28 @@ class _TestInstanceObject(object): self.assertNotIn('pci_devices', mock_fdo.call_args_list[0][1]['expected_attrs']) + @mock.patch('nova.db.instance_extra_update_by_uuid') + @mock.patch('nova.db.instance_update_and_get_original') + @mock.patch('nova.objects.Instance._from_db_object') + def test_save_updates_numa_topology(self, mock_fdo, mock_update, + mock_extra_update): + mock_update.return_value = None, None + inst = instance.Instance( + context=self.context, id=123, uuid='fake-uuid') + inst.numa_topology = ( + instance_numa_topology.InstanceNUMATopology.obj_from_topology( + test_instance_numa_topology.fake_numa_topology)) + inst.save() + mock_extra_update.assert_called_once_with( + self.context, inst.uuid, + {'numa_topology': + test_instance_numa_topology.fake_numa_topology.to_json()}) + mock_extra_update.reset_mock() + inst.numa_topology = None + inst.save() + mock_extra_update.assert_called_once_with( + self.context, inst.uuid, {'numa_topology': None}) + def test_get_deleted(self): fake_inst = dict(self.fake_instance, id=123, deleted=123) fake_uuid = fake_inst['uuid'] |