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

Add UTs for BFD, COPP, and MAC modules #287

Merged
merged 5 commits into from
Dec 18, 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
2 changes: 2 additions & 0 deletions changelogs/fragments/287-add-uts-for-bfd-copp-mac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- tests - Add UTs for BFD, COPP, and MAC modules (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/287).
71 changes: 37 additions & 34 deletions plugins/module_utils/network/sonic/config/copp/copp.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,31 +328,32 @@ def get_delete_copp_requests(self, commands, have, is_delete_all):
cir = group.get('cir', None)
cbs = group.get('cbs', None)

cfg_copp_groups = have.get('copp_groups', None)
if cfg_copp_groups:
for cfg_group in cfg_copp_groups:
cfg_copp_name = cfg_group.get('copp_name', None)
cfg_trap_priority = cfg_group.get('trap_priority', None)
cfg_trap_action = cfg_group.get('trap_action', None)
cfg_queue = cfg_group.get('queue', None)
cfg_cir = cfg_group.get('cir', None)
cfg_cbs = cfg_group.get('cbs', None)

if copp_name == cfg_copp_name:
if trap_priority and trap_priority == cfg_trap_priority:
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'trap-priority'))
if trap_action and trap_action == cfg_trap_action:
err_msg = "Deletion of trap-action attribute is not supported."
self._module.fail_json(msg=err_msg, code=405)
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'trap-action'))
if queue and queue == cfg_queue:
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'queue'))
if cir and cir == cfg_cir:
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'cir'))
if cbs and cbs == cfg_cbs:
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'cbs'))
if not trap_priority and not trap_action and not queue and not cir and not cbs:
requests.append(self.get_delete_single_copp_group_request(copp_name))
if have:
kerry-meyer marked this conversation as resolved.
Show resolved Hide resolved
cfg_copp_groups = have.get('copp_groups', None)
if cfg_copp_groups:
for cfg_group in cfg_copp_groups:
cfg_copp_name = cfg_group.get('copp_name', None)
cfg_trap_priority = cfg_group.get('trap_priority', None)
cfg_trap_action = cfg_group.get('trap_action', None)
cfg_queue = cfg_group.get('queue', None)
cfg_cir = cfg_group.get('cir', None)
cfg_cbs = cfg_group.get('cbs', None)

if copp_name == cfg_copp_name:
if trap_priority and trap_priority == cfg_trap_priority:
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'trap-priority'))
if trap_action and trap_action == cfg_trap_action:
err_msg = "Deletion of trap-action attribute is not supported."
self._module.fail_json(msg=err_msg, code=405)
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'trap-action'))
if queue and queue == cfg_queue:
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'queue'))
if cir and cir == cfg_cir:
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'cir'))
if cbs and cbs == cfg_cbs:
requests.append(self.get_delete_copp_groups_attr_request(copp_name, 'cbs'))
if not trap_priority and not trap_action and not queue and not cir and not cbs:
requests.append(self.get_delete_single_copp_group_request(copp_name))

return requests

Expand All @@ -370,15 +371,17 @@ def get_delete_single_copp_group_request(self, copp_name):

def filter_copp_groups(self, commands):
cfg_dict = {}
copp_groups = commands.get('copp_groups', None)
if copp_groups:
copp_groups_list = []
for group in copp_groups:
copp_name = group.get('copp_name', None)
if copp_name not in reserved_copp_names:
copp_groups_list.append(group)
if copp_groups_list:
cfg_dict['copp_groups'] = copp_groups_list

if commands:
copp_groups = commands.get('copp_groups', None)
if copp_groups:
copp_groups_list = []
for group in copp_groups:
copp_name = group.get('copp_name', None)
if copp_name not in reserved_copp_names:
copp_groups_list.append(group)
if copp_groups_list:
cfg_dict['copp_groups'] = copp_groups_list

return cfg_dict

Expand Down
56 changes: 29 additions & 27 deletions plugins/module_utils/network/sonic/config/mac/mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,38 +317,40 @@ def get_delete_mac_requests(self, commands, have, is_delete_all):
dampening_interval = mac.get('dampening_interval', None)
dampening_threshold = mac.get('dampening_threshold', None)
mac_table_entries = mac.get('mac_table_entries', [])
if mac_table_entries:
for entry in mac_table_entries:
mac_address = entry.get('mac_address', None)
vlan_id = entry.get('vlan_id', None)
interface = entry.get('interface', None)

for cfg in have:
cfg_vrf_name = cfg.get('vrf_name', None)
cfg_mac = cfg.get('mac', {})
if cfg_mac:
cfg_aging_time = cfg_mac.get('aging_time', None)
cfg_dampening_interval = cfg_mac.get('dampening_interval', None)
cfg_dampening_threshold = cfg_mac.get('dampening_threshold', None)
cfg_mac_table_entries = cfg_mac.get('mac_table_entries', [])
if cfg_mac_table_entries:
for cfg_entry in cfg_mac_table_entries:
cfg_mac_address = cfg_entry.get('mac_address', None)
cfg_vlan_id = cfg_entry.get('vlan_id', None)
cfg_interface = cfg_entry.get('interface', None)
if vrf_name and vrf_name == cfg_vrf_name:
if aging_time and aging_time == cfg_aging_time:
requests.append(self.get_delete_fdb_cfg_attr(vrf_name, 'mac-aging-time'))
if dampening_interval and dampening_interval == cfg_dampening_interval:
requests.append(self.get_delete_mac_dampening_attr(vrf_name, 'interval'))
if dampening_threshold and dampening_threshold == cfg_dampening_threshold:
requests.append(self.get_delete_mac_dampening_attr(vrf_name, 'threshold'))

for cfg in have:
kerry-meyer marked this conversation as resolved.
Show resolved Hide resolved
cfg_vrf_name = cfg.get('vrf_name', None)
cfg_mac = cfg.get('mac', {})
if cfg_mac:
cfg_aging_time = cfg_mac.get('aging_time', None)
cfg_dampening_interval = cfg_mac.get('dampening_interval', None)
cfg_dampening_threshold = cfg_mac.get('dampening_threshold', None)
cfg_mac_table_entries = cfg_mac.get('mac_table_entries', [])

if vrf_name and vrf_name == cfg_vrf_name:
if aging_time and aging_time == cfg_aging_time:
requests.append(self.get_delete_fdb_cfg_attr(vrf_name, 'mac-aging-time'))
if dampening_interval and dampening_interval == cfg_dampening_interval:
requests.append(self.get_delete_mac_dampening_attr(vrf_name, 'interval'))
if dampening_threshold and dampening_threshold == cfg_dampening_threshold:
requests.append(self.get_delete_mac_dampening_attr(vrf_name, 'threshold'))

if mac_table_entries:
for entry in mac_table_entries:
mac_address = entry.get('mac_address', None)
vlan_id = entry.get('vlan_id', None)
interface = entry.get('interface', None)

if cfg_mac_table_entries:
for cfg_entry in cfg_mac_table_entries:
cfg_mac_address = cfg_entry.get('mac_address', None)
cfg_vlan_id = cfg_entry.get('vlan_id', None)
cfg_interface = cfg_entry.get('interface', None)
if mac_address and vlan_id and mac_address == cfg_mac_address and vlan_id == cfg_vlan_id:
if interface and interface == cfg_interface:
requests.append(self.get_delete_mac_table_intf(vrf_name, mac_address, vlan_id))
elif not interface:
requests.append(self.get_delete_mac_table_entry(vrf_name, mac_address, vlan_id))

return requests

def get_delete_all_mac_requests(self, vrf_name):
Expand Down
1 change: 0 additions & 1 deletion plugins/module_utils/network/sonic/facts/bfd/bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,4 @@ def get_bfd_config(self, module):
bfd_cfg = response[0][1].get('openconfig-bfd:bfd', None)
except ConnectionError as exc:
module.fail_json(msg=str(exc), code=exc.code)

return bfd_cfg
62 changes: 31 additions & 31 deletions plugins/module_utils/network/sonic/facts/copp/copp.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,37 @@ def render_config(self, spec, conf):
def update_copp_groups(self, data):
config_dict = {}
all_copp_groups = []
copp_groups = data.get('copp-groups', None)
if copp_groups:
copp_group_list = copp_groups.get('copp-group', None)
if copp_group_list:
for group in copp_group_list:
group_dict = {}
copp_name = group['name']
config = group['config']
trap_priority = config.get('trap-priority', None)
trap_action = config.get('trap-action', None)
queue = config.get('queue', None)
cir = config.get('cir', None)
cbs = config.get('cbs', None)

if copp_name:
group_dict['copp_name'] = copp_name
if trap_priority:
group_dict['trap_priority'] = trap_priority
if trap_action:
group_dict['trap_action'] = trap_action
if queue:
group_dict['queue'] = queue
if cir:
group_dict['cir'] = cir
if cbs:
group_dict['cbs'] = cbs
if group_dict:
all_copp_groups.append(group_dict)

config_dict['copp_groups'] = all_copp_groups
if data:
copp_groups = data.get('copp-groups', None)
if copp_groups:
copp_group_list = copp_groups.get('copp-group', None)
if copp_group_list:
for group in copp_group_list:
group_dict = {}
copp_name = group['name']
config = group['config']
trap_priority = config.get('trap-priority', None)
trap_action = config.get('trap-action', None)
queue = config.get('queue', None)
cir = config.get('cir', None)
cbs = config.get('cbs', None)

if copp_name:
group_dict['copp_name'] = copp_name
if trap_priority:
group_dict['trap_priority'] = trap_priority
if trap_action:
group_dict['trap_action'] = trap_action
if queue:
group_dict['queue'] = queue
if cir:
group_dict['cir'] = cir
if cbs:
group_dict['cbs'] = cbs
if group_dict:
all_copp_groups.append(group_dict)
if all_copp_groups:
config_dict['copp_groups'] = all_copp_groups

return config_dict

Expand All @@ -123,5 +124,4 @@ def get_copp_config(self, module):
copp_cfg = response[0][1].get('openconfig-copp-ext:copp', None)
except ConnectionError as exc:
module.fail_json(msg=str(exc), code=exc.code)

return copp_cfg
12 changes: 8 additions & 4 deletions plugins/modules/sonic_bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@
# (No "bfd peers" configuration present)

- name: Merge BFD configuration
input:
dellemc.enterprise_sonic.sonic_bfd:
kerry-meyer marked this conversation as resolved.
Show resolved Hide resolved
config:
profiles:
- profile_name: 'p1'
enabled: True
Expand Down Expand Up @@ -364,7 +365,8 @@
# Echo transmission interval: 300ms

- name: Replace BFD configuration
input:
dellemc.enterprise_sonic.sonic_bfd:
config:
profiles:
- profile_name: 'p1'
transmit_interval: 144
Expand Down Expand Up @@ -456,7 +458,8 @@
# Echo transmission interval: 0ms

- name: Override BFD configuration
input:
dellemc.enterprise_sonic.sonic_bfd:
config:
single_hops:
- remote_address: '172.68.2.1'
vrf: 'default'
Expand Down Expand Up @@ -596,7 +599,8 @@
# Echo transmission interval: 0ms

- name: Delete BFD configuration
input:
dellemc.enterprise_sonic.sonic_bfd:
config:
profiles:
- profile_name: 'p1'
enabled: True
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/sonic_copp.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
# (No "copp actions" configuration present)

- name: Merge CoPP groups configuration
dellemc.enterprise_sonic.sonic_static_routes:
dellemc.enterprise_sonic.sonic_copp:
config:
copp_groups:
- copp_name: 'copp-1'
Expand Down Expand Up @@ -143,7 +143,7 @@
# police cir 45 cbs 45

- name: Replace CoPP groups configuration
dellemc.enterprise_sonic.sonic_static_routes:
dellemc.enterprise_sonic.sonic_copp:
config:
copp_groups:
- copp_name: 'copp-1'
Expand Down Expand Up @@ -190,7 +190,7 @@
# police cir 1000 cbs 1000

- name: Override CoPP groups configuration
dellemc.enterprise_sonic.sonic_static_routes:
dellemc.enterprise_sonic.sonic_copp:
config:
copp_groups:
- copp_name: 'copp-4'
Expand Down Expand Up @@ -230,7 +230,7 @@
# police cir 90 cbs 90

- name: Delete CoPP groups configuration
dellemc.enterprise_sonic.sonic_static_routes:
dellemc.enterprise_sonic.sonic_copp:
config:
copp_groups:
- copp_name: 'copp-1'
Expand Down
12 changes: 8 additions & 4 deletions plugins/modules/sonic_mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
# (No mac configuration pressent)

- name: Merge MAC configurations
input:
dellemc.enterprise_sonic.sonic_mac:
config:
- vrf_name: 'default'
mac:
aging_time: 50
Expand Down Expand Up @@ -161,7 +162,8 @@
# mac address-table aging-time 50

- name: Replace MAC configurations
input:
dellemc.enterprise_sonic.sonic_mac:
config:
- vrf_name: 'default'
mac:
aging_time: 45
Expand Down Expand Up @@ -203,7 +205,8 @@
# mac address-table aging-time 45

- name: Override MAC cofigurations
input:
dellemc.enterprise_sonic.sonic_mac:
config:
- vrf_name: 'default'
mac:
aging_time: 10
Expand Down Expand Up @@ -244,7 +247,8 @@
# mac address-table aging-time 10

- name: Delete MAC cofigurations
input:
dellemc.enterprise_sonic.sonic_mac:
config:
- vrf_name: 'default'
mac:
aging_time: 10
Expand Down
Loading