Some variable names are shortened for brevity and clarity.
Change-Id: Ib429ea4b390a17c3eae2b23b4060a12065312299
Parent-Id: I9caecfa09517a508882ae491df9e3d2da9386012
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
The last uses of the builtin os module are removed from generate
as the load_environment and load_user_configuration functions are
moved, along with the _extra_config method they rely upon. This
also moves the last use of the yaml module.
These functions are not refactored to make use of the other funcs
available in the filesystem package, and as a result there is
still an undesirable use of the dir_find func in the generate
script. These will all be cleaned up in a following patch to keep
this easier to review.
An unused left-over function is removed now that there are no
merge conflicts introduced by it.
A debug logging message is formatted consistent to other messages;
the only impact in this case is applying consistency in log
message formatting since the formatting was only occuring when the
log level is activated already.
Parent-Id: I4c7b45f16f8ffecb91bf509daeca47b2c2450681
Change-Id: I577cdbf4aadfcce846412edd7e2a394c257c0243
Refactor of the process for writing a hostnames and IPs file
during inventory generation.
The find_config_path is refactored as well since that was relied
upon in the implementation of the above.
To improve clarity of the file utility methods the pass_exception
parameter has been renamed and logic has been inverted.
Parent-Id: I0275eeeafeb2a4c89cd820d56dd0ad01d3124a80
Change-Id: I4c7b45f16f8ffecb91bf509daeca47b2c2450681
This patch moves the IP logic into a module separate from the overall
code. Ideally, this will serve as a way to abstract IP information
handling to be populated by pluggable backends in addition to existing
logic.
Further work is needed to remove various code smells from tests and provide a
more consistent public API that could be adopted as more generic.
Change-Id: I09a57c43064eca46f776e941cbedb2296f43fbbc
Segmenting the storage-related operations from the rest of the
inventory generation management tooling, in support of better
maintainability testability and future support for alternate storage
options.
Operations in manage.py are slightly updated to make use of common
code.
Change-Id: If032bcc9e4727d3895e4ef6cecb6aff511d4b0af
Segmenting out changes to the inventory generation script which are
related to datastructure manipulations in preparation for segmenting
out storage-related operations.
Change-Id: I3160862b4fea92bce4c951107e154fd3ddc21234
Previously our code was using both the older %-style and format-style
interpolation methods. This change consolidates the code base such that
the style used is consistent.
Logging lines were not changed, due to the logging library not
supporting format strings. The variables to interpolate are passed as
arguments and not actually interpolated unless the logging level is set;
this is a performance gain over making all strings passed to logging
methods pre-formatted.
Change-Id: I4fb7b821dd6f5662ef30ef67c456849a1d92da68
When running inventory tests locally on Python 2.7.12, the following
warning was displayed for some tests:
/home/nrb/projects/openstack-ansible/tests/test_inventory.py:565:
DeprecationWarning: BaseException.message has been deprecated as of
Python 2.6
This change updates references to exception.message to use the str
method of access, which is the replacement.
A __str__ method was also added the LxcHostsDefined exception to be more
consistent.
Change-Id: I75fd2da4a31b75916f10502134913c8bacbc34f0
When defining a configuration, it's possible that the groups defined in
the openstack_user_config.yml file might not match those defined by the
env.d contents. This isn't strictly a problem - in most cases it's
ignored and will simply result in extra data. However, if keys in the
configuration and the environment are mismatched, it could result in
variable data not being mapped correctly in the resultant inventory.
This patchset extends the -c/--check parameter to compare the configured
groups against the environment's groups, and issue a warning if there is
a mismatch, which should help deployers diagnose some configuration
issues.
The warnings were not added to standard run operations due to the amount
of output generated on stdout by the JSON dump.
Change-Id: I7a7e52b31909e963873063e43e28a5bb9a6963fd
Due to upstream Ansible deprecating the `ansible_ssh_host` variable,
this key is removed from the generated inventory in order to avoid
confusion. While Newton also supports Ansible 2.x, this change is
intended to only be in effect from Ocata forward.
From
http://docs.ansible.com/ansible/intro_inventory.html#hosts-and-groups:
"Ansible 2.0 has deprecated the “ssh” from ansible_ssh_user,
ansible_ssh_host, and ansible_ssh_port to become ansible_user,
ansible_host, and ansible_port. If you are using a version of Ansible
prior to 2.0, you should continue using the older style variables
(ansible_ssh_*). These shorter variables are ignored, without warning,
in older versions of Ansible."
Fixes-Bug: #1636606
Change-Id: If43b28247a9df3db76217b1147fab785f1235532
Most of the code from dynamic_inventory.py was moved to lib/generate.py
in order to consolidate the inventory code into one place.
Code changes from dynamic_inventoy.py to generate.py:
argparse and sys imports removed
args function definition removed
__main__ section removed
The `args` function was left in dynamic_inventory.py in order to ensure
the environment argument can use the relative path for
playbooks/inventory/env.d. As such, dynamic_inventory.py is imported in
order to provide test coverage.
Imports and coverage reports for tests were also updated.
Change-Id: Icd1ea365befd8e805dc2c48332c104bcd887899b