Skip to content

Commit

Permalink
Add new unreliable_los option (#453)
Browse files Browse the repository at this point in the history
* add new unreliable_los option

* add changelog

* remove print statement and extra spacing

* update config for deleted option

* current UT tests

* get rid of not needed comment

* add more UT tests

* add list of choices and update regression tests for 'unreliable_los'

* fix sanity check error

* fix spelling of 'unreliable_los' choice

* remove commented out line

* update regression test
  • Loading branch information
aida-shumburo committed Sep 26, 2024
1 parent 3aa8ae5 commit 9c46aa7
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- sonic_interfaces - add new unreliable-los option to interface resource module (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/453)
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def __init__(self, **kwargs):
"FEC_FC",
"FEC_DISABLED",
"FEC_DEFAULT",
"FEC_AUTO"]}
"FEC_AUTO"]},
"unreliable_los": {"type": "str",
"choices": ["UNRELIABLE_LOS_MODE_ON",
"UNRELIABLE_LOS_MODE_OFF",
"UNRELIABLE_LOS_MODE_AUTO"]}
},
"type": "list"
},
Expand Down
16 changes: 12 additions & 4 deletions plugins/module_utils/network/sonic/config/interfaces/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
port_num_regex = re.compile(r'[\d]{1,4}$')
loopback_attribute = ('description', 'enabled')
non_eth_attribute = ('description', 'mtu', 'enabled')
eth_attribute = ('description', 'mtu', 'enabled', 'auto_negotiate', 'speed', 'fec', 'advertised_speed')
eth_attribute = ('description', 'mtu', 'enabled', 'auto_negotiate', 'speed', 'fec', 'advertised_speed', 'unreliable_los')

non_eth_attributes_default_value = {
"description": '',
Expand All @@ -92,7 +92,8 @@
"enabled": False,
"auto_negotiate": False,
"fec": 'FEC_DISABLED',
"advertised_speed": []
"advertised_speed": [],
"unreliable_los": "UNRELIABLE_LOS_MODE_AUTO"
}
default_intf_speeds = {}
port_group_interfaces = None
Expand Down Expand Up @@ -426,7 +427,8 @@ def build_create_request(self, c_attr, h_attr, intf_name, attr):
"speed": 'port-speed',
"auto_negotiate": 'auto-negotiate',
"fec": 'openconfig-if-ethernet-ext2:port-fec',
"advertised_speed": 'openconfig-if-ethernet-ext2:advertised-speed'
"advertised_speed": 'openconfig-if-ethernet-ext2:advertised-speed',
"unreliable_los": 'openconfig-if-ethernet-ext2:unreliable-los'
}

config_url = (url + eth_conf_url) % quote(intf_name, safe='')
Expand Down Expand Up @@ -599,7 +601,8 @@ def build_delete_request(self, c_attr, h_attr, intf_name, attr):
"speed": 'port-speed',
"auto_negotiate": 'auto-negotiate',
"fec": 'openconfig-if-ethernet-ext2:port-fec',
"advertised_speed": 'openconfig-if-ethernet-ext2:advertised-speed'
"advertised_speed": 'openconfig-if-ethernet-ext2:advertised-speed',
"unreliable_los": 'openconfig-if-ethernet-ext2:unreliable-los'
}

config_url = (url + eth_conf_url) % quote(intf_name, safe='')
Expand All @@ -624,6 +627,11 @@ def build_delete_request(self, c_attr, h_attr, intf_name, attr):
payload_attr = attributes_payload[attr]
payload['openconfig-if-ethernet:config'][payload_attr] = 'FEC_DISABLED'
return {"path": config_url, "method": PATCH, "data": payload}

elif attr in ('unreliable_los'):
payload_attr = attributes_payload[attr]
payload['openconfig-if-ethernet:config'][payload_attr] = 'UNRELIABLE_LOS_MODE_AUTO'
return {"path": config_url, "method": PATCH, "data": payload}
else:
payload_attr = attributes_payload[attr]
if attr == 'auto_negotiate':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def transform_config(self, conf):
trans_cfg['advertised_speed'].sort()
if 'openconfig-if-ethernet-ext2:port-fec' in eth_conf:
trans_cfg['fec'] = eth_conf['openconfig-if-ethernet-ext2:port-fec'].split(':', 1)[-1]
if 'openconfig-if-ethernet-ext2:unreliable-los' in eth_conf:
trans_cfg['unreliable_los'] = eth_conf['openconfig-if-ethernet-ext2:unreliable-los'].split(':', 1)[-1]

return trans_cfg

Expand Down
7 changes: 7 additions & 0 deletions plugins/modules/sonic_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@
- FEC_DISABLED
- FEC_DEFAULT
- FEC_AUTO
unreliable_los:
description: Monitoring type to be used for generating a loss of service alarm.
type: str
choices:
- UNRELIABLE_LOS_MODE_ON
- UNRELIABLE_LOS_MODE_OFF
- UNRELIABLE_LOS_MODE_AUTO
state:
description:
- The state the configuration should be left in.
Expand Down
9 changes: 9 additions & 0 deletions tests/regression/roles/sonic_interfaces/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tests:
description: ansible Ethernet96
mtu: 6445
enabled: false
unreliable_los: UNRELIABLE_LOS_MODE_AUTO
- name: test_case_02
description: Update interface parameters
state: merged
Expand All @@ -41,18 +42,22 @@ tests:
description: ansible Ethernet96
mtu: 6444
enabled: true
unreliable_los: UNRELIABLE_LOS_MODE_OFF
- name: "{{ interface8 }}"
description: ansible Ethernet100
mtu: 6000
enabled: true
unreliable_los: UNRELIABLE_LOS_MODE_ON
- name: "{{ interface10 }}"
description: ansible Ethernet108
mtu: 5666
enabled: false
unreliable_los: UNRELIABLE_LOS_MODE_AUTO
- name: "{{ interface9 }}"
description: ansible Ethernet104
mtu: 5222
enabled: true
unreliable_los: UNRELIABLE_LOS_MODE_ON
- name: test_case_03
description: Configure interface parameter speed
state: merged
Expand All @@ -74,6 +79,7 @@ tests:
input:
- name: "{{ interface8 }}"
fec: FEC_AUTO
unreliable_los: UNRELIABLE_LOS_MODE_OFF
- name: test_case_06
description: Delete interface parameters
state: deleted
Expand All @@ -82,9 +88,11 @@ tests:
description:
- name: "{{ interface8 }}"
mtu: 6000
unreliable_los: UNRELIABLE_LOS_MODE_OFF
- name: "{{ interface10 }}"
enabled:
- name: "{{ interface9 }}"
unreliable_los: UNRELIABLE_LOS_MODE_ON
- name: test_case_07
description: Update interface parameters
state: merged
Expand Down Expand Up @@ -186,6 +194,7 @@ tests:
description: ansible Interface2 descr
mtu: 7500
enabled: true
unreliable_los: UNRELIABLE_LOS_MODE_ON
- name: test_case_18
description: Replace interface mtu parameters
state: replaced
Expand Down
179 changes: 171 additions & 8 deletions tests/unit/modules/network/sonic/fixtures/sonic_interfaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ merged_01:
- name: Loopback1
description: "Test Desc for Loopback1"
enabled: false
state: merged
existing_interfaces_config:
- path: "data/openconfig-interfaces:interfaces"
response:
Expand Down Expand Up @@ -36,7 +37,6 @@ merged_01:
- state:
member-if-end: "Eth1/4"
member-if-start: "Eth1/1"

expected_config_requests:
- path: "data/openconfig-interfaces:interfaces"
method: "patch"
Expand Down Expand Up @@ -71,6 +71,33 @@ merged_01:
data:
openconfig-interfaces:config:
enabled: false

merged_02:
module_args:
config:
- name: Eth1/15
unreliable_los: UNRELIABLE_LOS_MODE_ON
state: merged
existing_interfaces_config:
- path: "data/openconfig-interfaces:interfaces"
response:
code: 200
value:
openconfig-interfaces:interfaces:
interface:
- name: 'Eth1/15'
config:
mtu: 2000
description: ''
enabled: true
expected_config_requests:
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/openconfig-if-ethernet:ethernet/config"
method: "patch"
data:
openconfig-if-ethernet:config:
openconfig-if-ethernet-ext2:unreliable-los: UNRELIABLE_LOS_MODE_ON


deleted_01:
module_args:
state: deleted
Expand Down Expand Up @@ -110,7 +137,6 @@ deleted_01:
code: 200
value:
sonic-port:valid_speeds: "100000, 40000"

expected_config_requests:
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F1/config/description"
method: "delete"
Expand Down Expand Up @@ -169,8 +195,6 @@ deleted_02:
code: 200
value:
sonic-port:valid_speeds: "100000, 40000"


expected_config_requests:
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F1/openconfig-if-ethernet:ethernet/config"
method: "patch"
Expand All @@ -189,6 +213,35 @@ deleted_02:
openconfig-if-ethernet-ext2:advertised-speed: '40000'
- path: "data/openconfig-interfaces:interfaces/interface=Loopback123"
method: "delete"

deleted_03:
module_args:
state: deleted
config:
- name: 'Eth1/15'
unreliable_los: UNRELIABLE_LOS_MODE_ON
existing_interfaces_config:
- path: "data/openconfig-interfaces:interfaces"
response:
code: 200
value:
openconfig-interfaces:interfaces:
interface:
- name: 'Eth1/15'
config:
mtu: 6767
openconfig-if-ethernet:ethernet:
config:
port-speed: openconfig-if-ethernet:SPEED_40GB
openconfig-if-ethernet-ext2:unreliable-los: 'UNRELIABLE_LOS_MODE_ON'
expected_config_requests:
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/openconfig-if-ethernet:ethernet/config"
method: "patch"
data:
openconfig-if-ethernet:config:
openconfig-if-ethernet-ext2:unreliable-los: UNRELIABLE_LOS_MODE_AUTO


replaced_01:
module_args:
state: replaced
Expand Down Expand Up @@ -248,8 +301,6 @@ replaced_01:
code: 200
value:
sonic-port:valid_speeds: "100000, 40000"


expected_config_requests:
- path: "data/openconfig-interfaces:interfaces"
method: "patch"
Expand Down Expand Up @@ -282,6 +333,63 @@ replaced_01:
openconfig-if-ethernet:config:
port-speed: "openconfig-if-ethernet:SPEED_40GB"

replaced_02:
module_args:
state: replaced
config:
- name: 'Eth1/15'
mtu: 2000
speed: "SPEED_40GB"
unreliable_los: UNRELIABLE_LOS_MODE_OFF
existing_interfaces_config:
- path: "data/openconfig-interfaces:interfaces"
response:
code: 200
value:
openconfig-interfaces:interfaces:
interface:
- name: 'Eth1/15'
config:
mtu: 6767
openconfig-if-ethernet:ethernet:
config:
port-speed: openconfig-if-ethernet:SPEED_25GB
openconfig-if-ethernet-ext2:unreliable-los: 'UNRELIABLE_LOS_MODE_ON'
- path: "data/openconfig-port-group:port-groups"
response:
code: 200
value:
openconfig-port-group:port-groups:
port-group:
- state:
member-if-end: "Eth1/4"
member-if-start: "Eth1/3"
- path: "data/sonic-port:sonic-port/PORT/PORT_LIST=Eth1%2F15/valid_speeds"
response:
code: 200
value:
sonic-port:valid_speeds: "100000, 40000"
expected_config_requests:
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/config"
method: "patch"
data:
openconfig-interfaces:config:
mtu: 2000
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/config/enabled"
method: "patch"
data:
enabled: False
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/openconfig-if-ethernet:ethernet/config"
method: "patch"
data:
openconfig-if-ethernet:config:
port-speed: "openconfig-if-ethernet:SPEED_40GB"
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/openconfig-if-ethernet:ethernet/config"
method: "patch"
data:
openconfig-if-ethernet:config:
openconfig-if-ethernet-ext2:unreliable-los: UNRELIABLE_LOS_MODE_OFF

overridden_01:
module_args:
state: overridden
Expand Down Expand Up @@ -338,8 +446,6 @@ overridden_01:
code: 200
value:
sonic-port:valid_speeds: "100000, 40000"


expected_config_requests:
- path: "data/openconfig-interfaces:interfaces/interface=Loopback1"
method: "delete"
Expand Down Expand Up @@ -381,3 +487,60 @@ overridden_01:
data:
openconfig-if-ethernet:config:
auto-negotiate: false

overridden_02:
module_args:
state: overridden
config:
- name: Eth1/15
mtu: 1600
speed: "SPEED_40GB"
unreliable_los: UNRELIABLE_LOS_MODE_OFF
existing_interfaces_config:
- path: "data/openconfig-interfaces:interfaces"
response:
code: 200
value:
openconfig-interfaces:interfaces:
interface:
- name: 'Eth1/15'
config:
mtu: 2000
openconfig-if-ethernet:ethernet:
config:
port-speed: openconfig-if-ethernet:SPEED_25GB
openconfig-if-ethernet-ext2:unreliable-los: 'UNRELIABLE_LOS_MODE_ON'
- path: "data/openconfig-port-group:port-groups"
response:
code: 200
value:
openconfig-port-group:port-groups:
port-group:
- state:
member-if-end: "Eth1/4"
member-if-start: "Eth1/3"
- path: "data/sonic-port:sonic-port/PORT/PORT_LIST=Eth1%2F15/valid_speeds"
response:
code: 200
value:
sonic-port:valid_speeds: "100000, 40000"
expected_config_requests:
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/config"
method: "patch"
data:
openconfig-interfaces:config:
mtu: 1600
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/config/enabled"
method: "patch"
data:
enabled: False
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/openconfig-if-ethernet:ethernet/config"
method: "patch"
data:
openconfig-if-ethernet:config:
port-speed: "openconfig-if-ethernet:SPEED_40GB"
- path: "data/openconfig-interfaces:interfaces/interface=Eth1%2F15/openconfig-if-ethernet:ethernet/config"
method: "patch"
data:
openconfig-if-ethernet:config:
openconfig-if-ethernet-ext2:unreliable-los: "UNRELIABLE_LOS_MODE_OFF"
Loading

0 comments on commit 9c46aa7

Please sign in to comment.