# Buggy code
def _parse_network_settings(opts, current):
    """
    Filters given options and outputs valid settings for
    the global network settings file.
    """
    # Normalize keys
    opts = dict((k.lower(), v) for (k, v) in six.iteritems(opts))
    current = dict((k.lower(), v) for (k, v) in six.iteritems(current))

    # Check for supported parameters
    retain_settings = opts.get("retain_settings", False)
    result = current if retain_settings else {}

    valid = _CONFIG_TRUE + _CONFIG_FALSE
    if "enabled" not in opts:
        try:
            opts["networking"] = current["networking"]
            _log_default_network("networking", current["networking"])
        except ValueError:
            _raise_error_network("networking", valid)
    else:
        opts["networking"] = opts["enabled"]

    if opts["networking"] in valid:
        if opts["networking"] in _CONFIG_TRUE:
            result["networking"] = "yes"
        elif opts["networking"] in _CONFIG_FALSE:
            result["networking"] = "no"
    else:
        _raise_error_network("networking", valid)

    if "hostname" not in opts:
        try:
            opts["hostname"] = current["hostname"]
            _log_default_network("hostname", current["hostname"])
        except Exception:
            _raise_error_network("hostname", ["server1.example.com"])

    if opts["hostname"]:
        result["hostname"] = opts["hostname"]
    else:
        _raise_error_network("hostname", ["server1.example.com"])

    if "nozeroconf" in opts:
        if opts["nozeroconf"] in valid:
            if opts["nozeroconf"] in _CONFIG_TRUE:
                result["nozeroconf"] = "true"
            elif opts["nozeroconf"] in _CONFIG_FALSE:
                result["nozeroconf"] = "false"
        else:
            _raise_error_network("nozeroconf", valid)

    for opt in opts:
        if opt not in ["networking", "hostname", "nozeroconf"]:
            result[opt] = opts[opt]
    return result


# Traceback (TypeError)
# ... <elided> ...
[INFO    ] Loading fresh modules for state activity
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] In saltenv 'base', looking at rel_path 'test.sls' to resolve 'salt://test.sls'
[DEBUG   ] In saltenv 'base', ** considering ** path '/var/cache/salt/minion/files/base/test.sls' to resolve 'salt://test.sls'
[DEBUG   ] compile template: /var/cache/salt/minion/files/base/test.sls
[DEBUG   ] Jinja search path: ['/var/cache/salt/minion/files/base']
[PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test.sls' using 'jinja' renderer: 0.000791072845459
[DEBUG   ] Rendered data from file: /var/cache/salt/minion/files/base/test.sls:
set hostname:
network.system:
- hostname: foo
- apply_hostname: True
- retain_settings: True

[DEBUG   ] LazyLoaded config.get
[DEBUG   ] Results of YAML rendering:
OrderedDict([('set hostname', OrderedDict([('network.system', [OrderedDict([('hostname', 'foo')]), OrderedDict([('apply_hostname', True)]), OrderedDict([('retain_settings', True)])])]))])
[PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test.sls' using 'yaml' renderer: 0.0252919197083
[DEBUG   ] LazyLoaded ip.get_interface
[DEBUG   ] LazyLoaded network.system
[INFO    ] Running state [set hostname] at time 12:20:55.473338
[INFO    ] Executing state network.system for set hostname
[INFO    ] Using existing setting -- Setting: networking Value: "yes"
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/state.py", line 1746, in call
**cdata['kwargs'])
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1704, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/salt/states/network.py", line 528, in system
new = __salt__['ip.build_network_settings'](**kwargs)
File "/usr/lib/python2.6/site-packages/salt/modules/rh_ip.py", line 1209, in build_network_settings
opts = _parse_network_settings(settings, current_network_settings)
File "/usr/lib/python2.6/site-packages/salt/modules/rh_ip.py", line 806, in _parse_network_settings
_raise_error_network('networking', valid)
File "/usr/lib/python2.6/site-packages/salt/modules/rh_ip.py", line 848, in _raise_error_network
msg = _error_msg_network(option, expected)
File "/usr/lib/python2.6/site-packages/salt/modules/rh_ip.py", line 105, in _error_msg_network
return msg.format(option, '|'.join(expected))
TypeError: sequence item 4: expected string, bool found

[INFO    ] Completed state [set hostname] at time 12:20:55.475410 duration_in_ms=2.073
[DEBUG   ] File /var/cache/salt/minion/accumulator/52678352 does not exist, no need to cleanup.
[DEBUG   ] LazyLoaded config.option
[DEBUG   ] LazyLoaded highstate.output
local:
----------
ID: set hostname
Function: network.system
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/state.py", line 1746, in call
**cdata['kwargs'])
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1704, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/salt/states/network.py", line 528, in system
new = __salt__['ip.build_network_settings'](**kwargs)
File "/usr/lib/python2.6/site-packages/salt/modules/rh_ip.py", line 1209, in build_network_settings
opts = _parse_network_settings(settings, current_network_settings)
File "/usr/lib/python2.6/site-packages/salt/modules/rh_ip.py", line 806, in _parse_network_settings
_raise_error_network('networking', valid)
File "/usr/lib/python2.6/site-packages/salt/modules/rh_ip.py", line 848, in _raise_error_network
msg = _error_msg_network(option, expected)
File "/usr/lib/python2.6/site-packages/salt/modules/rh_ip.py", line 105, in _error_msg_network
return msg.format(option, '|'.join(expected))
TypeError: sequence item 4: expected string, bool found
Started: 12:20:55.473337
Duration: 2.073 ms
Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   2.073 ms

# Fixed code
def _parse_network_settings(opts, current):
    """
    Filters given options and outputs valid settings for
    the global network settings file.
    """
    # Normalize keys
    opts = dict((k.lower(), v) for (k, v) in six.iteritems(opts))
    current = dict((k.lower(), v) for (k, v) in six.iteritems(current))

    # Check for supported parameters
    retain_settings = opts.get("retain_settings", False)
    result = current if retain_settings else {}

    # Default quote type is an empty string, which will not quote values
    quote_type = ""

    valid = _CONFIG_TRUE + _CONFIG_FALSE
    if "enabled" not in opts:
        try:
            opts["networking"] = current["networking"]
            # If networking option is quoted, use its quote type
            quote_type = salt.utils.is_quoted(opts["networking"])
            _log_default_network("networking", current["networking"])
        except ValueError:
            _raise_error_network("networking", valid)
    else:
        opts["networking"] = opts["enabled"]

    true_val = "{0}yes{0}".format(quote_type)
    false_val = "{0}no{0}".format(quote_type)

    networking = salt.utils.dequote(opts["networking"])
    if networking in valid:
        if networking in _CONFIG_TRUE:
            result["networking"] = true_val
        elif networking in _CONFIG_FALSE:
            result["networking"] = false_val
    else:
        _raise_error_network("networking", valid)

    if "hostname" not in opts:
        try:
            opts["hostname"] = current["hostname"]
            _log_default_network("hostname", current["hostname"])
        except Exception:
            _raise_error_network("hostname", ["server1.example.com"])

    if opts["hostname"]:
        result["hostname"] = "{1}{0}{1}".format(
            salt.utils.dequote(opts["hostname"]), quote_type
        )
    else:
        _raise_error_network("hostname", ["server1.example.com"])

    if "nozeroconf" in opts:
        nozeroconf = salt.utils.dequote(opts["nozerconf"])
        if nozeroconf in valid:
            if nozeroconf in _CONFIG_TRUE:
                result["nozeroconf"] = true_val
            elif nozeroconf in _CONFIG_FALSE:
                result["nozeroconf"] = false_val
        else:
            _raise_error_network("nozeroconf", valid)

    for opt in opts:
        if opt not in ["networking", "hostname", "nozeroconf"]:
            result[opt] = "{1}{0}{1}".format(salt.utils.dequote(opts[opt]), quote_type)
    return result