saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.11k stars 5.47k forks source link

[BUG] network.routes wants to restart network.service on RHEL8 (and is not found) #62844

Open kees-closed opened 1 year ago

kees-closed commented 1 year ago

Description I want to add a route on a RHEL8.4 system, instead I get a failure about that network.service is not found on RHEL8. I can't find this network.service in the Salt code (quick searches via GitHub). I also don't see how I can override this behavior. It is also quite strange that it does this, as if the OS is not detected properly, or that the wrong conditional is triggered, or that simply the wrong service is called. The documentation also doesn't include more info about it: https://docs.saltproject.io/en/master/ref/states/all/salt.states.network.html#salt.states.network.routes

Setup (Please provide relevant configs and/or SLS files (be sure to remove sensitive info. There is no general set-up of Salt.)

Please be as specific as possible and give set-up details.

Steps to Reproduce the behavior (Include debug logs if possible and relevant)

The salt state I run.

elk_network:
  network.routes:
    - name: ens4f0np0
    - routes:
      - name: elk_cluster
        ipaddr: 192.168.0.0
        netmask: 255.255.255.224
        gateway: 172.18.48.1
[ERROR   ] Command 'systemd-run' failed with return code: 5
[ERROR   ] stderr: Running scope as unit: run-r1d9fd2a20f2e490587cae5966260d944.scope
Failed to restart network.service: Unit network.service not found.
[ERROR   ] retcode: 5
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/state.py", line 2180, in call
    *cdata["args"], **cdata["kwargs"]
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
    return callable(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1249, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/states/network.py", line 746, in routes
    __salt__["ip.apply_network_settings"](**kwargs)
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
    return callable(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/modules/rh_ip.py", line 1253, in apply_network_settings
    res = __salt__["service.restart"]("network")
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
    return callable(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/modules/systemd_service.py", line 964, in restart
    raise CommandExecutionError(_strip_scope(ret["stderr"]))
salt.exceptions.CommandExecutionError: Failed to restart network.service: Unit network.service not found.

local:
----------
          ID: elk_network
    Function: network.routes
        Name: ens4f0np0
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3.6/site-packages/salt/state.py", line 2180, in call
                  *cdata["args"], **cdata["kwargs"]
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
                  return callable(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1249, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/states/network.py", line 746, in routes
                  __salt__["ip.apply_network_settings"](**kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
                  return callable(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/modules/rh_ip.py", line 1253, in apply_network_settings
                  res = __salt__["service.restart"]("network")
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
                  return callable(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/modules/systemd_service.py", line 964, in restart
                  raise CommandExecutionError(_strip_scope(ret["stderr"]))
              salt.exceptions.CommandExecutionError: Failed to restart network.service: Unit network.service not found.
     Started: 10:27:28.812661
    Duration: 47.008 ms
     Changes:   

Summary for local
------------
Succeeded: 1
Failed:    1
------------
Total states run:     2
Total run time:   1.172 s

Expected behavior I expect the route to be added and active after Salt is done.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ```yaml Salt Version: Salt: 3004.1 Dependency Versions: cffi: 1.11.5 cherrypy: Not Installed dateutil: 2.6.1 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 2.10.1 libgit2: 0.26.8 M2Crypto: 0.35.2 Mako: Not Installed msgpack: 0.6.2 msgpack-pure: Not Installed mysql-python: Not Installed pycparser: 2.14 pycrypto: Not Installed pycryptodome: 3.9.7 pygit2: 0.26.4 Python: 3.6.8 (default, Sep 9 2021, 07:49:02) python-gnupg: Not Installed PyYAML: 3.12 PyZMQ: 19.0.0 smmap: Not Installed timelib: Not Installed Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: rhel 8.5 Ootpa locale: UTF-8 machine: x86_64 release: 4.18.0-348.el8.x86_64 system: Linux version: Red Hat Enterprise Linux 8.5 Ootpa ```

Additional context Add any other context about the problem here.

welcome[bot] commented 1 year ago

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey. Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. If you have additional questions, email us at saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

OrangeDog commented 1 year ago

Most networking states don't work properly on most current OS versions.

See also: #13085, #54791

rossengeorgiev commented 1 year ago

In RHEL8, and now RHEL9, you should be using NetworkManager manage network configuration. NM can handle the old network-scripts. See https://github.com/saltstack/salt/issues/54791#issuecomment-641332362

You could work around the unmaintained network.managed state module by using file.managed to generate the config files, which will work on 7/8/9, and then cmd.run to invoke nmcli to reload and activate networks.

kees-closed commented 1 year ago

In RHEL8, and now RHEL9, you should be using NetworkManager manage network configuration. NM can handle the old network-scripts. See #54791 (comment)

You could work around the unmaintained network.managed state module by using file.managed to generate the config files, which will work on 7/8/9, and then cmd.run to invoke nmcli to reload and activate networks.

It's possible to install network-scripts, but wouldn't it be much better if Salt supports what RHEL officially supports? I don't really want to install the deprecated network-scripts.