From 234b50384269647e52fc531e6f71426a647ffacf Mon Sep 17 00:00:00 2001 From: KB-perByte Date: Tue, 5 Apr 2022 13:47:16 +0530 Subject: [PATCH] update intg tests and changelog --- .../fragments/consolidate_filter_plugin.yml | 5 + .../targets/utils_consolidate/tasks/main.yaml | 14 ++ .../utils_consolidate/tasks/simple.yaml | 134 ++++++++++++++++++ .../targets/utils_consolidate/vars/main.yaml | 109 ++++++++++++++ 4 files changed, 262 insertions(+) create mode 100644 changelogs/fragments/consolidate_filter_plugin.yml create mode 100644 tests/integration/targets/utils_consolidate/tasks/main.yaml create mode 100644 tests/integration/targets/utils_consolidate/tasks/simple.yaml create mode 100644 tests/integration/targets/utils_consolidate/vars/main.yaml diff --git a/changelogs/fragments/consolidate_filter_plugin.yml b/changelogs/fragments/consolidate_filter_plugin.yml new file mode 100644 index 0000000..e745cda --- /dev/null +++ b/changelogs/fragments/consolidate_filter_plugin.yml @@ -0,0 +1,5 @@ +--- +minor_changes: + - "'consolidate' filter plugin added." +trivial: + - Fix sanity issues and update black vesion. diff --git a/tests/integration/targets/utils_consolidate/tasks/main.yaml b/tests/integration/targets/utils_consolidate/tasks/main.yaml new file mode 100644 index 0000000..eb1a94b --- /dev/null +++ b/tests/integration/targets/utils_consolidate/tasks/main.yaml @@ -0,0 +1,14 @@ +--- +- name: Recursively find all test files + find: + file_type: file + paths: "{{ role_path }}/tasks" + recurse: false + use_regex: true + patterns: + - '^(?!_|main).+$' + delegate_to: localhost + register: found + +- include: "{{ item.path }}" + loop: "{{ found.files }}" diff --git a/tests/integration/targets/utils_consolidate/tasks/simple.yaml b/tests/integration/targets/utils_consolidate/tasks/simple.yaml new file mode 100644 index 0000000..150a422 --- /dev/null +++ b/tests/integration/targets/utils_consolidate/tasks/simple.yaml @@ -0,0 +1,134 @@ +--- +- name: Build the data structure + ansible.builtin.set_fact: + data_source: + - data: + [ + { "name": "Loopback888" }, + { "name": "Loopback999" }, + { "name": "GigabitEthernet0/0" }, + { "name": "GigabitEthernet0/1" }, + { "name": "GigabitEthernet0/2" }, + ] + match_key: name + prefix: acl_interfaces + - data: + [ + { + "description": "Configured by Ansible Team", + "enabled": False, + "name": "Loopback888", + }, + { + "description": "Configured by Ansible Team", + "enabled": False, + "name": "Loopback888", + }, + { "enabled": True, "name": "Loopback999" }, + { + "description": "Configured and Managed By Ansible Team", + "enabled": True, + "name": "GigabitEthernet0/0", + }, + { + "description": "This is a user template", + "enabled": True, + "name": "GigabitEthernet0/1", + }, + { + "description": "This is a user template", + "enabled": True, + "name": "GigabitEthernet0/2", + }, + ] + match_key: name + prefix: interfaces + - data: + [ + { "name": "GigabitEthernet0/0" }, + { + "mode": "access", + "name": "GigabitEthernet0/1", + "trunk": + { + "allowed_vlans": + [ + "11", + "12", + "59", + "67", + "75", + "77", + "81", + "100", + "400-408", + "411-413", + "415", + "418", + "982", + "986", + "988", + "993", + ], + }, + }, + { + "mode": "trunk", + "name": "GigabitEthernet0/2", + "trunk": + { + "allowed_vlans": + [ + "11", + "12", + "59", + "67", + "75", + "77", + "81", + "100", + "400-408", + "411-413", + "415", + "418", + "982", + "986", + "988", + "993", + ], + "encapsulation": "dot1q", + }, + }, + ] + match_key: name + prefix: l2_interfaces + - data: + [ + { + "ipv4": [{ "address": "192.168.0.76/24" }], + "name": "GigabitEthernet0/0", + }, + { "name": "GigabitEthernet0/1" }, + { "name": "GigabitEthernet0/2" }, + { "name": "Loopback888" }, + { "name": "Loopback999" }, + ] + match_key: name + prefix: l3_interfaces + - data: + [ + { "no_name": True }, + { "name": "GigabitEthernet0/1" }, + { "name": "GigabitEthernet100/100" }, + ] + match_key: name + prefix: ospf_interfaces + +- name: Combine all the dictionaries based on match_keys + set_fact: + combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_value=False) }}" + +- name: Assert result dicts + assert: + that: + - combined == combined_facts diff --git a/tests/integration/targets/utils_consolidate/vars/main.yaml b/tests/integration/targets/utils_consolidate/vars/main.yaml new file mode 100644 index 0000000..239ab4d --- /dev/null +++ b/tests/integration/targets/utils_consolidate/vars/main.yaml @@ -0,0 +1,109 @@ +--- +combined_facts: + GigabitEthernet0/0: + acl_interfaces: + name: GigabitEthernet0/0 + interfaces: + description: Configured and Managed By Ansible Team + enabled: true + name: GigabitEthernet0/0 + l2_interfaces: + name: GigabitEthernet0/0 + l3_interfaces: + ipv4: + - address: 10.8.38.76/24 + name: GigabitEthernet0/0 + ospf_interfaces: {} + GigabitEthernet0/1: + acl_interfaces: + name: GigabitEthernet0/1 + interfaces: + description: This is a user template + enabled: true + name: GigabitEthernet0/1 + l2_interfaces: + mode: access + name: GigabitEthernet0/1 + trunk: + allowed_vlans: + - '11' + - '12' + - '59' + - '67' + - '75' + - '77' + - '81' + - '100' + - 400-408 + - 411-413 + - '415' + - '418' + - '982' + - '986' + - '988' + - '993' + l3_interfaces: + name: GigabitEthernet0/1 + ospf_interfaces: + name: GigabitEthernet0/1 + GigabitEthernet0/2: + acl_interfaces: + name: GigabitEthernet0/2 + interfaces: + description: This is a user template + enabled: true + name: GigabitEthernet0/2 + l2_interfaces: + mode: trunk + name: GigabitEthernet0/2 + trunk: + allowed_vlans: + - '11' + - '12' + - '59' + - '67' + - '75' + - '77' + - '81' + - '100' + - 400-408 + - 411-413 + - '415' + - '418' + - '982' + - '986' + - '988' + - '993' + encapsulation: dot1q + l3_interfaces: + name: GigabitEthernet0/2 + ospf_interfaces: {} + GigabitEthernet100/100: + acl_interfaces: {} + interfaces: {} + l2_interfaces: {} + l3_interfaces: {} + ospf_interfaces: + name: GigabitEthernet100/100 + Loopback888: + acl_interfaces: + name: Loopback888 + interfaces: + description: Configured by Ansible Team + enabled: false + name: Loopback888 + l2_interfaces: {} + l3_interfaces: + name: Loopback888 + ospf_interfaces: {} + Loopback999: + acl_interfaces: + name: Loopback999 + interfaces: + enabled: true + name: Loopback999 + l2_interfaces: {} + l3_interfaces: + name: Loopback999 + ospf_interfaces: {} +