Smart save in SwiftSlotManager

Recent pypowervm changes alter the override spec of SlotMapStore such
that load(), save(), and delete() should no longer be overridden;
instead the subclass should override _load(key), _save(key, blob), and
_delete(key).  Although the original spec is still supported, using the
new spec confers advantages provided by SlotMapStore to invoke the
expensive _save operation only if something has changed in the slot
map.

Change-Id: I4ef03370bb84917851b11b256155c3c6218d9ada
Partial-Bug: 1584946
This commit is contained in:
Eric Fried 2016-05-23 17:19:22 -05:00
parent e08975ee39
commit b0f5db2b42
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):