diff --git a/changelogs/fragments/468-cable-length.yaml b/changelogs/fragments/468-cable-length.yaml new file mode 100644 index 000000000..f92002552 --- /dev/null +++ b/changelogs/fragments/468-cable-length.yaml @@ -0,0 +1,2 @@ +minor_changes: + - sonic_qos_interfaces - Add 'cable_length' attribute (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/468). diff --git a/plugins/module_utils/network/sonic/argspec/qos_interfaces/qos_interfaces.py b/plugins/module_utils/network/sonic/argspec/qos_interfaces/qos_interfaces.py index 7dbb043bb..36f8aad56 100644 --- a/plugins/module_utils/network/sonic/argspec/qos_interfaces/qos_interfaces.py +++ b/plugins/module_utils/network/sonic/argspec/qos_interfaces/qos_interfaces.py @@ -79,7 +79,8 @@ def __init__(self, **kwargs): }, 'type': 'list' }, - 'scheduler_policy': {'type': 'str'} + 'scheduler_policy': {'type': 'str'}, + 'cable_length': {'choices': ['5m', '40m', '300m'], 'default': '40m', 'type': 'str'} }, 'type': 'list' }, diff --git a/plugins/module_utils/network/sonic/config/qos_interfaces/qos_interfaces.py b/plugins/module_utils/network/sonic/config/qos_interfaces/qos_interfaces.py index bed34d5eb..a56a965c6 100644 --- a/plugins/module_utils/network/sonic/config/qos_interfaces/qos_interfaces.py +++ b/plugins/module_utils/network/sonic/config/qos_interfaces/qos_interfaces.py @@ -249,6 +249,7 @@ def get_modify_qos_interfaces_requests(self, commands): intf_dict = {} name = intf.get('name') scheduler_policy = intf.get('scheduler_policy') + cable_length = intf.get('cable_length') qos_maps = intf.get('qos_maps') pfc = intf.get('pfc') queues = intf.get('queues') @@ -257,6 +258,8 @@ def get_modify_qos_interfaces_requests(self, commands): intf_dict.update({'interface-id': name, 'config': {'interface-id': name}}) if scheduler_policy: intf_dict['output'] = {'scheduler-policy': {'config': {'name': scheduler_policy}}} + if cable_length: + intf_dict['openconfig-qos-buffer:cable-length'] = {'config': {'length': cable_length}} if qos_maps: map_dict = {} dscp_fwd_group = qos_maps.get('dscp_fwd_group') @@ -364,6 +367,7 @@ def get_delete_qos_interfaces_requests(self, commands, have, is_delete_all): for intf in commands: name = intf.get('name') scheduler_policy = intf.get('scheduler_policy') + cable_length = intf.get('cable_length') qos_maps = intf.get('qos_maps') pfc = intf.get('pfc') queues = intf.get('queues') @@ -373,6 +377,7 @@ def get_delete_qos_interfaces_requests(self, commands, have, is_delete_all): continue config_dict = {} cfg_scheduler_policy = cfg_intf.get('scheduler_policy') + cfg_cable_length = cfg_intf.get('cable_length') cfg_qos_maps = cfg_intf.get('qos_maps') cfg_pfc = cfg_intf.get('pfc') cfg_queues = cfg_intf.get('queues') @@ -381,6 +386,12 @@ def get_delete_qos_interfaces_requests(self, commands, have, is_delete_all): url = '%s/interface=%s/output/scheduler-policy' % (QOS_INTF_PATH, name) requests.append({'path': url, 'method': DELETE}) config_dict.update({'name': name, 'scheduler_policy': scheduler_policy}) + + if cable_length and cable_length == cfg_cable_length: + url = '%s/interface=%s/openconfig-qos-buffer:cable-length' % (QOS_INTF_PATH, name) + requests.append({'path': url, 'method': DELETE}) + config_dict.update({'name': name, 'cable_length': cable_length}) + if qos_maps and cfg_qos_maps: maps_dict = {} dscp_fwd_group = qos_maps.get('dscp_fwd_group') @@ -508,7 +519,7 @@ def get_delete_qos_interfaces_requests(self, commands, have, is_delete_all): config_dict.update({'name': name, 'queues': queues_list}) if config_dict: config_list.append(config_dict) - if not scheduler_policy and not qos_maps and not pfc and not queues: + if not scheduler_policy and not qos_maps and not pfc and not queues and not cable_length: self._module.fail_json(msg='Deletion of a QoS interface not supported') commands = config_list @@ -556,6 +567,11 @@ def remove_default_entries(self, data): pfc.pop('priorities') if not pfc: intf.pop('pfc') + + cable_length = intf.get('cable_length') + if cable_length == '40m': + intf.pop('cable_length') + if 'name' in intf and (len(intf) == 1 or intf['name'] == 'CPU'): intf_idx = data.index(intf) intf_pop_list.insert(0, intf_idx) diff --git a/plugins/module_utils/network/sonic/facts/qos_interfaces/qos_interfaces.py b/plugins/module_utils/network/sonic/facts/qos_interfaces/qos_interfaces.py index a03a38767..f377e24c3 100644 --- a/plugins/module_utils/network/sonic/facts/qos_interfaces/qos_interfaces.py +++ b/plugins/module_utils/network/sonic/facts/qos_interfaces/qos_interfaces.py @@ -85,6 +85,10 @@ def update_qos_interfaces(self, module): scheduler_policy = intf['output']['scheduler-policy']['config']['name'] config_dict['scheduler_policy'] = scheduler_policy + if ('openconfig-qos-buffer:cable-length' in intf and 'config' in intf['openconfig-qos-buffer:cable-length']): + cable_length = intf['openconfig-qos-buffer:cable-length']['config']['length'] + config_dict['cable_length'] = cable_length + if 'openconfig-qos-maps-ext:interface-maps' in intf and 'config' in intf['openconfig-qos-maps-ext:interface-maps']: maps_dict = {} maps = intf['openconfig-qos-maps-ext:interface-maps']['config'] diff --git a/plugins/modules/sonic_qos_interfaces.py b/plugins/modules/sonic_qos_interfaces.py index 33329ac5a..c66c28995 100644 --- a/plugins/modules/sonic_qos_interfaces.py +++ b/plugins/modules/sonic_qos_interfaces.py @@ -72,6 +72,13 @@ description: - Name of scheduler policy to be applied to traffic on the interface type: str + cable_length: + version_added: 3.1.0 + description: + - Cable length of the interface + type: str + choices: ['5m', '40m', '300m'] + default: '40m' qos_maps: description: - QoS maps interface configuration @@ -182,6 +189,7 @@ - id: 0 wred_profile: profile1 scheduler_policy: policy1 + cable_length: 40m qos_maps: dscp_fwd_group: dscp_map1 dot1p_fwd_group: dot1p_map1 @@ -211,6 +219,7 @@ # interface Eth1/5 # queue 0 wred-policy profile1 # scheduler-policy policy1 +# cable-length 40m # qos-map dscp-tc dscp_map1 # qos-map dot1p-tc dot1p_map1 # qos-map tc-queue fwd_queue_map1 @@ -238,6 +247,7 @@ # queue 0 wred-policy profile2 # queue 1 wred-policy profile1 # scheduler-policy policy2 +# cable-length 5m # qos-map dscp-tc dscp_map2 # qos-map dot1p-tc dot1p_map2 # qos-map tc-queue fwd_queue_map2 @@ -255,6 +265,7 @@ # interface Eth1/6 # queue 0 wred-policy profile1 # scheduler-policy policy1 +# cable-length 40m # qos-map dscp-tc dscp_map1 # qos-map dot1p-tc dot1p_map1 # qos-map tc-queue fwd_queue_map1 @@ -277,6 +288,7 @@ wred_profile: profile2 - id: 1 scheduler_policy: policy2 + cable_length: 5m qos_maps: dscp_fwd_group: dscp_map2 dot1p_fwd_group: dot1p_map2 @@ -303,6 +315,7 @@ # sonic# show running-configuration interface Eth 1/5 # ! # interface Eth1/5 +# cable-length 40m # qos-map pfc-priority-queue pfc_queue_map1 # qos-map pfc-priority-pg pfc_pg_map1 # priority-flow-control priority 1 @@ -314,6 +327,7 @@ # interface Eth1/6 # queue 0 wred-policy profile1 # scheduler-policy policy1 +# cable-length 40m # qos-map dscp-tc dscp_map1 # qos-map dot1p-tc dot1p_map1 # qos-map tc-queue fwd_queue_map1 diff --git a/tests/regression/roles/sonic_qos_interfaces/defaults/main.yml b/tests/regression/roles/sonic_qos_interfaces/defaults/main.yml index 5271784ae..66a6fbd92 100644 --- a/tests/regression/roles/sonic_qos_interfaces/defaults/main.yml +++ b/tests/regression/roles/sonic_qos_interfaces/defaults/main.yml @@ -12,6 +12,7 @@ tests: - id: 0 wred_profile: profile1 scheduler_policy: policy1 + cable_length: 40m qos_maps: dscp_fwd_group: dscp_map1 dot1p_fwd_group: dot1p_map1 @@ -43,6 +44,7 @@ tests: - id: 1 wred_profile: profile1 scheduler_policy: policy2 + cable_length: 5m qos_maps: dscp_fwd_group: dscp_map2 dot1p_fwd_group: dot1p_map2 @@ -60,6 +62,7 @@ tests: - id: 0 wred_profile: profile1 scheduler_policy: policy1 + cable_length: 40m qos_maps: dscp_fwd_group: dscp_map1 dot1p_fwd_group: dot1p_map1 @@ -105,6 +108,7 @@ tests: wred_profile: profile2 - id: 1 scheduler_policy: policy2 + cable_length: 5m qos_maps: dscp_fwd_group: dscp_map2 dot1p_fwd_group: dot1p_map2 diff --git a/tests/regression/roles/sonic_qos_interfaces/tasks/cleanup_tests.yaml b/tests/regression/roles/sonic_qos_interfaces/tasks/cleanup_tests.yaml index 9ffcb333b..4e723dac6 100644 --- a/tests/regression/roles/sonic_qos_interfaces/tasks/cleanup_tests.yaml +++ b/tests/regression/roles/sonic_qos_interfaces/tasks/cleanup_tests.yaml @@ -15,3 +15,9 @@ config: [] state: deleted ignore_errors: yes + +- name: No Buffer Init + sonic_qos_buffer: + config: + buffer_init: false + ignore_errors: yes diff --git a/tests/regression/roles/sonic_qos_interfaces/tasks/preparation_tests.yaml b/tests/regression/roles/sonic_qos_interfaces/tasks/preparation_tests.yaml index 6cb82e73f..ca4fd6ba6 100644 --- a/tests/regression/roles/sonic_qos_interfaces/tasks/preparation_tests.yaml +++ b/tests/regression/roles/sonic_qos_interfaces/tasks/preparation_tests.yaml @@ -1,3 +1,8 @@ +- name: Buffer Init + sonic_qos_buffer: + config: + buffer_init: true + - name: Delete QoS interfaces configuration sonic_qos_interfaces: config: [] diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_qos_interfaces.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_qos_interfaces.yaml index 93ec86d54..628820d87 100644 --- a/tests/unit/modules/network/sonic/fixtures/sonic_qos_interfaces.yaml +++ b/tests/unit/modules/network/sonic/fixtures/sonic_qos_interfaces.yaml @@ -8,6 +8,7 @@ merged_01: - id: 1 wred_profile: profile2 scheduler_policy: policy1 + cable_length: 5m qos_maps: dscp_fwd_group: dscp_map1 dot1p_fwd_group: dot1p_map1 @@ -45,6 +46,9 @@ merged_01: scheduler-policy: config: name: policy1 + openconfig-qos-buffer:cable-length: + config: + length: 5m pfc: config: asymmetric: true @@ -96,6 +100,7 @@ deleted_01: wred_profile: profile1 - id: 1 scheduler_policy: policy1 + cable_length: 5m qos_maps: dscp_fwd_group: dscp_map1 dot1p_fwd_group: dot1p_map1 @@ -151,6 +156,9 @@ deleted_01: pfc-priority-to-queue: pfc_queue_map1 forwarding-group-to-priority-group: fwd_pg_map1 pfc-priority-to-priority-group: pfc_pg_map1 + openconfig-qos-buffer:cable-length: + config: + length: 5m - path: '/data/openconfig-qos:qos/queues/queue' response: code: 200 @@ -217,3 +225,6 @@ deleted_01: - path: '/data/openconfig-qos:qos/interfaces/interface=Eth1%2f5/pfc/pfc-priorities/pfc-priority=0/config/enable' method: 'delete' data: + - path: '/data/openconfig-qos:qos/interfaces/interface=Eth1%2f5/openconfig-qos-buffer:cable-length' + method: 'delete' + data: