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

Improve testing of FactCache #55739

wants to merge 1 commit into
base: devel


None yet
4 participants
Copy link

commented Apr 24, 2019


I think, I found a bug in the rewrite of FactCache (Commit bd7322a).
Added some tests to show the problem.

  • Feature Pull Request



Legacy calls of FactCache.update() should be handled by FactCache.first_order_merge(), but the latter one is not defined.
My additional tests are showing this:

bin/ansible-test units -v --python 3.6 test/units/plugins/cache/
[gw1] [100%] FAILED test/units/plugins/cache/
___________________________________________________ TestFactCache.test_update_legacy ____________________________________________________
[gw1] linux -- Python 3.6.7 /tmp/python-idtu1jeh-ansible/python
self = <units.plugins.cache.test_cache.TestFactCache testMethod=test_update_legacy>

    def test_update_legacy(self):
>       self.cache.update('cache_key', {'key2': 'updatedvalue'})

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ansible.plugins.cache.FactCache object at 0x7f23a05285f8>
args = ('cache_key', {'key2': 'updatedvalue'})

    def update(self, *args):
        Backwards compat shim
        We thought we needed this to ensure we always called the plugin's set() method but
        MutableMapping.update() will call our __setitem__() just fine.  It's the calls to update
        that we need to be careful of.  This contains a bug::
        It retrieves a *copy* of the facts for and then updates the copy.  So the changes
        aren't persisted.
        Instead we need to do::
            fact_cache.update({, facts})
        Which will use FactCache's update() method.
        We currently need this shim for backwards compat because the update() method that we had
        implemented took key and value as arguments instead of taking a dict.  We can remove the
        shim in 2.12 as MutableMapping.update() should do everything that we need.
        if len(args) == 2:
            # Deprecated.  Call the new function with this name
            display.deprecated('Calling FactCache().update(key, value) is deprecated.  Use'
                               ' FactCache().first_order_merge(key, value) if you want the old'
                               ' behaviour or use FactCache().update({key: value}) if you want'
                               ' dict-like behaviour.', version='2.12')
>           return self.first_order_merge(*args)
E           AttributeError: 'FactCache' object has no attribute 'first_order_merge'

lib/ansible/vars/ AttributeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.