diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32c6311..a9ef17e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,35 +1,34 @@ --- repos: - repo: https://github.com/ansible-network/collection_prep rev: 1.1.1 hooks: - - id: autoversion - id: update-docs - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - id: check-merge-conflict - id: debug-statements - id: end-of-file-fixer - id: no-commit-to-branch - id: trailing-whitespace - repo: https://github.com/pre-commit/mirrors-prettier rev: "v3.0.3" hooks: - id: prettier additional_dependencies: - prettier - prettier-plugin-toml - repo: https://github.com/PyCQA/isort rev: 5.12.0 hooks: - id: isort args: ["--filter-files"] - repo: https://github.com/psf/black rev: 23.9.1 hooks: - id: black diff --git a/changelogs/fragments/integration_test_fix.yml b/changelogs/fragments/integration_test_fix.yml new file mode 100644 index 0000000..d792424 --- /dev/null +++ b/changelogs/fragments/integration_test_fix.yml @@ -0,0 +1,3 @@ +--- +trivial: + - vyos_prefix_lists - fix vyos_prefix_lists in integration tests to resolve issues related to deletion. diff --git a/tests/integration/targets/vyos_prefix_lists/tests/cli/deleted.yaml b/tests/integration/targets/vyos_prefix_lists/tests/cli/deleted.yaml index 9209fad..efcb14c 100644 --- a/tests/integration/targets/vyos_prefix_lists/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_prefix_lists/tests/cli/deleted.yaml @@ -1,108 +1,109 @@ --- - debug: msg: START vyos_prefix_lists deleted integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - include_tasks: _populate_config.yaml - block: # Delete all prefix-lists - name: Delete all prefix-lists + ignore_errors: true register: result vyos.vyos.vyos_prefix_lists: &id006 config: state: deleted - name: Assert that before dicts are correctly generated assert: that: - "{{ result['before'][0] == merged['after'][0] }}" - "{{ result['before'][1] == merged['after'][1] }}" - name: Assert that correct set of commands were generated assert: that: - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ \ == 0 }}" - name: Assert that after dict is correctly generated assert: that: - result["after"] == [] - name: Delete all prefix-lists (IDEMPOTENT) register: result vyos.vyos.vyos_prefix_lists: *id006 - name: Assert that task was idempotent assert: that: - result['changed'] == false - result.commands|length == 0 - include_tasks: _remove_config.yaml - include_tasks: _populate_config.yaml # Delete all prefix-lists for an AFI - name: Delete all prefix-lists for IPv6 AFI register: result vyos.vyos.vyos_prefix_lists: config: - afi: "ipv6" state: deleted - name: Assert that before dicts are correctly generated assert: that: - "{{ result['before'][0] == merged['after'][0] }}" - "{{ result['before'][1] == merged['after'][1] }}" - "{{ result['before']|length == 2 }}" - name: Assert that correct set of commands were generated assert: that: - '"delete policy prefix-list6 AllowIPv6Prefix" in result.commands' - '"delete policy prefix-list6 DenyIPv6Prefix" in result.commands' - result.commands|length == 2 - name: Assert that after dict is correctly generated assert: that: - result["after"][0] == merged["after"][0] - result["after"]|length == 1 - include_tasks: _remove_config.yaml - include_tasks: _populate_config.yaml # Delete single prefix-list from different AFIs - name: Delete a single prefix-list from different AFIs register: result vyos.vyos.vyos_prefix_lists: config: - afi: "ipv4" prefix_lists: - name: "AnsibleIPv4PrefixList" - afi: "ipv6" prefix_lists: - name: "DenyIPv6Prefix" state: deleted - name: Assert that before dicts are correctly generated assert: that: - "{{ result['before'][0] == merged['after'][0] }}" - "{{ result['before'][1] == merged['after'][1] }}" - "{{ result['before']|length == 2 }}" - name: Assert that correct set of commands were generated assert: that: - '"delete policy prefix-list AnsibleIPv4PrefixList" in result.commands' - '"delete policy prefix-list6 DenyIPv6Prefix" in result.commands' - result.commands|length == 2 always: - include_tasks: _remove_config.yaml diff --git a/tests/sanity/ignore-2.17.txt b/tests/sanity/ignore-2.17.txt new file mode 100644 index 0000000..c835eef --- /dev/null +++ b/tests/sanity/ignore-2.17.txt @@ -0,0 +1 @@ +plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/tests/unit/mock/loader.py b/tests/unit/mock/loader.py index 258dccd..2828f38 100644 --- a/tests/unit/mock/loader.py +++ b/tests/unit/mock/loader.py @@ -1,116 +1,116 @@ # (c) 2012-2014, Michael DeHaan # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . # Make coding more python3-ish from __future__ import absolute_import, division, print_function __metaclass__ = type import os from ansible.errors import AnsibleParserError from ansible.module_utils._text import to_bytes, to_text from ansible.parsing.dataloader import DataLoader class DictDataLoader(DataLoader): def __init__(self, file_mapping=None): file_mapping = {} if file_mapping is None else file_mapping - assert type(file_mapping) == dict + assert isinstance(file_mapping, dict) super(DictDataLoader, self).__init__() self._file_mapping = file_mapping self._build_known_directories() self._vault_secrets = None def load_from_file(self, path, cache=True, unsafe=False): path = to_text(path) if path in self._file_mapping: return self.load(self._file_mapping[path], path) return None # TODO: the real _get_file_contents returns a bytestring, so we actually convert the # unicode/text it's created with to utf-8 def _get_file_contents(self, file_name): path = to_text(file_name) if path in self._file_mapping: return (to_bytes(self._file_mapping[file_name]), False) else: raise AnsibleParserError("file not found: %s" % file_name) def path_exists(self, path): path = to_text(path) return path in self._file_mapping or path in self._known_directories def is_file(self, path): path = to_text(path) return path in self._file_mapping def is_directory(self, path): path = to_text(path) return path in self._known_directories def list_directory(self, path): ret = [] path = to_text(path) for x in list(self._file_mapping.keys()) + self._known_directories: if x.startswith(path): if os.path.dirname(x) == path: ret.append(os.path.basename(x)) return ret def is_executable(self, path): # FIXME: figure out a way to make paths return true for this return False def _add_known_directory(self, directory): if directory not in self._known_directories: self._known_directories.append(directory) def _build_known_directories(self): self._known_directories = [] for path in self._file_mapping: dirname = os.path.dirname(path) while dirname not in ("/", ""): self._add_known_directory(dirname) dirname = os.path.dirname(dirname) def push(self, path, content): rebuild_dirs = False if path not in self._file_mapping: rebuild_dirs = True self._file_mapping[path] = content if rebuild_dirs: self._build_known_directories() def pop(self, path): if path in self._file_mapping: del self._file_mapping[path] self._build_known_directories() def clear(self): self._file_mapping = dict() self._known_directories = [] def get_basedir(self): return os.getcwd() def set_vault_secrets(self, vault_secrets): self._vault_secrets = vault_secrets