Skip to content

[GCU] apply-patch failed to get token from 'using' group #2041

@wen587

Description

@wen587

Description

When apply-patch a json file which yang has grouping member, the method cannot grab token.

Steps to reproduce the issue

  1. bgp-monitor.yang has member that defined in sonic-bgp-common.yang
    https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/yang-models/sonic-bgp-monitor.yang#L43
  2. When apply-patch, it failed to grab token.
admin@vlab-01:~$ sudo config apply-patch -i /FEATURE -i /QUEUE -i /SCHEDULER bgpl/add.json
Patch Applier: Patch application starting.
Patch Applier: Patch: [{"op": "add", "path": "/BGP_MONITORS", "value": {"11.0.0.1": {"admin_status": "up", "asn": "65100", "holdtime": "10", "keepalive": "3", "local_addr": "10.1.0.32", "name": "BGPMonitor", "nhopself": "0", "rrclient": "0"}}}]
...
Failed to apply patch
Usage: config apply-patch [OPTIONS] PATCH_FILE_PATH
Try "config apply-patch -h" for help.

Error: Token not found 
  1. some debug info when error occur in https://github.com/Azure/sonic-utilities/blob/master/generic_config_updater/gu_common.py#L551
    raise ValueError("Token not found model {} token_index {} path_tokens {}".format(model, token_index, path_tokens))
    The token is only got from leaf not from using
model OrderedDict([('@name', 'BGP_MONITORS_LIST'), 
('key', OrderedDict([('@value', 'addr')])), 
('description', OrderedDict([('text', 'This list is to support BGP monitor configuration handled by bgpcfgd')])), 
('leaf', OrderedDict([('@name', 'addr'), ('type', OrderedDict([('@name', 'inet:ip-address')])), 
('description', OrderedDict([('text', 'BGP monitor address')])), ('__isleafList', False)])), 

('uses', OrderedDict([('@name', 'bgpcmn:sonic-bgp-cmn-neigh'),    <===================================================

('refine', OrderedDict([('@target-node', 'name'), 
('must', OrderedDict([('@condition', "current() = 'BGPMonitor'"), 
('error-message', OrderedDict([('value', 'Invalid BGP monitor name')]))]))]))]))]) 
token_index 2 path_tokens ['BGP_MONITORS', '11.0.0.1', 'asn']

Describe the results you received

See above.

Describe the results you expected

Fix in two ways:

  1. We don't using grouping in Yang such that bgp-monitor has all member defined in itself.
  2. Handle using keyword in yang model.

Additional information you deem important (e.g. issue happens only occasionally)

Output of show version

(paste your output here)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions