Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FactCache] define first_order_merge method #55781

Merged
merged 3 commits into from Jun 10, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -0,0 +1,2 @@
bugfixes:
- fact_cache - Define the first_order_merge method for the legacy FactCache.update(key, value).
@@ -58,6 +58,19 @@ def flush(self):
""" Flush the fact cache of all keys. """
self._plugin.flush()

def first_order_merge(self, key, value):
host_facts = {key: value}

try:
host_cache = self._plugin.get(key)
if host_cache:
host_cache.update(value)
host_facts[key] = host_cache
except KeyError:
pass

super(FactCache, self).update(host_facts)

def update(self, *args):
"""
Backwards compat shim
@@ -117,6 +117,12 @@ def test_plugin_load_failure(self):
"Unable to load the facts cache plugin.*json.*",
FactCache)

def test_update_legacy_key_exists(self):
self.cache['cache_key'] = {'key': 'value', 'key2': 'value2'}
self.cache.update('cache_key', {'key': 'updatedvalue'})
assert self.cache['cache_key']['key'] == 'updatedvalue'
assert self.cache['cache_key']['key2'] == 'value2'


class TestAbstractClass(unittest.TestCase):

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.