Skip to content

Commit

Permalink
[sonic-cfggen]: yaml.load() is deprecated in latest versions of PyYAM…
Browse files Browse the repository at this point in the history
…L module (#3526)

From 5.1 version of PyYAML python module, yaml.load() API is deprecated. Code should be compatible to support both the versions, else error/warning messages are seen like below,

2019-07-02 08:25:35,284 – INFO: [D1] /usr/local/lib/python2.7/dist-packages/sonic_device_util.py:44: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  • Loading branch information
FuzailBrcm authored and lguohan committed Oct 11, 2019
1 parent 7988deb commit bdf7d24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ def main():

for yaml_file in args.yaml:
with open(yaml_file, 'r') as stream:
additional_data = yaml.load(stream)
if yaml.__version__ >= "5.1":
additional_data = yaml.full_load(stream)
else:
additional_data = yaml.load(stream)
deep_update(data, FormatConverter.to_deserialized(additional_data))

for json_file in args.json:
Expand Down
5 changes: 4 additions & 1 deletion src/sonic-config-engine/sonic_device_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def get_sonic_version_info():
return None
data = {}
with open('/etc/sonic/sonic_version.yml') as stream:
data = yaml.load(stream)
if yaml.__version__ >= "5.1":
data = yaml.full_load(stream)
else:
data = yaml.load(stream)
return data

def valid_mac_address(mac):
Expand Down

0 comments on commit bdf7d24

Please sign in to comment.