Skip to content

Commit 6483b0b

Browse files
QOS fieldvalue refernce ABNF format to string (sonic-net#1626)
Qos tables in config db and app db used ABNF format i.e "[TABLE_NAME|name] to refer fieldvalue other qos tables. Example: Config DB: "Ethernet92|3": { "scheduler": "[SCHEDULER|scheduler.1]", "wred_profile": "[WRED_PROFILE|AZURE_LOSSLESS]" }, "Ethernet0|0": { "profile": "[BUFFER_PROFILE|ingress_lossy_profile]" }, "Ethernet0": { "dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]", "pfc_enable": "3,4", "pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]", "tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]", "tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]" }, AppDB: "BUFFER_QUEUE_TABLE:Ethernet88:3-4": { "profile": "[BUFFER_PROFILE_TABLE:egress_lossless_profile]" }, 1#This format is not consistent with other DB schema followed in sonic. 2# Added db_migrator.py case to change from old format in config_db and appl_db to new format. 3#Modified the test case Dependent pull requests: sonic-net#7752 - To modify platfrom files sonic-net#7281 - Yang model sonic-net/sonic-swss#1754 - swss change to remove ABNF format
1 parent 8d16eb5 commit 6483b0b

File tree

100 files changed

+79718
-2762
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+79718
-2762
lines changed

config/main.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -3786,8 +3786,7 @@ def update_pg(ctx, interface_name, pg_map, override_profile, add = True):
37863786
ctx.fail("Profile {} doesn't exist".format(override_profile))
37873787
if not 'xoff' in profile_dict.keys() and 'size' in profile_dict.keys():
37883788
ctx.fail("Profile {} doesn't exist or isn't a lossless profile".format(override_profile))
3789-
profile_full_name = "[BUFFER_PROFILE|{}]".format(override_profile)
3790-
config_db.set_entry("BUFFER_PG", (interface_name, pg_map), {"profile": profile_full_name})
3789+
config_db.set_entry("BUFFER_PG", (interface_name, pg_map), {"profile": override_profile})
37913790
else:
37923791
config_db.set_entry("BUFFER_PG", (interface_name, pg_map), {"profile": "NULL"})
37933792
adjust_pfc_enable(ctx, interface_name, pg_map, True)
@@ -3809,7 +3808,7 @@ def remove_pg_on_port(ctx, interface_name, pg_map):
38093808
if port == interface_name and (not pg_map or pg_map == existing_pg):
38103809
need_to_remove = False
38113810
referenced_profile = v.get('profile')
3812-
if referenced_profile and referenced_profile == '[BUFFER_PROFILE|ingress_lossy_profile]':
3811+
if referenced_profile and referenced_profile == 'ingress_lossy_profile':
38133812
if pg_map:
38143813
ctx.fail("Lossy PG {} can't be removed".format(pg_map))
38153814
else:
@@ -4963,7 +4962,7 @@ def update_profile(ctx, config_db, profile_name, xon, xoff, size, dynamic_th, po
49634962

49644963
if not pool:
49654964
pool = 'ingress_lossless_pool'
4966-
params['pool'] = '[BUFFER_POOL|' + pool + ']'
4965+
params['pool'] = pool
49674966
if not config_db.get_entry('BUFFER_POOL', pool):
49684967
ctx.fail("Pool {} doesn't exist".format(pool))
49694968

@@ -5036,12 +5035,11 @@ def remove_profile(db, profile):
50365035
config_db = db.cfgdb
50375036
ctx = click.get_current_context()
50385037

5039-
full_profile_name = '[BUFFER_PROFILE|{}]'.format(profile)
50405038
existing_pgs = config_db.get_table("BUFFER_PG")
50415039
for k, v in existing_pgs.items():
50425040
port, pg = k
50435041
referenced_profile = v.get('profile')
5044-
if referenced_profile and referenced_profile == full_profile_name:
5042+
if referenced_profile and referenced_profile == profile:
50455043
ctx.fail("Profile {} is referenced by {}|{} and can't be removed".format(profile, port, pg))
50465044

50475045
entry = config_db.get_entry("BUFFER_PROFILE", profile)

scripts/db_migrator.py

+80-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, namespace, socket=None):
4444
none-zero values.
4545
build: sequentially increase within a minor version domain.
4646
"""
47-
self.CURRENT_VERSION = 'version_2_0_2'
47+
self.CURRENT_VERSION = 'version_2_0_3'
4848

4949
self.TABLE_NAME = 'VERSIONS'
5050
self.TABLE_KEY = 'DATABASE'
@@ -60,9 +60,11 @@ def __init__(self, namespace, socket=None):
6060
self.configDB = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace, **db_kwargs)
6161
self.configDB.db_connect('CONFIG_DB')
6262

63-
self.appDB = SonicV2Connector(host='127.0.0.1')
64-
if self.appDB is not None:
65-
self.appDB.connect(self.appDB.APPL_DB)
63+
if namespace is None:
64+
self.appDB = ConfigDBConnector(**db_kwargs)
65+
else:
66+
self.appDB = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace, **db_kwargs)
67+
self.appDB.db_connect('APPL_DB')
6668

6769
self.stateDB = SonicV2Connector(host='127.0.0.1')
6870
if self.stateDB is not None:
@@ -382,6 +384,69 @@ def migrate_config_db_port_table_for_auto_neg(self):
382384
elif value['autoneg'] == '0':
383385
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, key), 'autoneg', 'off')
384386

387+
def migrate_qos_db_fieldval_reference_remove(self, table_list, db, db_num, db_delimeter):
388+
for pair in table_list:
389+
table_name, fields_list = pair
390+
qos_table = db.get_table(table_name)
391+
for key, value in qos_table.items():
392+
if type(key) is tuple:
393+
db_key = table_name + db_delimeter + db_delimeter.join(key)
394+
else:
395+
db_key = table_name + db_delimeter + key
396+
397+
for field in fields_list:
398+
if field in value:
399+
fieldVal = value.get(field)
400+
if not fieldVal or fieldVal == "NULL":
401+
continue
402+
newFiledVal = ""
403+
# Check for ABNF format presence and convert ABNF to string
404+
if "[" in fieldVal and db_delimeter in fieldVal and "]" in fieldVal:
405+
log.log_info("Found ABNF format field value in table {} key {} field {} val {}".format(table_name, db_key, field, fieldVal))
406+
value_list = fieldVal.split(",")
407+
for item in value_list:
408+
if "[" != item[0] or db_delimeter not in item or "]" != item[-1]:
409+
continue
410+
newFiledVal = newFiledVal + item[1:-1].split(db_delimeter)[1] + ','
411+
newFiledVal = newFiledVal[:-1]
412+
db.set(db_num, db_key, field, newFiledVal)
413+
log.log_info("Modified ABNF format field value to string in table {} key {} field {} val {}".format(table_name, db_key, field, newFiledVal))
414+
return True
415+
416+
def migrate_qos_fieldval_reference_format(self):
417+
'''
418+
This is to change for first time to remove field refernces of ABNF format
419+
in APPL DB for warm boot.
420+
i.e "[Tabale_name:name]" to string in APPL_DB. Reasons for doing this
421+
- To consistent with all other SoNIC CONFIG_DB/APPL_DB tables and fields
422+
- References in DB is not required, this will be taken care by YANG model leafref.
423+
'''
424+
qos_app_table_list = [
425+
('BUFFER_PG_TABLE', ['profile']),
426+
('BUFFER_QUEUE_TABLE', ['profile']),
427+
('BUFFER_PROFILE_TABLE', ['pool']),
428+
('BUFFER_PORT_INGRESS_PROFILE_LIST_TABLE', ['profile_list']),
429+
('BUFFER_PORT_EGRESS_PROFILE_LIST_TABLE', ['profile_list'])
430+
]
431+
432+
log.log_info("Remove APPL_DB QOS tables field reference ABNF format")
433+
self.migrate_qos_db_fieldval_reference_remove(qos_app_table_list, self.appDB, self.appDB.APPL_DB, ':')
434+
435+
qos_table_list = [
436+
('QUEUE', ['scheduler', 'wred_profile']),
437+
('PORT_QOS_MAP', ['dscp_to_tc_map', 'dot1p_to_tc_map',
438+
'pfc_to_queue_map', 'tc_to_pg_map',
439+
'tc_to_queue_map', 'pfc_to_pg_map']),
440+
('BUFFER_PG', ['profile']),
441+
('BUFFER_QUEUE', ['profile']),
442+
('BUFFER_PROFILE', ['pool']),
443+
('BUFFER_PORT_INGRESS_PROFILE_LIST', ['profile_list']),
444+
('BUFFER_PORT_EGRESS_PROFILE_LIST', ['profile_list'])
445+
]
446+
log.log_info("Remove CONFIG_DB QOS tables field reference ABNF format")
447+
self.migrate_qos_db_fieldval_reference_remove(qos_table_list, self.configDB, self.configDB.CONFIG_DB, '|')
448+
return True
449+
385450
def version_unknown(self):
386451
"""
387452
version_unknown tracks all SONiC versions that doesn't have a version
@@ -542,9 +607,19 @@ def version_2_0_1(self):
542607

543608
def version_2_0_2(self):
544609
"""
545-
Current latest version. Nothing to do here.
610+
Version 2_0_2.
546611
"""
547612
log.log_info('Handling version_2_0_2')
613+
self.migrate_qos_fieldval_reference_format()
614+
self.set_version('version_2_0_3')
615+
return 'version_2_0_3'
616+
617+
618+
def version_2_0_3(self):
619+
"""
620+
Current latest version. Nothing to do here.
621+
"""
622+
log.log_info('Handling version_2_0_3')
548623
return None
549624

550625
def get_version(self):

tests/buffer_input/buffer_test_vectors.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@
3131
---- -------
3232
3333
Profile: ingress_lossy_profile
34-
---------- --------------------------------
34+
---------- ------------------
3535
dynamic_th 3
36-
pool [BUFFER_POOL|ingress_lossy_pool]
36+
pool ingress_lossy_pool
3737
size 0
38-
---------- --------------------------------
38+
---------- ------------------
3939
4040
Profile: headroom_profile
41-
---------- -----------------------------------
41+
---------- ---------------------
4242
dynamic_th 0
43-
pool [BUFFER_POOL|ingress_lossless_pool]
43+
pool ingress_lossless_pool
4444
xon 18432
4545
xoff 32768
4646
size 51200
47-
---------- -----------------------------------
47+
---------- ---------------------
4848
4949
Profile: alpha_profile
50-
------------- -----------------------------------
50+
------------- ---------------------
5151
dynamic_th 0
52-
pool [BUFFER_POOL|ingress_lossless_pool]
52+
pool ingress_lossless_pool
5353
headroom_type dynamic
54-
------------- -----------------------------------
54+
------------- ---------------------
5555
5656
"""
5757

@@ -85,20 +85,20 @@
8585
---- -------
8686
8787
Profile: ingress_lossy_profile
88-
---------- --------------------------------------
88+
---------- ------------------
8989
dynamic_th 3
90-
pool [BUFFER_POOL_TABLE|ingress_lossy_pool]
90+
pool ingress_lossy_pool
9191
size 0
92-
---------- --------------------------------------
92+
---------- ------------------
9393
9494
Profile: headroom_profile
95-
---------- -----------------------------------------
95+
---------- ---------------------
9696
dynamic_th 0
97-
pool [BUFFER_POOL_TABLE|ingress_lossless_pool]
97+
pool ingress_lossless_pool
9898
xon 18432
9999
xoff 32768
100100
size 51200
101-
---------- -----------------------------------------
101+
---------- ---------------------
102102
103103
"""
104104

tests/buffer_test.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_config_buffer_profile_headroom(self):
3434
print(result.output)
3535
assert result.exit_code == 0
3636
profile = db.cfgdb.get_entry('BUFFER_PROFILE', 'testprofile')
37-
assert profile == {'dynamic_th': '3', 'pool': '[BUFFER_POOL|ingress_lossless_pool]', 'xon': '18432', 'xoff': '32768', 'size': '18432'}
37+
assert profile == {'dynamic_th': '3', 'pool': 'ingress_lossless_pool', 'xon': '18432', 'xoff': '32768', 'size': '18432'}
3838

3939
def test_config_buffer_profile_dynamic_th(self):
4040
runner = CliRunner()
@@ -45,7 +45,7 @@ def test_config_buffer_profile_dynamic_th(self):
4545
print(result.output)
4646
assert result.exit_code == 0
4747
profile = db.cfgdb.get_entry('BUFFER_PROFILE', 'testprofile')
48-
assert profile == {'dynamic_th': '3', 'pool': '[BUFFER_POOL|ingress_lossless_pool]', 'headroom_type': 'dynamic'}
48+
assert profile == {'dynamic_th': '3', 'pool': 'ingress_lossless_pool', 'headroom_type': 'dynamic'}
4949

5050
def test_config_buffer_profile_add_existing(self):
5151
runner = CliRunner()
@@ -164,7 +164,7 @@ def test_config_buffer_profile_headroom_toggle_shp(self):
164164
print(result.output)
165165
assert result.exit_code == 0
166166
profile = db.cfgdb.get_entry('BUFFER_PROFILE', 'test1')
167-
assert profile == {'dynamic_th': '3', 'pool': '[BUFFER_POOL|ingress_lossless_pool]', 'xon': '18432', 'xoff': '32768', 'size': '51200'}
167+
assert profile == {'dynamic_th': '3', 'pool': 'ingress_lossless_pool', 'xon': '18432', 'xoff': '32768', 'size': '51200'}
168168

169169
# Xoff should equal size - xon
170170
result = runner.invoke(config.config.commands["buffer"].commands["profile"].commands["add"],
@@ -173,7 +173,7 @@ def test_config_buffer_profile_headroom_toggle_shp(self):
173173
print(result.output)
174174
assert result.exit_code == 0
175175
profile = db.cfgdb.get_entry('BUFFER_PROFILE', 'test2')
176-
assert profile == {'dynamic_th': '3', 'pool': '[BUFFER_POOL|ingress_lossless_pool]', 'xon': '18432', 'xoff': '14336', 'size': '32768'}
176+
assert profile == {'dynamic_th': '3', 'pool': 'ingress_lossless_pool', 'xon': '18432', 'xoff': '14336', 'size': '32768'}
177177

178178
# Neither xon nor size is provided
179179
result = runner.invoke(config.config.commands["buffer"].commands["profile"].commands["add"],
@@ -198,7 +198,7 @@ def test_config_buffer_profile_headroom_toggle_shp(self):
198198
print(result.output)
199199
assert result.exit_code == 0
200200
profile = db.cfgdb.get_entry('BUFFER_PROFILE', 'test2')
201-
assert profile == {'dynamic_th': '3', 'pool': '[BUFFER_POOL|ingress_lossless_pool]', 'xon': '18432', 'xoff': '14336', 'size': '65536'}
201+
assert profile == {'dynamic_th': '3', 'pool': 'ingress_lossless_pool', 'xon': '18432', 'xoff': '14336', 'size': '65536'}
202202

203203
# Set xon
204204
result = runner.invoke(config.config.commands["buffer"].commands["profile"].commands["set"],
@@ -207,7 +207,7 @@ def test_config_buffer_profile_headroom_toggle_shp(self):
207207
print(result.output)
208208
assert result.exit_code == 0
209209
profile = db.cfgdb.get_entry('BUFFER_PROFILE', 'test2')
210-
assert profile == {'dynamic_th': '3', 'pool': '[BUFFER_POOL|ingress_lossless_pool]', 'xon': '19456', 'xoff': '14336', 'size': '65536'}
210+
assert profile == {'dynamic_th': '3', 'pool': 'ingress_lossless_pool', 'xon': '19456', 'xoff': '14336', 'size': '65536'}
211211

212212
# Set xoff
213213
result = runner.invoke(config.config.commands["buffer"].commands["profile"].commands["set"],
@@ -216,7 +216,7 @@ def test_config_buffer_profile_headroom_toggle_shp(self):
216216
print(result.output)
217217
assert result.exit_code == 0
218218
profile = db.cfgdb.get_entry('BUFFER_PROFILE', 'test2')
219-
assert profile == {'dynamic_th': '3', 'pool': '[BUFFER_POOL|ingress_lossless_pool]', 'xon': '19456', 'xoff': '18432', 'size': '65536'}
219+
assert profile == {'dynamic_th': '3', 'pool': 'ingress_lossless_pool', 'xon': '19456', 'xoff': '18432', 'size': '65536'}
220220

221221
# Enable SHP by setting size
222222
result = runner.invoke(config.config.commands["buffer"].commands["shared-headroom-pool"].commands["size"],
@@ -232,7 +232,7 @@ def test_config_buffer_profile_headroom_toggle_shp(self):
232232
print(result.output)
233233
assert result.exit_code == 0
234234
profile = db.cfgdb.get_entry('BUFFER_PROFILE', 'testprofile3')
235-
assert profile == {'dynamic_th': '3', 'pool': '[BUFFER_POOL|ingress_lossless_pool]', 'xon': '18432', 'xoff': '32768', 'size': '18432'}
235+
assert profile == {'dynamic_th': '3', 'pool': 'ingress_lossless_pool', 'xon': '18432', 'xoff': '32768', 'size': '18432'}
236236

237237
# Negative test: xoff not provided
238238
result = runner.invoke(config.config.commands["buffer"].commands["profile"].commands["add"],

0 commit comments

Comments
 (0)