Replace yaml usage with a helper to ensure unicode is handled properly

Without allow_unicode=True, unicode characters are processed through the
str representer and on Python 2 are dumped as a Unicode code point (i.e.
a literal \u0414). This commit makes allow_unicode=True the default in
our salt.utils.yamlloader.safe_dump() helper. It also adds a new
salt.utils.yamlloader.dump() helper which wraps yaml.dump() and also
makes allow_unicode=True the default.

To make importing and using our custom yaml loader/dumper easier, a
convenience module called salt.utils.yaml has been added, which does a
wildcard import from both salt.utils.yamldumper and
salt.utils.yamlloader.

Refs to yaml.load/dump and yaml.safe_load/safe_dump have been updated to
salt.utils.yaml, to ensure that unicode is handled properly.
This commit is contained in:
Erik Johnson 2017-12-27 22:31:50 -06:00
parent 83452f78c8
commit 002aa88a97
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F
120 changed files with 706 additions and 863 deletions

View file

@ -144,17 +144,14 @@ Here is a simple YAML renderer example:
.. code-block:: python .. code-block:: python
import yaml import salt.utils.yaml
from salt.utils.yamlloader import SaltYamlSafeLoader from salt.utils.yamlloader import SaltYamlSafeLoader
from salt.ext import six from salt.ext import six
def render(yaml_data, saltenv='', sls='', **kws): def render(yaml_data, saltenv='', sls='', **kws):
if not isinstance(yaml_data, six.string_types): if not isinstance(yaml_data, six.string_types):
yaml_data = yaml_data.read() yaml_data = yaml_data.read()
data = yaml.load( data = salt.utils.yaml.safe_load(yaml_data)
yaml_data,
Loader=SaltYamlSafeLoader
)
return data if data else {} return data if data else {}
Full List of Renderers Full List of Renderers

View file

@ -37,6 +37,7 @@ import salt.utils.data
import salt.utils.dictupdate import salt.utils.dictupdate
import salt.utils.files import salt.utils.files
import salt.utils.verify import salt.utils.verify
import salt.utils.yaml
import salt.syspaths import salt.syspaths
from salt.template import compile_template from salt.template import compile_template
@ -48,7 +49,6 @@ except ImportError:
import Crypto.Random import Crypto.Random
except ImportError: except ImportError:
pass # pycrypto < 2.1 pass # pycrypto < 2.1
import yaml
from salt.ext import six from salt.ext import six
from salt.ext.six.moves import input # pylint: disable=import-error,redefined-builtin from salt.ext.six.moves import input # pylint: disable=import-error,redefined-builtin
@ -1393,7 +1393,7 @@ class Cloud(object):
try: try:
with salt.utils.files.fopen(self.opts['conf_file'], 'r') as mcc: with salt.utils.files.fopen(self.opts['conf_file'], 'r') as mcc:
main_cloud_config = yaml.safe_load(mcc) main_cloud_config = salt.utils.yaml.safe_load(mcc)
if not main_cloud_config: if not main_cloud_config:
main_cloud_config = {} main_cloud_config = {}
except KeyError: except KeyError:

View file

@ -59,13 +59,13 @@ import time
import logging import logging
import pprint import pprint
import base64 import base64
import yaml
import collections import collections
import salt.cache import salt.cache
import salt.config as config import salt.config as config
import salt.utils.cloud import salt.utils.cloud
import salt.utils.data import salt.utils.data
import salt.utils.files import salt.utils.files
import salt.utils.yaml
from salt.utils.versions import LooseVersion from salt.utils.versions import LooseVersion
from salt.ext import six from salt.ext import six
import salt.version import salt.version
@ -1070,7 +1070,7 @@ def request_instance(call=None, kwargs=None): # pylint: disable=unused-argument
) )
if isinstance(kwargs.get('volumes'), six.string_types): if isinstance(kwargs.get('volumes'), six.string_types):
volumes = yaml.safe_load(kwargs['volumes']) volumes = salt.utils.yaml.safe_load(kwargs['volumes'])
else: else:
volumes = kwargs.get('volumes') volumes = kwargs.get('volumes')

View file

@ -75,7 +75,6 @@ import time
import uuid import uuid
import pprint import pprint
import logging import logging
import yaml
# Import libs for talking to the EC2 API # Import libs for talking to the EC2 API
import hmac import hmac
@ -92,6 +91,7 @@ import salt.utils.cloud
import salt.utils.files import salt.utils.files
import salt.utils.hashutils import salt.utils.hashutils
import salt.utils.json import salt.utils.json
import salt.utils.yaml
from salt._compat import ElementTree as ET from salt._compat import ElementTree as ET
import salt.utils.http as http import salt.utils.http as http
import salt.utils.aws as aws import salt.utils.aws as aws
@ -2840,7 +2840,7 @@ def create_attach_volumes(name, kwargs, call=None, wait_to_finish=True):
kwargs['instance_id'] = _get_node(name)['instanceId'] kwargs['instance_id'] = _get_node(name)['instanceId']
if isinstance(kwargs['volumes'], six.string_types): if isinstance(kwargs['volumes'], six.string_types):
volumes = yaml.safe_load(kwargs['volumes']) volumes = salt.utils.yaml.safe_load(kwargs['volumes'])
else: else:
volumes = kwargs['volumes'] volumes = kwargs['volumes']
@ -4109,7 +4109,7 @@ def create_volume(kwargs=None, call=None, wait_to_finish=False):
# Allow tags to be set upon creation # Allow tags to be set upon creation
if 'tags' in kwargs: if 'tags' in kwargs:
if isinstance(kwargs['tags'], six.string_types): if isinstance(kwargs['tags'], six.string_types):
tags = yaml.safe_load(kwargs['tags']) tags = salt.utils.yaml.safe_load(kwargs['tags'])
else: else:
tags = kwargs['tags'] tags = kwargs['tags']

View file

@ -57,7 +57,6 @@ import logging
import base64 import base64
import pprint import pprint
import inspect import inspect
import yaml
import datetime import datetime
from Crypto.Hash import SHA256 from Crypto.Hash import SHA256
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
@ -70,6 +69,7 @@ import salt.utils.cloud
import salt.utils.files import salt.utils.files
import salt.utils.http import salt.utils.http
import salt.utils.json import salt.utils.json
import salt.utils.yaml
import salt.config as config import salt.config as config
from salt.cloud.libcloudfuncs import node_state from salt.cloud.libcloudfuncs import node_state
from salt.exceptions import ( from salt.exceptions import (
@ -1121,6 +1121,6 @@ def query(action=None,
if 'Content-Length' in result['headers']: if 'Content-Length' in result['headers']:
content = result['text'] content = result['text']
return_content = yaml.safe_load(content) return_content = salt.utils.yaml.safe_load(content)
return [result['status'], return_content] return [result['status'], return_content]

View file

@ -44,12 +44,12 @@ import copy
import logging import logging
import pprint import pprint
import time import time
import yaml
# Import salt libs # Import salt libs
import salt.config as config import salt.config as config
from salt.exceptions import SaltCloudSystemExit from salt.exceptions import SaltCloudSystemExit
import salt.utils.cloud import salt.utils.cloud
import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
from salt.ext import six from salt.ext import six
@ -711,7 +711,7 @@ def create_attach_volumes(name, kwargs, call=None, wait_to_finish=True):
kwargs = {} kwargs = {}
if isinstance(kwargs['volumes'], six.string_types): if isinstance(kwargs['volumes'], six.string_types):
volumes = yaml.safe_load(kwargs['volumes']) volumes = salt.utils.yaml.safe_load(kwargs['volumes'])
else: else:
volumes = kwargs['volumes'] volumes = kwargs['volumes']
@ -805,7 +805,7 @@ def create_attach_volumes(name, kwargs, call=None, wait_to_finish=True):
kwargs = {} kwargs = {}
if isinstance(kwargs['volumes'], six.string_types): if isinstance(kwargs['volumes'], six.string_types):
volumes = yaml.safe_load(kwargs['volumes']) volumes = salt.utils.yaml.safe_load(kwargs['volumes'])
else: else:
volumes = kwargs['volumes'] volumes = kwargs['volumes']
@ -2731,7 +2731,7 @@ def set_storage_container_metadata(kwargs=None, storage_conn=None, call=None):
if 'name' not in kwargs: if 'name' not in kwargs:
raise SaltCloudSystemExit('An storage container name must be specified as "name"') raise SaltCloudSystemExit('An storage container name must be specified as "name"')
x_ms_meta_name_values = yaml.safe_load( x_ms_meta_name_values = salt.utils.yaml.safe_load(
kwargs.get('meta_name_values', '') kwargs.get('meta_name_values', '')
) )

View file

@ -206,13 +206,13 @@ import os
import logging import logging
import socket import socket
import pprint import pprint
import yaml
# Import Salt Libs # Import Salt Libs
from salt.ext import six from salt.ext import six
import salt.utils.cloud import salt.utils.cloud
import salt.utils.files import salt.utils.files
import salt.utils.pycrypto import salt.utils.pycrypto
import salt.utils.yaml
import salt.client import salt.client
from salt.utils.openstack import nova from salt.utils.openstack import nova
try: try:
@ -1276,7 +1276,7 @@ def volume_create_attach(name, call=None, **kwargs):
) )
if type(kwargs['volumes']) is str: if type(kwargs['volumes']) is str:
volumes = yaml.safe_load(kwargs['volumes']) volumes = salt.utils.yaml.safe_load(kwargs['volumes'])
else: else:
volumes = kwargs['volumes'] volumes = kwargs['volumes']

View file

@ -15,7 +15,6 @@ import time
import codecs import codecs
import logging import logging
import types import types
import yaml
from copy import deepcopy from copy import deepcopy
# pylint: disable=import-error,no-name-in-module # pylint: disable=import-error,no-name-in-module
@ -34,6 +33,7 @@ import salt.utils.stringutils
import salt.utils.user import salt.utils.user
import salt.utils.validate.path import salt.utils.validate.path
import salt.utils.xdg import salt.utils.xdg
import salt.utils.yaml
import salt.utils.yamlloader as yamlloader import salt.utils.yamlloader as yamlloader
import salt.utils.zeromq import salt.utils.zeromq
import salt.syspaths import salt.syspaths
@ -2098,11 +2098,8 @@ def _read_conf_file(path):
log.debug('Reading configuration from {0}'.format(path)) log.debug('Reading configuration from {0}'.format(path))
with salt.utils.files.fopen(path, 'r') as conf_file: with salt.utils.files.fopen(path, 'r') as conf_file:
try: try:
conf_opts = yamlloader.load( conf_opts = salt.utils.yaml.safe_load(conf_file) or {}
conf_file.read(), except salt.utils.yaml.YAMLError as err:
Loader=yamlloader.SaltYamlSafeLoader,
) or {}
except yaml.YAMLError as err:
message = 'Error parsing configuration file: {0} - {1}'.format(path, err) message = 'Error parsing configuration file: {0} - {1}'.format(path, err)
log.error(message) log.error(message)
raise salt.exceptions.SaltConfigurationError(message) raise salt.exceptions.SaltConfigurationError(message)

View file

@ -99,7 +99,6 @@ import logging
import time import time
import re import re
import traceback import traceback
import yaml
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -119,7 +118,7 @@ import salt.utils.event
import salt.utils.http import salt.utils.http
import salt.utils.json import salt.utils.json
import salt.utils.slack import salt.utils.slack
from salt.utils.yamldumper import OrderedDumper import salt.utils.yaml
__virtualname__ = 'slack' __virtualname__ = 'slack'
@ -373,7 +372,7 @@ class SlackClient(object):
# Convert UTF to string # Convert UTF to string
_text = salt.utils.json.dumps(_text) _text = salt.utils.json.dumps(_text)
_text = yaml.safe_load(_text) _text = salt.utils.yaml.safe_load(_text)
if not _text: if not _text:
raise ValueError('_text has no value') raise ValueError('_text has no value')
@ -561,7 +560,7 @@ class SlackClient(object):
''' '''
Print out YAML using the block mode Print out YAML using the block mode
''' '''
params = dict(Dumper=OrderedDumper) params = {}
if 'output_indent' not in __opts__: if 'output_indent' not in __opts__:
# default indentation # default indentation
params.update(default_flow_style=False) params.update(default_flow_style=False)
@ -573,7 +572,7 @@ class SlackClient(object):
params.update(default_flow_style=True, params.update(default_flow_style=True,
indent=0) indent=0)
try: try:
#return yaml.dump(data, **params).replace("\n\n", "\n") #return salt.utils.yaml.safe_dump(data, **params).replace("\n\n", "\n")
return salt.utils.json.dumps(data, sort_keys=True, indent=1) return salt.utils.json.dumps(data, sort_keys=True, indent=1)
# pylint: disable=broad-except # pylint: disable=broad-except
except Exception as exc: except Exception as exc:
@ -627,7 +626,7 @@ class SlackClient(object):
# pylint is tripping # pylint is tripping
# pylint: disable=missing-whitespace-after-comma # pylint: disable=missing-whitespace-after-comma
job_data = salt.utils.json.dumps({key:val['return'] for key, val in jid_result.items()}) job_data = salt.utils.json.dumps({key:val['return'] for key, val in jid_result.items()})
results[jid] = yaml.load(job_data) results[jid] = salt.utils.yaml.safe_load(job_data)
return results return results
@ -692,7 +691,7 @@ class SlackClient(object):
content=return_text) content=return_text)
# Handle unicode return # Handle unicode return
log.debug('Got back {} via the slack client'.format(r)) log.debug('Got back {} via the slack client'.format(r))
resp = yaml.safe_load(salt.utils.json.dumps(r)) resp = salt.utils.yaml.safe_load(salt.utils.json.dumps(r))
if 'ok' in resp and resp['ok'] is False: if 'ok' in resp and resp['ok'] is False:
this_job['channel'].send_message('Error: {0}'.format(resp['error'])) this_job['channel'].send_message('Error: {0}'.format(resp['error']))
del outstanding[jid] del outstanding[jid]

View file

@ -6,12 +6,12 @@ from __future__ import absolute_import
import os import os
# Import third party libs # Import third party libs
import yaml
import logging import logging
# Import salt libs # Import salt libs
import salt.utils.files import salt.utils.files
import salt.utils.platform import salt.utils.platform
import salt.utils.yaml
__proxyenabled__ = ['*'] __proxyenabled__ = ['*']
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -69,7 +69,7 @@ def config():
log.debug('Loading static grains from %s', gfn) log.debug('Loading static grains from %s', gfn)
with salt.utils.files.fopen(gfn, 'rb') as fp_: with salt.utils.files.fopen(gfn, 'rb') as fp_:
try: try:
return yaml.safe_load(fp_.read()) return salt.utils.yaml.safe_load(fp_)
except Exception: except Exception:
log.warning("Bad syntax in grains file! Skipping.") log.warning("Bad syntax in grains file! Skipping.")
return {} return {}

View file

@ -786,6 +786,7 @@ class SMinion(MinionBase):
''' '''
def __init__(self, opts): def __init__(self, opts):
# Late setup of the opts grains, so we can log from the grains module # Late setup of the opts grains, so we can log from the grains module
import salt.loader
opts['grains'] = salt.loader.grains(opts) opts['grains'] = salt.loader.grains(opts)
super(SMinion, self).__init__(opts) super(SMinion, self).__init__(opts)
@ -803,8 +804,7 @@ class SMinion(MinionBase):
# If configured, cache pillar data on the minion # If configured, cache pillar data on the minion
if self.opts['file_client'] == 'remote' and self.opts.get('minion_pillar_cache', False): if self.opts['file_client'] == 'remote' and self.opts.get('minion_pillar_cache', False):
import yaml import salt.utils.yaml
from salt.utils.yamldumper import SafeOrderedDumper
pdir = os.path.join(self.opts['cachedir'], 'pillar') pdir = os.path.join(self.opts['cachedir'], 'pillar')
if not os.path.isdir(pdir): if not os.path.isdir(pdir):
os.makedirs(pdir, 0o700) os.makedirs(pdir, 0o700)
@ -815,21 +815,11 @@ class SMinion(MinionBase):
penv = 'base' penv = 'base'
cache_top = {penv: {self.opts['id']: ['cache']}} cache_top = {penv: {self.opts['id']: ['cache']}}
with salt.utils.files.fopen(ptop, 'wb') as fp_: with salt.utils.files.fopen(ptop, 'wb') as fp_:
fp_.write( salt.utils.yaml.safe_dump(cache_top, fp_)
yaml.dump(
cache_top,
Dumper=SafeOrderedDumper
)
)
os.chmod(ptop, 0o600) os.chmod(ptop, 0o600)
cache_sls = os.path.join(pdir, 'cache.sls') cache_sls = os.path.join(pdir, 'cache.sls')
with salt.utils.files.fopen(cache_sls, 'wb') as fp_: with salt.utils.files.fopen(cache_sls, 'wb') as fp_:
fp_.write( salt.utils.yaml.safe_dump(self.opts['pillar'], fp_)
yaml.dump(
self.opts['pillar'],
Dumper=SafeOrderedDumper
)
)
os.chmod(cache_sls, 0o600) os.chmod(cache_sls, 0o600)
def gen_modules(self, initial_load=False): def gen_modules(self, initial_load=False):

View file

@ -33,13 +33,13 @@ import os
import sys import sys
import logging import logging
import importlib import importlib
import yaml
import fnmatch import fnmatch
import subprocess import subprocess
import salt.utils.json import salt.utils.json
from salt.exceptions import LoaderError, CommandExecutionError from salt.exceptions import LoaderError, CommandExecutionError
from salt.utils import timed_subprocess import salt.utils.timed_subprocess
import salt.utils.yaml
try: try:
import ansible import ansible
@ -153,10 +153,12 @@ class AnsibleModuleCaller(object):
js_args = str('{{"ANSIBLE_MODULE_ARGS": {args}}}') # future lint: disable=blacklisted-function js_args = str('{{"ANSIBLE_MODULE_ARGS": {args}}}') # future lint: disable=blacklisted-function
js_args = js_args.format(args=salt.utils.json.dumps(kwargs)) js_args = js_args.format(args=salt.utils.json.dumps(kwargs))
proc_out = timed_subprocess.TimedProc(["echo", "{0}".format(js_args)], proc_out = salt.utils.timed_subprocess.TimedProc(
["echo", "{0}".format(js_args)],
stdout=subprocess.PIPE, timeout=self.timeout) stdout=subprocess.PIPE, timeout=self.timeout)
proc_out.run() proc_out.run()
proc_exc = timed_subprocess.TimedProc(['python', module.__file__], proc_exc = salt.utils.timed_subprocess.TimedProc(
['python', module.__file__],
stdin=proc_out.stdout, stdout=subprocess.PIPE, timeout=self.timeout) stdin=proc_out.stdout, stdout=subprocess.PIPE, timeout=self.timeout)
proc_exc.run() proc_exc.run()
@ -244,7 +246,7 @@ def help(module=None, *args):
ret = {} ret = {}
for docset in module.DOCUMENTATION.split('---'): for docset in module.DOCUMENTATION.split('---'):
try: try:
docset = yaml.load(docset) docset = salt.utils.yaml.safe_load(docset)
if docset: if docset:
doc.update(docset) doc.update(docset)
except Exception as err: except Exception as err:

View file

@ -25,7 +25,6 @@ import logging
import time import time
# Import third party libs # Import third party libs
import yaml
# pylint: disable=no-name-in-module,import-error,redefined-builtin # pylint: disable=no-name-in-module,import-error,redefined-builtin
from salt.ext import six from salt.ext import six
from salt.ext.six.moves.urllib.error import HTTPError from salt.ext.six.moves.urllib.error import HTTPError
@ -47,6 +46,7 @@ import salt.utils.pkg
import salt.utils.pkg.deb import salt.utils.pkg.deb
import salt.utils.systemd import salt.utils.systemd
import salt.utils.versions import salt.utils.versions
import salt.utils.yaml
from salt.exceptions import ( from salt.exceptions import (
CommandExecutionError, MinionError, SaltInvocationError CommandExecutionError, MinionError, SaltInvocationError
) )
@ -2644,8 +2644,8 @@ def set_selections(path=None, selection=None, clear=False, saltenv='base'):
if isinstance(selection, six.string_types): if isinstance(selection, six.string_types):
try: try:
selection = yaml.safe_load(selection) selection = salt.utils.yaml.safe_load(selection)
except (yaml.parser.ParserError, yaml.scanner.ScannerError) as exc: except (salt.utils.yaml.parser.ParserError, salt.utils.yaml.scanner.ScannerError) as exc:
raise SaltInvocationError( raise SaltInvocationError(
'Improperly-formatted selection: {0}'.format(exc) 'Improperly-formatted selection: {0}'.format(exc)
) )

