From 7ebd4a7914504d55439426284191b54250a57e4f Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Thu, 28 Jul 2022 11:48:27 +0200 Subject: [PATCH] Deprecate openstack_hostnames_ips We never used that faile anywhere in the inventory generation process, except saving mapping of hostnames to container_address. At the same time we never stored extra IPs there and as of today we can simplify workflow by simply dropping that file. Change-Id: Id8c4f6512bc913b2480106dedfa2e457c4776ae7 --- .../inventory/configure-inventory.rst | 11 +++----- .../reference/inventory/manage-inventory.rst | 10 +++---- osa_toolkit/filesystem.py | 26 ------------------- osa_toolkit/generate.py | 17 ------------ ...enstack_hostname_ips-1431c38c33529f81.yaml | 5 ++++ tests/test_inventory.py | 1 - 6 files changed, 13 insertions(+), 57 deletions(-) create mode 100644 releasenotes/notes/drop_openstack_hostname_ips-1431c38c33529f81.yaml diff --git a/doc/source/reference/inventory/configure-inventory.rst b/doc/source/reference/inventory/configure-inventory.rst index f6221762a3..55d2edbded 100644 --- a/doc/source/reference/inventory/configure-inventory.rst +++ b/doc/source/reference/inventory/configure-inventory.rst @@ -26,13 +26,10 @@ To understand how the dynamic inventory works, see .. warning:: - Never edit or delete the files - ``/etc/openstack_deploy/openstack_inventory.json`` or - ``/etc/openstack_deploy/openstack_hostnames_ips.yml``. This can - lead to file corruptions, and problems with the inventory: hosts - and container could disappear and new ones would appear, - breaking your existing deployment. - + Never edit or delete the file + ``/etc/openstack_deploy/openstack_inventory.json``. This can lead to + problems with the inventory: existng hosts and containers will be unmanaged + and new ones will be generated instead, breaking your existing deployment. Configuration constraints ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/source/reference/inventory/manage-inventory.rst b/doc/source/reference/inventory/manage-inventory.rst index 8442d80bc3..c27e6b503a 100644 --- a/doc/source/reference/inventory/manage-inventory.rst +++ b/doc/source/reference/inventory/manage-inventory.rst @@ -3,12 +3,10 @@ Inspecting and manipulating the inventory .. warning:: - Never edit or delete the files - ``/etc/openstack_deploy/openstack_inventory.json`` or - ``/etc/openstack_deploy/openstack_hostnames_ips.yml``. This can - lead to file corruptions, and problems with the inventory: hosts - and container could disappear and new ones would appear, - breaking your existing deployment. + Never edit or delete the file + ``/etc/openstack_deploy/openstack_inventory.json``. This can lead to + problems with the inventory: existng hosts and containers will be unmanaged + and new ones will be generated instead, breaking your existing deployment. The file ``scripts/inventory-manage.py`` is used to produce human readable output based on the ``/etc/openstack_deploy/openstack_inventory.json`` file. diff --git a/osa_toolkit/filesystem.py b/osa_toolkit/filesystem.py index f6565f5d63..414099b73a 100644 --- a/osa_toolkit/filesystem.py +++ b/osa_toolkit/filesystem.py @@ -187,32 +187,6 @@ def _get_backup_name(basename): return '{}-{}.json'.format(basename, utctime) -def write_hostnames(save_path, hostnames_ips): - """Write a list of all hosts and their given IP addresses - - NOTE: the file is saved in json format to a file with the name - ``openstack_hostnames_ips.yml`` - - :param save_path: path to save the file to, will use default location if - None or an invalid path is provided - :param hostnames_ips: the list of all hosts and their IP addresses - """ - - file_path = dir_find(save_path) - hostnames_ip_file = os.path.join(file_path, 'openstack_hostnames_ips.yml') - - with open(hostnames_ip_file, 'wb') as f: - f.write( - ('# This file is managed by openstack-ansible. No manual edits.\n' - + json.dumps( - hostnames_ips, - indent=4, - separators=(',', ': '), - sort_keys=True - )).encode('ascii') - ) - - def _load_from_json(filename, preferred_path=None, raise_if_missing=True): """Return a dictionary found in json format in a given file diff --git a/osa_toolkit/generate.py b/osa_toolkit/generate.py index 8619cefd39..2a0d62fa22 100755 --- a/osa_toolkit/generate.py +++ b/osa_toolkit/generate.py @@ -1081,19 +1081,6 @@ def _check_all_conf_groups_present(config, environment): return retval -def _collect_hostnames(inventory): - - # Generate a list of all hosts and their used IP addresses - hostnames_ips = {} - for _host, _vars in inventory['_meta']['hostvars'].items(): - host_hash = hostnames_ips[_host] = {} - for _key, _value in _vars.items(): - if _key.endswith('address') or _key == 'ansible_host': - host_hash[_key] = _value - - return hostnames_ips - - def _prepare_debug_logger(): log_fmt = "%(lineno)d - %(funcName)s: %(message)s" logging.basicConfig(format=log_fmt, filename='inventory.log') @@ -1212,10 +1199,6 @@ def main(config=None, check=False, debug=False, environment=None, **kwargs): if _check_all_conf_groups_present(user_defined_config, environment): return 'Configuration ok!' - # Save a list of all hosts and their given IP addresses - hostnames_ips = _collect_hostnames(inventory) - filesys.write_hostnames(config, hostnames_ips) - if logger.isEnabledFor(logging.DEBUG): num_hosts = len(inventory['_meta']['hostvars']) logger.debug("%d hosts found.", num_hosts) diff --git a/releasenotes/notes/drop_openstack_hostname_ips-1431c38c33529f81.yaml b/releasenotes/notes/drop_openstack_hostname_ips-1431c38c33529f81.yaml new file mode 100644 index 0000000000..35ccc27433 --- /dev/null +++ b/releasenotes/notes/drop_openstack_hostname_ips-1431c38c33529f81.yaml @@ -0,0 +1,5 @@ +--- +other: + - | + File ``/etc/openstack_deploy/openstack_hostnames_ips.yml`` is not used + anymore and can be safely removed from your deployment configuration. diff --git a/tests/test_inventory.py b/tests/test_inventory.py index d32597a485..eb51f366a2 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -46,7 +46,6 @@ USER_CONFIG_FILE = path.join(TARGET_DIR, 'openstack_user_config.yml') # They should be cleaned up between each test. CLEANUP = [ 'openstack_inventory.json', - 'openstack_hostnames_ips.yml', 'backup_openstack_inventory.tar' ]