fix cache 'update' method to be 'mapping' compatible

- also simplify the update functions
 - fix methods and allwow backwards compat with plugins overriding 'update'
This commit is contained in:
Brian Coca 2018-11-13 21:12:41 -05:00 committed by Brian Coca
parent 9973bea504
commit 68301f890a
3 changed files with 27 additions and 18 deletions

View file

@ -292,10 +292,18 @@ class FactCache(MutableMapping):
""" Flush the fact cache of all keys. """
self._plugin.flush()
def update(self, key, value):
host_cache = self._plugin.get(key)
host_cache.update(value)
self._plugin.set(key, host_cache)
def update(self, host_facts):
""" We override the normal update to ensure we always use the 'setter' method """
for key in host_facts:
try:
host_cache = self._plugin.get(key)
if host_cache:
host_cache.update(host_facts[key])
else:
host_cache = host_facts[key]
self._plugin.set(key, host_cache)
except KeyError:
self._plugin.set(key, host_facts[key])
class InventoryFileCacheModule(BaseFileCacheModule):
@ -314,7 +322,7 @@ class InventoryFileCacheModule(BaseFileCacheModule):
def validate_cache_connection(self):
try:
super(InventoryFileCacheModule, self).validate_cache_connection()
except AnsibleError as e:
except AnsibleError:
cache_connection_set = False
else:
cache_connection_set = True