diff options
| author | Ryan Harper <[email protected]> | 2019-05-07 14:02:02 +0000 |
|---|---|---|
| committer | Server Team CI Bot <[email protected]> | 2019-05-07 14:02:02 +0000 |
| commit | 5f7f6599a031b65931867feb5510f0481a00b83e (patch) | |
| tree | 59e0888c5f2a0e529006b0eb4e23546647edce57 | |
| parent | f99929eddc2f1132e3c857392b1da32d3a114979 (diff) | |
Fix up yaml.load warnings
Replace most calls with curtin.config.load_config. For a few
cases which parse strings, use yaml.safe_load.
| -rw-r--r-- | curtin/config.py | 2 | ||||
| -rw-r--r-- | tests/unittests/test_apt_custom_sources_list.py | 7 | ||||
| -rw-r--r-- | tests/vmtests/__init__.py | 9 | ||||
| -rw-r--r-- | tests/vmtests/test_apt_config_cmd.py | 4 | ||||
| -rw-r--r-- | tests/vmtests/test_apt_source.py | 4 | ||||
| -rw-r--r-- | tests/vmtests/test_install_umount.py | 2 | ||||
| -rw-r--r-- | tests/vmtests/test_old_apt_features.py | 5 |
7 files changed, 18 insertions, 15 deletions
diff --git a/curtin/config.py b/curtin/config.py index 9649b10c..2106b239 100644 --- a/curtin/config.py +++ b/curtin/config.py @@ -76,7 +76,7 @@ def cmdarg2cfg(cmdarg, delim="/"): def load_config_archive(content): - archive = yaml.load(content) + archive = yaml.safe_load(content) config = {} for part in archive: if isinstance(part, (str,)): diff --git a/tests/unittests/test_apt_custom_sources_list.py b/tests/unittests/test_apt_custom_sources_list.py index d77c750b..fb6eb0c9 100644 --- a/tests/unittests/test_apt_custom_sources_list.py +++ b/tests/unittests/test_apt_custom_sources_list.py @@ -5,16 +5,17 @@ Test templating of custom sources list """ import logging import os +import yaml import mock from mock import call import textwrap -import yaml from curtin import distro from curtin import paths from curtin import util from curtin.commands import apt_config +from curtin.config import load_config from .helpers import CiTestCase LOG = logging.getLogger(__name__) @@ -233,7 +234,7 @@ class TestApplyPreserveSourcesList(CiTestCase): m_get_pkg_ver.assert_has_calls( [mock.call('cloud-init', target=self.tmp)]) self.assertEqual( - yaml.load(util.load_file(self.tmp_cfg)), + load_config(self.tmp_cfg), {'apt_preserve_sources_list': True}) @mock.patch("curtin.commands.apt_config.distro.get_package_version") @@ -253,7 +254,7 @@ class TestApplyPreserveSourcesList(CiTestCase): m_get_pkg_ver.assert_has_calls( [mock.call('cloud-init', target=self.tmp)]) self.assertEqual( - yaml.load(util.load_file(self.tmp_cfg)), + load_config(self.tmp_cfg), {'apt': {'preserve_sources_list': True}}) # vi: ts=4 expandtab syntax=python diff --git a/tests/vmtests/__init__.py b/tests/vmtests/__init__.py index 5f4a17a0..0cfcad34 100644 --- a/tests/vmtests/__init__.py +++ b/tests/vmtests/__init__.py @@ -18,6 +18,7 @@ import yaml import curtin.net as curtin_net import curtin.util as util from curtin.block import iscsi +from curtin.config import load_config from .report_webhook_logger import CaptureReporting from curtin.commands.install import INSTALL_PASS_MSG @@ -1612,7 +1613,7 @@ class VMBaseClass(TestCase): logger.debug('test_dname_rules: checking disks: %s', disk_to_check) self.output_files_exist(["udev_rules.d"]) - cfg = yaml.load(self.load_collect_file("root/curtin-install-cfg.yaml")) + cfg = load_config(self.collect_path("root/curtin-install-cfg.yaml")) stgcfg = cfg.get("storage", {}).get("config", []) disks = [ent for ent in stgcfg if (ent.get('type') == 'disk' and 'name' in ent)] @@ -1751,10 +1752,10 @@ class VMBaseClass(TestCase): @classmethod def get_class_storage_config(cls): sc = cls.load_conf_file() - return yaml.load(sc).get('storage', {}).get('config', {}) + return yaml.safe_load(sc).get('storage', {}).get('config', {}) def get_storage_config(self): - cfg = yaml.load(self.load_collect_file("root/curtin-install-cfg.yaml")) + cfg = load_config(self.collect_path("root/curtin-install-cfg.yaml")) return cfg.get("storage", {}).get("config", []) def has_storage_config(self): @@ -1992,7 +1993,7 @@ def generate_user_data(collect_scripts=None, apt_proxy=None, capture=True) # precises' cloud-init version has limited support for cloud-config-archive # and expects cloud-config pieces to be appendable to a single file and - # yaml.load()'able. Resolve this by using yaml.dump() when generating + # yaml.safe_load()'able. Resolve this by using yaml.dump() when generating # a list of parts parts = [{'type': 'text/cloud-config', 'content': yaml.dump(base_cloudconfig, indent=1)}, diff --git a/tests/vmtests/test_apt_config_cmd.py b/tests/vmtests/test_apt_config_cmd.py index 12962405..e957a1f2 100644 --- a/tests/vmtests/test_apt_config_cmd.py +++ b/tests/vmtests/test_apt_config_cmd.py @@ -5,10 +5,10 @@ apt-config standalone command. """ import textwrap -import yaml from . import VMBaseClass from .releases import base_vm_classes as relbase +from curtin.config import load_config class TestAptConfigCMD(VMBaseClass): @@ -50,7 +50,7 @@ class TestAptConfigCMD(VMBaseClass): # For earlier than xenial 'apt_preserve_sources_list' is expected self.assertEqual( {'apt': {'preserve_sources_list': True}}, - yaml.load(self.load_collect_file("curtin-preserve-sources.cfg"))) + load_config(self.collect_path("curtin-preserve-sources.cfg"))) class XenialTestAptConfigCMDCMD(relbase.xenial, TestAptConfigCMD): diff --git a/tests/vmtests/test_apt_source.py b/tests/vmtests/test_apt_source.py index 2cd7267a..a090ffaf 100644 --- a/tests/vmtests/test_apt_source.py +++ b/tests/vmtests/test_apt_source.py @@ -4,13 +4,13 @@ Collection of tests for the apt configuration features """ import textwrap -import yaml from . import VMBaseClass from .releases import base_vm_classes as relbase from unittest import SkipTest from curtin import util +from curtin.config import load_config class TestAptSrcAbs(VMBaseClass): @@ -67,7 +67,7 @@ class TestAptSrcAbs(VMBaseClass): # For earlier than xenial 'apt_preserve_sources_list' is expected self.assertEqual( {'apt': {'preserve_sources_list': True}}, - yaml.load(self.load_collect_file("curtin-preserve-sources.cfg"))) + load_config(self.collect_path("curtin-preserve-sources.cfg"))) def test_source_files(self): """test_source_files - Check generated .lists for correct content""" diff --git a/tests/vmtests/test_install_umount.py b/tests/vmtests/test_install_umount.py index 931cf556..566c4c1b 100644 --- a/tests/vmtests/test_install_umount.py +++ b/tests/vmtests/test_install_umount.py @@ -28,7 +28,7 @@ class TestInstallUnmount(VMBaseClass): """Test that install ran with unmount: disabled""" collect_curtin_cfg = 'root/curtin-install-cfg.yaml' self.output_files_exist([collect_curtin_cfg]) - curtin_cfg = yaml.load(self.load_collect_file(collect_curtin_cfg)) + curtin_cfg = yaml.safe_load(self.load_collect_file(collect_curtin_cfg)) # check that we have # install: diff --git a/tests/vmtests/test_old_apt_features.py b/tests/vmtests/test_old_apt_features.py index ec3765c2..a114bf4c 100644 --- a/tests/vmtests/test_old_apt_features.py +++ b/tests/vmtests/test_old_apt_features.py @@ -5,12 +5,13 @@ """ import re import textwrap -import yaml + from . import VMBaseClass from .releases import base_vm_classes as relbase from curtin import util +from curtin.config import load_config def sources_to_dict(lines): @@ -75,7 +76,7 @@ class TestOldAptAbs(VMBaseClass): # For earlier than xenial 'apt_preserve_sources_list' is expected self.assertEqual( {'apt': {'preserve_sources_list': True}}, - yaml.load(self.load_collect_file("curtin-preserve-sources.cfg"))) + load_config(self.collect_path("curtin-preserve-sources.cfg"))) def test_debconf(self): """test_debconf - Check if debconf is in place""" |
