Skip to content

Commit a0b5d2f

Browse files
committed
refactored merged and replaced. Added ignore_fields to process_deepdiff. moved templates into separate folders
1 parent c195787 commit a0b5d2f

20 files changed

+1369
-1171
lines changed

plugins/action/tests/integration/ndfc_network_validate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def run(self, tmp=None, task_vars=None):
8585
test_data = self._task.args.get('test_data', None)
8686
config_path = self._task.args.get('config_path', None)
8787
check_deleted = self._task.args.get('check_deleted', False)
88-
88+
ignore_fields = list(self._task.args.get('ignore_fields', []))
8989
for input_item in [ndfc_data, test_data, config_path]:
9090
if input_item is None:
9191
results['failed'] = True
@@ -108,7 +108,6 @@ def run(self, tmp=None, task_vars=None):
108108
if deleted_results := self.verify_deleted(results, check_deleted, expected_data_parsed, ndfc_data_parsed, config_path):
109109
return deleted_results
110110

111-
# normal checking when check_delete is false
112111
validity = DeepDiff(
113112
expected_data_parsed,
114113
ndfc_data_parsed,
@@ -121,7 +120,8 @@ def run(self, tmp=None, task_vars=None):
121120
# Effects the iterable_item_added and iterable_item_removed to remove unneeded fields
122121
# ignore_extra_fields=True will ignore dictionary_item_added changes
123122
# This is useful when the the actual data has more fields than the expected data
124-
processed_validity = process_deepdiff(validity, ignore_extra_fields=True)
123+
# keys_to_ignore is a list of fields to ignore, useful for auto provisioned fields which are not known
124+
processed_validity = process_deepdiff(validity, keys_to_ignore=ignore_fields, ignore_extra_fields=True)
125125
if processed_validity == {}:
126126
results['failed'] = False
127127
results['msg'] = f'Data is valid. \n\n Expected data: \n\n{expected_data}\n\nActual data: \n\n{ndfc_data_parsed}'

plugins/action/tests/plugin_utils/pydantic_schemas/dcnm_network/schemas.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class NetworkTemplateConfig(BaseModel):
7070
mtu: Optional[CoercedStr] = ""
7171
vlanName: Optional[str] = None
7272
intfDescription: Optional[str] = None
73+
tag: Optional[CoercedStr] = None
7374

7475
class Parent(BaseModel):
7576
fabric: Optional[str] = None
@@ -158,6 +159,8 @@ def yaml_config_to_dict(cls, expected_config_data, test_fabric):
158159
network_dict["parent"]["networkTemplateConfig"]["vlanName"] = network['vlan_name']
159160
if 'int_desc' in network:
160161
network_dict["parent"]["networkTemplateConfig"]["intfDescription"] = network['int_desc']
162+
if 'routing_tag' in network:
163+
network_dict["parent"]["networkTemplateConfig"]["tag"] = network['routing_tag']
161164
if 'vrf_name' in network:
162165
network_dict["parent"]["vrf"] = network['vrf_name']
163166
# if deploy:

plugins/action/tests/plugin_utils/tools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def load_yaml_file(file_path):
1818
raise ValueError(f"Error parsing YAML file '{file_path}': {e}") from e
1919

2020

21-
def process_deepdiff(deepdiff_output, ignore_extra_fields=False):
21+
def process_deepdiff(deepdiff_output, keys_to_ignore, ignore_extra_fields=False):
2222
"""
2323
Process deepdiff output to extract paths ignoring indices and find differences.
2424
Returns a dictionary with the same structure as deepdiff output but with
@@ -135,6 +135,12 @@ def extract_values(data, current_path="", values=None):
135135
for path in paths_to_remove:
136136
del diff_paths['added_values'][path]
137137

138+
diff_paths_keys = list(diff_paths['added_values'].keys())
139+
for path in diff_paths_keys:
140+
for field in keys_to_ignore:
141+
if field in path:
142+
del diff_paths['added_values'][path]
143+
138144
# Remove added_values if it becomes empty after filtering
139145
if not diff_paths['added_values']:
140146
del diff_paths['added_values']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
# This NDFC test data structure is auto-generated
3+
# DO NOT EDIT MANUALLY
4+
#
5+
6+
7+
# ------------------------------
8+
# Network 1
9+
# ------------------------------
10+
- net_name: "{{ test_data_common.net1 }}"
11+
vrf_name: "{{ test_data_common.net1_vrf }}"
12+
net_id: "{{ test_data_common.net1_net_id }}"
13+
net_template: "{{ test_data_common.net1_default_net_template }}"
14+
net_extension_template: "{{ test_data_common.net1_net_extension_template }}"
15+
gw_ip_subnet: "{{ test_data_common.net1_gw_ip_subnet }}"
16+
attach:
17+
- ip_address: "{{ test_data_common.sw1 }}"
18+
ports: ["{{ test_data_common.sw1_int1 }}", "{{ test_data_common.sw1_int2 }}"]
19+
deploy: {{ test_data_common.deploy | bool }}
20+
21+
# ------------------------------
22+
# Network 2
23+
# ------------------------------
24+
- net_name: "{{ test_data_common.net2 }}"
25+
vrf_name: "{{ test_data_common.net2_vrf }}"
26+
net_id: "{{ test_data_common.net2_net_id }}"
27+
net_template: "{{ test_data_common.net2_default_net_template }}"
28+
net_extension_template: "{{ test_data_common.net2_net_extension_template }}"
29+
vlan_id: "{{ test_data_common.net2_vlan_id }}"
30+
gw_ip_subnet: "{{ test_data_common.net2_gw_ip_subnet }}"
31+
attach:
32+
- ip_address: "{{ test_data_common.sw2 }}"
33+
ports: ["{{ test_data_common.sw2_int3 }}", "{{ test_data_common.sw2_int4 }}"]
34+
deploy: {{ test_data_common.deploy | bool }}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
# This NDFC test data structure is auto-generated
3+
# DO NOT EDIT MANUALLY
4+
#
5+
6+
7+
# ------------------------------
8+
# Network 1
9+
# ------------------------------
10+
- net_name: "{{ test_data_common.net1 }}"
11+
vrf_name: "{{ test_data_common.net1_vrf }}"
12+
net_id: "{{ test_data_common.net1_net_id }}"
13+
net_template: "{{ test_data_common.net1_default_net_template }}"
14+
net_extension_template: "{{ test_data_common.net1_net_extension_template }}"
15+
vlan_id: "{{ test_data_common.net1_vlan_id }}"
16+
gw_ip_subnet: "{{ test_data_common.net1_gw_ip_subnet }}"
17+
attach:
18+
- ip_address: "{{ test_data_common.sw1 }}"
19+
ports: ["{{ test_data_common.sw1_int1 }}", "{{ test_data_common.sw1_int2 }}"]
20+
deploy: {{ test_data_common.deploy | bool }}
21+
22+
# ------------------------------
23+
# Network 2
24+
# ------------------------------
25+
- net_name: "{{ test_data_common.net2 }}"
26+
vrf_name: "{{ test_data_common.net2_vrf }}"
27+
net_id: "{{ test_data_common.net2_net_id }}"
28+
net_template: "{{ test_data_common.net2_default_net_template }}"
29+
net_extension_template: "{{ test_data_common.net2_net_extension_template }}"
30+
vlan_id: "{{ test_data_common.net2_vlan_id }}"
31+
gw_ip_subnet: "{{ test_data_common.net2_gw_ip_subnet }}"
32+
attach:
33+
- ip_address: "{{ test_data_common.sw2 }}"
34+
ports: ["{{ test_data_common.sw2_int3 }}", "{{ test_data_common.sw2_int4 }}"]
35+
deploy: {{ test_data_common.deploy | bool }}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ------------------------------
2+
# Network 1
3+
# ------------------------------
4+
- net_name: "{{ test_data_common.net1 }}"
5+
net_id: "{{ test_data_common.net1_net_id }}"
6+
net_template: "{{ test_data_common.net1_default_net_template }}"
7+
net_extension_template: "{{ test_data_common.net1_net_extension_template }}"
8+
vlan_id: "{{ test_data_common.net1_vlan_id }}"
9+
gw_ip_subnet: "{{ test_data_common.net1_gw_ip_subnet }}"
10+
mtu_l3intf: 7600
11+
arp_suppress: False
12+
# Leave 'arp_suppress' this false to avoid TCAM issue
13+
# Please configure TCAM region for Ingress ARP-Ether ACL before configuring ARP supression
14+
int_desc: 'test interface'
15+
is_l2only: True
16+
vlan_name: testvlan
17+
dhcp_srvr1_ip: '1.1.1.1'
18+
dhcp_srvr2_ip: '2.2.2.2'
19+
dhcp_srvr3_ip: '3.3.3.3'
20+
dhcp_srvr1_vrf: one
21+
dhcp_srvr2_vrf: two
22+
dhcp_srvr3_vrf: three
23+
attach:
24+
- ip_address: "{{ test_data_common.sw1 }}"
25+
ports: ["{{ test_data_common.sw1_int1 }}", "{{ test_data_common.sw1_int2 }}"]
26+
deploy: {{ test_data_common.deploy | bool }}
27+
28+
# ------------------------------
29+
# Network 2
30+
# ------------------------------
31+
- net_name: "{{ test_data_common.net2 }}"
32+
vrf_name: "{{ test_data_common.net2_vrf }}"
33+
net_id: "{{ test_data_common.net2_net_id }}"
34+
net_template: "{{ test_data_common.net2_default_net_template }}"
35+
net_extension_template: "{{ test_data_common.net2_net_extension_template }}"
36+
vlan_id: "{{ test_data_common.net2_vlan_id }}"
37+
gw_ip_subnet: "{{ test_data_common.net2_gw_ip_subnet }}"
38+
mtu_l3intf: 7600
39+
# Leave 'arp_suppress' this false to avoid TCAM issue
40+
# Please configure TCAM region for Ingress ARP-Ether ACL before configuring ARP supression
41+
arp_suppress: False
42+
int_desc: 'test interface 1'
43+
vlan_name: testvlan1
44+
dhcp_srvr1_ip: '1.1.1.1'
45+
dhcp_srvr2_ip: '2.2.2.2'
46+
dhcp_srvr3_ip: '3.3.3.3'
47+
dhcp_srvr1_vrf: one
48+
dhcp_srvr2_vrf: two
49+
dhcp_srvr3_vrf: three
50+
attach:
51+
- ip_address: "{{ test_data_common.sw2 }}"
52+
ports: ["{{ test_data_common.sw2_int3 }}", "{{ test_data_common.sw2_int4 }}"]
53+
deploy: {{ test_data_common.deploy | bool }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
# This NDFC test data structure is auto-generated
3+
# DO NOT EDIT MANUALLY
4+
#
5+
6+
7+
# ------------------------------
8+
# L2 only Network 1
9+
# ------------------------------
10+
- net_name: "{{ test_data_common.net1 }}"
11+
net_id: "{{ test_data_common.net1_net_id }}"
12+
net_template: "{{ test_data_common.net1_default_net_template }}"
13+
net_extension_template: "{{ test_data_common.net1_net_extension_template }}"
14+
vlan_id: "{{ test_data_common.net1_vlan_id }}"
15+
gw_ip_subnet: "{{ test_data_common.net1_gw_ip_subnet }}"
16+
mtu_l3intf: 7600
17+
arp_suppress: True
18+
int_desc: 'test interface'
19+
is_l2only: True
20+
vlan_name: testvlan
21+
dhcp_srvr1_ip: '1.1.1.1'
22+
dhcp_srvr2_ip: '2.2.2.2'
23+
dhcp_srvr3_ip: '3.3.3.3'
24+
dhcp_srvr1_vrf: one
25+
dhcp_srvr2_vrf: two
26+
dhcp_srvr3_vrf: three
27+
attach:
28+
- ip_address: "{{ test_data_common.sw1 }}"
29+
ports: ["{{ test_data_common.sw1_int1 }}", "{{ test_data_common.sw1_int2 }}"]
30+
deploy: {{ test_data_common.deploy | bool }}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# This NDFC test data structure is auto-generated
3+
# DO NOT EDIT MANUALLY
4+
#
5+
6+
7+
# ------------------------------
8+
# Network 1
9+
# ------------------------------
10+
- net_name: "{{ test_data_common.net1 }}"
11+
net_id: "{{ test_data_common.net1_net_id }}"
12+
vrf_name: "{{ test_data_common.net1_vrf }}"
13+
net_template: "{{ test_data_common.net1_default_net_template }}"
14+
net_extension_template: "{{ test_data_common.net1_net_extension_template }}"
15+
vlan_id: "{{ test_data_common.net1_vlan_id }}"
16+
gw_ip_subnet: "{{ test_data_common.net1_gw_ip_subnet }}"
17+
int_desc: 'test interface'
18+
vlan_name: testvlan
19+
dhcp_srvr1_ip: '1.1.1.1'
20+
dhcp_srvr2_ip: '2.2.2.2'
21+
dhcp_srvr3_ip: '3.3.3.3'
22+
dhcp_srvr1_vrf: one
23+
dhcp_srvr2_vrf: two
24+
dhcp_srvr3_vrf: three
25+
deploy: {{ test_data_common.deploy | bool }}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
# This NDFC test data structure is auto-generated
3+
# DO NOT EDIT MANUALLY
4+
#
5+
6+
7+
# ------------------------------
8+
# Network 1
9+
# ------------------------------
10+
- net_name: "{{ test_data_common.net1 }}"
11+
net_id: "{{ test_data_common.net1_net_id }}"
12+
vrf_name: "{{ test_data_common.net1_vrf }}"
13+
net_template: "{{ test_data_common.net1_default_net_template }}"
14+
net_extension_template: "{{ test_data_common.net1_net_extension_template }}"
15+
vlan_id: "{{ test_data_common.net1_vlan_id }}"
16+
gw_ip_subnet: "{{ test_data_common.net1_gw_ip_subnet }}"
17+
int_desc: 'test interface'
18+
vlan_name: testvlan
19+
dhcp_srvr1_ip: '1.1.1.1'
20+
dhcp_srvr2_ip: '2.2.2.2'
21+
dhcp_srvr3_ip: '3.3.3.3'
22+
dhcp_srvr1_vrf: one
23+
dhcp_srvr2_vrf: two
24+
dhcp_srvr3_vrf: three
25+
attach:
26+
- ip_address: "{{ test_data_common.sw1 }}"
27+
ports: ["{{ test_data_common.sw1_int1 }}", "{{ test_data_common.sw1_int2 }}"]
28+
deploy: {{ test_data_common.deploy | bool }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# This NDFC test data structure is auto-generated
3+
# DO NOT EDIT MANUALLY
4+
#
5+
6+
7+
# ------------------------------
8+
# L2 only Network 1
9+
# ------------------------------
10+
- net_name: "{{ test_data_common.net1 }}"
11+
vrf_name: "{{ test_data_common.net1_vrf }}"
12+
attach:
13+
- ip_address: "{{ test_data_common.sw1 }}"
14+
ports: ["{{ test_data_common.sw1_int1 }}", "{{ test_data_common.sw1_int2 }}"]
15+
deploy: {{ test_data_common.deploy | bool }}

0 commit comments

Comments
 (0)