Skip to content

Inventory: Remove unnecessary lists around singular host vars #141 #155

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

Merged
merged 22 commits into from
Apr 27, 2020

Conversation

DouglasHeriot
Copy link
Contributor

@DouglasHeriot DouglasHeriot commented Apr 3, 2020

Implements #141
There's a new plurals option on the inventory. It is True by default to maintain backwards compatibility. When set to False, the group_by options and host_vars all change names to become singular, and unnecessary lists around singular vars are removed.

Once #153 is merged to start on #56 inventory unit tests, I'll add some unit tests for plurals too.

@DouglasHeriot DouglasHeriot force-pushed the 141-plurals-optional branch from 9392cf4 to 432cf82 Compare April 3, 2020 06:14
@DouglasHeriot
Copy link
Contributor Author

This is still a work in progress, not actually ready to merge. Need to do a lot more testing.

@DouglasHeriot
Copy link
Contributor Author

This is getting closer. Currently working on #56 adding integration tests as part of this to ensure the work on the plurals option doesn't cause any regressions.

I've found the community.aws collection has a good example of how to do this. https://github.com/ansible-collections/community.aws/tree/master/tests/integration/targets/script_inventory_ec2

Got caught for a little bit on ansible/ansible#68963

@DouglasHeriot DouglasHeriot force-pushed the 141-plurals-optional branch 10 times, most recently from b7d1015 to f8090f7 Compare April 17, 2020 05:00
@DouglasHeriot DouglasHeriot force-pushed the 141-plurals-optional branch 7 times, most recently from f88a08a to 31f2f3b Compare April 21, 2020 00:32
…ta (netbox-community#56)

Also:
* Update .gitignore and galaxy.yml build_ignore with various development files to ignore.
* Added .editorconfig with indentation settings for .py and .yml files
@DouglasHeriot DouglasHeriot force-pushed the 141-plurals-optional branch 4 times, most recently from d17e8c9 to 5536ebf Compare April 21, 2020 14:46
…on-default options

Includes testing the Constructed inherited options.

Also added the same inventory from the past v0.2.0 release. I compared its output to the output of the actualy v0.2.0 release and can confirm nothing has changed - only added new host_vars (config_context, regions) since then, and changed the test data slightly. (ie. there should be no breaking change for existing users of this collection)
@DouglasHeriot
Copy link
Contributor Author

DouglasHeriot commented Apr 21, 2020

Ok, @FragmentedPacket this is finally ready for a proper review.
Sorry it's become so large - the plurals option is a substantial change so I wanted to submit tests. Ended up going down the rabbit hole of improving all of the integration tests along the way.

Here's a summary of what this pull request includes:

More details:

  • plurals defaults to True for backwards compatibility. (Tested by test-inventory-legacy.yml). Eventually we might want to add a warning and make the default False as it makes more sense.
  • When plurals is False, the host var device_role has been renamed to role to match role on VMs.
  • CONTRIBUTING.md has been updated with how I've set up my test environment. It also has details of how to update the inventory test output.
  • Existing integration tests for the modules have been moved into the tests/integration/targets directory, and changed slightly for compatibility with the ansible-test tool. The main benefit I see of this is we get tooling like code coverage checking sorted out automatically. As these are run like Ansible roles and not playbooks, the netbox.netbox prefix has to be added to all module calls.
  • Added travis testing against Netbox 2.8 with release version of Ansible. Stuck to Python 3.7 instead of 3.8 due to pylint sanity test fails on Python 3.8 ansible/ansible#67118 Using Netbox develop branch snapshot docker image due to django-rest-framework v3.11 dropped suppport for set_context in UniqueTogetherValidator netbox#4496
  • Consolidated integration tests - rather than have separate tests for Netbox v2.6, v2.7 and v2.8 (Introduced in Enhancement: Added option to not prepend group names with group_by option #147) I changed it to just v2.6 and latest. There's not yet anything different in 2.7 vs 2.8 so no point adding that complexity right now. Should help avoid mistakes like in Update rack width to comply with latest API documentation #168 the unit tests for 2.6 and 2.7 were updated, but not 2.8 as they didn't exist in the fork that was merged in.

@FragmentedPacket
Copy link
Contributor

@DouglasHeriot I will try and get to this during the weekend. Work has been kicking my butt so haven't had the mental capacity to walk through the PR.

Thanks for all your effort!

- If True, all host vars are contained inside single-element arrays for legacy compatibility. Group names will be plural (ie. "sites_mysite" instead of "site_mysite")
default: True
type: boolean
version_added: "0.1.11"
Copy link
Contributor

Choose a reason for hiding this comment

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

Update version to 0.2.1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

# Keep looping until the region has no parent
while region_id is not None:
region_slug = self.regions_lookup[region_id]
if region_slug in regions:
Copy link
Contributor

Choose a reason for hiding this comment

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

I tested this and appears it doesn't get stuck in a loop, but maybe my test data isn't correct for L710-L712

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No this will never get stuck in a loop – wasn't sure how defensively I should be programming against the Netbox API. It would only be in theory if Netbox had a corrupt database that somehow had a loop in it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok no problem. I don't feel strongly on either having it or not so we can leave it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've left this in but updated the comment to be more clear.

.travis.yml Outdated
- ansible-test sanity -v --requirements --python $PYTHON_VER --skip-test pep8 --skip-test validate-modules

# Unit tests, with code coverage
- ansible-test units -vvvv --coverage --python $PYTHON_VER
Copy link
Contributor

Choose a reason for hiding this comment

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

After looking at the tests, what is the least amount of verbosity can we get away with these commands? The test output is pretty heavy with setup information for all this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's very verbose. I wasn't sure whether to go for enough information to debug any issues, or just enough to read and see where it failed. These could probably all be changed to just -v or -vv

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that is definitely something to consider. I'll leave that decision up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed it to -v. Should be enough for most cases.

* Mostly updated comments to be clearer.
* Changed argument name
* Reduced verbosity of travis tests
@FragmentedPacket
Copy link
Contributor

@DouglasHeriot Thanks a lot for this. I can't tell you how much I appreciate your work on this. Great work and the quality is superb.

@DouglasHeriot
Copy link
Contributor Author

@FragmentedPacket thanks for being prompt and easy to work with!
(The Ansible 2.10 release is going to come with a bit of pain, but being able to actually get stuff like this merged with solid testing is big win)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants