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

config-setup factory failed to parse platform.json #9643

Closed
mykolaxgerasymenko opened this issue Dec 23, 2021 · 5 comments · Fixed by #10224
Closed

config-setup factory failed to parse platform.json #9643

mykolaxgerasymenko opened this issue Dec 23, 2021 · 5 comments · Fixed by #10224
Assignees
Labels
BRCM Triaged this issue has been triaged

Comments

@mykolaxgerasymenko
Copy link
Contributor

Description

If the platform.json file includes some fields with a boolean type value, an error occurred while parsing platform.json during config-setup factory.

Steps to reproduce the issue:

  1. Deploy SONiC image
  2. Added to platform.json file to node psus one more field with boolean type "temperature": false.
    For example:
        "psus": [ 
            { 
                "name": "psu-1", 
                "temperature": false 
            }, 
            { 
                "name": "psu-2", 
                "temperature": false 
            } 
        ], 
  1. Remove config_db.json file

sudo rm -f /etc/sonic/config_db.json

  1. Configure new config_db.json file

sudo config-setup factory

Note:
platform.json file must include an "interfaces" key with real interfaces inside, which describes all info about them.
For example:

    "interfaces": { 
        "Ethernet0": { 
            "index": "1,1,1,1,1,1,1,1", 
            "lanes": "0,1,2,3,4,5,6,7", 
            "breakout_modes": { 
                "1x400G[200G]": ["Ethernet0"], 
                "2x200G[100G,40G]": ["Ethernet0, Ethernet4"], 
                "4x100G[50G]": ["Ethernet0", "Ethernet2", "Ethernet4", "Ethernet6"], 
                "8x50G[25G,10G]": ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3", "Ethernet4", "Ethernet5", "Ethernet6", "Ethernet7"], 
                "1x200G[100G,40G](4)+4x50G[25G,10G](4)": ["Ethernet0", "Ethernet4", "Ethernet5", "Ethernet6", "Ethernet7"], 
                "4x50G[25G,10G](4)+1x200G[100G,40G](4)": ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3", "Ethernet4"] 
            } 
        }, 
    } 

If the "interfaces" key is empty, then the portconfig.py script will be use port_config.ini instead of platform.json to configure config_db.json file.

Describe the results you received:

Error logs:

admin@sonic:~$ sudo config-setup factory 
Traceback (most recent call last): 
  File "/usr/local/bin/sonic-cfggen", line 445, in <module> 
    main() 
  File "/usr/local/bin/sonic-cfggen", line 306, in main 
    (ports, _, _) = get_port_config(hwsku, platform, args.port_config, asic_id) 
  File "/usr/local/lib/python3.9/dist-packages/portconfig.py", line 135, in get_port_config 
    return parse_platform_json_file(hwsku_json_file, port_config_file) 
  File "/usr/local/lib/python3.9/dist-packages/portconfig.py", line 336, in parse_platform_json_file 
    raise Exception("port_dict is none") 
Exception: port_dict is none 

Was received empty /etc/sonic/config_db.json file with a string:

error occurred while parsing json: malformed node or string: <ast.Name object at 0x7f041464b9a0>

Describe the results you expected:

/etc/sonic/config_db.json file with a description of interfaces.

Output of show version:

admin@sonic:~$ show version 

SONiC Software Version: SONiC.master.60824-dirty-20211222.175417
Distribution: Debian 11.2
Kernel: 5.10.0-8-2-amd64
Build commit: 3aec72879
Build date: Wed Dec 22 18:17:20 UTC 2021
Built by: AzDevOps@sonic-build-workers-00108W

Platform: x86_64-accton_as9516_32d-r0
HwSKU: newport
ASIC: barefoot
ASIC Count: 1
Serial Number: 9516D2042001
Model Number: NP5ZZ8632007A
Hardware Revision: N/A
Uptime: 13:52:33 up  1:30,  2 users,  load average: 1.35, 1.06, 0.72

Docker images:
REPOSITORY                    TAG                                  IMAGE ID       SIZE
docker-syncd-bfn              latest                               a0afaeef16c4   1.59GB
docker-syncd-bfn              master.60824-dirty-20211222.175417   a0afaeef16c4   1.59GB
docker-dhcp-relay             latest                               7e706aadf245   436MB
docker-teamd                  latest                               c476d19dbc5f   436MB
docker-teamd                  master.60824-dirty-20211222.175417   c476d19dbc5f   436MB
docker-sonic-telemetry        latest                               7c8ac6843948   511MB
docker-sonic-telemetry        master.60824-dirty-20211222.175417   7c8ac6843948   511MB
docker-sonic-mgmt-framework   latest                               0110afb4ff20   578MB
docker-sonic-mgmt-framework   master.60824-dirty-20211222.175417   0110afb4ff20   578MB
docker-snmp                   latest                               c448ef8ced31   465MB
docker-snmp                   master.60824-dirty-20211222.175417   c448ef8ced31   465MB
docker-sflow                  latest                               9fdc29004196   436MB
docker-sflow                  master.60824-dirty-20211222.175417   9fdc29004196   436MB
docker-router-advertiser      latest                               e145b68bfebf   423MB
docker-router-advertiser      master.60824-dirty-20211222.175417   e145b68bfebf   423MB
docker-platform-monitor       latest                               8e15d89d8ed9   689MB
docker-platform-monitor       master.60824-dirty-20211222.175417   8e15d89d8ed9   689MB
docker-orchagent              latest                               69272c9bc4b9   455MB
docker-orchagent              master.60824-dirty-20211222.175417   69272c9bc4b9   455MB
docker-nat                    latest                               6ed1319d49b3   438MB
docker-nat                    master.60824-dirty-20211222.175417   6ed1319d49b3   438MB
docker-mux                    latest                               44be9fc4d782   475MB
docker-mux                    master.60824-dirty-20211222.175417   44be9fc4d782   475MB
docker-macsec                 latest                               bb261b14acdb   439MB
docker-macsec                 master.60824-dirty-20211222.175417   bb261b14acdb   439MB
docker-lldp                   latest                               97de57d4013c   463MB
docker-lldp                   master.60824-dirty-20211222.175417   97de57d4013c   463MB
docker-fpm-frr                latest                               ffb1a3a71a13   454MB
docker-fpm-frr                master.60824-dirty-20211222.175417   ffb1a3a71a13   454MB
docker-database               latest                               2730e07eea0f   423MB
docker-database               master.60824-dirty-20211222.175417   2730e07eea0f   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):

