From e716943eaba48731d4dd0f9906a534a5b98d8c3b Mon Sep 17 00:00:00 2001 From: stalabi1 <54641848+stalabi1@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:10:17 -0800 Subject: [PATCH] Add UTs for BFD, COPP, and MAC modules (#287) * Updated state examples and updated code for UT * Added UTs for BFD, COPP, and MAC * Added fragment * Addressed review comments --------- Co-authored-by: Shade Talabi --- .../287-add-uts-for-bfd-copp-mac.yaml | 2 + .../network/sonic/config/copp/copp.py | 71 ++- .../network/sonic/config/mac/mac.py | 56 +- .../network/sonic/facts/bfd/bfd.py | 1 - .../network/sonic/facts/copp/copp.py | 62 +- plugins/modules/sonic_bfd.py | 12 +- plugins/modules/sonic_copp.py | 8 +- plugins/modules/sonic_mac.py | 12 +- .../network/sonic/fixtures/sonic_bfd.yaml | 598 ++++++++++++++++++ .../network/sonic/fixtures/sonic_copp.yaml | 203 ++++++ .../network/sonic/fixtures/sonic_mac.yaml | 373 +++++++++++ .../modules/network/sonic/test_sonic_bfd.py | 86 +++ .../modules/network/sonic/test_sonic_copp.py | 86 +++ .../modules/network/sonic/test_sonic_mac.py | 86 +++ 14 files changed, 1551 insertions(+), 105 deletions(-) create mode 100644 changelogs/fragments/287-add-uts-for-bfd-copp-mac.yaml create mode 100644 tests/unit/modules/network/sonic/fixtures/sonic_bfd.yaml create mode 100644 tests/unit/modules/network/sonic/fixtures/sonic_copp.yaml create mode 100644 tests/unit/modules/network/sonic/fixtures/sonic_mac.yaml create mode 100644 tests/unit/modules/network/sonic/test_sonic_bfd.py create mode 100644 tests/unit/modules/network/sonic/test_sonic_copp.py create mode 100644 tests/unit/modules/network/sonic/test_sonic_mac.py diff --git a/changelogs/fragments/287-add-uts-for-bfd-copp-mac.yaml b/changelogs/fragments/287-add-uts-for-bfd-copp-mac.yaml new file mode 100644 index 000000000..c4f165eb6 --- /dev/null +++ b/changelogs/fragments/287-add-uts-for-bfd-copp-mac.yaml @@ -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). diff --git a/plugins/module_utils/network/sonic/config/copp/copp.py b/plugins/module_utils/network/sonic/config/copp/copp.py index a64c409ce..cec802e67 100644 --- a/plugins/module_utils/network/sonic/config/copp/copp.py +++ b/plugins/module_utils/network/sonic/config/copp/copp.py @@ -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: + 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 @@ -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 diff --git a/plugins/module_utils/network/sonic/config/mac/mac.py b/plugins/module_utils/network/sonic/config/mac/mac.py index c6fe285e6..866ff3934 100644 --- a/plugins/module_utils/network/sonic/config/mac/mac.py +++ b/plugins/module_utils/network/sonic/config/mac/mac.py @@ -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: + 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): diff --git a/plugins/module_utils/network/sonic/facts/bfd/bfd.py b/plugins/module_utils/network/sonic/facts/bfd/bfd.py index b1ee0d6b6..b8786947d 100644 --- a/plugins/module_utils/network/sonic/facts/bfd/bfd.py +++ b/plugins/module_utils/network/sonic/facts/bfd/bfd.py @@ -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 diff --git a/plugins/module_utils/network/sonic/facts/copp/copp.py b/plugins/module_utils/network/sonic/facts/copp/copp.py index 2e1876f4e..52a01d3d1 100644 --- a/plugins/module_utils/network/sonic/facts/copp/copp.py +++ b/plugins/module_utils/network/sonic/facts/copp/copp.py @@ -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 @@ -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 diff --git a/plugins/modules/sonic_bfd.py b/plugins/modules/sonic_bfd.py index 376297dc6..c969b1a69 100644 --- a/plugins/modules/sonic_bfd.py +++ b/plugins/modules/sonic_bfd.py @@ -239,7 +239,8 @@ # (No "bfd peers" configuration present) - name: Merge BFD configuration - input: + dellemc.enterprise_sonic.sonic_bfd: + config: profiles: - profile_name: 'p1' enabled: True @@ -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 @@ -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' @@ -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 diff --git a/plugins/modules/sonic_copp.py b/plugins/modules/sonic_copp.py index e044cad30..e4e7d358a 100644 --- a/plugins/modules/sonic_copp.py +++ b/plugins/modules/sonic_copp.py @@ -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' @@ -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' @@ -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' @@ -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' diff --git a/plugins/modules/sonic_mac.py b/plugins/modules/sonic_mac.py index de64b6db9..42acfd4fb 100644 --- a/plugins/modules/sonic_mac.py +++ b/plugins/modules/sonic_mac.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_bfd.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_bfd.yaml new file mode 100644 index 000000000..ed6c441b1 --- /dev/null +++ b/tests/unit/modules/network/sonic/fixtures/sonic_bfd.yaml @@ -0,0 +1,598 @@ +--- +merged_01: + module_args: + config: + profiles: + - profile_name: 'p1' + enabled: True + transmit_interval: 120 + receive_interval: 200 + detect_multiplier: 2 + passive_mode: True + min_ttl: 140 + echo_interval: 150 + echo_mode: True + single_hops: + - remote_address: '196.88.6.1' + vrf: 'default' + interface: 'Ethernet20' + local_address: '1.1.1.1' + enabled: True + transmit_interval: 50 + receive_interval: 80 + detect_multiplier: 4 + passive_mode: True + echo_interval: 110 + echo_mode: True + profile_name: 'p1' + multi_hops: + - remote_address: '192.40.1.3' + vrf: 'default' + local_address: '3.3.3.3' + enabled: True + transmit_interval: 75 + receive_interval: 100 + detect_multiplier: 3 + passive_mode: True + min_ttl: 125 + profile_name: 'p1' + existing_bfd_config: + - path: "/data/openconfig-bfd:bfd" + response: + code: 200 + expected_config_requests: + - path: "/data/openconfig-bfd:bfd" + method: "patch" + data: + openconfig-bfd:bfd: + openconfig-bfd-ext:bfd-profile: + profile: + - profile-name: 'p1' + config: + profile-name: 'p1' + enabled: True + desired-minimum-tx-interval: 120 + required-minimum-receive: 200 + detection-multiplier: 2 + passive-mode: True + minimum-ttl: 140 + desired-minimum-echo-receive: 150 + echo-active: True + openconfig-bfd-ext:bfd-shop-sessions: + single-hop: + - remote-address: '196.88.6.1' + vrf: 'default' + interface: 'Ethernet20' + local-address: '1.1.1.1' + config: + remote-address: '196.88.6.1' + vrf: 'default' + interface: 'Ethernet20' + local-address: '1.1.1.1' + enabled: True + desired-minimum-tx-interval: 50 + required-minimum-receive: 80 + detection-multiplier: 4 + passive-mode: True + desired-minimum-echo-receive: 110 + echo-active: True + profile-name: 'p1' + openconfig-bfd-ext:bfd-mhop-sessions: + multi-hop: + - remote-address: '192.40.1.3' + vrf: 'default' + local-address: '3.3.3.3' + interface: 'null' + config: + remote-address: '192.40.1.3' + vrf: 'default' + local-address: '3.3.3.3' + enabled: True + desired-minimum-tx-interval: 75 + required-minimum-receive: 100 + detection-multiplier: 3 + passive-mode: True + minimum-ttl: 125 + profile-name: 'p1' + interface: 'null' + +replaced_01: + module_args: + config: + profiles: + - profile_name: 'p2' + enabled: False + single_hops: + - remote_address: '194.56.2.1' + vrf: 'default' + interface: 'Ethernet24' + local_address: '2.2.2.2' + echo_interval: 125 + echo_mode: True + profile_name: 'p1' + multi_hops: + - remote_address: '198.72.1.4' + vrf: 'default' + local_address: '4.4.4.4' + enabled: True + transmit_interval: 71 + receive_interval: 286 + detect_multiplier: 9 + state: replaced + existing_bfd_config: + - path: "/data/openconfig-bfd:bfd" + response: + code: 200 + value: + openconfig-bfd:bfd: + openconfig-bfd-ext:bfd-profile: + profile: + - profile-name: 'p2' + config: + profile-name: 'p2' + enabled: True + desired-minimum-tx-interval: 135 + required-minimum-receive: 225 + detection-multiplier: 10 + passive-mode: True + minimum-ttl: 250 + desired-minimum-echo-receive: 250 + echo-active: True + openconfig-bfd-ext:bfd-shop-sessions: + single-hop: + - remote-address: '194.56.2.1' + vrf: 'default' + interface: 'Ethernet24' + local-address: '2.2.2.2' + config: + remote-address: '194.56.2.1' + vrf: 'default' + interface: 'Ethernet24' + local-address: '2.2.2.2' + enabled: False + desired-minimum-tx-interval: 65 + required-minimum-receive: 95 + detection-multiplier: 7 + passive-mode: False + desired-minimum-echo-receive: 145 + echo-active: False + profile-name: 'p2' + openconfig-bfd-ext:bfd-mhop-sessions: + multi-hop: + - remote-address: '198.72.1.4' + vrf: 'default' + local-address: '4.4.4.4' + config: + remote-address: '198.72.1.4' + vrf: 'default' + local-address: '4.4.4.4' + enabled: False + desired-minimum-tx-interval: 70 + required-minimum-receive: 285 + detection-multiplier: 8 + passive-mode: False + minimum-ttl: 155 + profile-name: 'p2' + expected_config_requests: + - path: "/data/openconfig-bfd:bfd" + method: "patch" + data: + openconfig-bfd:bfd: + openconfig-bfd-ext:bfd-profile: + profile: + - profile-name: 'p2' + config: + profile-name: 'p2' + enabled: False + desired-minimum-tx-interval: 300 + required-minimum-receive: 300 + detection-multiplier: 3 + passive-mode: False + minimum-ttl: 254 + desired-minimum-echo-receive: 300 + echo-active: False + openconfig-bfd-ext:bfd-shop-sessions: + single-hop: + - remote-address: '194.56.2.1' + vrf: 'default' + interface: 'Ethernet24' + local-address: '2.2.2.2' + config: + remote-address: '194.56.2.1' + vrf: 'default' + interface: 'Ethernet24' + local-address: '2.2.2.2' + enabled: True + desired-minimum-tx-interval: 300 + required-minimum-receive: 300 + detection-multiplier: 3 + passive-mode: False + desired-minimum-echo-receive: 125 + echo-active: True + profile-name: 'p1' + openconfig-bfd-ext:bfd-mhop-sessions: + multi-hop: + - remote-address: '198.72.1.4' + vrf: 'default' + local-address: '4.4.4.4' + interface: 'null' + config: + remote-address: '198.72.1.4' + vrf: 'default' + local-address: '4.4.4.4' + enabled: True + desired-minimum-tx-interval: 71 + required-minimum-receive: 286 + detection-multiplier: 9 + passive-mode: False + minimum-ttl: 254 + interface: 'null' +overridden_01: + module_args: + config: + profiles: + - profile_name: 'p3' + enabled: True + transmit_interval: 110 + receive_interval: 230 + detect_multiplier: 10 + passive_mode: True + min_ttl: 170 + echo_interval: 140 + echo_mode: True + - profile_name: 'p4' + single_hops: + - remote_address: '182.98.4.1' + vrf: 'default' + interface: 'Ethernet28' + local_address: '3.3.3.3' + enabled: True + transmit_interval: 42 + receive_interval: 84 + detect_multiplier: 8 + passive_mode: True + echo_interval: 115 + echo_mode: True + profile_name: 'p3' + - remote_address: '183.98.3.2' + vrf: 'default' + interface: 'Ethernet24' + local_address: '1.2.3.4' + multi_hops: + - remote_address: '182.44.1.2' + vrf: 'default' + local_address: '2.2.2.2' + enabled: True + transmit_interval: 74 + receive_interval: 101 + detect_multiplier: 6 + passive_mode: True + min_ttl: 127 + profile_name: 'p3' + - remote_address: '162.45.5.1' + vrf: 'default' + local_address: '2.1.1.1' + state: overridden + existing_bfd_config: + - path: "/data/openconfig-bfd:bfd" + response: + code: 200 + value: + openconfig-bfd:bfd: + openconfig-bfd-ext:bfd-profile: + profile: + - profile-name: 'p2' + config: + profile-name: 'p2' + enabled: True + desired-minimum-tx-interval: 135 + required-minimum-receive: 225 + detection-multiplier: 10 + passive-mode: True + minimum-ttl: 250 + desired-minimum-echo-receive: 250 + echo-active: True + openconfig-bfd-ext:bfd-shop-sessions: + single-hop: + - remote-address: '194.56.2.1' + vrf: 'default' + interface: 'Ethernet24' + local-address: '2.2.2.2' + config: + remote-address: '194.56.2.1' + vrf: 'default' + interface: 'Ethernet24' + local-address: '2.2.2.2' + enabled: False + desired-minimum-tx-interval: 65 + required-minimum-receive: 95 + detection-multiplier: 7 + passive-mode: False + desired-minimum-echo-receive: 145 + echo-active: False + profile-name: 'p2' + openconfig-bfd-ext:bfd-mhop-sessions: + multi-hop: + - remote-address: '198.72.1.4' + vrf: 'default' + local-address: '4.4.4.4' + config: + remote-address: '198.72.1.4' + vrf: 'default' + local-address: '4.4.4.4' + enabled: False + desired-minimum-tx-interval: 70 + required-minimum-receive: 285 + detection-multiplier: 8 + passive-mode: False + minimum-ttl: 155 + profile-name: 'p2' + expected_config_requests: + - path: "/data/openconfig-bfd:bfd" + method: "patch" + data: + openconfig-bfd:bfd: + openconfig-bfd-ext:bfd-profile: + profile: + - profile-name: 'p3' + config: + profile-name: 'p3' + enabled: True + desired-minimum-tx-interval: 110 + required-minimum-receive: 230 + detection-multiplier: 10 + passive-mode: True + minimum-ttl: 170 + desired-minimum-echo-receive: 140 + echo-active: True + openconfig-bfd-ext:bfd-shop-sessions: + single-hop: + - remote-address: '182.98.4.1' + vrf: 'default' + interface: 'Ethernet28' + local-address: '3.3.3.3' + config: + remote-address: '182.98.4.1' + vrf: 'default' + interface: 'Ethernet28' + local-address: '3.3.3.3' + enabled: True + desired-minimum-tx-interval: 42 + required-minimum-receive: 84 + detection-multiplier: 8 + passive-mode: True + desired-minimum-echo-receive: 115 + echo-active: True + profile-name: 'p3' + openconfig-bfd-ext:bfd-mhop-sessions: + multi-hop: + - remote-address: '162.45.5.1' + vrf: 'default' + local-address: '2.1.1.1' + interface: 'null' + config: + remote-address: '162.45.5.1' + vrf: 'default' + local-address: '2.1.1.1' + enabled: True + desired-minimum-tx-interval: 300 + required-minimum-receive: 300 + detection-multiplier: 3 + passive-mode: False + minimum-ttl: 254 + interface: 'null' + +deleted_01: + module_args: + config: + profiles: + - profile_name: 'p3' + enabled: True + transmit_interval: 110 + receive_interval: 230 + detect_multiplier: 10 + passive_mode: True + min_ttl: 170 + echo_interval: 140 + echo_mode: True + - profile_name: 'p4' + single_hops: + - remote_address: '182.98.4.1' + vrf: 'default' + interface: 'Ethernet28' + local_address: '3.3.3.3' + enabled: True + transmit_interval: 42 + receive_interval: 84 + detect_multiplier: 8 + passive_mode: True + echo_interval: 115 + echo_mode: True + profile_name: 'p3' + - remote_address: '183.98.3.2' + vrf: 'default' + interface: 'Ethernet24' + local_address: '1.2.3.4' + multi_hops: + - remote_address: '182.44.1.2' + vrf: 'default' + local_address: '2.2.2.2' + enabled: True + transmit_interval: 74 + receive_interval: 101 + detect_multiplier: 6 + passive_mode: True + min_ttl: 127 + profile_name: 'p3' + - remote_address: '162.45.5.1' + vrf: 'default' + local_address: '2.1.1.1' + state: deleted + existing_bfd_config: + - path: "/data/openconfig-bfd:bfd" + response: + code: 200 + value: + openconfig-bfd:bfd: + openconfig-bfd-ext:bfd-mhop-sessions: + multi-hop: + - config: + desired-minimum-tx-interval: 300 + detection-multiplier: 3 + enabled: true + interface: 'null' + local-address: 2.1.1.1 + minimum-ttl: 254 + passive-mode: false + remote-address: 162.45.5.1 + required-minimum-receive: 300 + vrf: default + interface: 'null' + local-address: 2.1.1.1 + remote-address: 162.45.5.1 + vrf: default + - config: + desired-minimum-tx-interval: 74 + detection-multiplier: 6 + enabled: true + interface: 'null' + local-address: 2.2.2.2 + minimum-ttl: 127 + passive-mode: true + profile-name: p3 + remote-address: 182.44.1.2 + required-minimum-receive: 101 + vrf: default + interface: 'null' + local-address: 2.2.2.2 + remote-address: 182.44.1.2 + vrf: default + openconfig-bfd-ext:bfd-profile: + profile: + - config: + desired-minimum-echo-receive: 140 + desired-minimum-tx-interval: 110 + detection-multiplier: 10 + echo-active: true + enabled: true + minimum-ttl: 170 + passive-mode: true + profile-name: p3 + required-minimum-receive: 230 + profile-name: p3 + - config: + desired-minimum-echo-receive: 300 + desired-minimum-tx-interval: 300 + detection-multiplier: 3 + echo-active: false + enabled: true + minimum-ttl: 254 + passive-mode: false + profile-name: p4 + required-minimum-receive: 300 + profile-name: p4 + openconfig-bfd-ext:bfd-shop-sessions: + single-hop: + - config: + desired-minimum-echo-receive: 115 + desired-minimum-tx-interval: 42 + detection-multiplier: 8 + echo-active: true + enabled: true + interface: Ethernet28 + local-address: 3.3.3.3 + passive-mode: true + profile-name: p3 + remote-address: 182.98.4.1 + required-minimum-receive: 84 + vrf: default + interface: Ethernet28 + local-address: 3.3.3.3 + remote-address: 182.98.4.1 + vrf: default + - config: + desired-minimum-echo-receive: 300 + desired-minimum-tx-interval: 300 + detection-multiplier: 3 + echo-active: false + enabled: true + interface: Ethernet24 + local-address: 1.2.3.4 + passive-mode: false + remote-address: 183.98.3.2 + required-minimum-receive: 300 + vrf: default + interface: Ethernet24 + local-address: 1.2.3.4 + remote-address: 183.98.3.2 + vrf: default + expected_config_requests: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-profile/profile=p3/config/desired-minimum-tx-interval" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-profile/profile=p3/config/required-minimum-receive" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-profile/profile=p3/config/detection-multiplier" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-profile/profile=p3/config/passive-mode" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-profile/profile=p3/config/minimum-ttl" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-profile/profile=p3/config/desired-minimum-echo-receive" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-profile/profile=p3/config/echo-active" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-profile/profile=p4" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-shop-sessions/single-hop=182.98.4.1,Ethernet28,default,3.3.3.3/config/desired-minimum-tx-interval" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-shop-sessions/single-hop=182.98.4.1,Ethernet28,default,3.3.3.3/config/required-minimum-receive" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-shop-sessions/single-hop=182.98.4.1,Ethernet28,default,3.3.3.3/config/detection-multiplier" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-shop-sessions/single-hop=182.98.4.1,Ethernet28,default,3.3.3.3/config/passive-mode" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-shop-sessions/single-hop=182.98.4.1,Ethernet28,default,3.3.3.3/config/desired-minimum-echo-receive" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-shop-sessions/single-hop=182.98.4.1,Ethernet28,default,3.3.3.3/config/echo-active" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-shop-sessions/single-hop=182.98.4.1,Ethernet28,default,3.3.3.3/config/profile-name" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-shop-sessions/single-hop=183.98.3.2,Ethernet24,default,1.2.3.4" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-mhop-sessions/multi-hop=182.44.1.2,null,default,2.2.2.2/config/desired-minimum-tx-interval" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-mhop-sessions/multi-hop=182.44.1.2,null,default,2.2.2.2/config/required-minimum-receive" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-mhop-sessions/multi-hop=182.44.1.2,null,default,2.2.2.2/config/detection-multiplier" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-mhop-sessions/multi-hop=182.44.1.2,null,default,2.2.2.2/config/passive-mode" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-mhop-sessions/multi-hop=182.44.1.2,null,default,2.2.2.2/config/minimum-ttl" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-mhop-sessions/multi-hop=182.44.1.2,null,default,2.2.2.2/config/profile-name" + method: "delete" + data: + - path: "/data/openconfig-bfd:bfd/openconfig-bfd-ext:bfd-mhop-sessions/multi-hop=162.45.5.1,null,default,2.1.1.1" + method: "delete" + data: diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_copp.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_copp.yaml new file mode 100644 index 000000000..c0bd0557c --- /dev/null +++ b/tests/unit/modules/network/sonic/fixtures/sonic_copp.yaml @@ -0,0 +1,203 @@ +--- +merged_01: + module_args: + config: + copp_groups: + - copp_name: 'copp-1' + trap_priority: 1 + trap_action: 'DROP' + queue: 1 + cir: '45' + cbs: '45' + - copp_name: 'copp-2' + trap_priority: 2 + trap_action: 'FORWARD' + queue: 2 + cir: '90' + cbs: '90' + existing_copp_config: + - path: "/data/openconfig-copp-ext:copp" + response: + code: 200 + expected_config_requests: + - path: "/data/openconfig-copp-ext:copp/copp-groups" + method: "patch" + data: + openconfig-copp-ext:copp-groups: + copp-group: + - name: 'copp-1' + config: + name: 'copp-1' + trap-priority: 1 + trap-action: 'DROP' + queue: 1 + cir: '45' + cbs: '45' + - name: 'copp-2' + config: + name: 'copp-2' + trap-priority: 2 + trap-action: 'FORWARD' + queue: 2 + cir: '90' + cbs: '90' + +replaced_01: + module_args: + config: + copp_groups: + - copp_name: 'copp-2' + trap_action: 'FORWARD' + cir: '60' + cbs: '60' + - copp_name: 'copp-3' + trap_priority: 3 + trap_action: 'DROP' + queue: 3 + cir: '70' + cbs: '70' + - copp_name: 'copp-4' + trap_priority: 5 + trap_action: 'DROP' + queue: 5 + cir: '75' + cbs: '75' + state: replaced + existing_copp_config: + - path: "/data/openconfig-copp-ext:copp" + response: + code: 200 + value: + openconfig-copp-ext:copp: + copp-groups: + copp-group: + - name: 'copp-1' + config: + name: 'copp-1' + trap-priority: 1 + trap-action: 'DROP' + queue: 1 + cir: '45' + cbs: '45' + expected_config_requests: + - path: "/data/openconfig-copp-ext:copp/copp-groups" + method: "patch" + data: + openconfig-copp-ext:copp-groups: + copp-group: + - name: 'copp-2' + config: + name: 'copp-2' + trap-action: 'FORWARD' + cir: '60' + cbs: '60' + - name: 'copp-3' + config: + name: 'copp-3' + trap-priority: 3 + trap-action: 'DROP' + queue: 3 + cir: '70' + cbs: '70' + - name: 'copp-4' + config: + name: 'copp-4' + trap-priority: 5 + trap-action: 'DROP' + queue: 5 + cir: '75' + cbs: '75' + +overridden_01: + module_args: + config: + copp_groups: + - copp_name: 'copp-5' + trap_priority: 1 + trap_action: 'FORWARD' + queue: 1 + cir: '15' + cbs: '15' + state: overridden + existing_copp_config: + - path: "/data/openconfig-copp-ext:copp" + response: + code: 200 + value: + openconfig-copp-ext:copp: + copp-groups: + copp-group: + - name: 'copp-1' + config: + name: 'copp-1' + trap-priority: 1 + trap-action: 'DROP' + queue: 1 + cir: '45' + cbs: '45' + expected_config_requests: + - path: "/data/openconfig-copp-ext:copp/copp-groups" + method: "patch" + data: + openconfig-copp-ext:copp-groups: + copp-group: + - name: 'copp-5' + config: + name: 'copp-5' + trap-priority: 1 + trap-action: 'FORWARD' + queue: 1 + cir: '15' + cbs: '15' + +deleted_01: + module_args: + config: + copp_groups: + - copp_name: 'copp-1' + trap_priority: 8 + queue: 8 + cir: '20' + cbs: '20' + - copp_name: 'copp-2' + state: deleted + existing_copp_config: + - path: "/data/openconfig-copp-ext:copp" + response: + code: 200 + value: + openconfig-copp-ext:copp: + copp-groups: + copp-group: + - name: 'copp-1' + config: + name: 'copp-1' + trap-priority: 8 + trap-action: 'DROP' + queue: 8 + cir: '20' + cbs: '20' + - name: 'copp-2' + config: + name: 'copp-2' + trap-priority: 2 + trap-action: 'FORWARD' + queue: 2 + cir: '60' + cbs: '60' + expected_config_requests: + - path: "/data/openconfig-copp-ext:copp/copp-groups/copp-group=copp-1/config/trap-priority" + method: "delete" + data: + - path: "/data/openconfig-copp-ext:copp/copp-groups/copp-group=copp-1/config/queue" + method: "delete" + data: + - path: "/data/openconfig-copp-ext:copp/copp-groups/copp-group=copp-1/config/cir" + method: "delete" + data: + - path: "/data/openconfig-copp-ext:copp/copp-groups/copp-group=copp-1/config/cbs" + method: "delete" + data: + - path: "/data/openconfig-copp-ext:copp/copp-groups/copp-group=copp-2" + method: "delete" + data: diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_mac.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_mac.yaml new file mode 100644 index 000000000..cd869a1a5 --- /dev/null +++ b/tests/unit/modules/network/sonic/fixtures/sonic_mac.yaml @@ -0,0 +1,373 @@ +--- +merged_01: + module_args: + config: + - vrf_name: 'default' + mac: + aging_time: 50 + dampening_interval: 20 + dampening_threshold: 30 + mac_table_entries: + - mac_address: '00:00:5e:00:53:af' + vlan_id: 1 + interface: 'Ethernet20' + - mac_address: '00:33:33:33:33:33' + vlan_id: 2 + interface: 'Ethernet24' + - mac_address: '00:00:4e:00:24:af' + vlan_id: 3 + interface: 'Ethernet28' + existing_mac_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: default + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/config/mac-aging-time" + response: + code: 200 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/openconfig-mac-dampening:mac-dampening/config" + response: + code: 200 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/mac-table/entries" + response: + code: 200 + expected_config_requests: + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb" + method: "patch" + data: + openconfig-network-instance:fdb: + config: + mac-aging-time: 50 + mac-table: + entries: + entry: + - mac-address: '00:00:5e:00:53:af' + vlan: 1 + config: + mac-address: '00:00:5e:00:53:af' + vlan: 1 + interface: + interface-ref: + config: + interface: 'Ethernet20' + subinterface: 0 + - mac-address: '00:33:33:33:33:33' + vlan: 2 + config: + mac-address: '00:33:33:33:33:33' + vlan: 2 + interface: + interface-ref: + config: + interface: 'Ethernet24' + subinterface: 0 + - mac-address: '00:00:4e:00:24:af' + vlan: 3 + config: + mac-address: '00:00:4e:00:24:af' + vlan: 3 + interface: + interface-ref: + config: + interface: 'Ethernet28' + subinterface: 0 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/openconfig-mac-dampening:mac-dampening" + method: "patch" + data: + openconfig-mac-dampening:mac-dampening: + config: + interval: 20 + threshold: 30 + +replaced_01: + module_args: + config: + - vrf_name: 'default' + mac: + aging_time: 45 + dampening_interval: 30 + dampening_threshold: 60 + mac_table_entries: + - mac_address: '00:00:5e:00:53:af' + vlan_id: 1 + interface: 'Ethernet20' + - mac_address: '00:44:44:44:44:44' + vlan_id: 2 + interface: 'Ethernet28' + existing_mac_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: default + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/config/mac-aging-time" + response: + code: 200 + value: + openconfig-network-instance:mac-aging-time: 50 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/openconfig-mac-dampening:mac-dampening/config" + response: + code: 200 + value: + openconfig-mac-dampening:config: + threshold: 30 + interval: 20 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/mac-table/entries" + response: + code: 200 + value: + openconfig-network-instance:entries: + entry: + - mac-address: 00:00:4e:00:24:af + vlan: 3 + config: + mac-address: 00:00:4e:00:24:af + vlan: 3 + interface: + interface-ref: + config: + interface: Ethernet28 + - mac-address: 00:00:5e:00:53:af + vlan: 1 + config: + mac-address: 00:00:5e:00:53:af + vlan: 1 + interface: + interface-ref: + config: + interface: Ethernet24 + - mac-address: '00:33:33:33:33:33' + vlan: 2 + config: + mac-address: '00:33:33:33:33:33' + vlan: 2 + interface: + interface-ref: + config: + interface: Ethernet20 + expected_config_requests: + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb" + method: "patch" + data: + openconfig-network-instance:fdb: + config: + mac-aging-time: 45 + mac-table: + entries: + entry: + - mac-address: '00:00:5e:00:53:af' + vlan: 1 + config: + mac-address: '00:00:5e:00:53:af' + vlan: 1 + interface: + interface-ref: + config: + interface: 'Ethernet20' + subinterface: 0 + - mac-address: '00:44:44:44:44:44' + vlan: 2 + config: + mac-address: '00:44:44:44:44:44' + vlan: 2 + interface: + interface-ref: + config: + interface: 'Ethernet28' + subinterface: 0 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/openconfig-mac-dampening:mac-dampening" + method: "patch" + data: + openconfig-mac-dampening:mac-dampening: + config: + interval: 30 + threshold: 60 + +overridden_01: + module_args: + config: + - vrf_name: 'default' + mac: + aging_time: 10 + dampening_interval: 20 + dampening_threshold: 30 + mac_table_entries: + - mac_address: '00:11:11:11:11:11' + vlan_id: 1 + interface: 'Ethernet20' + - mac_address: '00:22:22:22:22:22' + vlan_id: 2 + interface: 'Ethernet24' + - mac_address: '00:00:33:33:33:33' + vlan_id: 3 + interface: 'Ethernet28' + state: overridden + existing_mac_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: default + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/config/mac-aging-time" + response: + code: 200 + value: + openconfig-network-instance:mac-aging-time: 50 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/openconfig-mac-dampening:mac-dampening/config" + response: + code: 200 + value: + openconfig-mac-dampening:config: + threshold: 30 + interval: 20 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/mac-table/entries" + response: + code: 200 + value: + openconfig-network-instance:entries: + entry: + - mac-address: '00:00:5e:00:53:af' + vlan: 1 + config: + mac-address: '00:00:5e:00:53:af' + vlan: 1 + interface: + interface-ref: + config: + interface: 'Ethernet20' + subinterface: 0 + expected_config_requests: + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb" + method: "patch" + data: + openconfig-network-instance:fdb: + config: + mac-aging-time: 10 + mac-table: + entries: + entry: + - mac-address: '00:11:11:11:11:11' + vlan: 1 + config: + mac-address: '00:11:11:11:11:11' + vlan: 1 + interface: + interface-ref: + config: + interface: 'Ethernet20' + subinterface: 0 + - mac-address: '00:22:22:22:22:22' + vlan: 2 + config: + mac-address: '00:22:22:22:22:22' + vlan: 2 + interface: + interface-ref: + config: + interface: 'Ethernet24' + subinterface: 0 + - mac-address: '00:00:33:33:33:33' + vlan: 3 + config: + mac-address: '00:00:33:33:33:33' + vlan: 3 + interface: + interface-ref: + config: + interface: 'Ethernet28' + subinterface: 0 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/openconfig-mac-dampening:mac-dampening" + method: "patch" + data: + openconfig-mac-dampening:mac-dampening: + config: + interval: 20 + threshold: 30 + +deleted_01: + module_args: + config: + - vrf_name: 'default' + mac: + aging_time: 10 + dampening_interval: 20 + dampening_threshold: 30 + mac_table_entries: + - mac_address: '00:11:11:11:11:11' + vlan_id: 1 + interface: 'Ethernet20' + - mac_address: '00:00:33:33:33:33' + vlan_id: 3 + state: deleted + existing_mac_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: default + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/config/mac-aging-time" + response: + code: 200 + value: + openconfig-network-instance:mac-aging-time: 10 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/openconfig-mac-dampening:mac-dampening/config" + response: + code: 200 + value: + openconfig-mac-dampening:config: + threshold: 30 + interval: 20 + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/mac-table/entries" + response: + code: 200 + value: + openconfig-network-instance:entries: + entry: + - mac-address: '00:00:33:33:33:33' + vlan: 3 + config: + mac-address: '00:00:33:33:33:33' + vlan: 3 + interface: + interface-ref: + config: + interface: Ethernet28 + - mac-address: '00:11:11:11:11:11' + vlan: 1 + config: + mac-address: '00:11:11:11:11:11' + vlan: 1 + interface: + interface-ref: + config: + interface: Ethernet20 + - mac-address: '00:22:22:22:22:22' + vlan: 2 + config: + mac-address: '00:22:22:22:22:22' + vlan: 2 + interface: + interface-ref: + config: + interface: Ethernet24 + expected_config_requests: + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/config/mac-aging-time" + method: "delete" + data: + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/openconfig-mac-dampening:mac-dampening/config/interval" + method: "delete" + data: + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/openconfig-mac-dampening:mac-dampening/config/threshold" + method: "delete" + data: + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/mac-table/entries/entry=00:11:11:11:11:11,1/interface" + method: "delete" + data: + - path: "/data/openconfig-network-instance:network-instances/network-instance=default/fdb/mac-table/entries/entry=00:00:33:33:33:33,3" + method: "delete" + data: diff --git a/tests/unit/modules/network/sonic/test_sonic_bfd.py b/tests/unit/modules/network/sonic/test_sonic_bfd.py new file mode 100644 index 000000000..f30c90c79 --- /dev/null +++ b/tests/unit/modules/network/sonic/test_sonic_bfd.py @@ -0,0 +1,86 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.dellemc.enterprise_sonic.tests.unit.compat.mock import ( + patch, +) +from ansible_collections.dellemc.enterprise_sonic.plugins.modules import ( + sonic_bfd, +) +from ansible_collections.dellemc.enterprise_sonic.tests.unit.modules.utils import ( + set_module_args, +) +from .sonic_module import TestSonicModule + + +class TestSonicBfdModule(TestSonicModule): + module = sonic_bfd + + @classmethod + def setUpClass(cls): + cls.mock_facts_edit_config = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.facts.bfd.bfd.edit_config" + ) + cls.mock_config_edit_config = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.bfd.bfd.edit_config" + ) + cls.mock_utils_edit_config = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.bgp_utils.edit_config" + ) + cls.mock_get_interface_naming_mode = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.utils.get_device_interface_naming_mode" + ) + cls.mock_send_requests = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.bfd.bfd.send_requests" + ) + cls.fixture_data = cls.load_fixtures('sonic_bfd.yaml') + + def setUp(self): + super(TestSonicBfdModule, self).setUp() + self.facts_edit_config = self.mock_facts_edit_config.start() + self.config_edit_config = self.mock_config_edit_config.start() + self.facts_edit_config.side_effect = self.facts_side_effect + self.config_edit_config.side_effect = self.config_side_effect + self.get_interface_naming_mode = self.mock_get_interface_naming_mode.start() + self.get_interface_naming_mode.return_value = 'native' + self.send_requests = self.mock_send_requests.start() + self.send_requests.return_value = None + self.utils_edit_config = self.mock_utils_edit_config.start() + self.utils_edit_config.side_effect = self.facts_side_effect + + def tearDown(self): + super(TestSonicBfdModule, self).tearDown() + self.mock_facts_edit_config.stop() + self.mock_config_edit_config.stop() + self.mock_get_interface_naming_mode.stop() + self.mock_send_requests.stop() + self.mock_utils_edit_config.stop() + + def test_sonic_bfd_merged_01(self): + set_module_args(self.fixture_data['merged_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['merged_01']['existing_bfd_config']) + self.initialize_config_requests(self.fixture_data['merged_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_bfd_replaced_01(self): + set_module_args(self.fixture_data['replaced_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['replaced_01']['existing_bfd_config']) + self.initialize_config_requests(self.fixture_data['replaced_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_bfd_overridden_01(self): + set_module_args(self.fixture_data['overridden_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['overridden_01']['existing_bfd_config']) + self.initialize_config_requests(self.fixture_data['overridden_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_bfd_deleted_01(self): + set_module_args(self.fixture_data['deleted_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['deleted_01']['existing_bfd_config']) + self.initialize_config_requests(self.fixture_data['deleted_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() diff --git a/tests/unit/modules/network/sonic/test_sonic_copp.py b/tests/unit/modules/network/sonic/test_sonic_copp.py new file mode 100644 index 000000000..7e7c1be43 --- /dev/null +++ b/tests/unit/modules/network/sonic/test_sonic_copp.py @@ -0,0 +1,86 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.dellemc.enterprise_sonic.tests.unit.compat.mock import ( + patch, +) +from ansible_collections.dellemc.enterprise_sonic.plugins.modules import ( + sonic_copp, +) +from ansible_collections.dellemc.enterprise_sonic.tests.unit.modules.utils import ( + set_module_args, +) +from .sonic_module import TestSonicModule + + +class TestSonicCoppModule(TestSonicModule): + module = sonic_copp + + @classmethod + def setUpClass(cls): + cls.mock_facts_edit_config = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.facts.copp.copp.edit_config" + ) + cls.mock_config_edit_config = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.copp.copp.edit_config" + ) + cls.mock_utils_edit_config = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.bgp_utils.edit_config" + ) + cls.mock_get_interface_naming_mode = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.utils.get_device_interface_naming_mode" + ) + cls.mock_send_requests = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.copp.copp.send_requests" + ) + cls.fixture_data = cls.load_fixtures('sonic_copp.yaml') + + def setUp(self): + super(TestSonicCoppModule, self).setUp() + self.facts_edit_config = self.mock_facts_edit_config.start() + self.config_edit_config = self.mock_config_edit_config.start() + self.facts_edit_config.side_effect = self.facts_side_effect + self.config_edit_config.side_effect = self.config_side_effect + self.get_interface_naming_mode = self.mock_get_interface_naming_mode.start() + self.get_interface_naming_mode.return_value = 'native' + self.send_requests = self.mock_send_requests.start() + self.send_requests.return_value = None + self.utils_edit_config = self.mock_utils_edit_config.start() + self.utils_edit_config.side_effect = self.facts_side_effect + + def tearDown(self): + super(TestSonicCoppModule, self).tearDown() + self.mock_facts_edit_config.stop() + self.mock_config_edit_config.stop() + self.mock_get_interface_naming_mode.stop() + self.mock_send_requests.stop() + self.mock_utils_edit_config.stop() + + def test_sonic_copp_merged_01(self): + set_module_args(self.fixture_data['merged_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['merged_01']['existing_copp_config']) + self.initialize_config_requests(self.fixture_data['merged_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_copp_replaced_01(self): + set_module_args(self.fixture_data['replaced_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['replaced_01']['existing_copp_config']) + self.initialize_config_requests(self.fixture_data['replaced_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_copp_overridden_01(self): + set_module_args(self.fixture_data['overridden_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['overridden_01']['existing_copp_config']) + self.initialize_config_requests(self.fixture_data['overridden_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_copp_deleted_01(self): + set_module_args(self.fixture_data['deleted_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['deleted_01']['existing_copp_config']) + self.initialize_config_requests(self.fixture_data['deleted_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() diff --git a/tests/unit/modules/network/sonic/test_sonic_mac.py b/tests/unit/modules/network/sonic/test_sonic_mac.py new file mode 100644 index 000000000..1fb06e4a3 --- /dev/null +++ b/tests/unit/modules/network/sonic/test_sonic_mac.py @@ -0,0 +1,86 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.dellemc.enterprise_sonic.tests.unit.compat.mock import ( + patch, +) +from ansible_collections.dellemc.enterprise_sonic.plugins.modules import ( + sonic_mac, +) +from ansible_collections.dellemc.enterprise_sonic.tests.unit.modules.utils import ( + set_module_args, +) +from .sonic_module import TestSonicModule + + +class TestSonicMacModule(TestSonicModule): + module = sonic_mac + + @classmethod + def setUpClass(cls): + cls.mock_facts_edit_config = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.facts.mac.mac.edit_config" + ) + cls.mock_config_edit_config = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.mac.mac.edit_config" + ) + cls.mock_utils_edit_config = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.bgp_utils.edit_config" + ) + cls.mock_get_interface_naming_mode = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.utils.get_device_interface_naming_mode" + ) + cls.mock_send_requests = patch( + "ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.mac.mac.send_requests" + ) + cls.fixture_data = cls.load_fixtures('sonic_mac.yaml') + + def setUp(self): + super(TestSonicMacModule, self).setUp() + self.facts_edit_config = self.mock_facts_edit_config.start() + self.config_edit_config = self.mock_config_edit_config.start() + self.facts_edit_config.side_effect = self.facts_side_effect + self.config_edit_config.side_effect = self.config_side_effect + self.get_interface_naming_mode = self.mock_get_interface_naming_mode.start() + self.get_interface_naming_mode.return_value = 'native' + self.send_requests = self.mock_send_requests.start() + self.send_requests.return_value = None + self.utils_edit_config = self.mock_utils_edit_config.start() + self.utils_edit_config.side_effect = self.facts_side_effect + + def tearDown(self): + super(TestSonicMacModule, self).tearDown() + self.mock_facts_edit_config.stop() + self.mock_config_edit_config.stop() + self.mock_get_interface_naming_mode.stop() + self.mock_send_requests.stop() + self.mock_utils_edit_config.stop() + + def test_sonic_mac_merged_01(self): + set_module_args(self.fixture_data['merged_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['merged_01']['existing_mac_config']) + self.initialize_config_requests(self.fixture_data['merged_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_mac_replaced_01(self): + set_module_args(self.fixture_data['replaced_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['replaced_01']['existing_mac_config']) + self.initialize_config_requests(self.fixture_data['replaced_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_mac_overridden_01(self): + set_module_args(self.fixture_data['overridden_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['overridden_01']['existing_mac_config']) + self.initialize_config_requests(self.fixture_data['overridden_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_mac_deleted_01(self): + set_module_args(self.fixture_data['deleted_01']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['deleted_01']['existing_mac_config']) + self.initialize_config_requests(self.fixture_data['deleted_01']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests()