Merge lp:~barryprice/juju-deployer/resolve-yaml-warnings into lp:juju-deployer

Proposed by Barry Price
Status: Merged
Approved by: Barry Price
Approved revision: 219
Merged at revision: 219
Proposed branch: lp:~barryprice/juju-deployer/resolve-yaml-warnings
Merge into: lp:juju-deployer
Diff against target: 75 lines (+21/-5)
2 files modified
deployer/tests/test_config.py (+11/-2)
deployer/tests/test_diff.py (+10/-3)
To merge this branch: bzr merge lp:~barryprice/juju-deployer/resolve-yaml-warnings
Reviewer Review Type Date Requested Status
Benjamin Allot Approve
Canonical IS Reviewers Pending
Review via email: mp+391925@code.launchpad.net

Commit message

Fix yaml.load() deprecation warnings by using SafeLoader, e.g.:

/home/barryprice/juju-deployer/deployer/tests/test_config.py:102: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.

To post a comment you must log in.
Revision history for this message
Canonical IS Mergebot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Benjamin Allot (ballot) wrote :

LGTM.

Using safe_load lose the C binding optimization but is easier to read and maintain.

review: Approve
Revision history for this message
Canonical IS Mergebot (canonical-is-mergebot) wrote :

Change successfully merged at revision 219

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'deployer/tests/test_config.py'
2--- deployer/tests/test_config.py 2016-05-07 23:48:30 +0000
3+++ deployer/tests/test_config.py 2020-10-07 11:37:47 +0000
4@@ -3,6 +3,13 @@
5 import mock
6 import os
7 import tempfile
8+
9+try:
10+ from yaml import CSafeLoader, CSafeDumper
11+ SafeLoader, SafeDumper = CSafeLoader, CSafeDumper
12+except ImportError:
13+ from yaml import SafeLoader
14+
15 import yaml
16
17 import six
18@@ -98,8 +105,10 @@
19 # openstack.cfg
20 # includes -> ubuntu_base.cfg includes
21 # includes -> openstack_base.cfg
22- test_conf = yaml.load(open(
23- os.path.join(self.test_data_dir, "openstack", "openstack.cfg")))
24+ test_conf = yaml.load(
25+ open(os.path.join(self.test_data_dir, "openstack", "openstack.cfg")),
26+ Loader=SafeLoader
27+ )
28 includes = [
29 os.path.join(self.test_data_dir, "openstack", "ubuntu_base.cfg"),
30 os.path.join(self.test_data_dir, "openstack", "openstack_base.cfg")
31
32=== modified file 'deployer/tests/test_diff.py'
33--- deployer/tests/test_diff.py 2016-12-20 15:10:01 +0000
34+++ deployer/tests/test_diff.py 2020-10-07 11:37:47 +0000
35@@ -5,6 +5,13 @@
36 import shutil
37 import tempfile
38 import unittest
39+
40+try:
41+ from yaml import CSafeLoader, CSafeDumper
42+ SafeLoader, SafeDumper = CSafeLoader, CSafeDumper
43+except ImportError:
44+ from yaml import SafeLoader
45+
46 import yaml
47
48 from mock import patch, mock_open
49@@ -143,7 +150,7 @@
50 edited_config_file = os.path.join(self.get_dir(), 'saved.yaml')
51 dpl.save(edited_config_file)
52 # in memory edit yaml content
53- edited_config = yaml.load(open(edited_config_file))
54+ edited_config = yaml.load(open(edited_config_file), Loader=SafeLoader)
55 edited_config["relations"].remove(
56 ['nova-compute:amqp', 'rabbitmq-server:amqp'])
57 edited_config = yaml.dump({'openstack': edited_config})
58@@ -168,7 +175,7 @@
59 edited_config_file = os.path.join(self.get_dir(), 'saved.yaml')
60 dpl.save(edited_config_file)
61 # in memory edit yaml content
62- edited_config = yaml.load(open(edited_config_file))
63+ edited_config = yaml.load(open(edited_config_file), Loader=SafeLoader)
64 edited_config["relations"].remove(
65 ['ceilometer:identity-service', 'keystone:identity-service'])
66 edited_config = yaml.dump({'openstack': edited_config})
67@@ -193,7 +200,7 @@
68 edited_config_file = os.path.join(self.get_dir(), 'saved.yaml')
69 dpl.save(edited_config_file)
70 # in memory edit yaml content
71- edited_config = yaml.load(open(edited_config_file))
72+ edited_config = yaml.load(open(edited_config_file), Loader=SafeLoader)
73 # remove ':name' from service endpoint specification
74 for relation in edited_config["relations"]:
75 relation = [(relation[0] + ":").split(":")[0],

Subscribers

People subscribed via source and target branches