@msosyak
Copy link
Contributor

msosyak commented Dec 23, 2021

@qiluo-msft @samaity Have a look, Please

@yxieca
Copy link
Contributor

yxieca commented Jan 5, 2022

@msosyak can you elaborate what is the significance of step 2? In other words, if you execute step 1,3,4, will there be any issue?

Also, please attach show techsupport to the ticket.

@mykolaxgerasymenko
Copy link
Contributor Author

@yxieca Yes, you are right, if skip step 2 there will no issue.
But this step needed to add chassis configuration for example for PSU or something else. This additional information is needed because it is used for testing by some test-cases. For example, a test-case for test temperature:
https://github.com/Azure/sonic-mgmt/blob/8a47ab3de9fbbdea65689ef3f6d90c8ab1c0414a/tests/platform_tests/api/test_psu.py#L244

@zhangyanzhao zhangyanzhao added the Triaged this issue has been triaged label Jan 19, 2022
@qiluo-msft
Copy link
Collaborator

qiluo-msft commented Jan 19, 2022

I debug a little bit and find this line throw the error string. @samaity Could you please check?

https://github.com/Azure/sonic-buildimage/blob/bb3362760d01055d1c30cbda8ec3bf5ea4f5d7aa/src/sonic-config-engine/portconfig.py#L56

>>> data_dict = ast.literal_eval(json.dumps(data))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/ast.py", line 91, in literal_eval
    return _convert(node_or_string)
  File "/usr/lib/python3.7/ast.py", line 79, in _convert
    map(_convert, node.values)))
  File "/usr/lib/python3.7/ast.py", line 79, in _convert
    map(_convert, node.values)))
  File "/usr/lib/python3.7/ast.py", line 74, in _convert
    return list(map(_convert, node.elts))
  File "/usr/lib/python3.7/ast.py", line 79, in _convert
    map(_convert, node.values)))
  File "/usr/lib/python3.7/ast.py", line 90, in _convert
    return _convert_signed_num(node)
  File "/usr/lib/python3.7/ast.py", line 63, in _convert_signed_num
    return _convert_num(node)
  File "/usr/lib/python3.7/ast.py", line 55, in _convert_num
    raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.Name object at 0x7fb82e5604e0>

As a workaround, change the boolean to string will pass.

        "psus": [ 
            { 
                "name": "psu-1", 
                "temperature": "false"
            }, 
            { 
                "name": "psu-2", 
                "temperature": "false"
            } 
        ], 

@akokhan
Copy link
Contributor

akokhan commented Jan 28, 2022

As a workaround, change the boolean to string will pass.

@qiluo-msft , but this change will cause TC failure which expect True or False but not string

qiluo-msft pushed a commit that referenced this issue Mar 21, 2022
…0224)

#### Why I did it
To fix #9643

#### How I did it
Instead of ast.literal_eval added python2 compat code for json strings unicode -> str convertion.

We need python2 compatibility since py2 sonic config engine (buster/sonic_config_engine-1.0-py2-none-any.whl target) is still included into the build (ENABLE_PY2_MODULES flag is set for buster). Once we abandon buster and python2, this compat and ast.literal_eval could be cleaned up all through the code base.

#### How to verify it
run steps from the linked issue
judyjoseph pushed a commit that referenced this issue Mar 28, 2022
…0224)

#### Why I did it
To fix #9643

#### How I did it
Instead of ast.literal_eval added python2 compat code for json strings unicode -> str convertion.

We need python2 compatibility since py2 sonic config engine (buster/sonic_config_engine-1.0-py2-none-any.whl target) is still included into the build (ENABLE_PY2_MODULES flag is set for buster). Once we abandon buster and python2, this compat and ast.literal_eval could be cleaned up all through the code base.

#### How to verify it
run steps from the linked issue
qiluo-msft pushed a commit that referenced this issue Nov 23, 2022
…0224)

#### Why I did it
To fix #9643

#### How I did it
Instead of ast.literal_eval added python2 compat code for json strings unicode -> str convertion.

We need python2 compatibility since py2 sonic config engine (buster/sonic_config_engine-1.0-py2-none-any.whl target) is still included into the build (ENABLE_PY2_MODULES flag is set for buster). Once we abandon buster and python2, this compat and ast.literal_eval could be cleaned up all through the code base.

#### How to verify it
run steps from the linked issue
praveen-li pushed a commit to praveen-li/sonic-buildimage that referenced this issue Dec 23, 2022
…nic-net#10224)

Signed-off-by: Sangita Maity <samaity@linkedin.com>

To fix sonic-net#9643

Instead of ast.literal_eval added python2 compat code for json strings unicode -> str convertion.

We need python2 compatibility since py2 sonic config engine (buster/sonic_config_engine-1.0-py2-none-any.whl target) is still included into the build (ENABLE_PY2_MODULES flag is set for buster). Once we abandon buster and python2, this compat and ast.literal_eval could be cleaned up all through the code base.

run steps from the linked issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BRCM Triaged this issue has been triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants