From 43aec133da3e372c3cc387e4befe3c927b7a8aea Mon Sep 17 00:00:00 2001 From: Neetha John Date: Fri, 24 Mar 2023 10:41:48 -0700 Subject: [PATCH] [202012] [qos] Update RDMA-CENTRIC lossy profile to use static threshold for Th devices (#14398) Backport #14372 to 202012 Why I did it For better accounting purposes, updating the ingress lossy traffic profile to use static threshold. This change is only intended for Th devices using RDMA-CENTRIC profiles How I did it Update the buffer templates for Th devices in RDMA-CENTRIC folder to use the correct threshold Signed-off-by: Neetha John --- .../6100/RDMA-CENTRIC/buffers_defaults_t0.j2 | 2 +- .../6100/RDMA-CENTRIC/buffers_defaults_t1.j2 | 2 +- .../gen/RDMA-CENTRIC/buffers_defaults_t0.j2 | 2 +- .../gen/RDMA-CENTRIC/buffers_defaults_t1.j2 | 2 +- src/sonic-config-engine/minigraph.py | 16 +++++++-- .../tests/sample-dell-6100-t0-minigraph.xml | 10 +++--- .../sample_output/py2/buffers-dell6100.json | 2 +- .../sample_output/py3/buffers-dell6100.json | 2 +- src/sonic-config-engine/tests/test_j2files.py | 33 ++++++++++++++++--- 9 files changed, 54 insertions(+), 17 deletions(-) diff --git a/device/common/profiles/th/6100/RDMA-CENTRIC/buffers_defaults_t0.j2 b/device/common/profiles/th/6100/RDMA-CENTRIC/buffers_defaults_t0.j2 index ed5c9deac0..813ee0f48c 100644 --- a/device/common/profiles/th/6100/RDMA-CENTRIC/buffers_defaults_t0.j2 +++ b/device/common/profiles/th/6100/RDMA-CENTRIC/buffers_defaults_t0.j2 @@ -26,7 +26,7 @@ "ingress_lossy_profile": { "pool":"[BUFFER_POOL|ingress_lossless_pool]", "size":"0", - "dynamic_th":"3" + "static_th":"10875072" }, "egress_lossless_profile": { "pool":"[BUFFER_POOL|egress_lossless_pool]", diff --git a/device/common/profiles/th/6100/RDMA-CENTRIC/buffers_defaults_t1.j2 b/device/common/profiles/th/6100/RDMA-CENTRIC/buffers_defaults_t1.j2 index f1a4c9c2e2..14ef68e3ec 100644 --- a/device/common/profiles/th/6100/RDMA-CENTRIC/buffers_defaults_t1.j2 +++ b/device/common/profiles/th/6100/RDMA-CENTRIC/buffers_defaults_t1.j2 @@ -26,7 +26,7 @@ "ingress_lossy_profile": { "pool":"[BUFFER_POOL|ingress_lossless_pool]", "size":"0", - "dynamic_th":"3" + "static_th":"10875072" }, "egress_lossless_profile": { "pool":"[BUFFER_POOL|egress_lossless_pool]", diff --git a/device/common/profiles/th/gen/RDMA-CENTRIC/buffers_defaults_t0.j2 b/device/common/profiles/th/gen/RDMA-CENTRIC/buffers_defaults_t0.j2 index c671233a02..3be881c5b4 100644 --- a/device/common/profiles/th/gen/RDMA-CENTRIC/buffers_defaults_t0.j2 +++ b/device/common/profiles/th/gen/RDMA-CENTRIC/buffers_defaults_t0.j2 @@ -25,7 +25,7 @@ "ingress_lossy_profile": { "pool":"[BUFFER_POOL|ingress_lossless_pool]", "size":"0", - "dynamic_th":"3" + "static_th":"10875072" }, "egress_lossless_profile": { "pool":"[BUFFER_POOL|egress_lossless_pool]", diff --git a/device/common/profiles/th/gen/RDMA-CENTRIC/buffers_defaults_t1.j2 b/device/common/profiles/th/gen/RDMA-CENTRIC/buffers_defaults_t1.j2 index 11aab2cabd..8c9550c48d 100644 --- a/device/common/profiles/th/gen/RDMA-CENTRIC/buffers_defaults_t1.j2 +++ b/device/common/profiles/th/gen/RDMA-CENTRIC/buffers_defaults_t1.j2 @@ -25,7 +25,7 @@ "ingress_lossy_profile": { "pool":"[BUFFER_POOL|ingress_lossless_pool]", "size":"0", - "dynamic_th":"3" + "static_th":"10875072" }, "egress_lossless_profile": { "pool":"[BUFFER_POOL|egress_lossless_pool]", diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index fd8cc06ca1..ac4fcf7e92 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -5,6 +5,7 @@ import math import os import sys import json +import subprocess from collections import defaultdict from lxml import etree as ET @@ -62,6 +63,10 @@ class minigraph_encoder(json.JSONEncoder): return str(obj) return json.JSONEncoder.default(self, obj) +def exec_cmd(cmd): + p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE) + outs, errs = p.communicate() + def get_peer_switch_info(link_metadata, devices): peer_switch_table = {} peer_switch_ip = None @@ -1162,7 +1167,14 @@ def select_mmu_profiles(profile, platform, hwsku): files_to_copy = ['pg_profile_lookup.ini', 'qos.json.j2', 'buffers_defaults_t0.j2', 'buffers_defaults_t1.j2'] - path = os.path.join('/usr/share/sonic/device', platform, hwsku) + if os.environ.get("CFGGEN_UNIT_TESTING", "0") == "2": + for dir_path, dir_name, files in os.walk('/sonic/device'): + if platform in dir_path: + new_path = os.path.split(dir_path)[0] + break + else: + new_path = '/usr/share/sonic/device' + path = os.path.join(new_path, platform, hwsku) dir_path = os.path.join(path, profile) if os.path.exists(dir_path): @@ -1170,7 +1182,7 @@ def select_mmu_profiles(profile, platform, hwsku): file_in_dir = os.path.join(dir_path, file_item) if os.path.isfile(file_in_dir): base_file = os.path.join(path, file_item) - exec_cmd("sudo cp {} {}".format(file_in_dir, base_file)) + exec_cmd(["sudo", "cp", file_in_dir, base_file]) ############################################################################### # diff --git a/src/sonic-config-engine/tests/sample-dell-6100-t0-minigraph.xml b/src/sonic-config-engine/tests/sample-dell-6100-t0-minigraph.xml index cb84ce744e..fef3526bee 100644 --- a/src/sonic-config-engine/tests/sample-dell-6100-t0-minigraph.xml +++ b/src/sonic-config-engine/tests/sample-dell-6100-t0-minigraph.xml @@ -716,6 +716,11 @@ 10.0.0.16 + + SonicQosProfile + + RDMA-CENTRIC + @@ -731,11 +736,6 @@ True - - SonicQosProfile - - RDMA-CENTRIC - ARISTA01T1:Ethernet1;s6100-dev-1:fortyGigE1/1/1 diff --git a/src/sonic-config-engine/tests/sample_output/py2/buffers-dell6100.json b/src/sonic-config-engine/tests/sample_output/py2/buffers-dell6100.json index 4636c38382..8c933783b4 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/buffers-dell6100.json +++ b/src/sonic-config-engine/tests/sample_output/py2/buffers-dell6100.json @@ -93,7 +93,7 @@ "ingress_lossy_profile": { "pool":"[BUFFER_POOL|ingress_lossless_pool]", "size":"0", - "dynamic_th":"3" + "static_th":"10875072" }, "egress_lossless_profile": { "pool":"[BUFFER_POOL|egress_lossless_pool]", diff --git a/src/sonic-config-engine/tests/sample_output/py3/buffers-dell6100.json b/src/sonic-config-engine/tests/sample_output/py3/buffers-dell6100.json index a292c00b19..0c8bb58d30 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/buffers-dell6100.json +++ b/src/sonic-config-engine/tests/sample_output/py3/buffers-dell6100.json @@ -93,7 +93,7 @@ "ingress_lossy_profile": { "pool":"[BUFFER_POOL|ingress_lossless_pool]", "size":"0", - "dynamic_th":"3" + "static_th":"10875072" }, "egress_lossless_profile": { "pool":"[BUFFER_POOL|egress_lossless_pool]", diff --git a/src/sonic-config-engine/tests/test_j2files.py b/src/sonic-config-engine/tests/test_j2files.py index f3d64f2474..cbfa58fa57 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -244,14 +244,18 @@ class TestJ2Files(TestCase): self._test_qos_render_template('dell', 'x86_64-dellemc_z9332f_d1508-r0', 'DellEMC-Z9332f-O32', 'sample-dell-9332-t1-minigraph.xml', 'qos-dell9332.json') def test_qos_dell6100_render_template(self): - self._test_qos_render_template('dell', 'x86_64-dell_s6100_c2538-r0', 'Force10-S6100', 'sample-dell-6100-t0-minigraph.xml', 'qos-dell6100.json') + self._test_qos_render_template('dell', 'x86_64-dell_s6100_c2538-r0', 'Force10-S6100', 'sample-dell-6100-t0-minigraph.xml', 'qos-dell6100.json', copy_files=True) def test_qos_arista7260_render_template(self): self._test_qos_render_template('arista', 'x86_64-arista_7260cx3_64', 'Arista-7260CX3-D96C16', 'sample-arista-7260-t1-minigraph-remap-disabled.xml', 'qos-arista7260.json') - def _test_qos_render_template(self, vendor, platform, sku, minigraph, expected): + def _test_qos_render_template(self, vendor, platform, sku, minigraph, expected, copy_files=False): file_exist, dir_exist = self.create_machine_conf(platform, vendor) dir_path = os.path.join(self.test_dir, '..', '..', '..', 'device', vendor, platform, sku) + + if copy_files: + self.copy_mmu_templates(dir_path, revert=False) + qos_file = os.path.join(dir_path, 'qos.json.j2') port_config_ini_file = os.path.join(dir_path, 'port_config.ini') @@ -266,6 +270,8 @@ class TestJ2Files(TestCase): # cleanup qos_config_file_new = os.path.join(dir_path, 'qos_config.j2') os.remove(qos_config_file_new) + if copy_files: + self.copy_mmu_templates(dir_path, revert=True) self.remove_machine_conf(file_exist, dir_exist) @@ -273,7 +279,7 @@ class TestJ2Files(TestCase): assert utils.cmp(sample_output_file, self.output_file) def test_buffers_dell6100_render_template(self): - self._test_buffers_render_template('dell', 'x86_64-dell_s6100_c2538-r0', 'Force10-S6100', 'sample-dell-6100-t0-minigraph.xml', 'buffers.json.j2', 'buffers-dell6100.json') + self._test_buffers_render_template('dell', 'x86_64-dell_s6100_c2538-r0', 'Force10-S6100', 'sample-dell-6100-t0-minigraph.xml', 'buffers.json.j2', 'buffers-dell6100.json', copy_files=True) def test_buffers_mellanox2700_render_template(self): # Mellanox buffer template rendering for single ingress pool mode @@ -314,9 +320,26 @@ class TestJ2Files(TestCase): assert utils.cmp(config_sample_output_file, config_test_output) os.remove(config_test_output) - def _test_buffers_render_template(self, vendor, platform, sku, minigraph, buffer_template, expected): + def copy_mmu_templates(self, dir_path, revert=False): + files_to_copy = ['pg_profile_lookup.ini', 'qos.json.j2', 'buffers_defaults_t0.j2', 'buffers_defaults_t1.j2'] + + for file_name in files_to_copy: + src_file = os.path.join(dir_path, file_name) + dst_file = os.path.join(self.test_dir, file_name) + + if not revert: + shutil.copy2(src_file, dst_file) + else: + shutil.copy2(dst_file, src_file) + os.remove(dst_file) + + def _test_buffers_render_template(self, vendor, platform, sku, minigraph, buffer_template, expected, copy_files=False): file_exist, dir_exist = self.create_machine_conf(platform, vendor) dir_path = os.path.join(self.test_dir, '..', '..', '..', 'device', vendor, platform, sku) + + if copy_files: + self.copy_mmu_templates(dir_path, revert=False) + buffers_file = os.path.join(dir_path, buffer_template) port_config_ini_file = os.path.join(dir_path, 'port_config.ini') @@ -346,6 +369,8 @@ class TestJ2Files(TestCase): diff = diff + str(self.run_diff(sample_output_file, self.output_file)) os.remove(os.path.join(out_file_dir, expected_files[1])) + if copy_files: + self.copy_mmu_templates(dir_path, revert=True) assert match, diff