napalm-automation / napalm-salt

Modules for event-driven network automation and orchestration using Salt
Apache License 2.0
127 stars 36 forks source link

Proxy only working from command line, not deamon or service #64

Closed aegiacometti closed 5 years ago

aegiacometti commented 5 years ago

Description of Issue

I've just installed salt and napalm, following the guidelines at: https://github.com/napalm-automation/napalm-salt https://docs.saltstack.com/en/latest/topics/network_automation/index.html https://mirceaulinic.net/2016-11-17-network-orchestration-with-salt-and-napalm/

If i start the proxy process with the command line "sudo salt-proxy --proxyid=r1 -l debug" everything works just fine. (test.ping and net.connect) But, if i try to run it as a deamon with "-d" or as a service or as beacon, i go into a loop with this errors in the logs:

[2019-09-19 21:26:11,052 [salt.minion      :1041][CRITICAL][32620] Unexpected error while connecting to localhost
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1018, in _connect_minion
    yield minion.connect_master(failed=failed)
  File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 1055, in run
    value = future.result()
  File "/usr/lib/python2.7/dist-packages/tornado/concurrent.py", line 238, in result
    raise_exc_info(self._exc_info)
  File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 1063, in run
    yielded = self.gen.throw(*exc_info)
  File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1216, in connect_master
    yield self._post_master_init(master)
  File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 1055, in run
    value = future.result()
  File "/usr/lib/python2.7/dist-packages/tornado/concurrent.py", line 238, in result
    raise_exc_info(self._exc_info)
  File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 1069, in run
    yielded = self.gen.send(value)
  File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 3420, in _post_master_init
    proxy_init_fn(self.opts)
  File "/usr/lib/python2.7/dist-packages/salt/proxy/napalm.py", line 206, in init
    NETWORK_DEVICE.update(salt.utils.napalm.get_device(opts))
  File "/usr/lib/python2.7/dist-packages/salt/utils/napalm.py", line 340, in get_device
    network_device.get('DRIVER').open()
  File "/usr/local/lib/python2.7/dist-packages/napalm_ios/ios.py", line 140, in open
    **self.netmiko_optional_args)
  File "/usr/local/lib/python2.7/dist-packages/netmiko/ssh_dispatcher.py", line 246, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/netmiko/base_connection.py", line 317, in __init__
    self._open()
  File "/usr/local/lib/python2.7/dist-packages/netmiko/base_connection.py", line 322, in _open
    self.establish_connection()
  File "/usr/local/lib/python2.7/dist-packages/netmiko/base_connection.py", line 884, in establish_connection
    self.remote_conn_pre.connect(**ssh_connect_params)
TypeError: connect() got an unexpected keyword argument 'passphrase'
2019-09-19 21:26:11,290 [/usr/lib/python2.7/dist-packages/salt/utils/napalm.pyc:239 ][ERROR   ][32620] Cannot execute "get_facts" on [unspecified hostname] as . Reason: not connected!
2019-09-19 21:26:11,290 [/usr/lib/python2.7/dist-packages/salt/utils/napalm.pyc:240 ][ERROR   ][32620] Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/utils/napalm.py", line 169, in call
    raise Exception('not connected')
Exception: not connected](url)

Napalm seems to work fine:

>>> from napalm_base import get_network_driver
>>> d = get_network_driver('ios')
>>> e = d('r1', 'cisco', 'cisco', optional_args={'config_lock': False})
>>> e.open()
>>> e.get_facts()
{u'os_version': u'3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T13, RELEASE SOFTWARE (fc3)', u'uptime': 5400, u'interface_list': [u'FastEthernet0/0', u'FastEthernet0/1', u'FastEthernet1/0', u'FastEthernet2/0'], u'vendor': u'Cisco', u'serial_number': u'FTX0945W0MY', u'model': u'3725', u'hostname': u'r1', u'fqdn': u'r1.quadrant.edu'}
>>> e.close()

Setup

top.sls

base:
  'r1':
    - r1

r1.sls

proxy:
  proxytype: napalm
  driver: ios
  host: r1
  username: 'cisco'
  password: 'cisco'
  optional_args:
    use_keys: True
    auto_rollback_on_error: True

/etc/systemd/system/salt-proxy@.service

[Unit]
Description=Salt proxy minion
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/salt-proxy --proxyid=%i -l debug
User=root
Group=root
Restart=always
RestartPreventExitStatus=SIGHUP
RestartSec=5

[Install]
WantedBy=default.target
adrian@adrian-VirtualBox:/srv/pillar$ 

/etc/salt/proxy

master: localhost
multiprocessing: false
mine_enabled: true # not required, but nice to have
pki_dir: /etc/salt/pki/proxy # not required - this separates the proxy keys into a different directory

/etc/salt/minion master: localhost

Steps to Reproduce Issue

(Include debug logs if possible and relevant.)

Versions Report

salt-proxy --version salt-proxy 2019.2.0 (Fluorine)

salt --versions-report

Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: 1.12.3
       cherrypy: Not Installed
       dateutil: 2.6.1
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.10.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: 2.19
       pycrypto: 2.6.1
   pycryptodome: 3.8.2
         pygit2: Not Installed
         Python: 2.7.15+ (default, Jul  9 2019, 16:51:35)
   python-gnupg: 0.4.1
         PyYAML: 5.1.2
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.2.5

System Versions:
           dist: LinuxMint 19.1 tessa
         locale: UTF-8
        machine: x86_64
        release: 4.15.0-20-generic
         system: Linux
        version: LinuxMint 19.1 tessa

salt-minion --version

/usr/lib/python2.7/dist-packages/salt/scripts.py:198: DeprecationWarning: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date.  Salt will drop support for Python 2.7 in the Sodium release or later.
salt-minion 2019.2.0 (Fluorine)
aegiacometti commented 5 years ago

installing napalm 2.4 solved the issue. thanks @mirceaulinic !