View file

@ -15,11 +15,11 @@ Requires a ``subdomain`` and an ``apikey`` in ``/etc/salt/minion``:
# Import python libs # Import python libs
from __future__ import absolute_import, print_function from __future__ import absolute_import, print_function
import yaml
import logging import logging
# Import salt libs # Import salt libs
import salt.utils.http import salt.utils.http
import salt.utils.yaml
from salt.ext import six from salt.ext import six
from salt._compat import ElementTree as ET from salt._compat import ElementTree as ET
@ -167,7 +167,7 @@ def update_employee(emp_id, key=None, value=None, items=None):
return {'Error': 'At least one key/value pair is required'} return {'Error': 'At least one key/value pair is required'}
items = {key: value} items = {key: value}
elif isinstance(items, six.string_types): elif isinstance(items, six.string_types):
items = yaml.safe_load(items) items = salt.utils.yaml.safe_load(items)
xml_items = '' xml_items = ''
for pair in items: for pair in items:

View file

@ -11,12 +11,12 @@ from __future__ import absolute_import
import difflib import difflib
import logging import logging
import os import os
import yaml
# Import Salt libs # Import Salt libs
import salt.ext.six as six import salt.ext.six as six
import salt.utils.event import salt.utils.event
import salt.utils.files import salt.utils.files
import salt.utils.yaml
from salt.ext.six.moves import map from salt.ext.six.moves import map
# Get logging started # Get logging started
@ -75,8 +75,7 @@ def list_(return_yaml=True,
if beacons: if beacons:
if return_yaml: if return_yaml:
tmp = {'beacons': beacons} tmp = {'beacons': beacons}
yaml_out = yaml.safe_dump(tmp, default_flow_style=False) return salt.utils.yaml.safe_dump(tmp, default_flow_style=False)
return yaml_out
else: else:
return beacons return beacons
else: else:
@ -116,8 +115,7 @@ def list_available(return_yaml=True):
if beacons: if beacons:
if return_yaml: if return_yaml:
tmp = {'beacons': beacons} tmp = {'beacons': beacons}
yaml_out = yaml.safe_dump(tmp, default_flow_style=False) return salt.utils.yaml.safe_dump(tmp, default_flow_style=False)
return yaml_out
else: else:
return beacons return beacons
else: else:
@ -359,7 +357,7 @@ def save():
os.path.dirname(__opts__['default_include'])) os.path.dirname(__opts__['default_include']))
if beacons: if beacons:
tmp = {'beacons': beacons} tmp = {'beacons': beacons}
yaml_out = yaml.safe_dump(tmp, default_flow_style=False) yaml_out = salt.utils.yaml.safe_dump(tmp, default_flow_style=False)
else: else:
yaml_out = '' yaml_out = ''

View file

@ -58,7 +58,6 @@ log = logging.getLogger(__name__)
DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ" DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
# Import third party libs # Import third party libs
import yaml
from salt.ext import six from salt.ext import six
try: try:
import boto import boto
@ -522,20 +521,13 @@ def get_cloud_init_mime(cloud_init):
_cloud_init.attach(_script) _cloud_init.attach(_script)
if 'cloud-config' in cloud_init: if 'cloud-config' in cloud_init:
cloud_config = cloud_init['cloud-config'] cloud_config = cloud_init['cloud-config']
_cloud_config = email.mime.text.MIMEText(_safe_dump(cloud_config), _cloud_config = email.mime.text.MIMEText(
salt.utils.yaml.safe_dump(cloud_config, default_flow_style=False),
'cloud-config') 'cloud-config')
_cloud_init.attach(_cloud_config) _cloud_init.attach(_cloud_config)
return _cloud_init.as_string() return _cloud_init.as_string()
def _safe_dump(data):
def ordered_dict_presenter(dumper, data):
return dumper.represent_dict(six.iteritems(data))
yaml.add_representer(odict.OrderedDict, ordered_dict_presenter,
Dumper=yaml.dumper.SafeDumper)
return yaml.safe_dump(data, default_flow_style=False)
def launch_configuration_exists(name, region=None, key=None, keyid=None, def launch_configuration_exists(name, region=None, key=None, keyid=None,
profile=None): profile=None):
''' '''

View file

@ -58,8 +58,6 @@ import logging
import salt.ext.six as six import salt.ext.six as six
from salt.utils.odict import OrderedDict from salt.utils.odict import OrderedDict
import yaml
# Import third party libs # Import third party libs
try: try:
# pylint: disable=unused-import # pylint: disable=unused-import
@ -273,8 +271,8 @@ def export_distributions(region=None, key=None, keyid=None, profile=None):
# as opposed to being called from execution or state modules # as opposed to being called from execution or state modules
raise err raise err
dumper = __utils__['yamldumper.get_dumper']('IndentedSafeOrderedDumper') dumper = __utils__['yaml.get_dumper']('IndentedSafeOrderedDumper')
return yaml.dump( return __utils__['yaml.dump'](
results, results,
default_flow_style=False, default_flow_style=False,
Dumper=dumper, Dumper=dumper,

View file

@ -48,7 +48,7 @@ from __future__ import absolute_import
# Import Python libs # Import Python libs
import logging import logging
import yaml import yaml # pylint: disable=blacklisted-import
import salt.utils.json import salt.utils.json
import salt.utils.odict as odict import salt.utils.odict as odict
@ -100,31 +100,27 @@ def get_alarm(name, region=None, key=None, keyid=None, profile=None):
def _safe_dump(data): def _safe_dump(data):
########################################### '''
# this presenter magic makes yaml.safe_dump this presenter magic makes yaml.safe_dump
# work with the objects returned from work with the objects returned from
# boto.describe_alarms() boto.describe_alarms()
########################################### '''
def ordered_dict_presenter(dumper, data): custom_dumper = __utils__['yaml.get_dumper']('SafeOrderedDumper')
return dumper.represent_dict(list(data.items()))
yaml.add_representer(odict.OrderedDict, ordered_dict_presenter,
Dumper=yaml.dumper.SafeDumper)
def boto_listelement_presenter(dumper, data): def boto_listelement_presenter(dumper, data):
return dumper.represent_list(list(data)) return dumper.represent_list(list(data))
yaml.add_representer(boto.ec2.cloudwatch.listelement.ListElement, yaml.add_representer(boto.ec2.cloudwatch.listelement.ListElement,
boto_listelement_presenter, boto_listelement_presenter,
Dumper=yaml.dumper.SafeDumper) Dumper=custom_dumper)
def dimension_presenter(dumper, data): def dimension_presenter(dumper, data):
return dumper.represent_dict(dict(data)) return dumper.represent_dict(dict(data))
yaml.add_representer(boto.ec2.cloudwatch.dimension.Dimension, yaml.add_representer(boto.ec2.cloudwatch.dimension.Dimension,
dimension_presenter, Dumper=yaml.dumper.SafeDumper) dimension_presenter, Dumper=custom_dumper)
return yaml.safe_dump(data) return __utils__['yaml.dump'](data, Dumper=custom_dumper)
def get_all_alarms(region=None, prefix=None, key=None, keyid=None, def get_all_alarms(region=None, prefix=None, key=None, keyid=None,

View file

@ -40,7 +40,6 @@ Connection module for Amazon IAM
# Import Python libs # Import Python libs
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
import logging import logging
import yaml
import time import time
# Import salt libs # Import salt libs
@ -1566,21 +1565,6 @@ def delete_server_cert(cert_name, region=None, key=None, keyid=None, profile=Non
return False return False
def _safe_dump(data):
###########################################
# this presenter magic makes yaml.safe_dump
# work with the objects returned from
# boto.export_users()
###########################################
def ordered_dict_presenter(dumper, data):
return dumper.represent_dict(data.items())
yaml.add_representer(odict.OrderedDict, ordered_dict_presenter,
Dumper=yaml.dumper.SafeDumper)
return yaml.safe_dump(data, default_flow_style=False, indent=2)
def export_users(path_prefix='/', region=None, key=None, keyid=None, def export_users(path_prefix='/', region=None, key=None, keyid=None,
profile=None): profile=None):
''' '''
@ -1614,7 +1598,10 @@ def export_users(path_prefix='/', region=None, key=None, keyid=None,
user_sls.append({"policies": policies}) user_sls.append({"policies": policies})
user_sls.append({"path": user.path}) user_sls.append({"path": user.path})
results["manage user " + name] = {"boto_iam.user_present": user_sls} results["manage user " + name] = {"boto_iam.user_present": user_sls}
return _safe_dump(results) return __utils__['yaml.safe_dump'](
results,
default_flow_style=False,
indent=2)
def export_roles(path_prefix='/', region=None, key=None, keyid=None, profile=None): def export_roles(path_prefix='/', region=None, key=None, keyid=None, profile=None):
@ -1648,7 +1635,10 @@ def export_roles(path_prefix='/', region=None, key=None, keyid=None, profile=Non
role_sls.append({'policy_document': salt.utils.json.loads(_unquote(role.assume_role_policy_document))}) role_sls.append({'policy_document': salt.utils.json.loads(_unquote(role.assume_role_policy_document))})
role_sls.append({"path": role.path}) role_sls.append({"path": role.path})
results["manage role " + name] = {"boto_iam_role.present": role_sls} results["manage role " + name] = {"boto_iam_role.present": role_sls}
return _safe_dump(results) return __utils__['yaml.safe_dump'](
results,
default_flow_style=False,
indent=2)
def _get_policy_arn(name, region=None, key=None, keyid=None, profile=None): def _get_policy_arn(name, region=None, key=None, keyid=None, profile=None):

View file

@ -8,7 +8,6 @@ from __future__ import absolute_import
import copy import copy
import logging import logging
import os import os
import yaml
import salt.fileclient import salt.fileclient
import salt.utils.data import salt.utils.data
@ -16,11 +15,10 @@ import salt.utils.dictupdate as dictupdate
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
import salt.utils.url import salt.utils.url
import salt.utils.yaml
__virtualname__ = 'defaults' __virtualname__ = 'defaults'
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -57,7 +55,7 @@ def _load(formula):
suffix = file_.rsplit('.', 1)[-1] suffix = file_.rsplit('.', 1)[-1]
if suffix == 'yaml': if suffix == 'yaml':
loader = yaml.safe_load loader = salt.utils.yaml.safe_load
elif suffix == 'json': elif suffix == 'json':
loader = salt.utils.json.load loader = salt.utils.json.load
else: else:

View file

@ -18,7 +18,6 @@ import logging
import operator import operator
import collections import collections
import math import math
import yaml
from functools import reduce # pylint: disable=redefined-builtin from functools import reduce # pylint: disable=redefined-builtin
# Import Salt libs # Import Salt libs
@ -28,7 +27,7 @@ import salt.utils.data
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
import salt.utils.platform import salt.utils.platform
import salt.utils.yamldumper import salt.utils.yaml
from salt.defaults import DEFAULT_TARGET_DELIM from salt.defaults import DEFAULT_TARGET_DELIM
from salt.exceptions import SaltException from salt.exceptions import SaltException
from salt.ext.six.moves import range from salt.ext.six.moves import range
@ -273,8 +272,8 @@ def setvals(grains, destructive=False):
if os.path.isfile(gfn): if os.path.isfile(gfn):
with salt.utils.files.fopen(gfn, 'rb') as fp_: with salt.utils.files.fopen(gfn, 'rb') as fp_:
try: try:
grains = yaml.safe_load(fp_.read()) grains = salt.utils.yaml.safe_load(fp_)
except yaml.YAMLError as exc: except salt.utils.yaml.YAMLError as exc:
return 'Unable to read existing grains file: {0}'.format(exc) return 'Unable to read existing grains file: {0}'.format(exc)
if not isinstance(grains, dict): if not isinstance(grains, dict):
grains = {} grains = {}
@ -287,17 +286,16 @@ def setvals(grains, destructive=False):
else: else:
grains[key] = val grains[key] = val
__grains__[key] = val __grains__[key] = val
cstr = salt.utils.yamldumper.safe_dump(grains, default_flow_style=False)
try: try:
with salt.utils.files.fopen(gfn, 'w+') as fp_: with salt.utils.files.fopen(gfn, 'w+') as fp_:
fp_.write(cstr) salt.utils.yaml.safe_dump(grains, fp_, default_flow_style=False)
except (IOError, OSError): except (IOError, OSError):
msg = 'Unable to write to grains file at {0}. Check permissions.' msg = 'Unable to write to grains file at {0}. Check permissions.'
log.error(msg.format(gfn)) log.error(msg.format(gfn))
fn_ = os.path.join(__opts__['cachedir'], 'module_refresh') fn_ = os.path.join(__opts__['cachedir'], 'module_refresh')
try: try:
with salt.utils.files.flopen(fn_, 'w+') as fp_: with salt.utils.files.flopen(fn_, 'w+'):
fp_.write('') pass
except (IOError, OSError): except (IOError, OSError):
msg = 'Unable to write to cache file {0}. Check permissions.' msg = 'Unable to write to cache file {0}. Check permissions.'
log.error(msg.format(fn_)) log.error(msg.format(fn_))

View file

@ -44,19 +44,18 @@ Module for handling OpenStack Heat calls
from __future__ import absolute_import from __future__ import absolute_import
import time import time
import logging import logging
import yaml
# Import Salt libs # Import Salt libs
from salt.ext import six from salt.ext import six
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
import salt.utils.yaml
from salt.exceptions import SaltInvocationError from salt.exceptions import SaltInvocationError
# pylint: disable=import-error # pylint: disable=import-error
HAS_HEAT = False HAS_HEAT = False
try: try:
from heatclient import client import heatclient
from heatclient import exc
HAS_HEAT = True HAS_HEAT = True
except ImportError: except ImportError:
pass pass
@ -69,40 +68,14 @@ except ImportError:
pass pass
SECTIONS = ( SECTIONS = (
PARAMETER_DEFAULTS, PARAMETERS, RESOURCE_REGISTRY, EVENT_SINKS PARAMETER_DEFAULTS,
) = ( PARAMETERS,
'parameter_defaults', 'parameters', 'resource_registry', 'event_sinks' RESOURCE_REGISTRY,
) EVENT_SINKS) = (
'parameter_defaults',
if hasattr(yaml, 'CSafeLoader'): 'parameters',
YamlLoader = yaml.CSafeLoader 'resource_registry',
else: 'event_sinks')
YamlLoader = yaml.SafeLoader
if hasattr(yaml, 'CSafeDumper'):
YamlDumper = yaml.CSafeDumper
else:
YamlDumper = yaml.SafeDumper
def _represent_yaml_str(self, node):
'''
Represent for yaml
'''
return self.represent_scalar(node)
YamlDumper.add_representer(u'tag:yaml.org,2002:str',
_represent_yaml_str)
YamlDumper.add_representer(u'tag:yaml.org,2002:timestamp',
_represent_yaml_str)
def _construct_yaml_str(self, node):
'''
Construct for yaml
'''
return self.construct_scalar(node)
YamlLoader.add_constructor(u'tag:yaml.org,2002:timestamp',
_construct_yaml_str)
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -194,7 +167,7 @@ def _auth(profile=None, api_version=1, **connection_args):
kwargs)) kwargs))
# may raise exc.HTTPUnauthorized, exc.HTTPNotFound # may raise exc.HTTPUnauthorized, exc.HTTPNotFound
# but we deal with those elsewhere # but we deal with those elsewhere
return client.Client(api_version, endpoint=heat_endpoint, **kwargs) return heatclient.client.Client(api_version, endpoint=heat_endpoint, **kwargs)
def _parse_template(tmpl_str): def _parse_template(tmpl_str):
@ -206,12 +179,9 @@ def _parse_template(tmpl_str):
tpl = salt.utils.json.loads(tmpl_str) tpl = salt.utils.json.loads(tmpl_str)
else: else:
try: try:
tpl = yaml.load(tmpl_str, Loader=YamlLoader) tpl = salt.utils.yaml.safe_load(tmpl_str)
except yaml.YAMLError: except salt.utils.yaml.YAMLError as exc:
try: raise ValueError(six.text_type(exc))
tpl = yaml.load(tmpl_str, Loader=yaml.SafeLoader)
except yaml.YAMLError as yea:
raise ValueError(yea)
else: else:
if tpl is None: if tpl is None:
tpl = {} tpl = {}
@ -227,22 +197,20 @@ def _parse_enviroment(env_str):
Parsing template Parsing template
''' '''
try: try:
env = yaml.load(env_str, Loader=YamlLoader) env = salt.utils.yaml.safe_load(env_str)
except yaml.YAMLError: except salt.utils.yaml.YAMLError as exc:
try: raise ValueError(six.text_type(exc))
env = yaml.load(env_str, Loader=yaml.SafeLoader)
except yaml.YAMLError as yea:
raise ValueError(yea)
else: else:
if env is None: if env is None:
env = {} env = {}
elif not isinstance(env, dict): elif not isinstance(env, dict):
raise ValueError(('The environment is not a valid ' raise ValueError(
'YAML mapping data type.')) 'The environment is not a valid YAML mapping data type.'
)
for param in env: for param in env:
if param not in SECTIONS: if param not in SECTIONS:
raise ValueError(('environment has wrong section "{0}"').format(param)) raise ValueError('environment has wrong section "{0}"'.format(param))
return env return env
@ -255,8 +223,8 @@ def _get_stack_events(h_client, stack_id, event_args):
event_args['resource_name'] = None event_args['resource_name'] = None
try: try:
events = h_client.events.list(**event_args) events = h_client.events.list(**event_args)
except exc.HTTPNotFound as ex: except heatclient.exc.HTTPNotFound as ex:
raise exc.CommandError(str(ex)) raise heatclient.exc.CommandError(str(ex))
else: else:
for event in events: for event in events:
event.stack_name = stack_id.split('/')[0] event.stack_name = stack_id.split('/')[0]
@ -385,7 +353,7 @@ def show_stack(name=None, profile=None):
'links': links, 'links': links,
} }
ret['result'] = True ret['result'] = True
except exc.HTTPNotFound: except heatclient.exc.HTTPNotFound:
return { return {
'result': False, 'result': False,
'comment': 'No stack {0}'.format(name) 'comment': 'No stack {0}'.format(name)
@ -428,10 +396,10 @@ def delete_stack(name=None, poll=0, timeout=60, profile=None):
return ret return ret
try: try:
h_client.stacks.delete(name) h_client.stacks.delete(name)
except exc.HTTPNotFound: except heatclient.exc.HTTPNotFound:
ret['result'] = False ret['result'] = False
ret['comment'] = 'No stack {0}'.format(name) ret['comment'] = 'No stack {0}'.format(name)
except exc.HTTPForbidden as forbidden: except heatclient.exc.HTTPForbidden as forbidden:
log.exception(str(forbidden)) log.exception(str(forbidden))
ret['result'] = False ret['result'] = False
ret['comment'] = str(forbidden) ret['comment'] = str(forbidden)
@ -442,7 +410,7 @@ def delete_stack(name=None, poll=0, timeout=60, profile=None):
try: try:
stack_status, msg = _poll_for_events(h_client, name, action='DELETE', stack_status, msg = _poll_for_events(h_client, name, action='DELETE',
poll_period=poll, timeout=timeout) poll_period=poll, timeout=timeout)
except exc.CommandError: except heatclient.exc.CommandError:
ret['comment'] = 'Deleted stack {0}.'.format(name) ret['comment'] = 'Deleted stack {0}.'.format(name)
return ret return ret
except Exception as ex: # pylint: disable=W0703 except Exception as ex: # pylint: disable=W0703
@ -858,18 +826,18 @@ def template_stack(name=None, profile=None):
} }
try: try:
get_template = h_client.stacks.template(name) get_template = h_client.stacks.template(name)
except exc.HTTPNotFound: except heatclient.exc.HTTPNotFound:
return { return {
'result': False, 'result': False,
'comment': 'No stack with {0}'.format(name) 'comment': 'No stack with {0}'.format(name)
} }
except exc.BadRequest: except heatclient.exc.BadRequest:
return { return {
'result': False, 'result': False,
'comment': 'Bad request fot stack {0}'.format(name) 'comment': 'Bad request fot stack {0}'.format(name)
} }
if 'heat_template_version' in get_template: if 'heat_template_version' in get_template:
template = yaml.dump(get_template, Dumper=YamlDumper) template = salt.utils.yaml.safe_dump(get_template)
else: else:
template = jsonutils.dumps(get_template, indent=2, ensure_ascii=False) template = jsonutils.dumps(get_template, indent=2, ensure_ascii=False)

View file

@ -218,15 +218,14 @@ Some `replace_text_regex` values that might be helpfull.
from __future__ import absolute_import from __future__ import absolute_import
import re import re
import yaml
import logging import logging
import salt.utils.files import salt.utils.files
import salt.utils.templates as tpl import salt.utils.templates as tpl
from salt.utils.yamldumper import OrderedDumper import salt.utils.yaml
__virtualname__ = 'highstate_doc' __virtualname__ = 'highstate_doc'
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -519,8 +518,7 @@ def _state_data_to_yaml_string(data, whitelist=None, blacklist=None):
y[k] = data[k] y[k] = data[k]
if len(y) == 0: if len(y) == 0:
return None return None
y = yaml.dump(y, Dumper=OrderedDumper, default_flow_style=False) return salt.utils.yaml.safe_dump(y, default_flow_style=False)
return y
def _md_fix(text): def _md_fix(text):

View file

@ -40,7 +40,6 @@ import sys
import os.path import os.path
import base64 import base64
import logging import logging
import yaml
import tempfile import tempfile
import signal import signal
from time import sleep from time import sleep
@ -50,6 +49,7 @@ from salt.exceptions import CommandExecutionError
from salt.ext.six import iteritems from salt.ext.six import iteritems
import salt.utils.files import salt.utils.files
import salt.utils.templates import salt.utils.templates
import salt.utils.yaml
from salt.exceptions import TimeoutError from salt.exceptions import TimeoutError
from salt.ext.six.moves import range # pylint: disable=import-error from salt.ext.six.moves import range # pylint: disable=import-error
@ -1475,7 +1475,7 @@ def __read_and_render_yaml_file(source,
'Unknown template specified: {0}'.format( 'Unknown template specified: {0}'.format(
template)) template))
return yaml.load(contents) return salt.utils.yaml.safe_load(contents)
def __dict_to_object_meta(name, namespace, metadata): def __dict_to_object_meta(name, namespace, metadata):

