salt icon indicating copy to clipboard operation
salt copied to clipboard

Trouble with network.system

Open smithjm opened this issue 13 years ago • 24 comments

I'm trying to use the network module on a Fedora 17 host with a very simple config, using salt 0.16.3 on both the master and minion. The interface applies correctly, but the network.system fails.

/srv/base/net/init.sls:

system:
  network.system:
    - enabled: true
    - hostname: myhost.someplace.com
    - gateway: 10.198.19.254
    - gatewaydev: eth0
    - nozeroconf: true
    - requires_reboot: true

eth0:
  network.managed:
    - enabled: true
    - type: eth
    - proto: none
    - ipaddr: 10.198.16.45
    - netmask:  255.255.252.0
    - dns:
      - 10.192.0.1
      - 10.209.0.233

This seems to match the online documentation pretty precisely, however, when I try to apply the state to the host, I get the following error:

myhost.someplace.com:

State: - network
Name:      eth0
Function:  managed
    Result:    True
    Comment:   Interface eth0 is up to date.
    Changes:   

State: - network
Name:      system
Function:  system
    Result:    False
    Comment:   An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/salt/state.py", line 1237, in call
    *cdata['args'], **cdata['kwargs'])
  File "/usr/lib/python2.7/site-packages/salt/states/network.py", line 350, in system
    new = __salt__['ip.build_network_settings'](**kwargs)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 1017, in build_network_settings
    opts = _parse_network_settings(settings, current_network_settings)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 682, in _parse_network_settings
    _raise_error_network('networking', valid)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 732, in _raise_error_network
    msg = _error_msg_network(option, expected)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 98, in _error_msg_network
    return msg.format(option, '|'.join(expected))
TypeError: sequence item 4: expected string, bool found

    Changes:   

smithjm avatar Aug 27 '13 21:08 smithjm

So even though we return an error, the settings were actually applied properly? This is probably a sorting issue in the expected-vs-found settings comparison, plus a small type mismatch (the bool error). Shouldn't be too difficult to fix.

Thanks for the report!

basepi avatar Aug 27 '13 21:08 basepi

Actually, the error is on "network.system" which I don't think actually gets applied. However, the "network.managed" portion applies correctly (defining eth0). Thanks!

smithjm avatar Aug 27 '13 21:08 smithjm

Interestingly, when I comment out the three lines that have boolean values like so:

system:
  network.system:
    {# - enabled: true #}
    - hostname: myhost.someplace.com
    - gateway: 10.198.19.254
    - gatewaydev: eth0
    {# - nozeroconf: true #}
    {# - requires_reboot: true #}

I still get:

State: - network
Name:      system
Function:  system
    Result:    False
        Comment:   An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/salt/state.py", line 1237, in call
    *cdata['args'], **cdata['kwargs'])
  File "/usr/lib/python2.7/site-packages/salt/states/network.py", line 350, in system
    new = __salt__['ip.build_network_settings'](**kwargs)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 1017, in build_network_settings
    opts = _parse_network_settings(settings, current_network_settings)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 682, in _parse_network_settings
    _raise_error_network('networking', valid)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 732, in _raise_error_network
    msg = _error_msg_network(option, expected)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 98, in _error_msg_network
    return msg.format(option, '|'.join(expected))
TypeError: sequence item 4: expected string, bool found

        Changes:

smithjm avatar Aug 28 '13 12:08 smithjm

I have now successfully configured a much more complex host, using bonded interfaces, vlan bonding, and a bridge, without errors (by commenting out the entire network.system section and managing /etc/sysconfig/network by hand). This confirms two things:

  1. the network.managed interface, bond, and bridge code is fine
  2. the network.system code is where the problem is (which we already knew)

smithjm avatar Aug 28 '13 13:08 smithjm

Just wanted to confirm I'm still seeing this in 0.17.2, against both Fedora 17 and Fedora 19:

system: network.system: - enabled: True - hostname: {{ grains['fqdn'] }} - gateway: {{ gwinfo['gateway'] }} - gatewaydev: {{ gwdev }} - nozeroconf: True - requires_reboot: True

renders on one of my minions to:

system: network.system: - enabled: true - hostname: somename.our.domain.com - gateway: 10.0.0.1 - gatewaydev: eth0 - nozeroconf: True - requires_reboot: True

which in turn generates:

State: - network
Name:      system
Function:  system
    Result:    False
    Comment:   An exception occurred in this state: Traceback (most recent call last):

File "/usr/lib/python2.7/site-packages/salt/state.py", line 1278, in call _cdata['args'], *_cdata['kwargs']) File "/usr/lib/python2.7/site-packages/salt/states/network.py", line 348, in system new = salt'ip.build_network_settings' File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 1041, in build_network_settings opts = _parse_network_settings(settings, current_network_settings) File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 684, in _parse_network_settings _raise_error_network('networking', valid) File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 734, in _raise_error_network msg = _error_msg_network(option, expected) File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 100, in _error_msg_network return msg.format(option, '|'.join(expected)) TypeError: sequence item 4: expected string, bool found

    Changes:   

The rest of the network state still applies correctly as before, but the 'network.system' state does not apply.

smithjm avatar Dec 04 '13 21:12 smithjm

I had the same problem on CentOS 6 and was able to work around it - replace - enabled: True with - networking: True and the state will be applied as expected

sroegner avatar Jan 14 '14 16:01 sroegner

I can no longer replicate this bug in 2014.1.4. I would like to close this unless there are more recent reports of this failing.

cachedout avatar May 16 '14 22:05 cachedout

Replicatable on Ubuntu 14.04 w/ salt 2015.5 and no /etc/default/networking file;

Function: network.system
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
           File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1563, in call
             **cdata['kwargs'])
           File "/usr/lib/python2.7/dist-packages/salt/states/network.py", line 425, in system
             new = __salt__['ip.build_network_settings'](**kwargs)
           File "/usr/lib/python2.7/dist-packages/salt/modules/debian_ip.py", line 1805, in build_network_settings
             opts = _parse_network_settings(settings, current_network_settings)
           File "/usr/lib/python2.7/dist-packages/salt/modules/debian_ip.py", line 1288, in _parse_network_settings
             _raise_error_network('networking', valid)
           File "/usr/lib/python2.7/dist-packages/salt/modules/debian_ip.py", line 200, in _raise_error_network
             msg = _error_msg_network(option, expected)
           File "/usr/lib/python2.7/dist-packages/salt/modules/debian_ip.py", line 179, in _error_msg_network
             return msg.format(option, '|'.join(expected))
         TypeError: sequence item 4: expected string, bool found

Cause of the trace

The trace is caused because CONFIG_TRUE and/or CONFIG_FALSE are passed on to the expected var; These contain actual bools True / False, tripping over the '|'.join.

@rallytime / @cachedout: Putting those two bools behind quotes fixes the trace, but I'm very far from sure those aren't needed for value testing. The alternative would of course be something like '|'.join([str(expect) for expect in expected]). Also, I haven't checked the other ip modules

Cause of the cause of the trace

_parse_current_network_settings initializes opts['networking'] = '', then proceeds to look for CONFIGURE_INTERFACES in /etc/default/networking. Hence if that file or that var in that file can't be read, the value will be wrong and the message will be thrown. Properly of course it'd contain False or True depending on your world view of things, which leads to my aforementioned note of value testing (in which case it probably would need to be 'True' or 'False')

As a side note, setting - networking: True doesn't make a difference for me; I have to fill the CONFIGURE_INTERFACES with something valid

The-Loeki avatar May 28 '15 12:05 The-Loeki

@rallytime bump?

The-Loeki avatar Jul 03 '15 15:07 The-Loeki

@The-Loeki Since the code has changed so much since 2014.1.4 and 2015.5 (and since @cachedout wasn't able to reproduce it) I suspect this might be something different/new. Would you mind opening a new request with all of the details you posted above?

rallytime avatar Jul 03 '15 18:07 rallytime

@rallytime: The cause of the trace lies in the fact that the CONFIG_TRUE and CONFIG_FALSE variables contain bool True/False; they trip over '|'.join. This hasn't changed and is the direct cause of all these traces whenever CONFIG_TRUE or CONFIG_FALSE are tested. AFAIK this behaviour is the same on at least 2014+, and the same piece of code exists in both rhip and debian_ip.

Now as to why that test is triggered is a different discussion and an apparent semi-rarity; the one I documented is again reproducable with little to no reason to assume this has changed between 2014.1 and 2015.5 Also, although it's a different platform, notice the problem here is exactly the same; check network.system trips up violently if not provided with a bool somewhere in the config files; the only difference is that sroegners workaround (a formula-configured override) works for RHEL's, and not for Debians.

All in all there's two different components to this problem which need addressing; the '|'.join should deal with bool and/or the bool vals need to become a string (I would've patched, but I can't tell which one is the most reasonable here),

and, since /etc/default/networking can not be assumed to be there this shouldn't be cause for a trace but rather for a sensible (formula-supplied?) default or a decent error message.

The-Loeki avatar Jul 06 '15 09:07 The-Loeki

I've now got a CentOS 7 machine clean install exhibiting a variant of this behaviour (the first part of this bug is very similar).

  File "/usr/lib/python2.7/site-packages/salt/state.py", line 1561, in call
    **cdata['kwargs'])
  File "/usr/lib/python2.7/site-packages/salt/states/network.py", line 425, in system
    new = __salt__['ip.build_network_settings'](**kwargs)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 1097, in build_network_settings
    opts = _parse_network_settings(settings, current_network_settings)
  File "/usr/lib/python2.7/site-packages/salt/modules/rh_ip.py", line 715, in _parse_network_settings
    opts['networking'] = current['networking']
KeyError: 'networking'

The workaround in this case is the exact opposite of @sroegner; enabled: True won't check for current['networking'] therefore won't throw the KeyError

Problem is again that /etc/sysconfig/network remains empty, therefore the current dict as well.

The-Loeki avatar Aug 04 '15 10:08 The-Loeki

I'm seeing this issue with a very simple state that actually comes straight from the examples in the documentation:

system:
  network.system:
    - hostname: server.example.com
    - apply_hostname: True
    - retain_settings: True

This is on Debian 8 with Salt 2016.11.3

dsnopek avatar Mar 29 '17 18:03 dsnopek

Er, went through the stack trace which is this:

Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1746, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1703, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/states/network.py", line 528, in system
                  new = __salt__['ip.build_network_settings'](**kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/modules/debian_ip.py", line 1998, in build_network_settings
                  opts = _parse_network_settings(settings, current_network_settings)
                File "/usr/lib/python2.7/dist-packages/salt/modules/debian_ip.py", line 1445, in _parse_network_settings
                  _raise_error_network('networking', valid)
                File "/usr/lib/python2.7/dist-packages/salt/modules/debian_ip.py", line 203, in _raise_error_network
                  msg = _error_msg_network(option, expected)
                File "/usr/lib/python2.7/dist-packages/salt/modules/debian_ip.py", line 182, in _error_msg_network
                  return msg.format(option, '|'.join(expected))
              TypeError: sequence item 4: expected string, bool found

And found that this was a failed attempt to build an error message. The actual error appears to be no value for the 'networking' option, which I guess comes from 'enabled' in the state. If I change my state to:

system:
  network.system:
    - enabled: True
    - hostname: server.example.com
    - apply_hostname: True
    - retain_settings: True

... then it doesn't error out! (Still haven't tested if it does what I want yet, though.) This could probably use a documentation fix!

dsnopek avatar Mar 29 '17 18:03 dsnopek

I'm not sure what all enabled is doing for network.system, but it does seem necessary. Adding that line fixes the issue for me. The docs definitely need updated if enabled is truly necessary, with an explanation. Or else the code needs fixed if it shouldn't really be required.

nixjdm avatar Aug 11 '17 20:08 nixjdm

Just stumbled upon that issue under 2016.11.9, I had an empty /etc/sysconfig/network out of a cloud-init instance and it kept failing. @dsnopek's workaround worked perfectly but not before I lost a lot of time trying to troubleshoot that issue on my own :). Having either the docs or the code updated to reflect that behaviour would definitively be helpful.

lastmikoi avatar Feb 05 '18 17:02 lastmikoi

Still applies to 2018.3.2 on Ubuntu 18.04, where it can be easily reproduced using:

salt-call -l info state.single network.system name=set-hostname hostname=localhost

Resulting in:

[INFO    ] Loading fresh modules for state activity
[INFO    ] Running state [set-hostname] at time 17:10:01.541094
[INFO    ] Executing state network.system for [set-hostname]
[WARNING ] /var/cache/salt/minion/extmods/modules/__pycache__/icinga2.cpython-36.py:27: DeprecationWarning: Use of 'salt.utils.is_windows' detected. This function has been moved to 'salt.utils.platform.is_windows' as of Salt 2018.3.0. This warning will be removed in Salt Neon.[WARNING ] /var/cache/salt/minion/extmods/modules/__pycache__/icinga2.cpython-36.py:30: DeprecationWarning: Use of 'salt.utils.which' detected. This function has been moved to 'salt.utils.path.which' as of Salt 2018.3.0. This warning will be removed in Salt Neon.
[INFO    ] Executing command ['systemctl', 'status', 'networking.service', '-n', '0'] in directory '/root'
[INFO    ] Using existing setting -- Setting: networking Value:
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/state.py", line 1905, in call
    **cdata['kwargs'])
  File "/usr/lib/python3/dist-packages/salt/loader.py", line 1830, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/states/network.py", line 564, in system
    new = __salt__['ip.build_network_settings'](**kwargs)
  File "/usr/lib/python3/dist-packages/salt/modules/debian_ip.py", line 2009, in build_network_settings
    opts = _parse_network_settings(settings, current_network_settings)
  File "/usr/lib/python3/dist-packages/salt/modules/debian_ip.py", line 1448, in _parse_network_settings
    _raise_error_network('networking', valid)
  File "/usr/lib/python3/dist-packages/salt/modules/debian_ip.py", line 204, in _raise_error_network
    msg = _error_msg_network(option, expected)
  File "/usr/lib/python3/dist-packages/salt/modules/debian_ip.py", line 183, in _error_msg_network
    return msg.format(option, '|'.join(expected))
TypeError: sequence item 4: expected str instance, bool found

[INFO    ] Completed state [set-hostname] at time 17:10:02.839376 (duration_in_ms=1298.282)
local:
----------
          ID: set-hostname    Function: network.system
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3/dist-packages/salt/state.py", line 1905, in call
                  **cdata['kwargs'])
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 1830, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/states/network.py", line 564, in system
                  new = __salt__['ip.build_network_settings'](**kwargs)
                File "/usr/lib/python3/dist-packages/salt/modules/debian_ip.py", line 2009, in build_network_settings
                  opts = _parse_network_settings(settings, current_network_settings)
                File "/usr/lib/python3/dist-packages/salt/modules/debian_ip.py", line 1448, in _parse_network_settings
                  _raise_error_network('networking', valid)
                File "/usr/lib/python3/dist-packages/salt/modules/debian_ip.py", line 204, in _raise_error_network
                  msg = _error_msg_network(option, expected)
                File "/usr/lib/python3/dist-packages/salt/modules/debian_ip.py", line 183, in _error_msg_network
                  return msg.format(option, '|'.join(expected))
              TypeError: sequence item 4: expected str instance, bool found
     Started: 17:10:01.541094
    Duration: 1298.282 ms
     Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   1.298 s

eliasp avatar Sep 26 '18 15:09 eliasp

Just pushed a fix for the error message producing a stack trace.

waynew avatar Jan 28 '19 17:01 waynew

Salt version 2019.2.0, ubuntu 18.04 Same problem as @dsnopek . I have a simple state, as documented, to set the hostname. It crashes with the same stacktrace. If I add the 'enabled: True', it says:

          ID: network_hostname
    Function: network.system
      Result: True
     Comment: Global network settings are up to date.
     Started: 11:41:57.782510
    Duration: 4409.324 ms
     Changes:   
              ----------                                                              
              network_settings:
                  --- 
                  +++ 
                  @@ -1,2 +1,2 @@
                  -NETWORKING=no
                  
                  +NETWORKING=yes
                  
                   HOSTNAME=salt-master-dev

The problems:

  • I am not very sure it did change the hostname - it was already changed. I have to check on a different setup. UPDATE: it changed it, on a different system.
  • and, more importantly, I don't get what is about that 'NETWORKING=yes' change. The server HAD networking enabled, by my other states, via 'netplan'.

cr1st1p avatar Oct 23 '19 11:10 cr1st1p

@cr1st1p can you check the neon RC?

waynew avatar Jan 24 '20 14:01 waynew