[sonic-cfggen]: fix bug in file sonic-cfggen (#2834)

Fixing bug of file sonic-cfggen. Error occurs if argument --var-json is set when running sonic-cfggen,for example:

Command: sonic-cfggen -d --var-json VLAN_MEMBER
Configuration in config_db.json: 
            "VLAN_MEMBER": {
            ......
                "Vlan11|Ethernet32": {
                 "tagging_mode": "untagged"
             },
             ......
Error occurs because FormatConverter.to_serialized(data) in file sonic-cfggen doesn't serialize
keys correctly
This commit is contained in:
xiongjihai 2019-05-19 01:40:57 +08:00 committed by lguohan
parent 77919507f2
commit 71d0f46672

View File

@ -109,13 +109,13 @@ TODO(taoyl): Current version of config db only supports BGP admin states.
@staticmethod
def to_serialized(data):
for table in data:
if type(data[table]) is dict:
data[table] = OrderedDict(natsorted(data[table].items()))
for key in data[table].keys():
new_key = ConfigDBConnector.serialize_key(key)
if new_key != key:
data[table][new_key] = data[table].pop(key)
if type(data) is dict:
data = OrderedDict(natsorted(data.items()))
for key in data.keys():
new_key = ConfigDBConnector.serialize_key(key)
if new_key != key:
data[new_key] = data.pop(key)
data[new_key] = FormatConverter.to_serialized(data[new_key])
return data
@staticmethod