Commit Graph

10 Commits

Author SHA1 Message Date
Dmitriy Rabotyagov bb3a58604b Restore dynamic_inventory unit testing
It seems that we have dropped unit testing of our dynamic_inventory
some time ago. This patch aims to setup zuul tests using tox
and restore test functionality to make it passing with current codebase

Change-Id: I8ccee779fd629e8696ec2e12397b148b52cd0c73
2023-01-11 10:14:43 +00:00
wu.shiming 469b7d66b3 Use unittest.mock instead of mock
The mock third party library was needed for mock support in py2
runtimes. Since we now only support py36 and later, we can use the
standard lib unittest.mock module instead

Change-Id: Ie36f12a4a6dd3c06b9ffd9bfb7bbb0106311820f
2020-11-23 05:24:25 +00:00
Jesse Pretorius 7d98b2cece Correct E408 pep8 lint errors
With the changes to how to test-requirements are installed, some new
failures are showing. This patch corrects them.

Change-Id: I641b167f1b7f5bb283d73481ed6185e1ccbd8ed3
2018-07-06 09:20:11 +00:00
Jimmy McCrory c5551f2c8c Move inventory files to folder in root of repo
Move the playbooks/inventory folder, group_vars, and host_vars to
inventory/ in the root of the OpenStack-Ansible repo. This helps better
organize the repo structure since playbooks/ will now only contain
playbooks, shared task files, and included repo package var files.

group_vars and host_vars are moved alongside the inventory since that's
the default place that Ansible expects those folders and to help better
prepare for Ansible 2.4 where multiple inventories can be loaded,
automatically including relative group and host var files.

Effected docs, scripts, and variables have been updated with the new
paths.

Change-Id: If50e2412c3fd6575d7041deb8ecc9480b04184cc
2017-12-16 02:34:33 -08:00
Nolan Brubaker ea6954f72f Use python import machinery for inventory code
Change Idb7780f55e4a1fd77dd76becbf67c1ccbf220db7 restructured the python
inventory generation code so that it would be possible to install it
with pip. This change removes (most) of the import path hacks and
switches to using a pip-installed version of osa_toolkit.

Of note, the path hacks are left in place for the dynamic_inventory.py
file for now, as that file is really more of an endpoint, but is tested.

Also, the bootstrap-ansible.sh script was modified to install the code;
this is unnecessary with the tox environments because the tox directive
'usedevelop=True' does that already. Production environments still need
this, though.

Finally, to maintain usability when called directly, the interpreter for
dynamic_inventory.py was updated from `/usr/bin/env` to
`/opt/ansible-runime/python`. This change ensures that in a full
deployment the user is using the exact same code paths whether Ansible
invokes the script, or it is called directly. This also means that using
the script locally on a development machine, it must be invoked as an
argument to Python, unless the ansible-runtime directory exists.

Change-Id: Iafa573b1b144f98528d5e0aceb3f36e9de2a22a2
2017-07-28 16:39:52 +00:00
Nolan Brubaker f0e6184185 Cleanly catch keyboard interrupts during tests
When running the inventory tests on a development machine, using ctrl-c
to send sigint should gracefully finish the current test and clean up
the workspace (tests/inventory).

While most of our tests are well-behaved, without the catchbreak=True
option, sometimes the code would be interrupted in between file creation
and cleanup. Additionally, tearDownModule was never called, leaving
behind inventory/openstack_user_config.yml

This change allows the current test to finish, it's teardown methods to
run, and finally the tearDownModule function to execute, leaving behind
a clean workspace. Only the tests that directly touch the filesystem
were changed.

While this is not impactful for gate tests, it improves quality of life
for developers.

Change-Id: I992e514e58958264d90faab7bc295d6d8e89f039
2017-07-12 13:46:11 +00:00
Nolan Brubaker 2be3319ac9 Restructure lib directory to install via pip
This change allows the currently existing modules to be imported from
the `osa_toolkit` package.

In order to install the python modules used by the inventory via
setup.py with pbr, we need to rename the lib directory to match the name
of the package we wish to install.

pbr doesn't allow for doing any kind of directory renaming within the
setup.{cfg,py} files, but we need to keep using it in order to consume
global requirements updates.

Change-Id: Idb7780f55e4a1fd77dd76becbf67c1ccbf220db7
2017-03-30 10:19:01 -04:00
pangliye 183b30d7f4 Add Apache 2.0 license to source file
Source code should be licensed under the Apache 2.0 license.
All source files should have the licensing header.

Change-Id: Ib5d8c93f7a1078cd0aaf6a0c0a30247671bc3088
2016-12-19 19:59:49 -05:00
Steve Lewis 5cde716959 Inventory refactor SystemExit uses removed
The use of SystemExit exceptions in what is effectively library code
has been eliminated. A new exception is introduced and it is handled
with a translation to a SystemExit within generate.py when
appropriate.

When attempting to load an existing inventory, a tuple is returned
instead of simply the inventory. The tuple includes the path used to
load the inventory, or an appropriate path. This facilitates saving
to the correct place with save_inventory later.

Use of dir_find within generate.py was also eliminated and the logic
around path to configuration should be simpler now.

One debug logging message was adjusted to only run when the desired
file is actually loaded, where it was always trying to log a message
even if not file was found previously.

The manage.py file had imports updated to replicate the pattern used
in generate.py

Change-Id: I9caecfa09517a508882ae491df9e3d2da9386012
Parent-Id: I577cdbf4aadfcce846412edd7e2a394c257c0243
2016-11-23 00:33:14 -08:00
Steve Lewis ad566bffd7 DynamicInventory filesystem storage API cleanup
Update some function docstrings for accuracy/completeness
Make some methods module-private as they are not required to be
available for external use.

Tests were updated to accomodate for the now private functions.
The affected tests were identified as filesystem-centric and
moved to their own testing file, which will run under the inventory
tox target as well.

Parent-Id: I4d52f7363e00bba62ed878fe8fa6e593eb21fdde
Change-Id: I0275eeeafeb2a4c89cd820d56dd0ad01d3124a80
2016-11-19 10:12:51 -08:00