Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(eos_config_deploy_cvp): device_filter is not behaving correctly if input is a string #3046

Merged
merged 5 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,24 @@
execute_tasks: false
state: present
cv_collection: v3

- name: "Converge -- Build Cloudvision Configuration - empty filter as a string"
hosts: CVP
gather_facts: false
connection: local
vars:
root_dir: '{{ playbook_dir }}'
tasks:
- name: Run CVP provisioning
# tags: generate
ansible.builtin.import_role:
name: arista.avd.eos_config_deploy_cvp
vars:
container_root: 'DC1_FABRIC'
configlets_prefix: 'AVD'
device_filter: ''
execute_tasks: false
state: absent
cv_collection: v3
# overwriting the default structured_cvp_dir_name to get different files
structured_cvp_dir_name: cvp-empty-filter
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
cvp_devices:
- fqdn: DC1-BL1A
parentContainerName: DC1_BL1
configlets:
- AVD_DC1-BL1A
- fqdn: DC1-BL1B
parentContainerName: DC1_BL1
configlets:
- AVD_DC1-BL1B
- fqdn: DC1-L2LEAF1A
parentContainerName: DC1_L2LEAF1
configlets:
- AVD_DC1-L2LEAF1A
- fqdn: DC1-L2LEAF2A
parentContainerName: DC1_L2LEAF2
configlets:
- AVD_DC1-L2LEAF2A
- fqdn: DC1-L2LEAF2B
parentContainerName: DC1_L2LEAF2
configlets:
- AVD_DC1-L2LEAF2B
- fqdn: DC1-LEAF1A
parentContainerName: DC1_LEAF1
configlets:
- AVD_DC1-LEAF1A
- fqdn: DC1-LEAF2A
parentContainerName: DC1_LEAF2
configlets:
- AVD_DC1-LEAF2A
- fqdn: DC1-LEAF2B
parentContainerName: DC1_LEAF2
configlets:
- AVD_DC1-LEAF2B
- fqdn: DC1-SPINE1
parentContainerName: DC1_SPINES
configlets:
- AVD_DC1-SPINE1
- fqdn: DC1-SPINE2
parentContainerName: DC1_SPINES
configlets:
- AVD_DC1-SPINE2
- fqdn: DC1-SPINE3
parentContainerName: DC1_SPINES
configlets:
- AVD_DC1-SPINE3
- fqdn: DC1-SPINE4
parentContainerName: DC1_SPINES
configlets:
- AVD_DC1-SPINE4
cvp_containers:
DC1_BL1:
parentContainerName: DC1_LEAFS
DC1_FABRIC:
parentContainerName: Tenant
DC1_L2LEAF1:
parentContainerName: DC1_L2LEAFS
DC1_L2LEAF2:
parentContainerName: DC1_L2LEAFS
DC1_L2LEAFS:
parentContainerName: DC1_FABRIC
DC1_LEAF1:
parentContainerName: DC1_LEAFS
DC1_LEAF2:
parentContainerName: DC1_LEAFS
DC1_LEAFS:
parentContainerName: DC1_FABRIC
DC1_SPINES:
parentContainerName: DC1_FABRIC
DC1_SVC3:
parentContainerName: DC1_LEAFS

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@
from ansible.inventory.manager import InventoryManager
from ansible.parsing.yaml.dumper import AnsibleDumper
from ansible.plugins.action import ActionBase
from ansible.utils.display import Display

# Root container on CloudVision.
# Shall not be changed unless CloudVision changes it in the core.
CVP_ROOT_CONTAINER = "Tenant"

display = Display()


class ActionModule(ActionBase):
def _maybe_convert_device_filter(self):
# Converting string device filter to list
device_filter = self._task.args.get("device_filter")
if device_filter is not None and not isinstance(device_filter, list):
display.debug(f"device_filter must be of type list, got '{device_filter}' of type {type(device_filter)} instead. Converting...")
self._task.args["device_filter"] = [device_filter]

def run(self, tmp=None, task_vars=None):
if task_vars is None:
task_vars = {}

self._maybe_convert_device_filter()

module_args = self._task.args.copy()

# Run regular module
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
- name: Test with device_filter as a string
register: cvp_vars
inventory_to_container:
inventory: '{{ inventory_path }}/inventory.yml'
container_root: 'DC1_FABRIC'
configlet_dir: '{{ configlet_path }}'
configlet_prefix: 'AVD'
device_filter: 'DC1-LE'
destination: "{{ actual_output }}"

- name: Compare actual output with expected output
ansible.builtin.shell: diff "{{ expected_output }}/expected_with_device_filter_as_string.yml" "{{ actual_output }}"
failed_when: "diff_output.rc > 1"
register: diff_output
delegate_to: localhost

- name: Validate output
assert:
that:
- cvp_vars is success
- cvp_vars.cvp_topology != {}
- cvp_vars.cvp_configlets != {}
- item is defined
- "'AVD_DC1-LE' in item[0:10]"
- diff_output.stdout == ""
with_items: "{{ cvp_vars.cvp_configlets }}"

- name: Validate cvp_topology
assert:
that:
- item is defined
- item == "Tenant"
with_items: "{{ cvp_vars.cvp_topology.DC1_FABRIC.parent_container }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
- name: Test with device_filter as empty string
register: cvp_vars
inventory_to_container:
inventory: '{{ inventory_path }}/inventory.yml'
container_root: 'DC1_FABRIC'
configlet_dir: '{{ configlet_path }}'
configlet_prefix: 'AVD'
device_filter: ""
destination: "{{ actual_output }}"

- name: Compare actual output with expected output
ansible.builtin.shell: diff "{{ expected_output }}/expected_with_device_filter_empty_string.yml" "{{ actual_output }}"
failed_when: "diff_output.rc > 1"
register: diff_output
delegate_to: localhost

- name: Validate output
assert:
that:
- cvp_vars is success
- cvp_vars.cvp_topology != {}
- cvp_vars.cvp_configlets != {}
- item is defined
- "'AVD' in item[0:3]"
- diff_output.stdout == ""
with_items: "{{ cvp_vars.cvp_configlets }}"

- name: Validate cvp_topology
assert:
that:
- item is defined
- item == "Tenant"
with_items: "{{ cvp_vars.cvp_topology.DC1_FABRIC.parent_container }}"
Loading