* Bug in del(list) logic. Say you have a list of 4 elements a[0-3]
and you have to remove index 1 and 3, if you remove index 1 first
then list is cut short a[0-2] and does not have index 3
Fix: Remove indexes in reverse sorted order e.g. 3 and 1 in above
example so that order of indexes remain preserved even after deleting
fix is to remove indexes in reverse sorted order
* Add test cases for failed case
(cherry picked from commit 0bbea9a579
)
This commit is contained in:
parent
52c85f6c66
commit
3b0686ffe8
3 changed files with 21 additions and 1 deletions
|
@ -80,6 +80,8 @@ Ansible Changes By Release
|
|||
* Fix using ansible_*_interpreter on Python3 with non-new-style modules
|
||||
(old-style ansible python modules, modules written in another language, etc)
|
||||
https://github.com/ansible/ansible/pull/36541
|
||||
* Fix vyos_config IndexError in sanitize_config
|
||||
(https://github.com/ansible/ansible/issues/36351)
|
||||
|
||||
|
||||
<a id="2.4.3"></a
|
||||
|
|
|
@ -205,11 +205,15 @@ def diff_config(commands, config):
|
|||
|
||||
def sanitize_config(config, result):
|
||||
result['filtered'] = list()
|
||||
index_to_filter = list()
|
||||
for regex in CONFIG_FILTERS:
|
||||
for index, line in enumerate(list(config)):
|
||||
if regex.search(line):
|
||||
result['filtered'].append(line)
|
||||
del config[index]
|
||||
index_to_filter.append(index)
|
||||
# Delete all filtered configs
|
||||
for filter_index in sorted(index_to_filter, reverse=True):
|
||||
del config[filter_index]
|
||||
|
||||
|
||||
def run(module, result):
|
||||
|
|
|
@ -26,4 +26,18 @@
|
|||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: check multiple line config filter is working
|
||||
vyos_config:
|
||||
lines:
|
||||
- set system login user esa level admin
|
||||
- set system login user esa authentication encrypted-password '!abc!'
|
||||
- set system login user vyos level admin
|
||||
- set system login user vyos authentication encrypted-password 'abc'
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "{{ result.filtered|length }} == 2"
|
||||
|
||||
- debug: msg="END cli/config_check.yaml"
|
||||
|
|
Loading…
Reference in a new issue