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

Feature/test inventory #30707

Merged
merged 6 commits into from Oct 3, 2017
Merged

Feature/test inventory #30707

merged 6 commits into from Oct 3, 2017

Conversation

4383
Copy link
Contributor

@4383 4383 commented Sep 21, 2017

SUMMARY

Adding unit test for yaml inventory plugin related to #30663

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

test/units/plugins/inventory/test_inventory.py

ANSIBLE VERSION
ansible 2.5.0 (feature/test-inventory d730b962a0) last updated 2017/09/21 16:51:18 (GMT +200)
  config file = None
  configured module search path = ['/home/herve/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/herve/dev/ansible/lib/ansible
  executable location = /home/herve/dev/ansible/bin/ansible
  python version = 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609]
ADDITIONAL INFORMATION

After change

$ pytest -s -v test/units/plugins/inventory/test_inventory.py::IniInventory::test_yaml_inventory
============================================================= test session starts =============================================================
platform linux -- Python 3.5.2, pytest-3.2.2, py-1.4.34, pluggy-0.4.0 -- /home/herve/dev/ansible/venv/bin/python3.5
cachedir: .cache
rootdir: /home/herve/dev/ansible, inifile:
plugins: xdist-1.20.0, f5-sdk-3.0.1, forked-0.2, mock-1.6.3
collected 1 item                                                                                                                               

test/units/plugins/inventory/test_inventory.py::IniInventory::test_yaml_inventory PASSED

========================================================== 1 passed in 0.57 seconds ===========================================================

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 feature_pull_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 Sep 21, 2017
@bcoca
Copy link
Member

bcoca commented Sep 21, 2017

i actually added a yaml inventory file to testing so we could use it to run the other tests (uses ini now, but could split the load) .. but it got moved to legacy :-(

@mscherer mscherer removed the needs_triage Needs a first human triage before being processed. label Sep 21, 2017
@mock.patch('os.access')
def test_yaml_inventory(self, p_access, p_exist):
inventory_content = """
---
Copy link
Contributor

@pilou- pilou- Sep 21, 2017

Choose a reason for hiding this comment

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

textwrap.dedent could be used here.

@mattclay
Copy link
Member

mattclay commented Sep 21, 2017

The unit test should be self-contained, so having it provide its own inventory is good.

@bcoca
Copy link
Member

bcoca commented Sep 21, 2017

not an 'either/or' ... part of testing the plugin is seeing that the verify_file method works.

@mattclay
Copy link
Member

mattclay commented Sep 21, 2017

Using files in unit tests is fine. However, those files should be stored alongside the unit tests instead of shared with integration tests. Mixing the two complicates dependency analysis when looking at changes to determine which tests to execute.

@4383
Copy link
Contributor Author

4383 commented Sep 21, 2017

@pilou- improved code

@@ -173,7 +173,7 @@ def test_yaml_inventory(self):
""")}
C.INVENTORY_ENABLED = ['yaml']
Copy link
Contributor Author

@4383 4383 Sep 21, 2017

Choose a reason for hiding this comment

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

@pilou- C.INVENTORY_ENABLED must be reset after using?

Copy link
Contributor

@pilou- pilou- Sep 21, 2017

Choose a reason for hiding this comment

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

Yes. The new method is inside IniInventory class, it could be moved in another class (YamlInventory ?), then setUp and tearDown methods could be used in order to 1. save, 2. set (in setUp) and 3. restore (in tearDown) C.INVENTORY_ENABLED.

@bcoca
Copy link
Member

bcoca commented Sep 21, 2017

@mattclay good point, i was trying to leverage the file but it does make cross dependencies that I didn't realize

Copy link
Contributor Author

@4383 4383 left a comment

Applied

@ansibot
Copy link
Contributor

ansibot commented Sep 21, 2017

The test ansible-test sanity --test pep8 [?] failed with the following error:

test/units/plugins/inventory/test_inventory.py:165:38: E231 missing whitespace after ','

click here for bot help

@ansibot ansibot added 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. labels Sep 21, 2017
@ansibot ansibot 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. labels Sep 21, 2017
pilou-
pilou- approved these changes Sep 25, 2017
Copy link
Contributor

@pilou- pilou- left a comment

Looks good to me

@bcoca bcoca added this to In Progress in Inventory revamp Sep 27, 2017
@bcoca
Copy link
Member

bcoca commented Sep 29, 2017

code lgtm, reorg .. i'll let @mattclay decide

@mattclay mattclay merged commit db70eeb into ansible:devel Oct 3, 2017
BondAnthony pushed a commit to BondAnthony/ansible that referenced this pull request Oct 5, 2017
* [test] move inventory test to right path
* [feat] add unit test for yaml inventory plugin
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 5, 2018
@bcoca bcoca moved this from In Progress to Done in Inventory revamp Nov 13, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 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
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants