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

Merged
merged 2 commits into from
Jun 10, 2019

Conversation

egroeper
Copy link
Contributor

SUMMARY

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

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

FactCache

ADDITIONAL INFORMATION

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/test_cache.py
[...]
[gw1] [100%] FAILED test/units/plugins/cache/test_cache.py::TestFactCache::test_update_legacy
[...]
___________________________________________________ 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'})

test/units/plugins/cache/test_cache.py:123: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

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::
    
            fact_cache[host.name].update(facts)
    
        It retrieves a *copy* of the facts for host.name and then updates the copy.  So the changes
        aren't persisted.
    
        Instead we need to do::
    
            fact_cache.update({host.name, 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/fact_cache.py:90: AttributeError

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 24, 2019
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Apr 24, 2019
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Apr 25, 2019
@s-hertel s-hertel self-requested a review April 25, 2019 19:21
@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label May 2, 2019
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 8, 2019
@ansibot
Copy link
Contributor

ansibot commented May 25, 2019

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

test/units/plugins/cache/test_cache.py:98:1: E302 expected 2 blank lines, found 1
test/units/plugins/cache/test_cache.py:118:5: E301 expected 1 blank line, found 0

click here for bot help

Copy link
Contributor

@s-hertel s-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 598a058

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jun 10, 2019
@s-hertel s-hertel merged commit 1ed7a65 into ansible:devel Jun 10, 2019
agowa pushed a commit to agowa/ansible-1 that referenced this pull request Jun 30, 2019
* Improve testing of FactCache
@ansible ansible locked and limited conversation to collaborators Aug 5, 2019
@egroeper egroeper deleted the fact_cache-improve_testing branch April 14, 2020 09:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants