Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scope to field validator. #3675

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

xincunli-sonic
Copy link
Contributor

@xincunli-sonic xincunli-sonic commented Dec 11, 2024

What I did

This is for fix issue:sonic-net/sonic-buildimage#20379

How I did it

For field_operation_validators, add scope if need read state_db.

How to verify it

admin@str2-7250-lc1-2:~$ sonic-db-cli STATE_DB -n asic0 hget "PORT_TABLE|Ethernet0" supported_fecs
none,rs

admin@str2-7250-lc1-2:~$ cat fec.json 
[
    {
        "op": "add",
        "path": "/asic0/PORT/Ethernet0/fec",
        "value": "fc"
    }
]

admin@str2-7250-lc1-2:~$ sudo config apply-patch fec.json 
Patch Applier: asic0: Patch application starting.
Patch Applier: asic0: Patch: [{"op": "add", "path": "/PORT/Ethernet0/fec", "value": "fc"}]
Patch Applier: asic0 getting current config db.
Patch Applier: asic0: simulating the target full config after applying the patch.
Patch Applier: asic0: validating all JsonPatch operations are permitted on the specified fields
Failed to apply patch due to: Failed to apply patch on the following scopes:
- asic0: Modification of PORT table is illegal- validating function generic_config_updater.field_operation_validators.port_config_update_validator returned False
Usage: config apply-patch [OPTIONS] PATCH_FILE_PATH
Try "config apply-patch -h" for help.

Error: Failed to apply patch on the following scopes:
- asic0: Modification of PORT table is illegal- validating function generic_config_updater.field_operation_validators.port_config_update_validator returned False

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

@xincunli-sonic xincunli-sonic requested review from isabelmsft, wen587, qiluo-msft and judyjoseph and removed request for isabelmsft December 11, 2024 05:59
@@ -189,7 +189,7 @@ def _invoke_validating_function(cmd, jsonpatch_element):
raise GenericConfigUpdaterError("Attempting to call invalid method {} in module {}. Module must be generic_config_updater.field_operation_validators, and method must be a defined validator".format(method_name, module_name))
module = importlib.import_module(module_name, package=None)
method_to_call = getattr(module, method_name)
return method_to_call(jsonpatch_element)
return method_to_call(self.scope, jsonpatch_element)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a temp function, should we define the self.scope outside this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants