Skip to content

[BUG] Module rh_ip.py calls service.restart network , should be NetworkManager for EL8 variants #61538

Closed

Description

@mastrong

Description of Issue

rh_ip.py incorrectly calls "service.restart network" for RHEL 8. RHEL 8 no longer uses network.service, it is now NetworkManager.service.

Setup

State file that brought the issue to our attention (hostname.sls):

{% set hostname = salt['grains.get']('id')%}

change_hostname:
  network.system:
    - hostname: {{ hostname }}
    - apply_hostname: True
    - retain_settings: True

Running the state file results:

          ID: change_hostname
    Function: network.system
      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 813, in system
                  __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: 14:27:51.324309
    Duration: 231.632 ms
     Changes:

Testing network.service module for network:

[me@master~]$ sudo salt 'el8minion*' service.restart network
el8minion.mydomain:
    ERROR: Failed to restart network.service: Unit network.service not found.
ERROR: Minions returned with non-zero exit code
[me@master~]$ sudo salt 'el8minion*' service.restart NetworkManager
el8minion.mydomain:
    True

From the minion itself, no salt used:

[me@el8minion~]$ sudo systemctl restart network
Failed to restart network.service: Unit network.service not found.

[me@el8minion~]$ sudo systemctl restart NetworkManager
[me@el8minion~]$

Steps to Reproduce Issue

On RHEL 8/variant minion: applying above state (hostname.sls) or using the ip module from the command line to apply network settings (ip.apply_network_settings).

The state network.system function calls ip.apply_network_settings (ip being the virtual name for rh_ip.py, in this case). At the end of apply_network_settings function, service.restart "network" is called. Suggest implementing a check against majorrelease grain to run service.restart "NetworkManager" for 8+.

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Master:

Salt Version:
          Salt: 3004

Dependency Versions:
          cffi: 1.11.5
      cherrypy: unknown
      dateutil: 2.6.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: 1.1.0
      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: Not Installed
        pygit2: 1.6.1
        Python: 3.6.8 (default, Nov 17 2021, 16:10:06)
  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: almalinux 8.5 Arctic Sphynx
        locale: UTF-8
       machine: x86_64
       release: 4.18.0-305.19.1.el8_4.x86_64
        system: Linux
       version: AlmaLinux 8.5 Arctic Sphynx

Minion:

    Salt Version:
              Salt: 3004

    Dependency Versions:
              cffi: Not Installed
          cherrypy: Not Installed
          dateutil: 2.6.1
         docker-py: Not Installed
             gitdb: Not Installed
         gitpython: Not Installed
            Jinja2: 2.10.1
           libgit2: Not Installed
          M2Crypto: 0.35.2
              Mako: Not Installed
           msgpack: 0.6.2
      msgpack-pure: Not Installed
      mysql-python: Not Installed
         pycparser: Not Installed
          pycrypto: Not Installed
      pycryptodome: Not Installed
            pygit2: Not Installed
            Python: 3.6.8 (default, Nov 17 2021, 16:10:06)
      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: almalinux 8.5 Arctic Sphynx
            locale: UTF-8
           machine: x86_64
           release: 4.18.0-348.12.2.el8_5.x86_64
            system: Linux
           version: AlmaLinux 8.5 Arctic Sphynx

Activity

  1. welcome commented on Jan 28, 2022

    @welcome

    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 [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

  2. mastrong commented on Jan 31, 2022

    @mastrong
    CollaboratorAuthor

    Working on a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions