Commit Graph

12 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
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
npraveen35 2ab98d9702 trivialfix
inline comments trivial corrections

Change-Id: Ib50da8a36c978b6d3f518621b7fe91a635541978
2017-08-17 10:19:35 +00: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
Joel Griffiths 3a08bb7b78 Fix error during 'inventory-manage.py -r' calls
Use load_inventory instead for load_from_json. Rename
load_from_json to _load_from_json.

Move most of the --clear-ip and --remove calls to their
corresponding functions. Modified other calls to account
for the change

Add a test to test for inventory item removal.

fixes bug: 1663328

Change-Id: I2dbecb085383b3d02e298cc09b02566d1e52a064
2017-02-24 19:37:06 +00: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
Nolan Brubaker 21c77b27d2 Add command to remove IPs from inventory
This change adds support for removing container IP information from
inventory. This might be useful in situations where an environment is
deployed, but network information has changed, or there was a mistake in
subnetting (such as an expanded used_ips range).

Updating configs, such as LXC interface files and HAProxy or other load
balancers is not handled via this command.

Change-Id: Ibad9d587e14c41ecd486ed8668f9f815e348a94a
2016-11-11 12:12:22 -05:00
Nolan Brubaker 0d9eb88ab1 Move management code to inventory lib.
This change moves the management code into a library file for
consolidated access to the code. Nothing is changed with the interface
to the inventory-manage script.

The lib/__init__.py file is necessary for python to
import the lib directory as a package, which will become more important
as more code is relocated there.

The code was originally moved to playbooks/inventory/lib, but doing so
made Ansible try to run the python files, which they intentionally will
not do.

Change-Id: I2e31927ec48022c7a504096780977319882c6bdf
2016-10-11 19:16:24 +00:00
Nolan Brubaker f94b2d41f6 Create complete AIO inventory config for tests
With commit f7a50a24b9 (Change ID:
I99541d36aed6d4b9f83746c1cd1a5521b310f1f6,
https://review.openstack.org/#/c/369485/) the inventory configuration
was split into multiple files to enable scenario AIO testing. This had
the side effect of no longer populating inventory with a full config
file - the tests/inventory/openstack_user_config.yml file was a symlink
to etc/openstack_deploy/openstack_user_config.yml.aio, which only had a
handful of groups.

The result was that only 7 host entries appeared in inventory: aio1,
galera, rabbitmq, memcache, log, repo, and haproxy containers. These
coincide with the groups defined only in the
openstack_user_config.yml.aio file.

To make the inventory tests more robust against changes like these, this
patch adds some module-level fixtures that generate the test
configuration file from all the files ending with '.aio'. This file is
dynamically constructed at the beginning of each test run, and deleted
afterwards. The symlink to the openstack_user_config.yml.aio file is
removed in favor of this dynamically created file, though a placeholder
file remains to keep the directory in git.

A test was added to ensure any configured groups have hosts added; this
should serve as a safeguard against similar reconstructions. No check is
made for groups defined by the environment but unpopulated by config,
such as cinder_volumes_containers.

The original file could have been kept as a placeholder, but it would be
marked as changed by git after every test run.

The management tests were also updated to make use of the dynamic
configuration creation.

Change-Id: Ie4ba9c50315736a0b86e0caa2cccb0908c452a49
2016-09-23 15:56:14 -04:00
Nolan Brubaker 18c9e1faee Add export host option for inventory-manage script
The export host option allows users to export their existing host
information for import into a third party system. The output is
'pivoted', so that the key is the host/container name, and the values
are the group memberships and hostvar information. Some top level
networking information, such as load balancer IP addresses, as well as
provider networks, are also provided.

Test scaffolding was added to ensure the export does what is intended.

The tox inventory environment was modified to do coverage testing of
both the dynamic_inventory.py and manage_inventory.py files. The
coverage data is erased between runs, since combined output lead to
incorrect results for dynamic_inventory.py.

Change-Id: I2caa5a0c070b12a74ac26334c63ac8d0de704042
2016-09-22 02:50:01 +00:00