Skip to content

Commit 40431a6

Browse files
authored
Merge pull request #358 from mssonicbld/sonicbld/202603-merge
```<br>* baf758f - (HEAD -> 202603) Merge branch '202511' of https://github.com/sonic-net/sonic-utilities into 202603 (2026-06-03) [Sonic Automation] * ae048e7 - (origin/202511) Add remove operation for buffer_profile if remove entire profile. (#4585) (2026-06-03) [mssonicbld]<br>```
2 parents 01870b0 + baf758f commit 40431a6

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

generic_config_updater/field_operation_validators.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,30 @@ def rdma_config_update_validator(scope, patch_element):
171171

172172

173173
def buffer_profile_config_update_validator(scope, patch_element):
174+
"""
175+
Enhanced buffer profile validator that handles both field-level and object-level operations.
176+
- Field-level operations (e.g., /BUFFER_PROFILE/profile/dynamic_th) follow existing rules
177+
- Object-level operations (e.g., /BUFFER_PROFILE/profile) allow remove operations
178+
"""
179+
path = patch_element["path"]
180+
path_parts = jsonpointer.JsonPointer(path).parts
181+
182+
# Determine if this is an object-level operation (entire profile) or field-level operation
183+
# Object-level: /BUFFER_PROFILE/profile_name (2 parts)
184+
# Field-level: /BUFFER_PROFILE/profile_name/field_name (3+ parts)
185+
is_object_level = len(path_parts) == 2 # table + profile_name only
186+
187+
if is_object_level:
188+
# For object-level operations, we're more permissive
189+
# Allow add/remove/replace operations for entire profile objects
190+
allowed_object_operations = ['add', 'remove', 'replace']
191+
192+
if patch_element['op'] in allowed_object_operations:
193+
return True # Allow object-level operations
194+
else:
195+
return False # Disallow unsupported operations
196+
197+
# For field-level operations, use the existing validation logic
174198
return rdma_config_update_validator_common(scope, patch_element)
175199

176200

tests/generic_config_updater/field_operation_validator_test.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,50 @@ def test_buffer_profile_config_update_validator(self, scope, asic, field, value,
273273
):
274274
assert fov.buffer_profile_config_update_validator(scope, patch_element) is True
275275

276+
def test_buffer_profile_config_update_validator_object_level_remove(self):
277+
"""Test that object-level remove operations are allowed (fixes rollback issue)"""
278+
patch_element = {
279+
"path": "/BUFFER_PROFILE/pg_lossless_40000_5m_profile",
280+
"op": "remove"
281+
}
282+
283+
# Object-level remove should be allowed without ASIC/version validation
284+
assert fov.buffer_profile_config_update_validator("localhost", patch_element) is True
285+
286+
def test_buffer_profile_config_update_validator_object_level_add(self):
287+
"""Test that object-level add operations are allowed"""
288+
patch_element = {
289+
"path": "/BUFFER_PROFILE/new_profile",
290+
"op": "add",
291+
"value": {"size": "1024", "pool": "ingress_lossless_pool"}
292+
}
293+
294+
# Object-level add should be allowed
295+
assert fov.buffer_profile_config_update_validator("localhost", patch_element) is True
296+
297+
def test_buffer_profile_config_update_validator_object_level_unsupported_op(self):
298+
"""Test that unsupported operations on object-level are denied"""
299+
patch_element = {
300+
"path": "/BUFFER_PROFILE/my_profile",
301+
"op": "move", # Unsupported operation
302+
"from": "/BUFFER_PROFILE/old_profile"
303+
}
304+
305+
assert fov.buffer_profile_config_update_validator("localhost", patch_element) is False
306+
307+
def test_buffer_profile_config_update_validator_field_level_uses_existing_validation(self):
308+
"""Test that field-level operations use existing validation logic"""
309+
patch_element = {
310+
"path": "/BUFFER_PROFILE/my_profile/dynamic_th",
311+
"op": "replace",
312+
"value": "2"
313+
}
314+
315+
# Mock the existing validation to return True
316+
with patch("generic_config_updater.field_operation_validators.rdma_config_update_validator_common",
317+
return_value=True):
318+
assert fov.buffer_profile_config_update_validator("localhost", patch_element) is True
319+
276320
@patch("sonic_py_common.device_info.get_sonic_version_info",
277321
mock.Mock(return_value={"build_version": "SONiC.20220530"}))
278322
@patch("generic_config_updater.field_operation_validators.get_asic_name",

0 commit comments

Comments
 (0)