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.17k stars 5.48k forks source link

[BUG] `network.routes` execution module tracebacks on blackhole route #60126

Open alexandre-allard opened 3 years ago

alexandre-allard commented 3 years ago

Description

The network.routes execution module does not handle blackhole routes when netstat is not installed. If netstat is not installed, then the module uses ip, which does not display backhole route the same way, and ends up with a traceback:

# salt-call network.routes
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
ValueError: 'blackhole' does not appear to be an IPv4 or IPv6 network
Traceback (most recent call last):
  File "/bin/salt-call", line 11, in <module>
    load_entry_point('salt==3002.6', 'console_scripts', 'salt-call')()
  File "/usr/lib/python3.6/site-packages/salt/scripts.py", line 449, in salt_call
    client.run()
  File "/usr/lib/python3.6/site-packages/salt/cli/call.py", line 58, in run
    caller.run()
  File "/usr/lib/python3.6/site-packages/salt/cli/caller.py", line 112, in run
    ret = self.call()
  File "/usr/lib/python3.6/site-packages/salt/cli/caller.py", line 220, in call
    self.opts, data, func, args, kwargs
  File "/usr/lib/python3.6/site-packages/salt/executors/direct_call.py", line 12, in execute
    return func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/modules/network.py", line 1769, in routes
    routes_ = _ip_route_linux()
  File "/usr/lib/python3.6/site-packages/salt/modules/network.py", line 554, in _ip_route_linux
    address_mask = convert_cidr(comps[0])
  File "/usr/lib/python3.6/site-packages/salt/modules/network.py", line 1237, in convert_cidr
    cidr = calc_net(cidr)
  File "/usr/lib/python3.6/site-packages/salt/modules/network.py", line 1260, in calc_net
    return __utils__["network.calc_net"](ip_addr, netmask)
  File "/usr/lib/python3.6/site-packages/salt/utils/network.py", line 1109, in calc_net
    return str(ipaddress.ip_network(ipaddr, strict=False))
  File "/usr/lib64/python3.6/ipaddress.py", line 84, in ip_network
    address)

Setup

Steps to Reproduce the behavior Ensure that net-tools package is not present, then setup a backhole route and run the following command:

salt-call network.routes

Expected behavior The module returns a list of all routes on the host.

Versions Report

$ salt-call --versions-report
Salt Version:
          Salt: 3002.6

Dependency Versions:
          cffi: 1.9.1
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.11.1
       libgit2: Not Installed
      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: Not Installed
        Python: 3.6.8 (default, Nov 16 2020, 16:55:22)
  python-gnupg: Not Installed
        PyYAML: 3.13
         PyZMQ: 17.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.1.4

System Versions:
          dist: centos 7 Core
        locale: UTF-8
       machine: x86_64
       release: 3.10.0-1127.el7.x86_64
        system: Linux
       version: CentOS Linux 7 Core
sagetherage commented 3 years ago

@alexandre-allard-scality thank you for the bug report! We will review a PR for salt if you are so inclined to open one :)

alexandre-allard commented 3 years ago

@sagetherage sure, I'll do it.