Browse Source

Merge "Raise InstanceMappingNotFound if StaleDataError is encountered"

changes/12/726512/13
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
b1f4b303f7
2 changed files with 20 additions and 2 deletions
  1. +11
    -2
      nova/objects/instance_mapping.py
  2. +9
    -0
      nova/tests/unit/objects/test_instance_mapping.py

+ 11
- 2
nova/objects/instance_mapping.py View File

@@ -15,6 +15,7 @@ import collections
from oslo_log import log as logging
from oslo_utils import versionutils
import six
from sqlalchemy.orm import exc as orm_exc
from sqlalchemy.orm import joinedload
from sqlalchemy.sql import false
from sqlalchemy.sql import func
@@ -161,8 +162,16 @@ class InstanceMapping(base.NovaTimestampObject, base.NovaObject):
def save(self):
changes = self.obj_get_changes()
changes = self._update_with_cell_id(changes)
db_mapping = self._save_in_db(self._context, self.instance_uuid,
changes)
try:
db_mapping = self._save_in_db(self._context, self.instance_uuid,
changes)
except orm_exc.StaleDataError:
# NOTE(melwitt): If the instance mapping has been deleted out from
# under us by conductor (delete requested while booting), we will
# encounter a StaleDataError after we retrieved the row and try to
# update it after it's been deleted. We can treat this like an
# instance mapping not found and allow the caller to handle it.
raise exception.InstanceMappingNotFound(uuid=self.instance_uuid)
self._from_db_object(self._context, self, db_mapping)
self.obj_reset_changes()



+ 9
- 0
nova/tests/unit/objects/test_instance_mapping.py View File

@@ -12,6 +12,7 @@

import mock
from oslo_utils import uuidutils
from sqlalchemy.orm import exc as orm_exc

from nova import exception
from nova import objects
@@ -151,6 +152,14 @@ class _TestInstanceMappingObject(object):
comparators={
'cell_mapping': self._check_cell_map_value})

@mock.patch.object(instance_mapping.InstanceMapping, '_save_in_db')
def test_save_stale_data_error(self, save_in_db):
save_in_db.side_effect = orm_exc.StaleDataError
mapping_obj = objects.InstanceMapping(self.context)
mapping_obj.instance_uuid = uuidutils.generate_uuid()

self.assertRaises(exception.InstanceMappingNotFound, mapping_obj.save)

@mock.patch.object(instance_mapping.InstanceMapping, '_destroy_in_db')
def test_destroy(self, destroy_in_db):
uuid = uuidutils.generate_uuid()


Loading…
Cancel
Save