Merge "Smart save in SwiftSlotManager"

This commit is contained in:
Jenkins 2016-05-25 01:28:06 +00:00 committed by Gerrit Code Review
commit 831a4a3f0d
2 changed files with 19 additions and 13 deletions

View File

@ -59,10 +59,7 @@ class TestSwiftSlotManager(test.TestCase):
instance=self.inst)
def test_load(self):
# Run load
self.slot_mgr.load()
# Validate the call
# load() should have been called internally by __init__
self.store_api.fetch_slot_map.assert_called_with(
self.inst.uuid + '_slot_map')
@ -73,6 +70,16 @@ class TestSwiftSlotManager(test.TestCase):
# Run save
self.slot_mgr.save()
# Not called because nothing changed
self.store_api.store_slot_map.assert_not_called()
# Change something
mock_vfcmap = mock.Mock(server_adapter=mock.Mock(lpar_slot_num=123))
self.slot_mgr.register_vfc_mapping(mock_vfcmap, 'fabric')
# Run save
self.slot_mgr.save()
# Validate the call
self.store_api.store_slot_map.assert_called_once_with(
self.inst.uuid + '_slot_map', mock.ANY)

View File

@ -170,20 +170,19 @@ class SwiftSlotManager(NovaSlotManager):
self.store_api = store_api
super(SwiftSlotManager, self).__init__(**kwargs)
def load(self):
return self.store_api.fetch_slot_map(self.inst_key)
def _load(self, key):
return self.store_api.fetch_slot_map(key)
def save(self):
self.store_api.store_slot_map(self.inst_key, self.serialized)
def _save(self, key, blob):
self.store_api.store_slot_map(key, blob)
def delete(self):
def _delete(self, key):
try:
self.store_api.delete_slot_map(self.inst_key)
self.store_api.delete_slot_map(key)
except Exception:
LOG.warning(_LW("Unable to delete the slot map from Swift backing "
"store with ID %(inst_key)s. Will require "
"manual cleanup."), {'inst_key': self.inst_key},
self.instance)
"store with ID %(key)s. Will require "
"manual cleanup."), {'key': key}, self.instance)
class NoopSlotManager(NovaSlotManager):