Skip to content

[init_cfg.json][YANG] The initial configuration /etc/sonic/init_cfg.json does not pass YANG validation #9598

Open
@stepanblyschak

Description

@stepanblyschak

Description

The init_cfg.json does not pass YANG validation due to:

Value "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}" does not satisfy the constraint "enabled|disabled|always_enabled|always_disabled" (range, length, or pattern).

Steps to reproduce the issue:

There is no user interface flow to reproduce it, but it is going to be sonic-package-manager (sonic-net/sonic-utilities#1650). With sonic-net/sonic-utilities#1650 the SONiC build will fail due to invalid init_cfg.json.

Simple steps to reproduce:

admin@r-boxer-sw01:~$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from config.config_mgmt import ConfigMgmt
>>> mgmt = ConfigMgmt(source='/etc/sonic/init_cfg.json')
Note: Below table(s) have no YANG models:
WJH, WJH_CHANNEL,
libyang[0]: Value "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}" does not satisfy the
constraint "enabled|disabled|always_enabled|always_disabled" (range, length, or pattern). (path: /sonic-feature:sonic-feature/FEATURE/FEATURE_LIST[name='dhcp_relay']/state)
sonic_yang(3):Data Loading Failed:Value "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}" does not satisfy the constraint "enabled|disabled|always_enabled|always_disabled" (range, length, or pattern).
Data Loading Failed
Value "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}" does not satisfy the constraint "enabled|disabled|always_enabled|always_disabled" (range, length, or pattern).
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/sonic_yang_ext.py", line 1065, in loadData
    self.root = self.ctx.parse_data_mem(dumps(self.xlateJson), \
  File "/usr/lib/python3/dist-packages/yang.py", line 2604, in parse_data_mem
    return _yang.Context_parse_data_mem(self, data, format, options)
RuntimeError: Value "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}" does not satisfy the constraint "enabled|disabled|always_enabled|always_disabled" (range, length, or pattern).

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/config/config_mgmt.py", line 65, in __init__
    self.sy.loadData(self.configdbJsonIn)
  File "/usr/local/lib/python3.9/dist-packages/sonic_yang_ext.py", line 1072, in loadData
    raise SonicYangException("Data Loading Failed\n{}".format(str(e)))
sonic_yang_ext.SonicYangException: Data Loading Failed
Value "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}" does not satisfy the constraint "enabled|disabled|always_enabled|always_disabled" (range, length, or pattern).

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/config/config_mgmt.py", line 73, in __init__
    raise Exception('ConfigMgmt Class creation failed')
Exception: ConfigMgmt Class creation failed

Describe the results you received:

A RuntimeError is thrown due to invalid state field value.

Describe the results you expected:

ConfigMgmt(source='/etc/sonic/init_cfg.json') class creation succedes.

Output of show version:

SONiC Software Version: SONiC.master.241-0d327abe9_Internal
Distribution: Debian 11.2
Kernel: 5.10.0-8-2-amd64
Build commit: 0d327abe9
Build date: Mon Dec 20 09:09:58 UTC 2021
Built by: sw-r2d2-bot@r-build-sonic02-005

Platform: x86_64-mlnx_msn2010-r0
HwSKU: ACS-MSN2010
ASIC: mellanox
ASIC Count: 1
Serial Number: Undefined.
Model Number: Undefined.
Hardware Revision: N/A
Uptime: 16:58:49 up  3:29,  1 user,  load average: 1.14, 1.34, 0.91

Docker images:
REPOSITORY                                         TAG                             IMAGE ID       SIZE
docker-teamd                                       latest                          2f47d005bb95   436MB
docker-teamd                                       master.241-0d327abe9_Internal   2f47d005bb95   436MB
docker-syncd-mlnx                                  latest                          cc4d31e33915   1.01GB
docker-syncd-mlnx                                  master.241-0d327abe9_Internal   cc4d31e33915   1.01GB
docker-platform-monitor                            latest                          6b9c00dab5b7   809MB
docker-platform-monitor                            master.241-0d327abe9_Internal   6b9c00dab5b7   809MB
docker-orchagent                                   latest                          5c891ff8f214   455MB
docker-orchagent                                   master.241-0d327abe9_Internal   5c891ff8f214   455MB
docker-dhcp-relay                                  latest                          c646bc83cc8c   436MB
docker-sonic-telemetry                             latest                          606f26ae194f   511MB
docker-sonic-telemetry                             master.241-0d327abe9_Internal   606f26ae194f   511MB
docker-sonic-mgmt-framework                        latest                          7c86fd946748   578MB
docker-sonic-mgmt-framework                        master.241-0d327abe9_Internal   7c86fd946748   578MB
docker-snmp                                        latest                          546605aaf36c   465MB
docker-snmp                                        master.241-0d327abe9_Internal   546605aaf36c   465MB
docker-sflow                                       latest                          68f7233b21a9   436MB
docker-sflow                                       master.241-0d327abe9_Internal   68f7233b21a9   436MB
docker-router-advertiser                           latest                          dafc3d1fb775   423MB
docker-router-advertiser                           master.241-0d327abe9_Internal   dafc3d1fb775   423MB
docker-nat                                         latest                          47bf92fce979   438MB
docker-nat                                         master.241-0d327abe9_Internal   47bf92fce979   438MB
docker-mux                                         latest                          b68969e05d75   475MB
docker-mux                                         master.241-0d327abe9_Internal   b68969e05d75   475MB
docker-macsec                                      latest                          acb05bec6969   439MB
docker-macsec                                      master.241-0d327abe9_Internal   acb05bec6969   439MB
docker-lldp                                        latest                          85f1ea2eb1a0   463MB
docker-lldp                                        master.241-0d327abe9_Internal   85f1ea2eb1a0   463MB
docker-fpm-frr                                     latest                          ebb395f4d389   454MB
docker-fpm-frr                                     master.241-0d327abe9_Internal   ebb395f4d389   454MB
docker-database                                    latest                          89d24c1c4f64   423MB
docker-database                                    master.241-0d327abe9_Internal   89d24c1c4f64   423MB

Output of show techsupport:

(paste your output here or download and attach the file here )

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions