Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions generic_config_updater/field_operation_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def rdma_config_update_validator(scope, patch_element):
return rdma_config_update_validator_common(scope, patch_element, exact_field_match=True, remove_port=True)


def buffer_profile_config_update_validator(scope, patch_element):
return rdma_config_update_validator_common(scope, patch_element)


def wred_profile_config_update_validator(scope, patch_element):
return rdma_config_update_validator_common(scope, patch_element)

Expand Down
26 changes: 23 additions & 3 deletions generic_config_updater/gcu_field_operation_validators.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,18 @@
}
},
"BUFFER_PROFILE": {
"field_operation_validators": [ "generic_config_updater.field_operation_validators.rdma_config_update_validator" ],
"field_operation_validators": [
"generic_config_updater.field_operation_validators.buffer_profile_config_update_validator"
],
"validator_data": {
"rdma_config_update_validator": {
"Dynamic threshold tuning": {
"fields": [
"dynamic_th"
],
"operations": ["replace"],
"operations": [
"replace"
],
"platforms": {
"spc1": "20181100",
"spc2": "20191100",
Expand All @@ -144,7 +148,9 @@
"fields": [
"xoff"
],
"operations": ["replace"],
"operations": [
"replace"
],
"platforms": {
"spc1": "20191100",
"spc2": "20191100",
Expand All @@ -163,6 +169,20 @@
"j2c+": "20220500",
"cisco-8000": "20201200"
}
},
"Packet trimming eligibility modification": {
"fields": [
"packet_discard_action"
],
"operations": [
"add",
"replace"
],
"platforms": {
"spc4": "20241200",
"spc5": "20241200",
"th5": "20241200"
}
}
}
}
Expand Down
50 changes: 45 additions & 5 deletions tests/generic_config_updater/field_operation_validator_test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import pytest
import mock
import unittest
import generic_config_updater
import generic_config_updater.field_operation_validators as fov
import generic_config_updater.gu_common as gu_common

from unittest.mock import MagicMock, Mock, mock_open
from unittest.mock import mock_open
from mock import patch
from sonic_py_common.device_info import get_hwsku, get_sonic_version_info


class TestValidateFieldOperation(unittest.TestCase):
class TestValidateFieldOperation:

@patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value=""))
def test_port_config_update_validator_valid_speed_no_state_db(self):
Expand Down Expand Up @@ -233,6 +233,46 @@ def test_rdma_config_update_validator_td3_asic_invalid_version(self):
assert generic_config_updater.field_operation_validators.\
rdma_config_update_validator(scope, patch_element) is False

@pytest.mark.parametrize(
"field,value,op", [
pytest.param("xoff", "1000", "replace"),
pytest.param("dynamic_th", "0", "replace"),
pytest.param("packet_discard_action", "trim", "add"),
pytest.param("packet_discard_action", "drop", "replace")
]
)
@pytest.mark.parametrize(
"asic", [
"spc4",
"spc5",
"th5"
]
)
@pytest.mark.parametrize(
"scope", [
"localhost",
"asic0"
]
)
def test_buffer_profile_config_update_validator(self, scope, asic, field, value, op):
patch_element = {
"path": "/BUFFER_PROFILE/sample_profile/{}".format(field),
"op": op,
"value": value
}

with (
patch(
"generic_config_updater.field_operation_validators.get_asic_name",
return_value=asic
),
patch(
"sonic_py_common.device_info.get_sonic_version_info",
return_value={"build_version": "SONiC.20241200"}
)
):
assert fov.buffer_profile_config_update_validator(scope, patch_element) is True

@patch("sonic_py_common.device_info.get_sonic_version_info",
mock.Mock(return_value={"build_version": "SONiC.20220530"}))
@patch("generic_config_updater.field_operation_validators.get_asic_name",
Expand Down Expand Up @@ -453,7 +493,7 @@ def test_validate_field_operation_illegal__pfcwd(self):
old_config = {"PFC_WD": {"GLOBAL": {"POLL_INTERVAL": "60"}}}
target_config = {"PFC_WD": {"GLOBAL": {}}}
config_wrapper = gu_common.ConfigWrapper()
self.assertRaises(
pytest.raises(
gu_common.IllegalPatchOperationError,
config_wrapper.validate_field_operation,
old_config,
Expand Down Expand Up @@ -494,7 +534,7 @@ def test_validate_field_operation_illegal__rm_loopback0(self):
}
}
config_wrapper = gu_common.ConfigWrapper()
self.assertRaises(
pytest.raises(
gu_common.IllegalPatchOperationError,
config_wrapper.validate_field_operation,
old_config,
Expand Down
Loading