View file

@ -18,14 +18,13 @@ Module for Firing Events via PagerDuty
''' '''
from __future__ import absolute_import from __future__ import absolute_import
# Import python libs # Import Salt libs
import yaml
# Import salt libs
import salt.utils.functools import salt.utils.functools
import salt.utils.json import salt.utils.json
import salt.utils.pagerduty import salt.utils.pagerduty
from salt.ext.six import string_types
# Import 3rd-party libs
from salt.ext import six
def __virtual__(): def __virtual__():
@ -176,9 +175,9 @@ def create_event(service_key=None, description=None, details=None,
''' '''
trigger_url = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json' trigger_url = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json'
if isinstance(details, string_types): if isinstance(details, six.string_types):
details = yaml.safe_load(details) details = salt.utils.yaml.safe_load(details)
if isinstance(details, string_types): if isinstance(details, six.string_types):
details = {'details': details} details = {'details': details}
ret = salt.utils.json.loads(salt.utils.pagerduty.query( ret = salt.utils.json.loads(salt.utils.pagerduty.query(

View file

@ -24,11 +24,11 @@ from __future__ import absolute_import
import re import re
import logging import logging
import shlex import shlex
import yaml
# Import salt libs # Import salt libs
import salt.utils.locales import salt.utils.locales
import salt.utils.path import salt.utils.path
import salt.utils.yaml
from salt.exceptions import SaltInvocationError from salt.exceptions import SaltInvocationError
# Import 3rd party libs # Import 3rd party libs
@ -476,8 +476,8 @@ def snapshot_id_to_name(name, snap_id, strict=False, runas=None):
# Try to interpret the information # Try to interpret the information
try: try:
data = yaml.safe_load(info) data = salt.utils.yaml.safe_load(info)
except yaml.YAMLError as err: except salt.utils.yaml.YAMLError as err:
log.warning( log.warning(
'Could not interpret snapshot data returned from prlctl: ' 'Could not interpret snapshot data returned from prlctl: '
'{0}'.format(err) '{0}'.format(err)

View file

@ -12,7 +12,6 @@ import copy
import os import os
import copy import copy
import logging import logging
import yaml
from salt.ext import six from salt.ext import six
# Import salt libs # Import salt libs
@ -22,6 +21,7 @@ import salt.utils.data
import salt.utils.dictupdate import salt.utils.dictupdate
import salt.utils.functools import salt.utils.functools
import salt.utils.odict import salt.utils.odict
import salt.utils.yaml
from salt.defaults import DEFAULT_TARGET_DELIM from salt.defaults import DEFAULT_TARGET_DELIM
from salt.exceptions import CommandExecutionError from salt.exceptions import CommandExecutionError
@ -429,8 +429,8 @@ def ext(external, pillar=None):
.. code-block:: python .. code-block:: python
>>> import yaml >>> import salt.utils.yaml
>>> ext_pillar = yaml.safe_load(""" >>> ext_pillar = salt.utils.yaml.safe_load("""
... ext_pillar: ... ext_pillar:
... - git: ... - git:
... - issue38440 https://github.com/terminalmage/git_pillar: ... - issue38440 https://github.com/terminalmage/git_pillar:
@ -463,7 +463,7 @@ def ext(external, pillar=None):
salt '*' pillar.ext "{'git': [{'mybranch https://github.com/myuser/myrepo': [{'env': 'base'}]}]}" salt '*' pillar.ext "{'git': [{'mybranch https://github.com/myuser/myrepo': [{'env': 'base'}]}]}"
''' '''
if isinstance(external, six.string_types): if isinstance(external, six.string_types):
external = yaml.safe_load(external) external = salt.utils.yaml.safe_load(external)
pillar_obj = salt.pillar.get_pillar( pillar_obj = salt.pillar.get_pillar(
__opts__, __opts__,
__grains__, __grains__,

View file

@ -12,12 +12,12 @@ import os
import pprint import pprint
# Import third party libs # Import third party libs
import yaml
from salt.ext import six from salt.ext import six
# Import salt libs # Import salt libs
import salt.utils.data import salt.utils.data
import salt.utils.versions import salt.utils.versions
import salt.utils.yaml
from salt.exceptions import SaltInvocationError from salt.exceptions import SaltInvocationError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -72,8 +72,8 @@ def pack_sources(sources, normalize=True):
if isinstance(sources, six.string_types): if isinstance(sources, six.string_types):
try: try:
sources = yaml.safe_load(sources) sources = salt.utils.yaml.safe_load(sources)
except yaml.parser.ParserError as err: except salt.utils.yaml.parser.ParserError as err:
log.error(err) log.error(err)
return {} return {}
ret = {} ret = {}

View file

@ -15,10 +15,10 @@ import salt.utils.args
import salt.utils.files import salt.utils.files
import salt.utils.path import salt.utils.path
import salt.utils.platform import salt.utils.platform
import salt.utils.yaml
from salt.exceptions import CommandExecutionError from salt.exceptions import CommandExecutionError
# Import 3rd-party libs # Import 3rd-party libs
import yaml
from salt.ext import six from salt.ext import six
from salt.ext.six.moves import range from salt.ext.six.moves import range
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -312,7 +312,7 @@ def summary():
try: try:
with salt.utils.files.fopen(puppet.lastrunfile, 'r') as fp_: with salt.utils.files.fopen(puppet.lastrunfile, 'r') as fp_:
report = yaml.safe_load(fp_.read()) report = salt.utils.yaml.safe_load(fp_)
result = {} result = {}
if 'time' in report: if 'time' in report:
@ -330,7 +330,7 @@ def summary():
if 'resources' in report: if 'resources' in report:
result['resources'] = report['resources'] result['resources'] = report['resources']
except yaml.YAMLError as exc: except salt.utils.yaml.YAMLError as exc:
raise CommandExecutionError( raise CommandExecutionError(
'YAML error parsing puppet run summary: {0}'.format(exc) 'YAML error parsing puppet run summary: {0}'.format(exc)
) )

View file

@ -52,10 +52,10 @@ import logging
import os import os
import time import time
from json import loads, dumps from json import loads, dumps
import yaml
try: try:
import salt.utils.files import salt.utils.files
import salt.utils.path import salt.utils.path
import salt.utils.yaml
import salt.client import salt.client
import salt.exceptions import salt.exceptions
except ImportError: except ImportError:
@ -557,7 +557,7 @@ class StateTestLoader(object):
with __utils__['files.fopen'](filepath, 'r') as myfile: with __utils__['files.fopen'](filepath, 'r') as myfile:
# with salt.utils.files.fopen(filepath, 'r') as myfile: # with salt.utils.files.fopen(filepath, 'r') as myfile:
# with open(filepath, 'r') as myfile: # with open(filepath, 'r') as myfile:
contents_yaml = yaml.load(myfile) contents_yaml = salt.utils.yaml.safe_load(myfile)
for key, value in contents_yaml.items(): for key, value in contents_yaml.items():
self.test_dict[key] = value self.test_dict[key] = value
except: except:

View file

@ -12,12 +12,12 @@ import copy as pycopy
import difflib import difflib
import logging import logging
import os import os
import yaml
# Import salt libs # Import salt libs
import salt.utils.event import salt.utils.event
import salt.utils.files import salt.utils.files
import salt.utils.odict import salt.utils.odict
import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
from salt.ext import six from salt.ext import six
@ -140,8 +140,7 @@ def list_(show_all=False,
if schedule: if schedule:
if return_yaml: if return_yaml:
tmp = {'schedule': schedule} tmp = {'schedule': schedule}
yaml_out = yaml.safe_dump(tmp, default_flow_style=False) return salt.utils.yaml.safe_dump(tmp, default_flow_style=False)
return yaml_out
else: else:
return schedule return schedule
else: else:
@ -808,8 +807,8 @@ def reload_():
if os.path.isfile(sfn): if os.path.isfile(sfn):
with salt.utils.files.fopen(sfn, 'rb') as fp_: with salt.utils.files.fopen(sfn, 'rb') as fp_:
try: try:
schedule = yaml.safe_load(fp_.read()) schedule = salt.utils.yaml.safe_load(fp_)
except yaml.YAMLError as exc: except salt.utils.yaml.YAMLError as exc:
ret['comment'].append('Unable to read existing schedule file: {0}'.format(exc)) ret['comment'].append('Unable to read existing schedule file: {0}'.format(exc))
if schedule: if schedule:

View file

@ -23,7 +23,6 @@ Module for interop with the Splunk API
# Import python libs # Import python libs
from __future__ import absolute_import from __future__ import absolute_import
import logging import logging
import yaml
import urllib import urllib
# Import third party libs # Import third party libs
@ -37,6 +36,7 @@ except ImportError:
pass pass
# Import salt libs # Import salt libs
import salt.utils.yaml
from salt.utils.odict import OrderedDict from salt.utils.odict import OrderedDict
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -239,12 +239,6 @@ def list_all(prefix=None, app=None, owner=None, description_contains=None,
''' '''
client = _get_splunk(profile) client = _get_splunk(profile)
# yaml magic to output OrderedDict
def ordered_dict_presenter(dumper, data):
return dumper.represent_dict(six.iteritems(data))
yaml.add_representer(
OrderedDict, ordered_dict_presenter, Dumper=yaml.dumper.SafeDumper)
# splunklib doesn't provide the default settings for saved searches. # splunklib doesn't provide the default settings for saved searches.
# so, in order to get the defaults, we create a search with no # so, in order to get the defaults, we create a search with no
# configuration, get that search, and then delete it. We use its contents # configuration, get that search, and then delete it. We use its contents
@ -306,4 +300,4 @@ def list_all(prefix=None, app=None, owner=None, description_contains=None,
continue continue
results["manage splunk search " + name] = {"splunk_search.present": d} results["manage splunk search " + name] = {"splunk_search.present": d}
return yaml.safe_dump(results, default_flow_style=False, width=120) return salt.utils.yaml.safe_dump(results, default_flow_style=False, width=120)

View file

@ -22,7 +22,6 @@ import datetime
from xml.etree import ElementTree from xml.etree import ElementTree
# Import third party libs # Import third party libs
import yaml
import jinja2 import jinja2
import jinja2.exceptions import jinja2.exceptions
from salt.ext import six from salt.ext import six
@ -42,6 +41,7 @@ import salt.utils.path
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.templates import salt.utils.templates
import salt.utils.validate.net import salt.utils.validate.net
import salt.utils.yaml
from salt.exceptions import CommandExecutionError, SaltInvocationError from salt.exceptions import CommandExecutionError, SaltInvocationError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -400,7 +400,7 @@ def _qemu_image_create(vm_name,
qcow2 = False qcow2 = False
if salt.utils.path.which('qemu-img'): if salt.utils.path.which('qemu-img'):
res = __salt__['cmd.run']('qemu-img info {}'.format(sfn)) res = __salt__['cmd.run']('qemu-img info {}'.format(sfn))
imageinfo = yaml.load(res) imageinfo = salt.utils.yaml.safe_load(res)
qcow2 = imageinfo['file format'] == 'qcow2' qcow2 = imageinfo['file format'] == 'qcow2'
try: try:
if enable_qcow and qcow2: if enable_qcow and qcow2:
@ -1134,9 +1134,9 @@ def get_disks(vm_):
continue continue
output.append(line) output.append(line)
output = '\n'.join(output) output = '\n'.join(output)
disks[dev].update(yaml.safe_load(output)) disks[dev].update(salt.utils.yaml.safe_load(output))
except TypeError: except TypeError:
disks[dev].update(yaml.safe_load('image: Does not exist')) disks[dev].update({'image': 'Does not exist'})
return disks return disks
@ -1594,7 +1594,7 @@ def seed_non_shared_migrate(disks, force=False):
size = data['virtual size'].split()[1][1:] size = data['virtual size'].split()[1][1:]
if os.path.isfile(fn_) and not force: if os.path.isfile(fn_) and not force:
# the target exists, check to see if it is compatible # the target exists, check to see if it is compatible
pre = yaml.safe_load(subprocess.Popen('qemu-img info arch', pre = salt.utils.yaml.safe_load(subprocess.Popen('qemu-img info arch',
shell=True, shell=True,
stdout=subprocess.PIPE).communicate()[0]) stdout=subprocess.PIPE).communicate()[0])
if pre['file format'] != data['file format']\ if pre['file format'] != data['file format']\

View file

@ -17,7 +17,6 @@ import glob
import random import random
import ctypes import ctypes
import tempfile import tempfile
import yaml
import re import re
import datetime import datetime
import ast import ast
@ -177,7 +176,7 @@ def _parse_openssl_req(csr_filename):
output = re.sub(r': rsaEncryption', ':', output) output = re.sub(r': rsaEncryption', ':', output)
output = re.sub(r'[0-9a-f]{2}:', '', output) output = re.sub(r'[0-9a-f]{2}:', '', output)
return yaml.safe_load(output) return salt.utils.yaml.safe_load(output)
def _get_csr_extensions(csr): def _get_csr_extensions(csr):
@ -266,7 +265,7 @@ def _parse_openssl_crl(crl_filename):
rev_sn = revoked.split('\n')[0].strip() rev_sn = revoked.split('\n')[0].strip()
revoked = rev_sn + ':\n' + '\n'.join(revoked.split('\n')[1:]) revoked = rev_sn + ':\n' + '\n'.join(revoked.split('\n')[1:])
rev_yaml = yaml.safe_load(revoked) rev_yaml = salt.utils.yaml.safe_load(revoked)
# pylint: disable=unused-variable # pylint: disable=unused-variable
for rev_item, rev_values in six.iteritems(rev_yaml): for rev_item, rev_values in six.iteritems(rev_yaml):
# pylint: enable=unused-variable # pylint: enable=unused-variable

View file

@ -606,7 +606,6 @@ except ImportError:
cpstats = None cpstats = None
logger.warn('Import of cherrypy.cpstats failed.') logger.warn('Import of cherrypy.cpstats failed.')
import yaml
# pylint: enable=import-error, 3rd-party-module-not-gated # pylint: enable=import-error, 3rd-party-module-not-gated
# Import Salt libs # Import Salt libs
@ -617,6 +616,7 @@ import salt.utils.event
import salt.utils.json import salt.utils.json
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.versions import salt.utils.versions
import salt.utils.yaml
from salt.ext import six from salt.ext import six
from salt.ext.six import BytesIO from salt.ext.six import BytesIO
@ -837,7 +837,7 @@ def cors_tool():
ct_out_map = ( ct_out_map = (
('application/json', salt.utils.json.dumps), ('application/json', salt.utils.json.dumps),
('application/x-yaml', functools.partial( ('application/x-yaml', functools.partial(
yaml.safe_dump, default_flow_style=False)), salt.utils.yaml.safe_dump, default_flow_style=False)),
) )
@ -998,7 +998,7 @@ def yaml_processor(entity):
contents.seek(0) contents.seek(0)
body = salt.utils.stringutils.to_unicode(contents.read()) body = salt.utils.stringutils.to_unicode(contents.read())
try: try:
cherrypy.serving.request.unserialized_data = yaml.safe_load(body) cherrypy.serving.request.unserialized_data = salt.utils.yaml.safe_load(body)
except ValueError: except ValueError:
raise cherrypy.HTTPError(400, 'Invalid YAML document') raise cherrypy.HTTPError(400, 'Invalid YAML document')

View file

@ -196,7 +196,6 @@ from collections import defaultdict
# pylint: disable=import-error # pylint: disable=import-error
import cgi import cgi
import yaml
import tornado.escape import tornado.escape
import tornado.httpserver import tornado.httpserver
import tornado.ioloop import tornado.ioloop
@ -215,6 +214,7 @@ import salt.netapi
import salt.utils.args import salt.utils.args
import salt.utils.event import salt.utils.event
import salt.utils.json import salt.utils.json
import salt.utils.yaml
from salt.utils.event import tagify from salt.utils.event import tagify
import salt.client import salt.client
import salt.runner import salt.runner
@ -399,7 +399,7 @@ class EventListener(object):
class BaseSaltAPIHandler(tornado.web.RequestHandler, SaltClientsMixIn): # pylint: disable=W0223 class BaseSaltAPIHandler(tornado.web.RequestHandler, SaltClientsMixIn): # pylint: disable=W0223
ct_out_map = ( ct_out_map = (
('application/json', _json_dumps), ('application/json', _json_dumps),
('application/x-yaml', yaml.safe_dump), ('application/x-yaml', salt.utils.yaml.safe_dump),
) )
def _verify_client(self, low): def _verify_client(self, low):
@ -523,8 +523,8 @@ class BaseSaltAPIHandler(tornado.web.RequestHandler, SaltClientsMixIn): # pylin
ct_in_map = { ct_in_map = {
'application/x-www-form-urlencoded': self._form_loader, 'application/x-www-form-urlencoded': self._form_loader,
'application/json': salt.utils.json.loads, 'application/json': salt.utils.json.loads,
'application/x-yaml': yaml.safe_load, 'application/x-yaml': salt.utils.yaml.safe_load,
'text/yaml': yaml.safe_load, 'text/yaml': salt.utils.yaml.safe_load,
# because people are terrible and don't mean what they say # because people are terrible and don't mean what they say
'text/plain': salt.utils.json.loads 'text/plain': salt.utils.json.loads
} }

View file

@ -21,10 +21,9 @@ from __future__ import absolute_import, print_function, unicode_literals
# Import third party libs # Import third party libs
import logging import logging
import yaml
# Import salt libs # Import salt libs
from salt.utils.yamldumper import SafeOrderedDumper import salt.utils.yaml
# Define the module's virtual name # Define the module's virtual name
__virtualname__ = 'yaml' __virtualname__ = 'yaml'
@ -41,7 +40,7 @@ def output(data, **kwargs): # pylint: disable=unused-argument
Print out YAML using the block mode Print out YAML using the block mode
''' '''
params = dict(Dumper=SafeOrderedDumper) params = {}
if 'output_indent' not in __opts__: if 'output_indent' not in __opts__:
# default indentation # default indentation
params.update(default_flow_style=False) params.update(default_flow_style=False)
@ -53,7 +52,7 @@ def output(data, **kwargs): # pylint: disable=unused-argument
params.update(default_flow_style=True, params.update(default_flow_style=True,
indent=0) indent=0)
try: try:
return yaml.dump(data, **params) return salt.utils.yaml.safe_dump(data, **params)
except Exception as exc: except Exception as exc:
import pprint import pprint
log.exception( log.exception(

View file

@ -7,11 +7,11 @@ from __future__ import absolute_import
# Don't "fix" the above docstring to put it on two lines, as the sphinx # Don't "fix" the above docstring to put it on two lines, as the sphinx
# autosummary pulls only the first line for its description. # autosummary pulls only the first line for its description.
# Import python libs # Import Python libs
import logging import logging
# Import third party libs # Import Salt party libs
import yaml import salt.utils.yaml
# Set up logging # Set up logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -25,8 +25,11 @@ def ext_pillar(minion_id, # pylint: disable=W0613
''' '''
try: try:
command = command.replace('%s', minion_id) command = command.replace('%s', minion_id)
return yaml.safe_load( output = __salt__['cmd.run_stdout'](command, python_shell=True)
__salt__['cmd.run_stdout']('{0}'.format(command), python_shell=True)) return salt.utils.yaml.safe_load(output)
except Exception: except Exception:
log.critical('YAML data from {0} failed to parse'.format(command)) log.critical(
'YAML data from \'%s\' failed to parse. Command output:\n%s',
command, output
)
return {} return {}

View file

@ -125,12 +125,11 @@ from __future__ import absolute_import
# Import python libs # Import python libs
import logging import logging
import re import re
import yaml
from salt.exceptions import CommandExecutionError from salt.exceptions import CommandExecutionError
from salt.utils.dictupdate import update as dict_merge from salt.utils.dictupdate import update as dict_merge
import salt.utils.minions import salt.utils.minions
from salt.utils.yamlloader import SaltYamlSafeLoader import salt.utils.yaml
# Import third party libs # Import third party libs
try: try:
@ -253,10 +252,7 @@ def pillar_format(ret, keys, value):
# If value is not None then it's a string # If value is not None then it's a string
# Use YAML to parse the data # Use YAML to parse the data
# YAML strips whitespaces unless they're surrounded by quotes # YAML strips whitespaces unless they're surrounded by quotes
pillar_value = yaml.load( pillar_value = salt.utils.yaml.safe_load(value)
value,
Loader=SaltYamlSafeLoader
)
keyvalue = keys.pop() keyvalue = keys.pop()
pil = {keyvalue: pillar_value} pil = {keyvalue: pillar_value}

View file

@ -6,10 +6,10 @@ Use hiera data as a Pillar source
# Import Python libs # Import Python libs
from __future__ import absolute_import from __future__ import absolute_import
import logging import logging
import yaml
# Import salt libs # Import salt libs
import salt.utils.path import salt.utils.path
import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
from salt.ext import six from salt.ext import six
@ -37,7 +37,7 @@ def ext_pillar(minion_id, # pylint: disable=W0613
if isinstance(val, six.string_types): if isinstance(val, six.string_types):
cmd += ' {0}=\'{1}\''.format(key, val) cmd += ' {0}=\'{1}\''.format(key, val)
try: try:
data = yaml.safe_load(__salt__['cmd.run'](cmd)) data = salt.utils.yaml.safe_load(__salt__['cmd.run'](cmd))
except Exception: except Exception:
log.critical( log.critical(
'Hiera YAML data failed to parse from conf {0}'.format(conf) 'Hiera YAML data failed to parse from conf {0}'.format(conf)

View file

@ -375,12 +375,14 @@ You can also select a custom merging strategy using a ``__`` object in a list:
# Import Python libs # Import Python libs
from __future__ import absolute_import from __future__ import absolute_import
import functools
import os import os
import logging import logging
from functools import partial
import yaml
# Import Salt libs # Import Salt libs
import salt.utils.yaml
# Import 3rd-party libs
from salt.ext import six from salt.ext import six
try: try:
@ -411,9 +413,9 @@ def ext_pillar(minion_id, pillar, *args, **kwargs):
stack = {} stack = {}
stack_config_files = list(args) stack_config_files = list(args)
traverse = { traverse = {
'pillar': partial(salt.utils.data.traverse_dict_and_list, pillar), 'pillar': functools.partial(salt.utils.data.traverse_dict_and_list, pillar),
'grains': partial(salt.utils.data.traverse_dict_and_list, __grains__), 'grains': functools.partial(salt.utils.data.traverse_dict_and_list, __grains__),
'opts': partial(salt.utils.data.traverse_dict_and_list, __opts__), 'opts': functools.partial(salt.utils.data.traverse_dict_and_list, __opts__),
} }
for matcher, matchs in six.iteritems(kwargs): for matcher, matchs in six.iteritems(kwargs):
t, matcher = matcher.split(':', 1) t, matcher = matcher.split(':', 1)
@ -456,7 +458,7 @@ def _process_stack_cfg(cfg, stack, minion_id, pillar, namespace):
__grains__=__grains__, __grains__=__grains__,
minion_id=minion_id, minion_id=minion_id,
pillar=pillar, stack=stack) pillar=pillar, stack=stack)
obj = yaml.safe_load(p) obj = salt.utils.yaml.safe_load(p)
if not isinstance(obj, dict): if not isinstance(obj, dict):
log.info('Ignoring Stack template "{0}": Can\'t parse ' log.info('Ignoring Stack template "{0}": Can\'t parse '
'as a valid yaml dictionary'.format(path)) 'as a valid yaml dictionary'.format(path))
@ -541,9 +543,11 @@ def _merge_list(stack, obj):
def _parse_top_cfg(content): def _parse_top_cfg(content):
"""Allow top_cfg to be YAML""" '''
Allow top_cfg to be YAML
'''
try: try:
obj = yaml.safe_load(content) obj = salt.utils.yaml.safe_load(content)
if isinstance(obj, list): if isinstance(obj, list):
return obj return obj
except Exception as e: except Exception as e:

View file

@ -271,19 +271,18 @@ __license__ = 'Apache License, Version 2.0'
__version__ = '0.6.6' __version__ = '0.6.6'
# Import python libs # Import python libs
import logging
import sys
import glob import glob
import yaml
import jinja2 import jinja2
import logging
import os
import re import re
from os.path import isfile, join import sys
# Import Salt libs # Import Salt libs
from salt.ext import six from salt.ext import six
from salt.ext.six.moves import input # pylint: disable=import-error,redefined-builtin from salt.ext.six.moves import input # pylint: disable=import-error,redefined-builtin
import salt.utils.files import salt.utils.files
from salt.utils.yamlloader import SaltYamlSafeLoader import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
try: try:
@ -409,9 +408,9 @@ def ext_pillar(minion_id, pillar, resource, sequence, subkey=False, subkey_only=
templdir = None templdir = None
if info and 'base_only' in info and info['base_only']: if info and 'base_only' in info and info['base_only']:
templdir = join(roots['base'], resource, alias) templdir = os.path.join(roots['base'], resource, alias)
else: else:
templdir = join(roots[inp['environment']], resource, alias) templdir = os.path.join(roots[inp['environment']], resource, alias)
entries = [] entries = []
if isinstance(inp[categ], list): if isinstance(inp[categ], list):
@ -425,8 +424,8 @@ def ext_pillar(minion_id, pillar, resource, sequence, subkey=False, subkey_only=
for entry in entries: for entry in entries:
results_jinja = None results_jinja = None
results = None results = None
fn = join(templdir, re.sub(r'\W', '_', entry.lower()) + '.yaml') fn = os.path.join(templdir, re.sub(r'\W', '_', entry.lower()) + '.yaml')
if isfile(fn): if os.path.isfile(fn):
log.info("Loading template: {0}".format(fn)) log.info("Loading template: {0}".format(fn))
with salt.utils.files.fopen(fn) as fhr: with salt.utils.files.fopen(fn) as fhr:
template = jinja2.Template(fhr.read()) template = jinja2.Template(fhr.read())
@ -437,13 +436,10 @@ def ext_pillar(minion_id, pillar, resource, sequence, subkey=False, subkey_only=
data['grains'] = __grains__.copy() data['grains'] = __grains__.copy()
data['pillar'] = pillar.copy() data['pillar'] = pillar.copy()
results_jinja = template.render(data) results_jinja = template.render(data)
results = yaml.load( results = salt.utils.yaml.safe_load(results_jinja)
results_jinja,
Loader=SaltYamlSafeLoader
)
except jinja2.UndefinedError as err: except jinja2.UndefinedError as err:
log.error('Failed to parse JINJA template: {0}\n{1}'.format(fn, err)) log.error('Failed to parse JINJA template: {0}\n{1}'.format(fn, err))
except yaml.YAMLError as err: except salt.utils.yaml.YAMLError as err:
log.error('Failed to parse YAML in template: {0}\n{1}'.format(fn, err)) log.error('Failed to parse YAML in template: {0}\n{1}'.format(fn, err))
else: else:
log.info("Template doesn't exist: {0}".format(fn)) log.info("Template doesn't exist: {0}".format(fn))
@ -522,7 +518,7 @@ def validate(output, resource):
roots = __opts__['pepa_roots'] roots = __opts__['pepa_roots']
valdir = join(roots['base'], resource, 'validate') valdir = os.path.join(roots['base'], resource, 'validate')
all_schemas = {} all_schemas = {}
pepa_schemas = [] pepa_schemas = []
@ -533,10 +529,7 @@ def validate(output, resource):
data = output data = output
data['grains'] = __grains__.copy() data['grains'] = __grains__.copy()
data['pillar'] = __pillar__.copy() data['pillar'] = __pillar__.copy()
schema = yaml.load( schema = salt.utils.yaml.safe_load(template.render(data))
template.render(data),
Loader=SaltYamlSafeLoader
)
all_schemas.update(schema) all_schemas.update(schema)
pepa_schemas.append(fn) pepa_schemas.append(fn)
@ -552,18 +545,13 @@ def validate(output, resource):
# Only used when called from a terminal # Only used when called from a terminal
if __name__ == '__main__': if __name__ == '__main__':
# Load configuration file # Load configuration file
if not isfile(args.config): if not os.path.isfile(args.config):
log.critical("Configuration file doesn't exist: {0}".format(args.config)) log.critical("Configuration file doesn't exist: {0}".format(args.config))
sys.exit(1) sys.exit(1)
# Get configuration # Get configuration
with salt.utils.files.fopen(args.config) as fh_: with salt.utils.files.fopen(args.config) as fh_:
__opts__.update( __opts__.update(salt.utils.yaml.safe_load(fh_))
yaml.load(
fh_.read(),
Loader=SaltYamlSafeLoader
)
)
loc = 0 loc = 0
for name in [next(iter(list(e.keys()))) for e in __opts__['ext_pillar']]: for name in [next(iter(list(e.keys()))) for e in __opts__['ext_pillar']]:
@ -576,24 +564,14 @@ if __name__ == '__main__':
if 'pepa_grains' in __opts__: if 'pepa_grains' in __opts__:
__grains__ = __opts__['pepa_grains'] __grains__ = __opts__['pepa_grains']
if args.grains: if args.grains:
__grains__.update( __grains__.update(salt.utils.yaml.safe_load(args.grains))
yaml.load(
args.grains,
Loader=SaltYamlSafeLoader
)
)
# Get pillars # Get pillars
__pillar__ = {} __pillar__ = {}
if 'pepa_pillar' in __opts__: if 'pepa_pillar' in __opts__:
__pillar__ = __opts__['pepa_pillar'] __pillar__ = __opts__['pepa_pillar']
if args.pillar: if args.pillar:
__pillar__.update( __pillar__.update(salt.utils.yaml.safe_load(args.pillar))
yaml.load(
args.pillar,
Loader=SaltYamlSafeLoader
)
)
# Validate or not # Validate or not
if args.validate: if args.validate:
@ -644,7 +622,16 @@ if __name__ == '__main__':
if __opts__['pepa_validate']: if __opts__['pepa_validate']:
validate(result, __opts__['ext_pillar'][loc]['pepa']['resource']) validate(result, __opts__['ext_pillar'][loc]['pepa']['resource'])
yaml.dumper.SafeDumper.ignore_aliases = lambda self, data: True try:
orig_ignore = salt.utils.yaml.SafeOrderedDumper.ignore_aliases
salt.utils.yaml.SafeOrderedDumper.ignore_aliases = lambda x, y: True
def _print_result(result):
print(salt.utils.yaml.safe_dump(
result,
indent=4,
default_flow_style=False))
if not args.no_color: if not args.no_color:
try: try:
# pylint: disable=import-error # pylint: disable=import-error
@ -652,11 +639,15 @@ if __name__ == '__main__':
import pygments.lexers import pygments.lexers
import pygments.formatters import pygments.formatters
# pylint: disable=no-member # pylint: disable=no-member
print(pygments.highlight(yaml.safe_dump(result), print(pygments.highlight(
salt.utils.yaml.safe_dump(result),
pygments.lexers.YamlLexer(), pygments.lexers.YamlLexer(),
pygments.formatters.TerminalFormatter())) pygments.formatters.TerminalFormatter()))
# pylint: enable=no-member, import-error # pylint: enable=no-member, import-error
except ImportError: except ImportError:
print(yaml.safe_dump(result, indent=4, default_flow_style=False)) _print_result(result)
else: else:
print(yaml.safe_dump(result, indent=4, default_flow_style=False)) _print_result(result)
finally:
# Undo monkeypatching
salt.utils.yaml.SafeOrderedDumper.ignore_aliases = orig_ignore

View file

@ -113,8 +113,7 @@ TODO: see also ``_result_to_dict()`` documentation
''' '''
# Import python libs # Import python libs
from __future__ import print_function from __future__ import absolute_import, print_function
from __future__ import absolute_import
import os import os
import logging import logging
@ -122,7 +121,6 @@ import logging
from salt.exceptions import SaltInvocationError from salt.exceptions import SaltInvocationError
# Import third party libs # Import third party libs
import yaml
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
try: try:
import ldap # pylint: disable=W0611 import ldap # pylint: disable=W0611
@ -278,10 +276,11 @@ def ext_pillar(minion_id, # pylint: disable=W0613
Execute LDAP searches and return the aggregated data Execute LDAP searches and return the aggregated data
''' '''
if os.path.isfile(config_file): if os.path.isfile(config_file):
import salt.utils.yaml
try: try:
#open(config_file, 'r') as raw_config: #open(config_file, 'r') as raw_config:
config = _render_template(config_file) or {} config = _render_template(config_file) or {}
opts = yaml.safe_load(config) or {} opts = salt.utils.yaml.safe_load(config) or {}
opts['conf_file'] = config_file opts['conf_file'] = config_file
except Exception as err: except Exception as err:
import salt.log import salt.log

View file

@ -7,11 +7,11 @@ from __future__ import absolute_import
# Don't "fix" the above docstring to put it on two lines, as the sphinx # Don't "fix" the above docstring to put it on two lines, as the sphinx
# autosummary pulls only the first line for its description. # autosummary pulls only the first line for its description.
# Import python libs # Import Python libs
import logging import logging
# Import third party libs # Import Salt libs
import yaml import salt.utils.yaml
# Set up logging # Set up logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -24,9 +24,8 @@ def ext_pillar(minion_id,
Execute an unmodified puppet_node_classifier and read the output as YAML Execute an unmodified puppet_node_classifier and read the output as YAML
''' '''
try: try:
data = yaml.safe_load(__salt__['cmd.run']('{0} {1}'.format(command, minion_id))) data = salt.utils.yaml.safe_load(__salt__['cmd.run']('{0} {1}'.format(command, minion_id)))
data = data['parameters'] return data['parameters']
return data
except Exception: except Exception:
log.critical( log.critical(
'YAML data from {0} failed to parse'.format(command) 'YAML data from {0} failed to parse'.format(command)

View file

@ -376,20 +376,19 @@ You can also select a custom merging strategy using a ``__`` object in a list:
# Import Python libs # Import Python libs
from __future__ import absolute_import from __future__ import absolute_import
import functools
import glob
import os import os
import posixpath import posixpath
import logging import logging
from functools import partial
from glob import glob
import yaml
from jinja2 import FileSystemLoader, Environment from jinja2 import FileSystemLoader, Environment
# Import Salt libs # Import Salt libs
from salt.ext import six from salt.ext import six
import salt.utils.data import salt.utils.data
import salt.utils.jinja import salt.utils.jinja
import salt.utils.yaml
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
strategies = ('overwrite', 'merge-first', 'merge-last', 'remove') strategies = ('overwrite', 'merge-first', 'merge-last', 'remove')
@ -399,9 +398,9 @@ def ext_pillar(minion_id, pillar, *args, **kwargs):
stack = {} stack = {}
stack_config_files = list(args) stack_config_files = list(args)
traverse = { traverse = {
'pillar': partial(salt.utils.data.traverse_dict_and_list, pillar), 'pillar': functools.partial(salt.utils.data.traverse_dict_and_list, pillar),
'grains': partial(salt.utils.data.traverse_dict_and_list, __grains__), 'grains': functools.partial(salt.utils.data.traverse_dict_and_list, __grains__),
'opts': partial(salt.utils.data.traverse_dict_and_list, __opts__), 'opts': functools.partial(salt.utils.data.traverse_dict_and_list, __opts__),
} }
for matcher, matchs in six.iteritems(kwargs): for matcher, matchs in six.iteritems(kwargs):
t, matcher = matcher.split(':', 1) t, matcher = matcher.split(':', 1)
@ -432,7 +431,6 @@ def _construct_unicode(loader, node):
def _process_stack_cfg(cfg, stack, minion_id, pillar): def _process_stack_cfg(cfg, stack, minion_id, pillar):
log.debug('Config: {0}'.format(cfg)) log.debug('Config: {0}'.format(cfg))
basedir, filename = os.path.split(cfg) basedir, filename = os.path.split(cfg)
yaml.SafeLoader.add_constructor("tag:yaml.org,2002:python/unicode", _construct_unicode)
jenv = Environment(loader=FileSystemLoader(basedir), extensions=['jinja2.ext.do', salt.utils.jinja.SerializerExtension]) jenv = Environment(loader=FileSystemLoader(basedir), extensions=['jinja2.ext.do', salt.utils.jinja.SerializerExtension])
jenv.globals.update({ jenv.globals.update({
"__opts__": __opts__, "__opts__": __opts__,
@ -448,7 +446,7 @@ def _process_stack_cfg(cfg, stack, minion_id, pillar):
jenv.get_template(filename).render(stack=stack)): jenv.get_template(filename).render(stack=stack)):
if not item.strip(): if not item.strip():
continue # silently ignore whitespace or empty lines continue # silently ignore whitespace or empty lines
paths = glob(os.path.join(basedir, item)) paths = glob.glob(os.path.join(basedir, item))
if not paths: if not paths:
log.warning('Ignoring pillar stack template "{0}": can\'t find from ' log.warning('Ignoring pillar stack template "{0}": can\'t find from '
'root dir "{1}"'.format(item, basedir)) 'root dir "{1}"'.format(item, basedir))
@ -457,7 +455,7 @@ def _process_stack_cfg(cfg, stack, minion_id, pillar):
log.debug('YAML: basedir={0}, path={1}'.format(basedir, path)) log.debug('YAML: basedir={0}, path={1}'.format(basedir, path))
# FileSystemLoader always expects unix-style paths # FileSystemLoader always expects unix-style paths
unix_path = _to_unix_slashes(os.path.relpath(path, basedir)) unix_path = _to_unix_slashes(os.path.relpath(path, basedir))
obj = yaml.safe_load(jenv.get_template(unix_path).render(stack=stack)) obj = salt.utils.yaml.safe_load(jenv.get_template(unix_path).render(stack=stack))
if not isinstance(obj, dict): if not isinstance(obj, dict):
log.info('Ignoring pillar stack template "{0}": Can\'t parse ' log.info('Ignoring pillar stack template "{0}": Can\'t parse '
'as a valid yaml dictionary'.format(path)) 'as a valid yaml dictionary'.format(path))
@ -535,7 +533,7 @@ def _parse_stack_cfg(content):
Allow top level cfg to be YAML Allow top level cfg to be YAML
''' '''
try: try:
obj = yaml.safe_load(content) obj = salt.utils.yaml.safe_load(content)
if isinstance(obj, list): if isinstance(obj, list):
return obj return obj
except Exception as e: except Exception as e:

View file

@ -84,7 +84,6 @@ import smtplib
import cgi import cgi
from email.mime.text import MIMEText from email.mime.text import MIMEText
import yaml
from salt.ext.six.moves import range from salt.ext.six.moves import range
from salt.ext.six.moves import StringIO from salt.ext.six.moves import StringIO
from salt.ext import six from salt.ext import six
@ -92,6 +91,7 @@ from salt.ext import six
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.yaml
import salt.returners import salt.returners
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -427,7 +427,7 @@ def _produce_output(report, failed, setup):
report_text = salt.utils.json.dumps(report) report_text = salt.utils.json.dumps(report)
elif report_format == 'yaml': elif report_format == 'yaml':
string_file = StringIO() string_file = StringIO()
yaml.safe_dump(report, string_file, default_flow_style=False) salt.utils.yaml.safe_dump(report, string_file, default_flow_style=False)
string_file.seek(0) string_file.seek(0)
report_text = string_file.read() report_text = string_file.read()
else: else:
@ -494,7 +494,7 @@ def __test_html():
''' '''
with salt.utils.files.fopen('test.rpt', 'r') as input_file: with salt.utils.files.fopen('test.rpt', 'r') as input_file:
data_text = salt.utils.stringutils.to_unicode(input_file.read()) data_text = salt.utils.stringutils.to_unicode(input_file.read())
data = yaml.safe_load(data_text) data = salt.utils.yaml.safe_load(data_text)
string_file = StringIO() string_file = StringIO()
_generate_html(data, string_file) _generate_html(data, string_file)

View file

@ -79,7 +79,6 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
# Import Python libs # Import Python libs
import yaml
import pprint import pprint
import logging import logging
@ -91,7 +90,7 @@ from salt.ext.six.moves.urllib.parse import urlencode as _urlencode
# Import Salt Libs # Import Salt Libs
import salt.returners import salt.returners
import salt.utils.slack import salt.utils.slack
from salt.utils.yamldumper import SafeOrderedDumper import salt.utils.yaml
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -212,7 +211,7 @@ def returner(ret):
returns = dict((key, value) for key, value in returns.items() if value['result'] is not True or value['changes']) returns = dict((key, value) for key, value in returns.items() if value['result'] is not True or value['changes'])
if yaml_format is True: if yaml_format is True:
returns = yaml.dump(returns, Dumper=SafeOrderedDumper) returns = salt.utils.yaml.safe_dump(returns)
else: else:
returns = pprint.pformat(returns) returns = pprint.pformat(returns)

View file

@ -17,13 +17,11 @@ Runner Module for Firing Events via PagerDuty
''' '''
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import yaml
# Import salt libs # Import salt libs
import salt.utils.functools import salt.utils.functools
import salt.utils.json import salt.utils.json
import salt.utils.pagerduty import salt.utils.pagerduty
import salt.utils.yaml
from salt.ext import six from salt.ext import six
@ -176,7 +174,7 @@ def create_event(service_key=None, description=None, details=None,
trigger_url = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json' trigger_url = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json'
if isinstance(details, six.string_types): if isinstance(details, six.string_types):
details = yaml.safe_load(details) details = salt.utils.yaml.safe_load(details)
if isinstance(details, six.string_types): if isinstance(details, six.string_types):
details = {'details': details} details = {'details': details}

View file

@ -8,7 +8,6 @@ This module provides the point of entry to SPM, the Salt Package Manager
# Import Python libs # Import Python libs
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
import os import os
import yaml
import tarfile import tarfile
import shutil import shutil
import hashlib import hashlib
@ -36,7 +35,7 @@ import salt.utils.http as http
import salt.utils.path import salt.utils.path
import salt.utils.platform import salt.utils.platform
import salt.utils.win_functions import salt.utils.win_functions
from salt.utils.yamldumper import SafeOrderedDumper import salt.utils.yaml
# Get logging started # Get logging started
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -255,7 +254,7 @@ class SPMClient(object):
formula_tar = tarfile.open(pkg, 'r:bz2') formula_tar = tarfile.open(pkg, 'r:bz2')
formula_ref = formula_tar.extractfile('{0}/FORMULA'.format(pkg_name)) formula_ref = formula_tar.extractfile('{0}/FORMULA'.format(pkg_name))
formula_def = yaml.safe_load(formula_ref) formula_def = salt.utils.yaml.safe_load(formula_ref)
file_map[pkg_name] = pkg file_map[pkg_name] = pkg
to_, op_, re_ = self._check_all_deps( to_, op_, re_ = self._check_all_deps(
@ -459,7 +458,7 @@ class SPMClient(object):
self.ui.status('... installing {0}'.format(pkg_name)) self.ui.status('... installing {0}'.format(pkg_name))
formula_tar = tarfile.open(pkg_file, 'r:bz2') formula_tar = tarfile.open(pkg_file, 'r:bz2')
formula_ref = formula_tar.extractfile('{0}/FORMULA'.format(pkg_name)) formula_ref = formula_tar.extractfile('{0}/FORMULA'.format(pkg_name))
formula_def = yaml.safe_load(formula_ref) formula_def = salt.utils.yaml.safe_load(formula_ref)
for field in ('version', 'release', 'summary', 'description'): for field in ('version', 'release', 'summary', 'description'):
if field not in formula_def: if field not in formula_def:
@ -625,7 +624,7 @@ class SPMClient(object):
for repo_file in repo_files: for repo_file in repo_files:
repo_path = '{0}.d/{1}'.format(self.opts['spm_repos_config'], repo_file) repo_path = '{0}.d/{1}'.format(self.opts['spm_repos_config'], repo_file)
with salt.utils.files.fopen(repo_path) as rph: with salt.utils.files.fopen(repo_path) as rph:
repo_data = yaml.safe_load(rph) repo_data = salt.utils.yaml.safe_load(rph)
for repo in repo_data: for repo in repo_data:
if repo_data[repo].get('enabled', True) is False: if repo_data[repo].get('enabled', True) is False:
continue continue
@ -662,7 +661,7 @@ class SPMClient(object):
try: try:
if query: if query:
if 'SPM-METADATA' in dl_path: if 'SPM-METADATA' in dl_path:
response = yaml.safe_load(query.get('text', '{}')) response = salt.utils.yaml.safe_load(query.get('text', '{}'))
else: else:
response = query.get('text') response = query.get('text')
else: else:
@ -683,7 +682,7 @@ class SPMClient(object):
if dl_path.startswith('file://'): if dl_path.startswith('file://'):
dl_path = dl_path.replace('file://', '') dl_path = dl_path.replace('file://', '')
with salt.utils.files.fopen(dl_path, 'r') as rpm: with salt.utils.files.fopen(dl_path, 'r') as rpm:
metadata = yaml.safe_load(rpm) metadata = salt.utils.yaml.safe_load(rpm)
else: else:
metadata = self._query_http(dl_path, repo_info) metadata = self._query_http(dl_path, repo_info)
@ -738,7 +737,7 @@ class SPMClient(object):
spm_name = '-'.join(comps[:-2]) spm_name = '-'.join(comps[:-2])
spm_fh = tarfile.open(spm_path, 'r:bz2') spm_fh = tarfile.open(spm_path, 'r:bz2')
formula_handle = spm_fh.extractfile('{0}/FORMULA'.format(spm_name)) formula_handle = spm_fh.extractfile('{0}/FORMULA'.format(spm_name))
formula_conf = yaml.safe_load(formula_handle.read()) formula_conf = salt.utils.yaml.safe_load(formula_handle.read())
use_formula = True use_formula = True
if spm_name in repo_metadata: if spm_name in repo_metadata:
@ -784,13 +783,12 @@ class SPMClient(object):
metadata_filename = '{0}/SPM-METADATA'.format(repo_path) metadata_filename = '{0}/SPM-METADATA'.format(repo_path)
with salt.utils.files.fopen(metadata_filename, 'w') as mfh: with salt.utils.files.fopen(metadata_filename, 'w') as mfh:
yaml.dump( salt.utils.yaml.safe_dump(
repo_metadata, repo_metadata,
mfh, mfh,
indent=4, indent=4,
canonical=False, canonical=False,
default_flow_style=False, default_flow_style=False,
Dumper=SafeOrderedDumper
) )
log.debug('Wrote %s', metadata_filename) log.debug('Wrote %s', metadata_filename)
@ -900,7 +898,7 @@ class SPMClient(object):
formula_tar = tarfile.open(pkg_file, 'r:bz2') formula_tar = tarfile.open(pkg_file, 'r:bz2')
formula_ref = formula_tar.extractfile('{0}/FORMULA'.format(name)) formula_ref = formula_tar.extractfile('{0}/FORMULA'.format(name))
formula_def = yaml.safe_load(formula_ref) formula_def = salt.utils.yaml.safe_load(formula_ref)
self.ui.status(self._get_info(formula_def)) self.ui.status(self._get_info(formula_def))
@ -1017,7 +1015,7 @@ class SPMClient(object):
if not os.path.exists(formula_path): if not os.path.exists(formula_path):
raise SPMPackageError('Formula file {0} not found'.format(formula_path)) raise SPMPackageError('Formula file {0} not found'.format(formula_path))
with salt.utils.files.fopen(formula_path) as fp_: with salt.utils.files.fopen(formula_path) as fp_:
formula_conf = yaml.safe_load(fp_) formula_conf = salt.utils.yaml.safe_load(fp_)
for field in ('name', 'version', 'release', 'summary', 'description'): for field in ('name', 'version', 'release', 'summary', 'description'):
if field not in formula_conf: if field not in formula_conf:

View file

@ -52,12 +52,11 @@ import hashlib
import logging import logging
import os import os
import re import re
import yaml
# Import Salt Libs # Import Salt Libs
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
from salt.utils.yamlloader import SaltYamlSafeLoader import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
from salt.ext import six from salt.ext import six
@ -718,10 +717,7 @@ class _Swagger(object):
error_response_template, error_response_template,
response_template) response_template)
with salt.utils.files.fopen(self._swagger_file, 'rb') as sf: with salt.utils.files.fopen(self._swagger_file, 'rb') as sf:
self._cfg = yaml.load( self._cfg = salt.utils.yaml.safe_load(sf)
sf,
Loader=SaltYamlSafeLoader
)
self._swagger_version = '' self._swagger_version = ''
else: else:
raise IOError('Invalid swagger file path, {0}'.format(swagger_file_path)) raise IOError('Invalid swagger file path, {0}'.format(swagger_file_path))

View file

@ -49,8 +49,6 @@ from __future__ import absolute_import
import difflib import difflib
import logging import logging
import yaml
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -176,14 +174,16 @@ def present(
) )
def _yaml_safe_dump(attrs): def _yaml_safe_dump(attrs):
'''Safely dump YAML using a readable flow style''' '''
Safely dump YAML using a readable flow style
'''
dumper_name = 'IndentedSafeOrderedDumper' dumper_name = 'IndentedSafeOrderedDumper'
dumper = __utils__['yamldumper.get_dumper'](dumper_name) dumper = __utils__['yaml.get_dumper'](dumper_name)
return yaml.dump( return __utils__['yaml.dump'](
attrs, attrs,
default_flow_style=False, default_flow_style=False,
Dumper=dumper, Dumper=dumper)
)
changes_diff = ''.join(difflib.unified_diff( changes_diff = ''.join(difflib.unified_diff(
_yaml_safe_dump(full_config_old).splitlines(True), _yaml_safe_dump(full_config_old).splitlines(True),
_yaml_safe_dump(full_config_new).splitlines(True), _yaml_safe_dump(full_config_new).splitlines(True),

View file

@ -55,8 +55,6 @@ import copy
import difflib import difflib
import logging import logging
import yaml
# Import Salt libs # Import Salt libs
import salt.ext.six as six import salt.ext.six as six
import salt.utils.hashutils import salt.utils.hashutils
@ -265,14 +263,16 @@ def object_present(
action = 'create' action = 'create'
def _yaml_safe_dump(attrs): def _yaml_safe_dump(attrs):
'''Safely dump YAML using a readable flow style''' '''
Safely dump YAML using a readable flow style
'''
dumper_name = 'IndentedSafeOrderedDumper' dumper_name = 'IndentedSafeOrderedDumper'
dumper = __utils__['yamldumper.get_dumper'](dumper_name) dumper = __utils__['yaml.get_dumper'](dumper_name)
return yaml.dump( return __utils__['yaml.dump'](
attrs, attrs,
default_flow_style=False, default_flow_style=False,
Dumper=dumper, Dumper=dumper)
)
changes_diff = ''.join(difflib.unified_diff( changes_diff = ''.join(difflib.unified_diff(
_yaml_safe_dump(s3_metadata).splitlines(True), _yaml_safe_dump(s3_metadata).splitlines(True),
_yaml_safe_dump(desired_metadata).splitlines(True), _yaml_safe_dump(desired_metadata).splitlines(True),

View file

@ -62,7 +62,6 @@ from __future__ import absolute_import
# Import Python libs # Import Python libs
import difflib import difflib
import logging import logging
import yaml
# Import Salt libs # Import Salt libs
import salt.utils.json import salt.utils.json
@ -204,14 +203,15 @@ def present(
final_attributes.update(attrs_to_set) final_attributes.update(attrs_to_set)
def _yaml_safe_dump(attrs): def _yaml_safe_dump(attrs):
'''Safely dump YAML using a readable flow style''' '''
dumper_name = 'IndentedSafeOrderedDumper' Safely dump YAML using a readable flow style
dumper = __utils__['yamldumper.get_dumper'](dumper_name) '''
return yaml.dump( dumper = __utils__['yaml.get_dumper']('IndentedSafeOrderedDumper')
return __utils__['yaml.dump'](
attrs, attrs,
default_flow_style=False, default_flow_style=False,
Dumper=dumper, Dumper=dumper)
)
attributes_diff = ''.join(difflib.unified_diff( attributes_diff = ''.join(difflib.unified_diff(
_yaml_safe_dump(current_attributes).splitlines(True), _yaml_safe_dump(current_attributes).splitlines(True),
_yaml_safe_dump(final_attributes).splitlines(True), _yaml_safe_dump(final_attributes).splitlines(True),

View file

@ -37,11 +37,11 @@ mysql:
# Import Python libs # Import Python libs
from __future__ import absolute_import from __future__ import absolute_import
import logging import logging
import yaml
# Import Salt libs # Import Salt libs
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
import salt.utils.yaml
import salt.exceptions import salt.exceptions
# Import 3rd-party libs # Import 3rd-party libs
@ -55,36 +55,6 @@ try:
except ImportError: except ImportError:
pass pass
if hasattr(yaml, 'CSafeLoader'):
YamlLoader = yaml.CSafeLoader
else:
YamlLoader = yaml.SafeLoader
if hasattr(yaml, 'CSafeDumper'):
YamlDumper = yaml.CSafeDumper
else:
YamlDumper = yaml.SafeDumper
def _represent_yaml_str(self, node):
'''
Represent for yaml
'''
return self.represent_scalar(node)
YamlDumper.add_representer('tag:yaml.org,2002:str',
_represent_yaml_str)
YamlDumper.add_representer('tag:yaml.org,2002:timestamp',
_represent_yaml_str)
def _construct_yaml_str(self, node):
'''
Construct for yaml
'''
return self.construct_scalar(node)
YamlLoader.add_constructor('tag:yaml.org,2002:timestamp',
_construct_yaml_str)
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -108,12 +78,9 @@ def _parse_template(tmpl_str):
tpl = salt.utils.json.loads(tmpl_str) tpl = salt.utils.json.loads(tmpl_str)
else: else:
try: try:
tpl = yaml.load(tmpl_str, Loader=YamlLoader) tpl = salt.utils.yaml.safe_load(tmpl_str)
except yaml.YAMLError: except salt.utils.yaml.YAMLError as exc:
try: raise ValueError(six.text_type(exc))
tpl = yaml.load(tmpl_str, Loader=yaml.SafeLoader)
except yaml.YAMLError as yea:
raise ValueError(yea)
else: else:
if tpl is None: if tpl is None:
tpl = {} tpl = {}
@ -220,7 +187,7 @@ def deployed(name, template=None, enviroment=None, params=None, poll=5,
tpl = tpl.decode('utf-8') tpl = tpl.decode('utf-8')
template_parse = _parse_template(tpl) template_parse = _parse_template(tpl)
if 'heat_template_version' in template_parse: if 'heat_template_version' in template_parse:
template_new = yaml.dump(template_parse, Dumper=YamlDumper) template_new = salt.utils.yaml.safe_dump(template_parse)
else: else:
template_new = jsonutils.dumps(template_parse, indent=2, ensure_ascii=False) template_new = jsonutils.dumps(template_parse, indent=2, ensure_ascii=False)
salt.utils.files.safe_rm(template_tmp_file) salt.utils.files.safe_rm(template_tmp_file)

View file

@ -28,11 +28,10 @@ log = logging.getLogger(__file__)
# Import third party libs # Import third party libs
try: try:
import yaml # pylint: disable=unused-import
# pylint: disable=W0611
import napalm_yang import napalm_yang
HAS_NAPALM_YANG = True HAS_NAPALM_YANG = True
# pylint: enable=W0611 # pylint: enable=unused-import
except ImportError: except ImportError:
HAS_NAPALM_YANG = False HAS_NAPALM_YANG = False
@ -40,6 +39,7 @@ except ImportError:
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
import salt.utils.napalm import salt.utils.napalm
import salt.utils.yaml
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# state properties # state properties
@ -157,7 +157,7 @@ def managed(name,
data = {'to_dict': data} data = {'to_dict': data}
data = [data] data = [data]
with salt.utils.files.fopen(temp_file, 'w') as file_handle: with salt.utils.files.fopen(temp_file, 'w') as file_handle:
yaml.safe_dump(salt.utils.json.loads(salt.utils.json.dumps(data)), file_handle, encoding='utf-8', allow_unicode=True) salt.utils.yaml.safe_dump(salt.utils.json.loads(salt.utils.json.dumps(data)), file_handle, encoding='utf-8')
device_config = __salt__['napalm_yang.parse'](*models, device_config = __salt__['napalm_yang.parse'](*models,
config=True, config=True,
profiles=profiles) profiles=profiles)

View file

@ -47,12 +47,12 @@ The above essentially is the same as a top.sls containing the following:
''' '''
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
# Import python libs # Import Python libs
import logging import logging
import subprocess import subprocess
# Import third party libs # Import Salt libs
import yaml import salt.utils.yaml
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -76,12 +76,12 @@ def top(**kwargs):
__opts__['master_tops']['ext_nodes'], __opts__['master_tops']['ext_nodes'],
kwargs['opts']['id'] kwargs['opts']['id']
) )
ndata = yaml.safe_load( ndata = salt.utils.yaml.safe_load(
subprocess.Popen( subprocess.Popen(
cmd, cmd,
shell=True, shell=True,
stdout=subprocess.PIPE stdout=subprocess.PIPE.communicate()[0])
).communicate()[0]) )
if not ndata: if not ndata:
log.info('master_tops ext_nodes call did not return any data') log.info('master_tops ext_nodes call did not return any data')
ret = {} ret = {}

View file

@ -18,6 +18,7 @@ from salt.ext.six.moves import zip # pylint: disable=import-error,redefined-bui
import salt.utils.data import salt.utils.data
import salt.utils.jid import salt.utils.jid
import salt.utils.versions import salt.utils.versions
import salt.utils.yaml
if six.PY3: if six.PY3:
@ -154,19 +155,19 @@ def yamlify_arg(arg):
try: try:
# Explicit late import to avoid circular import. DO NOT MOVE THIS. # Explicit late import to avoid circular import. DO NOT MOVE THIS.
import salt.utils.yamlloader as yamlloader import salt.utils.yaml
original_arg = arg original_arg = arg
if '#' in arg: if '#' in arg:
# Only yamlify if it parses into a non-string type, to prevent # Only yamlify if it parses into a non-string type, to prevent
# loss of content due to # as comment character # loss of content due to # as comment character
parsed_arg = yamlloader.load(arg, Loader=yamlloader.SaltYamlSafeLoader) parsed_arg = salt.utils.yaml.safe_load(arg)
if isinstance(parsed_arg, six.string_types) or parsed_arg is None: if isinstance(parsed_arg, six.string_types) or parsed_arg is None:
return arg return arg
return parsed_arg return parsed_arg
if arg == 'None': if arg == 'None':
arg = None arg = None
else: else:
arg = yamlloader.load(arg, Loader=yamlloader.SaltYamlSafeLoader) arg = salt.utils.yaml.safe_load(arg)
if isinstance(arg, dict): if isinstance(arg, dict):
# dicts must be wrapped in curly braces # dicts must be wrapped in curly braces

View file

@ -53,8 +53,8 @@ import salt.utils.files
import salt.utils.platform import salt.utils.platform
import salt.utils.versions import salt.utils.versions
import salt.utils.vt import salt.utils.vt
import salt.utils.yaml
from salt.utils.nb_popen import NonBlockingPopen from salt.utils.nb_popen import NonBlockingPopen
from salt.utils.yamldumper import SafeOrderedDumper
from salt.utils.validate.path import is_writeable from salt.utils.validate.path import is_writeable
# Import salt cloud libs # Import salt cloud libs
@ -72,7 +72,6 @@ from salt.exceptions import (
from salt.ext import six from salt.ext import six
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin,W0611 from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin,W0611
from jinja2 import Template from jinja2 import Template
import yaml
# Let's import pwd and catch the ImportError. We'll raise it if this is not # Let's import pwd and catch the ImportError. We'll raise it if this is not
# Windows. This import has to be below where we import salt.utils.platform! # Windows. This import has to be below where we import salt.utils.platform!
@ -287,10 +286,10 @@ def salt_config_to_yaml(configuration, line_break='\n'):
''' '''
Return a salt configuration dictionary, master or minion, as a yaml dump Return a salt configuration dictionary, master or minion, as a yaml dump
''' '''
return yaml.dump(configuration, return salt.utils.yaml.safe_dump(
configuration,
line_break=line_break, line_break=line_break,
default_flow_style=False, default_flow_style=False)
Dumper=SafeOrderedDumper)
def bootstrap(vm_, opts=None): def bootstrap(vm_, opts=None):

View file

@ -11,7 +11,6 @@ import os
# Import Salt libs # Import Salt libs
from salt.ext import six from salt.ext import six
from salt.textformat import TextFormat from salt.textformat import TextFormat
import salt.utils.files
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -21,13 +20,14 @@ def get_color_theme(theme):
Return the color theme to use Return the color theme to use
''' '''
# Keep the heavy lifting out of the module space # Keep the heavy lifting out of the module space
import yaml import salt.utils.files
import salt.utils.yaml
if not os.path.isfile(theme): if not os.path.isfile(theme):
log.warning('The named theme {0} if not available'.format(theme)) log.warning('The named theme {0} if not available'.format(theme))
try: try:
with salt.utils.files.fopen(theme, 'rb') as fp_: with salt.utils.files.fopen(theme, 'rb') as fp_:
colors = yaml.safe_load(fp_.read()) colors = salt.utils.yaml.safe_load(fp_)
ret = {} ret = {}
for color in colors: for color in colors:
ret[color] = '\033[{0}m'.format(colors[color]) ret[color] = '\033[{0}m'.format(colors[color])

View file

@ -12,11 +12,11 @@ import copy
import fnmatch import fnmatch
import logging import logging
import re import re
import yaml
# Import Salt libs # Import Salt libs
import salt.utils.dictupdate import salt.utils.dictupdate
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.yaml
from salt.defaults import DEFAULT_TARGET_DELIM from salt.defaults import DEFAULT_TARGET_DELIM
from salt.exceptions import SaltException from salt.exceptions import SaltException
from salt.utils.decorators.jinja import jinja_filter from salt.utils.decorators.jinja import jinja_filter
@ -473,8 +473,8 @@ def repack_dictlist(data,
''' '''
if isinstance(data, six.string_types): if isinstance(data, six.string_types):
try: try:
data = yaml.safe_load(data) data = salt.utils.yaml.safe_load(data)
except yaml.parser.ParserError as err: except salt.utils.yaml.parser.ParserError as err:
log.error(err) log.error(err)
return {} return {}

View file

@ -13,7 +13,6 @@ import logging
import os import os
import pprint import pprint
import socket import socket
import yaml
import io import io
import zlib import zlib
import gzip import gzip
@ -47,6 +46,7 @@ import salt.utils.json
import salt.utils.network import salt.utils.network
import salt.utils.platform import salt.utils.platform
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.yaml
import salt.version import salt.version
import salt.utils.xmlutil as xml import salt.utils.xmlutil as xml
from salt._compat import ElementTree as ET from salt._compat import ElementTree as ET
@ -657,7 +657,7 @@ def query(url,
for item in items: for item in items:
ret['dict'].append(xml.to_dict(item)) ret['dict'].append(xml.to_dict(item))
elif decode_type == 'yaml': elif decode_type == 'yaml':
ret['dict'] = yaml.safe_load(result_text) ret['dict'] = salt.utils.yaml.safe_load(result_text)
else: else:
text = True text = True

View file

@ -19,7 +19,6 @@ from xml.etree.ElementTree import Element, SubElement, tostring
# Import third party libs # Import third party libs
import jinja2 import jinja2
from salt.ext import six from salt.ext import six
import yaml
from jinja2 import BaseLoader, Markup, TemplateNotFound, nodes from jinja2 import BaseLoader, Markup, TemplateNotFound, nodes
from jinja2.environment import TemplateModule from jinja2.environment import TemplateModule
from jinja2.exceptions import TemplateRuntimeError from jinja2.exceptions import TemplateRuntimeError
@ -32,7 +31,7 @@ import salt.utils.data
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
import salt.utils.url import salt.utils.url
import salt.utils.yamldumper import salt.utils.yaml
from salt.utils.decorators.jinja import jinja_filter, jinja_test, jinja_global from salt.utils.decorators.jinja import jinja_filter, jinja_test, jinja_global
from salt.utils.odict import OrderedDict from salt.utils.odict import OrderedDict
@ -785,7 +784,7 @@ class SerializerExtension(Extension, object):
return Markup(salt.utils.json.dumps(value, sort_keys=sort_keys, indent=indent).strip()) return Markup(salt.utils.json.dumps(value, sort_keys=sort_keys, indent=indent).strip())
def format_yaml(self, value, flow_style=True): def format_yaml(self, value, flow_style=True):
yaml_txt = salt.utils.yamldumper.safe_dump( yaml_txt = salt.utils.yaml.safe_dump(
value, default_flow_style=flow_style).strip() value, default_flow_style=flow_style).strip()
if yaml_txt.endswith('\n...'): if yaml_txt.endswith('\n...'):
yaml_txt = yaml_txt[:len(yaml_txt)-4] yaml_txt = yaml_txt[:len(yaml_txt)-4]
@ -844,7 +843,7 @@ class SerializerExtension(Extension, object):
if isinstance(value, TemplateModule): if isinstance(value, TemplateModule):
value = str(value) value = str(value)
try: try:
return yaml.safe_load(value) return salt.utils.yaml.safe_load(value)
except AttributeError: except AttributeError:
raise TemplateRuntimeError( raise TemplateRuntimeError(
'Unable to load yaml from {0}'.format(value)) 'Unable to load yaml from {0}'.format(value))

View file

@ -5,10 +5,10 @@ Utilities for managing kickstart
.. versionadded:: Beryllium .. versionadded:: Beryllium
''' '''
from __future__ import absolute_import from __future__ import absolute_import
import yaml
import shlex import shlex
import argparse # pylint: disable=minimum-python-version import argparse # pylint: disable=minimum-python-version
import salt.utils.files import salt.utils.files
import salt.utils.yaml
from salt.ext.six.moves import range from salt.ext.six.moves import range
@ -1176,6 +1176,6 @@ def mksls(src, dst=None):
if dst: if dst:
with salt.utils.files.fopen(dst, 'w') as fp_: with salt.utils.files.fopen(dst, 'w') as fp_:
fp_.write(yaml.safe_dump(sls, default_flow_style=False)) salt.utils.yaml.safe_dump(sls, fp_, default_flow_style=False)
else: else:
return yaml.safe_dump(sls, default_flow_style=False) return salt.utils.yaml.safe_dump(sls, default_flow_style=False)

View file

@ -7,15 +7,13 @@ Common functions for managing mounts
from __future__ import absolute_import from __future__ import absolute_import
import logging import logging
import os import os
import yaml
# Import Salt libs # Import Salt libs
import salt.utils.files import salt.utils.files
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.yaml
import salt.utils.versions import salt.utils.versions
from salt.utils.yamldumper import SafeOrderedDumper
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -25,7 +23,7 @@ def _read_file(path):
''' '''
try: try:
with salt.utils.files.fopen(path, 'rb') as contents: with salt.utils.files.fopen(path, 'rb') as contents:
return yaml.safe_load(contents.read()) return salt.utils.yaml.safe_load(contents)
except (OSError, IOError): except (OSError, IOError):
return {} return {}
@ -53,10 +51,7 @@ def write_cache(cache, opts):
try: try:
_cache = salt.utils.stringutils.to_bytes( _cache = salt.utils.stringutils.to_bytes(
yaml.dump( salt.utils.yaml.safe_dump(cache)
cache,
Dumper=SafeOrderedDumper
)
) )
with salt.utils.files.fopen(cache_file, 'wb+') as fp_: with salt.utils.files.fopen(cache_file, 'wb+') as fp_:
fp_.write(_cache) fp_.write(_cache)

View file

@ -20,7 +20,6 @@ import getpass
import logging import logging
import optparse import optparse
import traceback import traceback
import yaml
from functools import partial from functools import partial
@ -39,13 +38,13 @@ import salt.utils.process
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.user import salt.utils.user
import salt.utils.xdg import salt.utils.xdg
import salt.utils.yaml
from salt.defaults import DEFAULT_TARGET_DELIM from salt.defaults import DEFAULT_TARGET_DELIM
from salt.utils.validate.path import is_writeable from salt.utils.validate.path import is_writeable
from salt.utils.verify import verify_files from salt.utils.verify import verify_files
import salt.exceptions import salt.exceptions
from salt.ext import six from salt.ext import six
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
from salt.utils.yamldumper import SafeOrderedDumper
def _sorted(mixins_or_funcs): def _sorted(mixins_or_funcs):
@ -2091,11 +2090,9 @@ class SaltCMDOptionParser(six.with_metaclass(OptionParserMeta,
if self.options.config_dump: if self.options.config_dump:
cfg = config.master_config(self.get_config_file_path()) cfg = config.master_config(self.get_config_file_path())
sys.stdout.write( sys.stdout.write(
yaml.dump( salt.utils.yaml.safe_dump(
cfg, cfg,
default_flow_style=False, default_flow_style=False)
Dumper=SafeOrderedDumper
)
) )
sys.exit(salt.defaults.exitcodes.EX_OK) sys.exit(salt.defaults.exitcodes.EX_OK)

View file

@ -5,9 +5,9 @@ Utilities for managing Debian preseed
.. versionadded:: Beryllium .. versionadded:: Beryllium
''' '''
from __future__ import absolute_import from __future__ import absolute_import
import yaml
import shlex import shlex
import salt.utils.files import salt.utils.files
import salt.utils.yaml
def mksls(src, dst=None): def mksls(src, dst=None):
@ -73,6 +73,6 @@ def mksls(src, dst=None):
if dst is not None: if dst is not None:
with salt.utils.files.fopen(dst, 'w') as fh_: with salt.utils.files.fopen(dst, 'w') as fh_:
fh_.write(yaml.safe_dump(sls, default_flow_style=False)) salt.utils.yaml.safe_dump(sls, fh_, default_flow_style=False)
else: else:
return yaml.safe_dump(sls, default_flow_style=False) return salt.utils.yaml.safe_dump(sls, default_flow_style=False)

View file

@ -20,11 +20,11 @@ import salt.utils.data
import salt.utils.event import salt.utils.event
import salt.utils.files import salt.utils.files
import salt.utils.process import salt.utils.process
import salt.utils.yaml
import salt.wheel import salt.wheel
import salt.defaults.exitcodes import salt.defaults.exitcodes
# Import 3rd-party libs # Import 3rd-party libs
import yaml
from salt.ext import six from salt.ext import six
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -111,7 +111,7 @@ class Reactor(salt.utils.process.SignalHandlingMultiprocessingProcess, salt.stat
if isinstance(self.opts['reactor'], six.string_types): if isinstance(self.opts['reactor'], six.string_types):
try: try:
with salt.utils.files.fopen(self.opts['reactor']) as fp_: with salt.utils.files.fopen(self.opts['reactor']) as fp_:
react_map = yaml.safe_load(fp_.read()) react_map = salt.utils.yaml.safe_load(fp_)
except (OSError, IOError): except (OSError, IOError):
log.error( log.error(
'Failed to read reactor map: "{0}"'.format( 'Failed to read reactor map: "{0}"'.format(
@ -148,7 +148,7 @@ class Reactor(salt.utils.process.SignalHandlingMultiprocessingProcess, salt.stat
log.debug('Reading reactors from yaml {0}'.format(self.opts['reactor'])) log.debug('Reading reactors from yaml {0}'.format(self.opts['reactor']))
try: try:
with salt.utils.files.fopen(self.opts['reactor']) as fp_: with salt.utils.files.fopen(self.opts['reactor']) as fp_:
react_map = yaml.safe_load(fp_.read()) react_map = salt.utils.yaml.safe_load(fp_)
except (OSError, IOError): except (OSError, IOError):
log.error( log.error(
'Failed to read reactor map: "{0}"'.format( 'Failed to read reactor map: "{0}"'.format(

View file

@ -4,11 +4,11 @@ from __future__ import absolute_import
import os import os
import re import re
import logging import logging
import yaml
from jinja2 import FileSystemLoader, Environment from jinja2 import FileSystemLoader, Environment
# Import Salt libs # Import Salt libs
import salt.utils.path import salt.utils.path
import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
from salt.ext.six import iteritems from salt.ext.six import iteritems
@ -32,7 +32,7 @@ def render_jinja(_file, salt_data):
# Renders yaml from rendered jinja # Renders yaml from rendered jinja
def render_yaml(_file, salt_data): def render_yaml(_file, salt_data):
return yaml.safe_load(render_jinja(_file, salt_data)) return salt.utils.yaml.safe_load(render_jinja(_file, salt_data))
# Returns a dict from a class yaml definition # Returns a dict from a class yaml definition

View file

@ -24,7 +24,6 @@ import logging
import errno import errno
import random import random
import weakref import weakref
import yaml
# Import Salt libs # Import Salt libs
import salt.config import salt.config
@ -38,6 +37,7 @@ import salt.utils.platform
import salt.utils.process import salt.utils.process
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.user import salt.utils.user
import salt.utils.yaml
import salt.loader import salt.loader
import salt.minion import salt.minion
import salt.payload import salt.payload
@ -46,7 +46,6 @@ import salt.exceptions
import salt.log.setup as log_setup import salt.log.setup as log_setup
import salt.defaults.exitcodes import salt.defaults.exitcodes
from salt.utils.odict import OrderedDict from salt.utils.odict import OrderedDict
from salt.utils.yamldumper import SafeOrderedDumper
# Import 3rd-party libs # Import 3rd-party libs
from salt.ext import six from salt.ext import six
@ -176,9 +175,8 @@ class Schedule(object):
with salt.utils.files.fopen(schedule_conf, 'wb+') as fp_: with salt.utils.files.fopen(schedule_conf, 'wb+') as fp_:
fp_.write( fp_.write(
salt.utils.stringutils.to_bytes( salt.utils.stringutils.to_bytes(
yaml.dump( salt.utils.yaml.safe_dump(
{'schedule': self._get_schedule(include_pillar=False)}, {'schedule': self._get_schedule(include_pillar=False)}
Dumper=SafeOrderedDumper
) )
) )
) )

View file

@ -328,10 +328,10 @@ import functools
# Import salt libs # Import salt libs
import salt.utils.args import salt.utils.args
#import salt.utils.yaml
from salt.utils.odict import OrderedDict from salt.utils.odict import OrderedDict
# Import 3rd-party libs # Import 3rd-party libs
#import yaml
from salt.ext import six from salt.ext import six
BASE_SCHEMA_URL = 'https://non-existing.saltstack.com/schemas' BASE_SCHEMA_URL = 'https://non-existing.saltstack.com/schemas'
@ -871,7 +871,7 @@ class BaseSchemaItem(SchemaItem):
# width=RENDER_COMMENT_YAML_MAX_LINE_LENGTH, # width=RENDER_COMMENT_YAML_MAX_LINE_LENGTH,
# initial_indent='# ')) # initial_indent='# '))
# output += '\n' # output += '\n'
# yamled_default_value = yaml.dump(self.default, default_flow_style=False).split('\n...', 1)[0] # yamled_default_value = salt.utils.yaml.safe_dump(self.default, default_flow_style=False).split('\n...', 1)[0]
# output += '# Default: {0}\n'.format(yamled_default_value) # output += '# Default: {0}\n'.format(yamled_default_value)
# output += '#{0}: {1}\n'.format(name, yamled_default_value) # output += '#{0}: {1}\n'.format(name, yamled_default_value)
# output += '# <---- ' # output += '# <---- '

View file

@ -512,6 +512,8 @@ def gen_min(cachedir, extra_mods='', overwrite=False, so_mods='',
'salt/utils/vt.py', 'salt/utils/vt.py',
'salt/utils/templates.py', 'salt/utils/templates.py',
'salt/utils/aggregation.py', 'salt/utils/aggregation.py',
'salt/utils/yaml.py',
'salt/utils/yamldumper.py',
'salt/utils/yamlloader.py', 'salt/utils/yamlloader.py',
'salt/utils/event.py', 'salt/utils/event.py',
'salt/serializers', 'salt/serializers',

10
salt/utils/yaml.py Normal file
View file

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
'''
Convenience module that provides our custom loader and dumper in a single module
'''
from __future__ import absolute_import, print_function, unicode_literals
# pylint: disable=wildcard-import,unused-wildcard-import,unused-import
from yaml import YAMLError, parser, scanner
from salt.utils.yamldumper import *
from salt.utils.yamlloader import *

View file

@ -15,7 +15,7 @@ except ImportError:
from yaml import Dumper from yaml import Dumper
from yaml import SafeDumper from yaml import SafeDumper
import yaml import yaml # pylint: disable=blacklisted-import
import collections import collections
from salt.utils.odict import OrderedDict from salt.utils.odict import OrderedDict
@ -27,6 +27,9 @@ except ImportError:
odict = None odict = None
HAS_IOFLO = False HAS_IOFLO = False
__all__ = ['OrderedDumper', 'SafeOrderedDumper', 'IndentedSafeOrderedDumper',
'get_dumper', 'dump', 'safe_dump']
class IndentMixin(Dumper): class IndentMixin(Dumper):
''' '''
@ -75,6 +78,13 @@ SafeOrderedDumper.add_representer(
yaml.representer.SafeRepresenter.represent_dict yaml.representer.SafeRepresenter.represent_dict
) )
OrderedDumper.add_representer(
'tag:yaml.org,2002:timestamp',
OrderedDumper.represent_scalar)
SafeOrderedDumper.add_representer(
'tag:yaml.org,2002:timestamp',
SafeOrderedDumper.represent_scalar)
if HAS_IOFLO: if HAS_IOFLO:
OrderedDumper.add_representer(odict, represent_ordereddict) OrderedDumper.add_representer(odict, represent_ordereddict)
SafeOrderedDumper.add_representer(odict, represent_ordereddict) SafeOrderedDumper.add_representer(odict, represent_ordereddict)
@ -88,9 +98,24 @@ def get_dumper(dumper_name):
}.get(dumper_name) }.get(dumper_name)
def dump(data, stream=None, **kwargs):
'''
.. versionadded:: Oxygen
Helper that wraps yaml.dump and ensures that we encode unicode strings
unless explicitly told not to.
'''
if 'allow_unicode' not in kwargs:
kwargs['allow_unicode'] = True
return yaml.dump(data, stream, **kwargs)
def safe_dump(data, stream=None, **kwargs): def safe_dump(data, stream=None, **kwargs):
''' '''
Use a custom dumper to ensure that defaultdict and OrderedDict are Use a custom dumper to ensure that defaultdict and OrderedDict are
represented properly represented properly. Ensure that unicode strings are encoded unless
explicitly told not to.
''' '''
if 'allow_unicode' not in kwargs:
kwargs['allow_unicode'] = True
return yaml.dump(data, stream, Dumper=SafeOrderedDumper, **kwargs) return yaml.dump(data, stream, Dumper=SafeOrderedDumper, **kwargs)

View file

@ -8,7 +8,7 @@ from __future__ import absolute_import
import io import io
# Import 3rd-party libs # Import 3rd-party libs
import yaml import yaml # pylint: disable=blacklisted-import
from salt.ext import six from salt.ext import six
# Import salt libs # Import salt libs

View file

@ -9,7 +9,7 @@ import warnings
# Import third party libs # Import third party libs
import re import re
import yaml import yaml # pylint: disable=blacklisted-import
from yaml.nodes import MappingNode, SequenceNode from yaml.nodes import MappingNode, SequenceNode
from yaml.constructor import ConstructorError from yaml.constructor import ConstructorError
try: try:
@ -18,11 +18,7 @@ try:
except Exception: except Exception:
pass pass
# This function is safe and needs to stay as yaml.load. The load function __all__ = ['SaltYamlSafeLoader', 'load', 'safe_load']
# accepts a custom loader, and every time this function is used in Salt
# the custom loader defined below is used. This should be altered though to
# not require the custom loader to be explicitly added.
load = yaml.load # pylint: disable=C0103
class DuplicateKeyWarning(RuntimeWarning): class DuplicateKeyWarning(RuntimeWarning):
@ -53,6 +49,9 @@ class SaltYamlSafeLoader(yaml.SafeLoader, object):
self.add_constructor( self.add_constructor(
'tag:yaml.org,2002:python/unicode', 'tag:yaml.org,2002:python/unicode',
type(self).construct_unicode) type(self).construct_unicode)
self.add_constructor(
'tag:yaml.org,2002:timestamp',
type(self).construct_scalar)
self.dictclass = dictclass self.dictclass = dictclass
def construct_yaml_map(self, node): def construct_yaml_map(self, node):
@ -153,3 +152,16 @@ class SaltYamlSafeLoader(yaml.SafeLoader, object):
mergeable_items = [x for x in merge if x[0].value not in existing_nodes] mergeable_items = [x for x in merge if x[0].value not in existing_nodes]
node.value = mergeable_items + node.value node.value = mergeable_items + node.value
def load(stream, Loader=SaltYamlSafeLoader):
return yaml.load(stream, Loader=Loader)
def safe_load(stream, Loader=SaltYamlSafeLoader):
'''
.. versionadded:: Oxygen
Helper function which automagically uses our custom loader.
'''
return yaml.load(stream, Loader=Loader)

View file

@ -8,7 +8,7 @@ from __future__ import absolute_import
from salt._compat import ElementTree as ET from salt._compat import ElementTree as ET
import salt.utils.xmlutil as xml import salt.utils.xmlutil as xml
import salt.utils.files import salt.utils.files
import yaml import salt.utils.yaml
def mksls(src, dst=None): def mksls(src, dst=None):
@ -20,6 +20,6 @@ def mksls(src, dst=None):
if dst is not None: if dst is not None:
with salt.utils.files.fopen(dst, 'w') as fh_: with salt.utils.files.fopen(dst, 'w') as fh_:
fh_.write(yaml.safe_dump(ps_opts, default_flow_style=False)) salt.utils.yaml.safe_dump(ps_opts, fh_, default_flow_style=False)
else: else:
return yaml.safe_dump(ps_opts, default_flow_style=False) return salt.utils.yaml.safe_dump(ps_opts, default_flow_style=False)

View file

@ -8,13 +8,10 @@ from __future__ import absolute_import, print_function, unicode_literals
import logging import logging
import os import os
# Import third party libs
import yaml
# Import salt libs # Import salt libs
import salt.config import salt.config
import salt.utils.files import salt.utils.files
from salt.utils.yamldumper import SafeOrderedDumper import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
from salt.ext import six from salt.ext import six
@ -44,13 +41,7 @@ def apply(key, value):
data = values() data = values()
data[key] = value data[key] = value
with salt.utils.files.fopen(path, 'w+') as fp_: with salt.utils.files.fopen(path, 'w+') as fp_:
fp_.write( salt.utils.yaml.safe_dump(data, default_flow_style=False)
yaml.dump(
data,
default_flow_style=False,
Dumper=SafeOrderedDumper
)
)
def update_config(file_name, yaml_contents): def update_config(file_name, yaml_contents):
@ -84,7 +75,7 @@ def update_config(file_name, yaml_contents):
dir_path = os.path.join(__opts__['config_dir'], dir_path = os.path.join(__opts__['config_dir'],
os.path.dirname(__opts__['default_include'])) os.path.dirname(__opts__['default_include']))
try: try:
yaml_out = yaml.safe_dump(yaml_contents, default_flow_style=False) yaml_out = salt.utils.yaml.safe_dump(yaml_contents, default_flow_style=False)
if not os.path.exists(dir_path): if not os.path.exists(dir_path):
log.debug('Creating directory %s', dir_path) log.debug('Creating directory %s', dir_path)
@ -95,5 +86,5 @@ def update_config(file_name, yaml_contents):
fp_.write(yaml_out) fp_.write(yaml_out)
return 'Wrote {0}'.format(file_name) return 'Wrote {0}'.format(file_name)
except (IOError, OSError, yaml.YAMLError, ValueError) as err: except (IOError, OSError, salt.utils.yaml.YAMLError, ValueError) as err:
return six.text_type(err) return six.text_type(err)

View file

@ -11,9 +11,9 @@ import optparse
# Import Salt libs # Import Salt libs
import salt.utils.color import salt.utils.color
import salt.utils.files import salt.utils.files
import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
import yaml
from salt.ext import six from salt.ext import six
colors = salt.utils.color.get_colors() colors = salt.utils.color.get_colors()
@ -47,7 +47,7 @@ def run(command):
cmd = r'salt \* {0} --yaml-out -t 500 > high'.format(command) cmd = r'salt \* {0} --yaml-out -t 500 > high'.format(command)
subprocess.call(cmd, shell=True) subprocess.call(cmd, shell=True)
with salt.utils.files.fopen('high') as fp_: with salt.utils.files.fopen('high') as fp_:
data = yaml.load(fp_) data = salt.utils.yaml.safe_load(fp_)
hashes = set() hashes = set()
for key, val in six.iteritems(data): for key, val in six.iteritems(data):
has = hashlib.md5(str(val)).hexdigest() has = hashlib.md5(str(val)).hexdigest()

View file

@ -54,6 +54,7 @@ import salt.utils.path
import salt.utils.platform import salt.utils.platform
import salt.utils.process import salt.utils.process
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.yaml
import salt.log.setup as salt_log_setup import salt.log.setup as salt_log_setup
from salt.utils.verify import verify_env from salt.utils.verify import verify_env
from salt.utils.immutabletypes import freeze from salt.utils.immutabletypes import freeze
@ -67,7 +68,6 @@ except ImportError:
pass pass
# Import 3rd-party libs # Import 3rd-party libs
import yaml
import msgpack import msgpack
from salt.ext import six from salt.ext import six
from salt.ext.six.moves import cStringIO from salt.ext.six.moves import cStringIO
@ -933,24 +933,18 @@ class TestDaemon(object):
for entry in ('master', 'minion', 'sub_minion', 'syndic', 'syndic_master', 'proxy'): for entry in ('master', 'minion', 'sub_minion', 'syndic', 'syndic_master', 'proxy'):
computed_config = copy.deepcopy(locals()['{0}_opts'.format(entry)]) computed_config = copy.deepcopy(locals()['{0}_opts'.format(entry)])
with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry), 'w') as fp_: with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry), 'w') as fp_:
fp_.write(yaml.dump(computed_config, default_flow_style=False)) salt.utils.yaml.safe_dump(computed_config, fp_, default_flow_style=False)
sub_minion_computed_config = copy.deepcopy(sub_minion_opts) sub_minion_computed_config = copy.deepcopy(sub_minion_opts)
with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'minion'), 'w') as wfh: with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'minion'), 'w') as wfh:
wfh.write( salt.utils.yaml.safe_dump(sub_minion_computed_config, wfh, default_flow_style=False)
yaml.dump(sub_minion_computed_config, default_flow_style=False)
)
shutil.copyfile(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'), os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'master')) shutil.copyfile(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'), os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'master'))
syndic_master_computed_config = copy.deepcopy(syndic_master_opts) syndic_master_computed_config = copy.deepcopy(syndic_master_opts)
with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR, 'master'), 'w') as wfh: with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR, 'master'), 'w') as wfh:
wfh.write( salt.utils.yaml.safe_dump(syndic_master_computed_config, wfh, default_flow_style=False)
yaml.dump(syndic_master_computed_config, default_flow_style=False)
)
syndic_computed_config = copy.deepcopy(syndic_opts) syndic_computed_config = copy.deepcopy(syndic_opts)
with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'minion'), 'w') as wfh: with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'minion'), 'w') as wfh:
wfh.write( salt.utils.yaml.safe_dump(syndic_computed_config, wfh, default_flow_style=False)
yaml.dump(syndic_computed_config, default_flow_style=False)
)
shutil.copyfile(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'), os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'master')) shutil.copyfile(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'), os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'master'))
# <---- Transcribe Configuration ----------------------------------------------------------------------------- # <---- Transcribe Configuration -----------------------------------------------------------------------------

View file

@ -20,12 +20,12 @@ from tests.support.unit import skipIf
from tests.support.helpers import requires_system_grains from tests.support.helpers import requires_system_grains
# Import 3rd-party libs # Import 3rd-party libs
import yaml
from salt.ext import six from salt.ext import six
# Import salt libs # Import salt libs
import salt.utils.files import salt.utils.files
import salt.utils.path import salt.utils.path
import salt.utils.yaml
import salt.pillar as pillar import salt.pillar as pillar
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -272,7 +272,7 @@ class DecryptGPGPillarTest(ModuleCase):
Test recursive decryption of secrets:vault as well as the fallback to Test recursive decryption of secrets:vault as well as the fallback to
default decryption renderer. default decryption renderer.
''' '''
decrypt_pillar_opts = yaml.safe_load(textwrap.dedent('''\ decrypt_pillar_opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
decrypt_pillar: decrypt_pillar:
- 'secrets:vault' - 'secrets:vault'
''')) '''))
@ -287,7 +287,7 @@ class DecryptGPGPillarTest(ModuleCase):
Test recursive decryption of secrets:vault using a pipe instead of a Test recursive decryption of secrets:vault using a pipe instead of a
colon as the nesting delimiter. colon as the nesting delimiter.
''' '''
decrypt_pillar_opts = yaml.safe_load(textwrap.dedent('''\ decrypt_pillar_opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
decrypt_pillar_delimiter: '|' decrypt_pillar_delimiter: '|'
decrypt_pillar: decrypt_pillar:
- 'secrets|vault' - 'secrets|vault'
@ -303,7 +303,7 @@ class DecryptGPGPillarTest(ModuleCase):
Test recursive decryption, only with a more deeply-nested target. This Test recursive decryption, only with a more deeply-nested target. This
should leave the other keys in secrets:vault encrypted. should leave the other keys in secrets:vault encrypted.
''' '''
decrypt_pillar_opts = yaml.safe_load(textwrap.dedent('''\ decrypt_pillar_opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
decrypt_pillar: decrypt_pillar:
- 'secrets:vault:qux' - 'secrets:vault:qux'
''')) '''))
@ -322,7 +322,7 @@ class DecryptGPGPillarTest(ModuleCase):
explicitly defined, overriding the default. Setting the default to a explicitly defined, overriding the default. Setting the default to a
nonexistant renderer so we can be sure that the override happened. nonexistant renderer so we can be sure that the override happened.
''' '''
decrypt_pillar_opts = yaml.safe_load(textwrap.dedent('''\ decrypt_pillar_opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
decrypt_pillar_default: asdf decrypt_pillar_default: asdf
decrypt_pillar_renderers: decrypt_pillar_renderers:
- asdf - asdf
@ -341,7 +341,7 @@ class DecryptGPGPillarTest(ModuleCase):
Test decryption using a missing renderer. It should fail, leaving the Test decryption using a missing renderer. It should fail, leaving the
encrypted keys intact, and add an error to the pillar dictionary. encrypted keys intact, and add an error to the pillar dictionary.
''' '''
decrypt_pillar_opts = yaml.safe_load(textwrap.dedent('''\ decrypt_pillar_opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
decrypt_pillar_default: asdf decrypt_pillar_default: asdf
decrypt_pillar_renderers: decrypt_pillar_renderers:
- asdf - asdf
@ -365,7 +365,7 @@ class DecryptGPGPillarTest(ModuleCase):
fail, leaving the encrypted keys intact, and add an error to the pillar fail, leaving the encrypted keys intact, and add an error to the pillar
dictionary. dictionary.
''' '''
decrypt_pillar_opts = yaml.safe_load(textwrap.dedent('''\ decrypt_pillar_opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
decrypt_pillar_default: foo decrypt_pillar_default: foo
decrypt_pillar_renderers: decrypt_pillar_renderers:
- foo - foo

View file

@ -1650,10 +1650,10 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
''' '''
helper class to add pillar data at runtime helper class to add pillar data at runtime
''' '''
import yaml import salt.utils.yaml
with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE,
'pillar.sls'), 'w') as fp: 'pillar.sls'), 'w') as fp:
fp.write(yaml.dump(pillar)) salt.utils.yaml.safe_dump(pillar, fp)
with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, 'top.sls'), 'w') as fp: with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, 'top.sls'), 'w') as fp:
fp.write(textwrap.dedent('''\ fp.write(textwrap.dedent('''\

View file

@ -7,7 +7,6 @@ from __future__ import absolute_import, print_function, unicode_literals
import errno import errno
import os import os
import tempfile import tempfile
import yaml
# Import Salt Testing libs # Import Salt Testing libs
from tests.support.case import ShellCase from tests.support.case import ShellCase
@ -18,6 +17,7 @@ import salt.payload
import salt.utils.args import salt.utils.args
import salt.utils.files import salt.utils.files
import salt.utils.jid import salt.utils.jid
import salt.utils.yaml
class RunnerReturnsTest(ShellCase): class RunnerReturnsTest(ShellCase):
@ -73,7 +73,7 @@ class RunnerReturnsTest(ShellCase):
''' '''
Dump the config dict to the conf file Dump the config dict to the conf file
''' '''
self.conf.write(yaml.dump(data, default_flow_style=False)) self.conf.write(salt.utils.yaml.safe_dump(data, default_flow_style=False))
self.conf.flush() self.conf.flush()
def test_runner_returns_disabled(self): def test_runner_returns_disabled(self):

View file

@ -11,7 +11,6 @@ import shutil
import signal import signal
import tempfile import tempfile
import textwrap import textwrap
import yaml
import threading import threading
from salt.ext.six.moves import queue from salt.ext.six.moves import queue
@ -26,6 +25,7 @@ import salt.utils.event
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
from salt.ext import six from salt.ext import six
@ -275,7 +275,7 @@ class OrchEventTest(ShellCase):
''' '''
Dump the config dict to the conf file Dump the config dict to the conf file
''' '''
self.conf.write(yaml.dump(data, default_flow_style=False)) self.conf.write(salt.utils.yaml.safe_dump(data, default_flow_style=False))
self.conf.flush() self.conf.flush()
def test_jid_in_ret_event(self): def test_jid_in_ret_event(self):

View file

@ -17,9 +17,6 @@ import shutil
from datetime import datetime from datetime import datetime
import logging import logging
# Import 3rd-party libs
import yaml
# Import Salt Testing libs # Import Salt Testing libs
from tests.support.case import ShellCase from tests.support.case import ShellCase
from tests.support.unit import skipIf from tests.support.unit import skipIf
@ -30,6 +27,7 @@ from tests.integration.utils import testprogram
# Import salt libs # Import salt libs
import salt.utils.files import salt.utils.files
import salt.utils.yaml
from salt.ext import six from salt.ext import six
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -175,7 +173,7 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
os.makedirs(config_dir) os.makedirs(config_dir)
with salt.utils.files.fopen(self.get_config_file_path('master')) as fhr: with salt.utils.files.fopen(self.get_config_file_path('master')) as fhr:
master_config = yaml.load(fhr.read()) master_config = salt.utils.yaml.safe_load(fhr)
master_root_dir = master_config['root_dir'] master_root_dir = master_config['root_dir']
this_minion_key = os.path.join( this_minion_key = os.path.join(
@ -205,9 +203,7 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
# Let's first test with a master running # Let's first test with a master running
with salt.utils.files.fopen(minion_config_file, 'w') as fh_: with salt.utils.files.fopen(minion_config_file, 'w') as fh_:
fh_.write( salt.utils.yaml.safe_dump(minion_config, fh_, default_flow_style=False)
yaml.dump(minion_config, default_flow_style=False)
)
ret = self.run_script( ret = self.run_script(
'salt-call', 'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format( '--config-dir {0} cmd.run "echo foo"'.format(
@ -235,9 +231,7 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
minion_config.pop('master') minion_config.pop('master')
minion_config.pop('master_port') minion_config.pop('master_port')
with salt.utils.files.fopen(minion_config_file, 'w') as fh_: with salt.utils.files.fopen(minion_config_file, 'w') as fh_:
fh_.write( salt.utils.yaml.safe_dump(minion_config, fh_, default_flow_style=False)
yaml.dump(minion_config, default_flow_style=False)
)
out = self.run_script( out = self.run_script(
'salt-call', 'salt-call',
@ -283,9 +277,7 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
# Should work with local file client # Should work with local file client
minion_config['file_client'] = 'local' minion_config['file_client'] = 'local'
with salt.utils.files.fopen(minion_config_file, 'w') as fh_: with salt.utils.files.fopen(minion_config_file, 'w') as fh_:
fh_.write( salt.utils.yaml.safe_dump(minion_config, fh_, default_flow_style=False)
yaml.dump(minion_config, default_flow_style=False)
)
ret = self.run_script( ret = self.run_script(
'salt-call', 'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format( '--config-dir {0} cmd.run "echo foo"'.format(
@ -310,12 +302,10 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
os.chdir(config_dir) os.chdir(config_dir)
with salt.utils.files.fopen(self.get_config_file_path('minion'), 'r') as fh_: with salt.utils.files.fopen(self.get_config_file_path('minion'), 'r') as fh_:
minion_config = yaml.load(fh_.read()) minion_config = salt.utils.yaml.safe_load(fh_)
minion_config['log_file'] = 'file:///dev/log/LOG_LOCAL3' minion_config['log_file'] = 'file:///dev/log/LOG_LOCAL3'
with salt.utils.files.fopen(os.path.join(config_dir, 'minion'), 'w') as fh_: with salt.utils.files.fopen(os.path.join(config_dir, 'minion'), 'w') as fh_:
fh_.write( salt.utils.yaml.safe_dump(minion_config, fh_, default_flow_style=False)
yaml.dump(minion_config, default_flow_style=False)
)
ret = self.run_script( ret = self.run_script(
'salt-call', 'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format( '--config-dir {0} cmd.run "echo foo"'.format(

View file

@ -15,9 +15,6 @@ import pipes
import shutil import shutil
import tempfile import tempfile
# Import 3rd-party libs
import yaml
# Import Salt Testing libs # Import Salt Testing libs
from tests.support.case import ShellCase from tests.support.case import ShellCase
from tests.support.paths import TMP from tests.support.paths import TMP
@ -25,6 +22,7 @@ from tests.support.mixins import ShellCaseCommonTestsMixin
# Import salt libs # Import salt libs
import salt.utils.files import salt.utils.files
import salt.utils.yaml
# Import 3rd-party libs # Import 3rd-party libs
from salt.ext import six from salt.ext import six
@ -42,7 +40,7 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
for line in self.run_salt('--out yaml "*" test.ping'): for line in self.run_salt('--out yaml "*" test.ping'):
if not line: if not line:
continue continue
data = yaml.load(line) data = salt.utils.yaml.safe_load(line)
minions.extend(data.keys()) minions.extend(data.keys())
self.assertNotEqual(minions, []) self.assertNotEqual(minions, [])
@ -62,7 +60,7 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
pipes.quote(minion), TMP pipes.quote(minion), TMP
) )
) )
data = yaml.load('\n'.join(ret)) data = salt.utils.yaml.safe_load('\n'.join(ret))
if data[minion] is False: if data[minion] is False:
ret = self.run_salt( ret = self.run_salt(
'--out yaml {0} file.makedirs {1}'.format( '--out yaml {0} file.makedirs {1}'.format(
@ -71,7 +69,7 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
) )
) )
data = yaml.load('\n'.join(ret)) data = salt.utils.yaml.safe_load('\n'.join(ret))
self.assertTrue(data[minion]) self.assertTrue(data[minion])
minion_testfile = os.path.join( minion_testfile = os.path.join(
@ -84,7 +82,7 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
pipes.quote(minion_testfile) pipes.quote(minion_testfile)
)) ))
data = yaml.load('\n'.join(ret)) data = salt.utils.yaml.safe_load('\n'.join(ret))
for part in six.itervalues(data): for part in six.itervalues(data):
self.assertTrue(part[minion_testfile]) self.assertTrue(part[minion_testfile])
@ -94,7 +92,7 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
pipes.quote(minion_testfile) pipes.quote(minion_testfile)
) )
) )
data = yaml.load('\n'.join(ret)) data = salt.utils.yaml.safe_load('\n'.join(ret))
self.assertTrue(data[minion]) self.assertTrue(data[minion])
ret = self.run_salt( ret = self.run_salt(
@ -104,7 +102,7 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
pipes.quote(testfile_contents) pipes.quote(testfile_contents)
) )
) )
data = yaml.load('\n'.join(ret)) data = salt.utils.yaml.safe_load('\n'.join(ret))
self.assertTrue(data[minion]) self.assertTrue(data[minion])
ret = self.run_salt( ret = self.run_salt(
'--out yaml {0} file.remove {1}'.format( '--out yaml {0} file.remove {1}'.format(
@ -112,7 +110,7 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
pipes.quote(minion_testfile) pipes.quote(minion_testfile)
) )
) )
data = yaml.load('\n'.join(ret)) data = salt.utils.yaml.safe_load('\n'.join(ret))
self.assertTrue(data[minion]) self.assertTrue(data[minion])
def test_issue_7754(self): def test_issue_7754(self):
@ -126,12 +124,10 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
config_file_name = 'master' config_file_name = 'master'
with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr: with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr:
config = yaml.load(fhr.read()) config = salt.utils.yaml.safe_load(fhr)
config['log_file'] = 'file:///dev/log/LOG_LOCAL3' config['log_file'] = 'file:///dev/log/LOG_LOCAL3'
with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw: with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw:
fhw.write( salt.utils.yaml.safe_dump(config, fhw, default_flow_style=False)
yaml.dump(config, default_flow_style=False)
)
try: try:
fd_, fn_ = tempfile.mkstemp() fd_, fn_ = tempfile.mkstemp()

View file

@ -13,12 +13,12 @@ from tests.support.paths import TMP
from tests.support.mixins import ShellCaseCommonTestsMixin from tests.support.mixins import ShellCaseCommonTestsMixin
# Import 3rd-party libs # Import 3rd-party libs
import yaml
from salt.ext import six from salt.ext import six
# Import Salt libs # Import Salt libs
import salt.utils.files import salt.utils.files
import salt.utils.platform import salt.utils.platform
import salt.utils.yaml
USERA = 'saltdev' USERA = 'saltdev'
USERA_PWD = 'saltdev' USERA_PWD = 'saltdev'
@ -156,8 +156,8 @@ class KeyTest(ShellCase, ShellCaseCommonTestsMixin):
data = self.run_key('-L --out yaml') data = self.run_key('-L --out yaml')
ret = {} ret = {}
try: try:
import yaml import salt.utils.yaml
ret = yaml.load('\n'.join(data)) ret = salt.utils.yaml.safe_load('\n'.join(data))
except Exception: except Exception:
pass pass
@ -289,12 +289,10 @@ class KeyTest(ShellCase, ShellCaseCommonTestsMixin):
config_file_name = 'master' config_file_name = 'master'
with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr: with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr:
config = yaml.load(fhr.read()) config = salt.utils.yaml.safe_load(fhr)
config['log_file'] = 'file:///dev/log/LOG_LOCAL3' config['log_file'] = 'file:///dev/log/LOG_LOCAL3'
with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw: with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw:
fhw.write( salt.utils.yaml.safe_dump(config, fhw, default_flow_style=False)
yaml.dump(config, default_flow_style=False)
)
ret = self.run_script( ret = self.run_script(
self._call_binary_, self._call_binary_,
'--config-dir {0} -L'.format( '--config-dir {0} -L'.format(

View file

@ -13,11 +13,9 @@ import os
import signal import signal
import shutil import shutil
# Import 3rd-party libs
import yaml
# Import salt libs # Import salt libs
import salt.utils.files import salt.utils.files
import salt.utils.yaml
# Import salt test libs # Import salt test libs
import tests.integration.utils import tests.integration.utils
@ -42,16 +40,14 @@ class MasterTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
config_file_name = 'master' config_file_name = 'master'
pid_path = os.path.join(config_dir, '{0}.pid'.format(config_file_name)) pid_path = os.path.join(config_dir, '{0}.pid'.format(config_file_name))
with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr: with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr:
config = yaml.load(fhr.read()) config = salt.utils.yaml.safe_load(fhr)
config['root_dir'] = config_dir config['root_dir'] = config_dir
config['log_file'] = 'file:///tmp/log/LOG_LOCAL3' config['log_file'] = 'file:///tmp/log/LOG_LOCAL3'
config['ret_port'] = config['ret_port'] + 10 config['ret_port'] = config['ret_port'] + 10
config['publish_port'] = config['publish_port'] + 10 config['publish_port'] = config['publish_port'] + 10
with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw: with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw:
fhw.write( salt.utils.yaml.safe_dump(config, fhw, default_flow_style=False)
yaml.dump(config, default_flow_style=False)
)
ret = self.run_script( ret = self.run_script(
self._call_binary_, self._call_binary_,

View file

@ -6,9 +6,6 @@ import os
import shutil import shutil
import time import time
# Import 3rd-party libs
import yaml
# Import Salt Testing libs # Import Salt Testing libs
from tests.support.case import ShellCase from tests.support.case import ShellCase
from tests.support.paths import TMP from tests.support.paths import TMP
@ -16,6 +13,7 @@ from tests.support.mixins import ShellCaseCommonTestsMixin
# Import salt libs # Import salt libs
import salt.utils.files import salt.utils.files
import salt.utils.yaml
def minion_in_returns(minion, lines): def minion_in_returns(minion, lines):
@ -285,7 +283,7 @@ class MatchTest(ShellCase, ShellCaseCommonTestsMixin):
def test_ipcidr(self): def test_ipcidr(self):
subnets_data = self.run_salt('--out yaml \'*\' network.subnets') subnets_data = self.run_salt('--out yaml \'*\' network.subnets')
yaml_data = yaml.load('\n'.join(subnets_data)) yaml_data = salt.utils.yaml.safe_load('\n'.join(subnets_data))
# We're just after the first defined subnet from 'minion' # We're just after the first defined subnet from 'minion'
subnet = yaml_data['minion'][0] subnet = yaml_data['minion'][0]
@ -349,14 +347,10 @@ class MatchTest(ShellCase, ShellCaseCommonTestsMixin):
config_file_name = 'master' config_file_name = 'master'
with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr: with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr:
config = yaml.load( config = salt.utils.yaml.safe_load(fhr)
fhr.read()
)
config['log_file'] = 'file:///dev/log/LOG_LOCAL3' config['log_file'] = 'file:///dev/log/LOG_LOCAL3'
with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw: with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw:
fhw.write( salt.utils.yaml.safe_dump(config, fhw, default_flow_style=False)
yaml.dump(config, default_flow_style=False)
)
ret = self.run_script( ret = self.run_script(
self._call_binary_, self._call_binary_,
'--config-dir {0} minion test.ping'.format( '--config-dir {0} minion test.ping'.format(

View file

@ -17,9 +17,6 @@ import signal
import shutil import shutil
import logging import logging
# Import 3rd-party libs
import yaml
# Import Salt Testing libs # Import Salt Testing libs
import tests.integration.utils import tests.integration.utils
from tests.support.case import ShellCase from tests.support.case import ShellCase
@ -33,6 +30,7 @@ from salt.ext import six
# Import salt libs # Import salt libs
import salt.utils.files import salt.utils.files
import salt.utils.yaml
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -61,13 +59,11 @@ class MinionTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
config_file_name = 'minion' config_file_name = 'minion'
pid_path = os.path.join(config_dir, '{0}.pid'.format(config_file_name)) pid_path = os.path.join(config_dir, '{0}.pid'.format(config_file_name))
with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr: with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr:
config = yaml.load(fhr.read()) config = salt.utils.yaml.safe_load(fhr)
config['log_file'] = 'file:///tmp/log/LOG_LOCAL3' config['log_file'] = 'file:///tmp/log/LOG_LOCAL3'
with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw: with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw:
fhw.write( salt.utils.yaml.safe_dump(config, fhw, default_flow_style=False)
yaml.dump(config, default_flow_style=False)
)
ret = self.run_script( ret = self.run_script(
self._call_binary_, self._call_binary_,

View file

@ -16,12 +16,10 @@ from tests.support.paths import TMP
from tests.support.mixins import ShellCaseCommonTestsMixin from tests.support.mixins import ShellCaseCommonTestsMixin
from tests.support.helpers import skip_if_not_root from tests.support.helpers import skip_if_not_root
# Import 3rd-party libs
import yaml
# Import Salt libs # Import Salt libs
import salt.utils.files import salt.utils.files
import salt.utils.platform import salt.utils.platform
import salt.utils.yaml
USERA = 'saltdev' USERA = 'saltdev'
USERA_PWD = 'saltdev' USERA_PWD = 'saltdev'
@ -102,12 +100,10 @@ class RunTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin)
config_file_name = 'master' config_file_name = 'master'
with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr: with salt.utils.files.fopen(self.get_config_file_path(config_file_name), 'r') as fhr:
config = yaml.load(fhr.read()) config = salt.utils.yaml.safe_load(fhr)
config['log_file'] = 'file:///dev/log/LOG_LOCAL3' config['log_file'] = 'file:///dev/log/LOG_LOCAL3'
with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw: with salt.utils.files.fopen(os.path.join(config_dir, config_file_name), 'w') as fhw:
fhw.write( salt.utils.yaml.safe_dump(config, fhw, default_flow_style=False)
yaml.dump(config, default_flow_style=False)
)
ret = self.run_script( ret = self.run_script(
self._call_binary_, self._call_binary_,
'--config-dir {0} -d'.format( '--config-dir {0} -d'.format(

View file

@ -14,9 +14,6 @@ import signal
import shutil import shutil
import logging import logging
# Import 3rd-party libs
import yaml
# Import Salt Testing libs # Import Salt Testing libs
from tests.support.case import ShellCase from tests.support.case import ShellCase
from tests.support.paths import TMP from tests.support.paths import TMP
@ -25,7 +22,7 @@ from tests.integration.utils import testprogram
# Import salt libs # Import salt libs
import salt.utils.files import salt.utils.files
import salt.utils.yaml
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -48,7 +45,7 @@ class SyndicTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
for fname in ('master', 'minion'): for fname in ('master', 'minion'):
pid_path = os.path.join(config_dir, '{0}.pid'.format(fname)) pid_path = os.path.join(config_dir, '{0}.pid'.format(fname))
with salt.utils.files.fopen(self.get_config_file_path(fname), 'r') as fhr: with salt.utils.files.fopen(self.get_config_file_path(fname), 'r') as fhr:
config = yaml.load(fhr.read()) config = salt.utils.yaml.safe_load(fhr)
config['log_file'] = config['syndic_log_file'] = 'file:///tmp/log/LOG_LOCAL3' config['log_file'] = config['syndic_log_file'] = 'file:///tmp/log/LOG_LOCAL3'
config['root_dir'] = config_dir config['root_dir'] = config_dir
if 'ret_port' in config: if 'ret_port' in config:
@ -56,9 +53,7 @@ class SyndicTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
config['publish_port'] = int(config['publish_port']) + 10 config['publish_port'] = int(config['publish_port']) + 10
with salt.utils.files.fopen(os.path.join(config_dir, fname), 'w') as fhw: with salt.utils.files.fopen(os.path.join(config_dir, fname), 'w') as fhw:
fhw.write( salt.utils.yaml.safe_dump(config, fhw, default_flow_style=False)
yaml.dump(config, default_flow_style=False)
)
ret = self.run_script( ret = self.run_script(
self._call_binary_, self._call_binary_,

View file

@ -19,11 +19,10 @@ import sys
import tempfile import tempfile
import time import time
import yaml
import salt.utils.files import salt.utils.files
import salt.utils.process import salt.utils.process
import salt.utils.psutil_compat as psutils import salt.utils.psutil_compat as psutils
import salt.utils.yaml
import salt.defaults.exitcodes as exitcodes import salt.defaults.exitcodes as exitcodes
from salt.ext import six from salt.ext import six
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
@ -600,7 +599,7 @@ class TestSaltProgram(six.with_metaclass(TestSaltProgramMeta, TestProgram)):
@staticmethod @staticmethod
def config_caster(cfg): def config_caster(cfg):
return yaml.safe_load(cfg) return salt.utils.yaml.safe_load(cfg)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if len(args) < 2 and 'program' not in kwargs: if len(args) < 2 and 'program' not in kwargs:
@ -649,8 +648,7 @@ class TestSaltProgram(six.with_metaclass(TestSaltProgramMeta, TestProgram)):
cfg[key] = val.format(**subs) cfg[key] = val.format(**subs)
else: else:
cfg[key] = val cfg[key] = val
scfg = yaml.safe_dump(cfg, default_flow_style=False) return salt.utils.yaml.safe_dump(cfg, default_flow_style=False)
return scfg
def setup(self, *args, **kwargs): def setup(self, *args, **kwargs):
super(TestSaltProgram, self).setup(*args, **kwargs) super(TestSaltProgram, self).setup(*args, **kwargs)

View file

@ -23,6 +23,7 @@ import random
import salt.utils.files import salt.utils.files
import salt.utils.json import salt.utils.json
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.yaml
try: try:
from salt.utils.nb_popen import NonBlockingPopen from salt.utils.nb_popen import NonBlockingPopen
except ImportError: except ImportError:
@ -44,7 +45,6 @@ except ImportError:
from nb_popen import NonBlockingPopen from nb_popen import NonBlockingPopen
# Import 3rd-party libs # Import 3rd-party libs
import yaml
try: try:
import requests import requests
HAS_REQUESTS = True HAS_REQUESTS = True
@ -77,7 +77,7 @@ def build_pillar_data(options):
pillar['package_artifact_dir'] = options.package_artifact_dir pillar['package_artifact_dir'] = options.package_artifact_dir
if options.pillar: if options.pillar:
pillar.update(dict(options.pillar)) pillar.update(dict(options.pillar))
return yaml.dump(pillar, default_flow_style=True, indent=0, width=sys.maxint).rstrip() return salt.utils.yaml.safe_dump(pillar, default_flow_style=True, indent=0, width=sys.maxint).rstrip()
def build_minion_target(options, vm_name): def build_minion_target(options, vm_name):

View file

@ -24,9 +24,9 @@ import uuid
# Import salt libs # Import salt libs
import salt import salt
import salt.utils.files import salt.utils.files
import salt.utils.yaml
# Import third party libs # Import third party libs
import yaml
from salt.ext import six from salt.ext import six
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
@ -301,7 +301,7 @@ class MinionSwarm(Swarm):
if self.opts['config_dir']: if self.opts['config_dir']:
spath = os.path.join(self.opts['config_dir'], 'minion') spath = os.path.join(self.opts['config_dir'], 'minion')
with salt.utils.files.fopen(spath) as conf: with salt.utils.files.fopen(spath) as conf:
data = yaml.load(conf) or {} data = salt.utils.yaml.safe_load(conf) or {}
minion_id = '{0}-{1}'.format( minion_id = '{0}-{1}'.format(
self.opts['name'], self.opts['name'],
str(idx).zfill(self.zfill) str(idx).zfill(self.zfill)
@ -360,7 +360,7 @@ class MinionSwarm(Swarm):
data['grains']['uuid'] = str(uuid.uuid4()) data['grains']['uuid'] = str(uuid.uuid4())
with salt.utils.files.fopen(path, 'w+') as fp_: with salt.utils.files.fopen(path, 'w+') as fp_:
yaml.dump(data, fp_) salt.utils.yaml.safe_dump(data, fp_)
self.confs.add(dpath) self.confs.add(dpath)
def prep_configs(self): def prep_configs(self):
@ -414,7 +414,7 @@ class MasterSwarm(Swarm):
if self.opts['config_dir']: if self.opts['config_dir']:
spath = os.path.join(self.opts['config_dir'], 'master') spath = os.path.join(self.opts['config_dir'], 'master')
with salt.utils.files.fopen(spath) as conf: with salt.utils.files.fopen(spath) as conf:
data = yaml.load(conf) data = salt.utils.yaml.safe_load(conf)
data.update({ data.update({
'log_file': os.path.join(self.conf, 'master.log'), 'log_file': os.path.join(self.conf, 'master.log'),
'open_mode': True # TODO Pre-seed keys 'open_mode': True # TODO Pre-seed keys
@ -424,7 +424,7 @@ class MasterSwarm(Swarm):
path = os.path.join(self.conf, 'master') path = os.path.join(self.conf, 'master')
with salt.utils.files.fopen(path, 'w+') as fp_: with salt.utils.files.fopen(path, 'w+') as fp_:
yaml.dump(data, fp_) salt.utils.yaml.safe_dump(data, fp_)
def shutdown(self): def shutdown(self):
print('Killing master') print('Killing master')

View file

@ -12,8 +12,8 @@ import sys
import os import os
import modulefinder import modulefinder
import pprint import pprint
import yaml
import salt.utils.json import salt.utils.json
import salt.utils.yaml
def parse(): def parse():
@ -97,7 +97,7 @@ if __name__ == '__main__':
try: try:
scand = scan(opts) scand = scan(opts)
if opts['format'] == 'yaml': if opts['format'] == 'yaml':
print(yaml.dump(scand)) print(salt.utils.yaml.safe_dump(scand))
if opts['format'] == 'json': if opts['format'] == 'json':
print(salt.utils.json.dumps(scand)) print(salt.utils.json.dumps(scand))
else: else:

View file

@ -42,14 +42,11 @@ import salt.runner
import jinja2 import jinja2
from salt.ext.six.moves import builtins # pylint: disable=import-error from salt.ext.six.moves import builtins # pylint: disable=import-error
# pylint: disable=unused-import
# pylint: disable=W0611
# These are imported to be available in the spawned shell # These are imported to be available in the spawned shell
import salt.utils.yaml
import yaml
import pprint import pprint
# pylint: enable=unused-import
HISTFILE = '{HOME}/.saltsh_history'.format(**os.environ) HISTFILE = '{HOME}/.saltsh_history'.format(**os.environ)

View file

@ -655,13 +655,13 @@ class SPMCase(TestCase, AdaptedConfigurationTestCaseMixin):
}) })
import salt.utils.files import salt.utils.files
import yaml import salt.utils.yaml
if not os.path.isdir(config['formula_path']): if not os.path.isdir(config['formula_path']):
os.makedirs(config['formula_path']) os.makedirs(config['formula_path'])
with salt.utils.files.fopen(os.path.join(self._tmp_spm, 'spm'), 'w') as fp: with salt.utils.files.fopen(os.path.join(self._tmp_spm, 'spm'), 'w') as fp:
fp.write(yaml.dump(config)) salt.utils.yaml.safe_dump(config, fp)
return config return config

View file

@ -7,7 +7,8 @@ import argparse # pylint: disable=minimum-python-version
import os import os
import paramiko import paramiko
import subprocess import subprocess
import yaml
import salt.utils.yaml
class DownloadArtifacts(object): class DownloadArtifacts(object):
@ -19,7 +20,7 @@ class DownloadArtifacts(object):
def setup_transport(self): def setup_transport(self):
# pylint: disable=minimum-python-version # pylint: disable=minimum-python-version
config = yaml.load(subprocess.check_output(['bundle', 'exec', 'kitchen', 'diagnose', self.instance])) config = salt.utils.yaml.safe_load(subprocess.check_output(['bundle', 'exec', 'kitchen', 'diagnose', self.instance]))
# pylint: enable=minimum-python-version # pylint: enable=minimum-python-version
state = config['instances'][self.instance]['state_file'] state = config['instances'][self.instance]['state_file']
tport = config['instances'][self.instance]['transport'] tport = config['instances'][self.instance]['transport']

View file

@ -15,11 +15,11 @@ import signal
import tempfile import tempfile
import textwrap import textwrap
import time import time
import yaml
# Import Salt libs # Import Salt libs
import salt.utils.files import salt.utils.files
import salt.utils.path import salt.utils.path
import salt.utils.yaml
from salt.fileserver import gitfs from salt.fileserver import gitfs
from salt.pillar import git_pillar from salt.pillar import git_pillar
from salt.ext.six.moves import range # pylint: disable=redefined-builtin from salt.ext.six.moves import range # pylint: disable=redefined-builtin
@ -331,7 +331,7 @@ class GitPillarTestBase(GitTestBase, LoaderModuleMockMixin):
''' '''
cachedir = tempfile.mkdtemp(dir=TMP) cachedir = tempfile.mkdtemp(dir=TMP)
self.addCleanup(shutil.rmtree, cachedir, ignore_errors=True) self.addCleanup(shutil.rmtree, cachedir, ignore_errors=True)
ext_pillar_opts = yaml.safe_load( ext_pillar_opts = salt.utils.yaml.safe_load(
ext_pillar_conf.format( ext_pillar_conf.format(
cachedir=cachedir, cachedir=cachedir,
extmods=os.path.join(cachedir, 'extmods'), extmods=os.path.join(cachedir, 'extmods'),

View file

@ -36,6 +36,7 @@ import salt.utils.files
import salt.utils.functools import salt.utils.functools
import salt.utils.path import salt.utils.path
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.yaml
import salt.version import salt.version
import salt.exceptions import salt.exceptions
from salt.utils.verify import verify_env from salt.utils.verify import verify_env
@ -43,7 +44,6 @@ from salt.utils.immutabletypes import freeze
from salt._compat import ElementTree as etree from salt._compat import ElementTree as etree
# Import 3rd-party libs # Import 3rd-party libs
import yaml
from salt.ext import six from salt.ext import six
from salt.ext.six.moves import zip # pylint: disable=import-error,redefined-builtin from salt.ext.six.moves import zip # pylint: disable=import-error,redefined-builtin
@ -118,7 +118,7 @@ class AdaptedConfigurationTestCaseMixin(object):
rdict['config_dir'] = conf_dir rdict['config_dir'] = conf_dir
rdict['conf_file'] = os.path.join(conf_dir, config_for) rdict['conf_file'] = os.path.join(conf_dir, config_for)
with salt.utils.files.fopen(rdict['conf_file'], 'w') as wfh: with salt.utils.files.fopen(rdict['conf_file'], 'w') as wfh:
wfh.write(yaml.dump(rdict, default_flow_style=False)) salt.utils.yaml.safe_dump(rdict, wfh, default_flow_style=False)
return rdict return rdict
@staticmethod @staticmethod

Some files were not shown because too many files have changed in this diff Show more