From 022954982b3b2ce198f893bd50590e82a66b65ac Mon Sep 17 00:00:00 2001 From: sbbroot <86356638+sbbroot@users.noreply.github.com> Date: Tue, 28 Jun 2022 16:16:20 +0200 Subject: [PATCH] [2.0.1] Adaptive mode for downloading requirements (#3188) * Split available_roles and roles_mapping into separate yaml documents (#3097) (#3119) * available_roles splitted into feature-mappings and features documents * feature-mappings added to the Init by default * Add manifest file parsing (#3105) (#3130) * Add `-m/--manifest` flag to accept manifest.yml produced by `epicli init/prepare` * Add `-v/--verbose` mode for printing out parsed manifest data * Add ManifestReader class used for paring the manifest.yml file * Move src/command/*.py to debian/redhat subdirs where needed * Optimize Grafana dashboards downloading (#3131) (#3150) * Optimize files downloading (#3116) (#3156) * Add image-registry configuration reading (#3106) (#3159) --- .ansible-lint | 1 + ansible/playbooks/filter_plugins/container.py | 27 + ansible/playbooks/repository.yml | 2 +- .../roles/download/tasks/list_files.yml | 28 +- .../roles/download/tasks/list_images.yml | 9 + .../download/tasks/list_requirements.yml | 25 + .../roles/image_registry/tasks/main.yml | 47 +- .../roles/opensearch/defaults/main.yml | 1 - .../roles/repository/defaults/main.yml | 3 +- .../download-requirements.py | 4 +- .../requirements/aarch64/files.yml | 16 +- .../requirements/aarch64/images.yml | 88 ++-- .../requirements/x86_64/files.yml | 19 +- .../requirements/x86_64/images.yml | 263 +++++----- .../src/command/{ => debian}/apt.py | 0 .../src/command/{ => debian}/apt_cache.py | 0 .../src/command/{ => debian}/apt_key.py | 0 .../src/command/{ => redhat}/dnf.py | 18 +- .../{ => redhat}/dnf_config_manager.py | 0 .../src/command/{ => redhat}/dnf_download.py | 2 +- .../src/command/{ => redhat}/dnf_repoquery.py | 0 .../src/command/{ => redhat}/rpm.py | 0 .../src/command/toolchain.py | 16 +- .../src/config/config.py | 156 +++++- .../src/config/manifest_reader.py | 117 +++++ .../src/config/version.py | 24 + .../files/download-requirements/src/error.py | 27 +- .../src/mode/base_mode.py | 36 +- .../tests/command/{ => debian}/test_apt.py | 2 +- .../command/{ => debian}/test_apt_cache.py | 2 +- .../command/{ => debian}/test_apt_key.py | 2 +- .../tests/command/{ => redhat}/test_dnf.py | 4 +- .../command/{ => redhat}/test_dnf_base.py | 2 +- .../{ => redhat}/test_dnf_config_manager.py | 2 +- .../command/{ => redhat}/test_dnf_download.py | 2 +- .../{ => redhat}/test_dnf_repoquery.py | 2 +- .../tests/command/{ => redhat}/test_rpm.py | 2 +- .../tests/config/test_config.py | 75 +++ .../tests/config/test_manifest_reader.py | 26 + .../tests/config/test_version.py | 17 + .../tests/data/config.py | 475 ++++++++++++++++++ .../tests/data/manifest_reader.py | 438 ++++++++++++++++ .../repository/tasks/clean-up-epirepo.yml | 34 +- .../tasks/copy-download-requirements.yml | 6 + .../tasks/download-requirements.yml | 23 +- .../roles/repository/tasks/setup.yml | 4 +- cli/epicli.py | 4 + cli/src/Config.py | 19 + cli/src/ansible/AnsibleInventoryCreator.py | 8 +- cli/src/ansible/AnsibleVarsGenerator.py | 12 +- cli/src/commands/Apply.py | 36 +- cli/src/commands/Init.py | 3 + cli/src/commands/Upgrade.py | 5 + cli/src/schema/ConfigurationAppender.py | 75 +-- docs/changelogs/CHANGELOG-2.0.md | 12 +- docs/home/howto/CLUSTER.md | 67 +-- docs/home/howto/DATABASES.md | 6 +- docs/home/howto/KUBERNETES.md | 8 +- docs/home/howto/MODULES.md | 403 +++++++++++++++ docs/home/howto/UPGRADE.md | 6 +- ...ature-mapping.yml => feature-mappings.yml} | 56 +-- .../defaults/configuration/features.yml | 54 ++ .../defaults/configuration/image-registry.yml | 475 +++++++++--------- ...ature-mapping.yml => feature-mappings.yml} | 15 +- .../validation/configuration/features.yml | 15 + .../configuration/image-registry.yml | 104 ++-- schema/common/validation/epiphany-cluster.yml | 4 +- 67 files changed, 2717 insertions(+), 717 deletions(-) create mode 100644 ansible/playbooks/filter_plugins/container.py create mode 100644 ansible/playbooks/roles/download/tasks/list_images.yml create mode 100644 ansible/playbooks/roles/download/tasks/list_requirements.yml rename ansible/playbooks/roles/repository/files/download-requirements/src/command/{ => debian}/apt.py (100%) rename ansible/playbooks/roles/repository/files/download-requirements/src/command/{ => debian}/apt_cache.py (100%) rename ansible/playbooks/roles/repository/files/download-requirements/src/command/{ => debian}/apt_key.py (100%) rename ansible/playbooks/roles/repository/files/download-requirements/src/command/{ => redhat}/dnf.py (93%) rename ansible/playbooks/roles/repository/files/download-requirements/src/command/{ => redhat}/dnf_config_manager.py (100%) rename ansible/playbooks/roles/repository/files/download-requirements/src/command/{ => redhat}/dnf_download.py (96%) rename ansible/playbooks/roles/repository/files/download-requirements/src/command/{ => redhat}/dnf_repoquery.py (100%) rename ansible/playbooks/roles/repository/files/download-requirements/src/command/{ => redhat}/rpm.py (100%) create mode 100644 ansible/playbooks/roles/repository/files/download-requirements/src/config/manifest_reader.py create mode 100644 ansible/playbooks/roles/repository/files/download-requirements/src/config/version.py rename ansible/playbooks/roles/repository/files/download-requirements/tests/command/{ => debian}/test_apt.py (97%) rename ansible/playbooks/roles/repository/files/download-requirements/tests/command/{ => debian}/test_apt_cache.py (93%) rename ansible/playbooks/roles/repository/files/download-requirements/tests/command/{ => debian}/test_apt_key.py (88%) rename ansible/playbooks/roles/repository/files/download-requirements/tests/command/{ => redhat}/test_dnf.py (97%) rename ansible/playbooks/roles/repository/files/download-requirements/tests/command/{ => redhat}/test_dnf_base.py (86%) rename ansible/playbooks/roles/repository/files/download-requirements/tests/command/{ => redhat}/test_dnf_config_manager.py (93%) rename ansible/playbooks/roles/repository/files/download-requirements/tests/command/{ => redhat}/test_dnf_download.py (94%) rename ansible/playbooks/roles/repository/files/download-requirements/tests/command/{ => redhat}/test_dnf_repoquery.py (96%) rename ansible/playbooks/roles/repository/files/download-requirements/tests/command/{ => redhat}/test_rpm.py (96%) create mode 100644 ansible/playbooks/roles/repository/files/download-requirements/tests/config/test_config.py create mode 100644 ansible/playbooks/roles/repository/files/download-requirements/tests/config/test_manifest_reader.py create mode 100644 ansible/playbooks/roles/repository/files/download-requirements/tests/config/test_version.py create mode 100644 ansible/playbooks/roles/repository/files/download-requirements/tests/data/config.py create mode 100644 ansible/playbooks/roles/repository/files/download-requirements/tests/data/manifest_reader.py create mode 100644 docs/home/howto/MODULES.md rename schema/common/defaults/configuration/{feature-mapping.yml => feature-mappings.yml} (57%) create mode 100644 schema/common/defaults/configuration/features.yml rename schema/common/validation/configuration/{feature-mapping.yml => feature-mappings.yml} (78%) create mode 100644 schema/common/validation/configuration/features.yml diff --git a/.ansible-lint b/.ansible-lint index 92478d5e18..30affe3883 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -38,6 +38,7 @@ skip_list: - meta-no-info - package-latest - fqcn-builtins + - no-jinja-when ################## # Tags to follow # diff --git a/ansible/playbooks/filter_plugins/container.py b/ansible/playbooks/filter_plugins/container.py new file mode 100644 index 0000000000..8aaae8d8a4 --- /dev/null +++ b/ansible/playbooks/filter_plugins/container.py @@ -0,0 +1,27 @@ +from typing import Any, Dict, List + + +class FilterModule: + """ Filters for Python's container types """ + + def filters(self): + return { + 'dict_to_list': self.dict_to_list + } + + def dict_to_list(self, data: Dict, only_values: bool = False, only_keys: bool = False) -> List: + """ + Convert dict to list without using Ansible's loop mechanism with dict2items filter. + + :param data: to be converted into a list + :param only_values: construct list with only dict's values + :param only_keys: construct list with only dict's keys + :return: data transformed into a list + """ + if only_values: + return list(data.values()) + + if only_keys: + return list(data.keys()) + + return list(data.items()) diff --git a/ansible/playbooks/repository.yml b/ansible/playbooks/repository.yml index b76cdda5fb..7a7a5e55a4 100644 --- a/ansible/playbooks/repository.yml +++ b/ansible/playbooks/repository.yml @@ -1,5 +1,5 @@ --- -# This playbook is empty by purpose, just to enable repository role in configuration/feature-mapping +# This playbook is empty by purpose, just to enable repository role in configuration/features # to populate defaults/configuration to Ansible vars - hosts: "!all" tasks: [] diff --git a/ansible/playbooks/roles/download/tasks/list_files.yml b/ansible/playbooks/roles/download/tasks/list_files.yml index 270fe93070..987e5adc52 100644 --- a/ansible/playbooks/roles/download/tasks/list_files.yml +++ b/ansible/playbooks/roles/download/tasks/list_files.yml @@ -1,25 +1,9 @@ --- -- name: Get file listing - uri: - method: GET - url: "{{ repository_url }}/files/?F=0" # F=0 formats the listing as a simple list (not FancyIndexed) - body_format: raw - return_content: true - validate_certs: "{{ validate_certs | default(false, true) | bool }}" # handling "undefined", "null", "empty" and "boolean" values all at once - register: uri_list_files - until: uri_list_files is success - retries: 3 - delay: 2 - become: false +- name: Get files list from the repository + include_tasks: list_requirements.yml + vars: + _requirements: files -# TODO: make it work with yaml or json (instead of html, sic!). -- name: Parse html response and return file listing +- name: Set files in repository as fact set_fact: - list_files_result: >- - {{ lines | select('match', regexp) - | reject('match', '.*Parent Directory.*') - | map('regex_replace', regexp, '\1') - | list }} - vars: - lines: "{{ uri_list_files.content.splitlines() }}" - regexp: '.*