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:

Home Page:https://repo.saltproject.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Unable to add users on junos via napalm

orachimary opened this issue · comments

Description
Then applying netusers state as described there https://docs.saltproject.io/en/latest/ref/states/all/salt.states.netusers.html got following error:

  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/netusers.py", line 327, in managed
    expected_users = _expand_users(users, defaults)
  File "/usr/lib/python3.6/site-packages/salt/states/netusers.py", line 74, in _expand_users
    expected_users.update(device_users)
AttributeError: 'NoneType' object has no attribute 'update'

Also if i try set users thru salt.modules.napalm_users.set_users got next error

sudo salt 'router1' users.set_users '{"micrea":{}}'
router1:
    ----------
    comment:
        Local file source set_users does not exist
    out:
        None
    result:
        False
ERROR: Minions returned with non-zero exit code

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

Juniper EX-3400

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

  • on-prem machine
  • VM (Virtualbox, KVM, etc. please specify)
  • VM running on a cloud service, please be explicit and add details
  • container (Kubernetes, Docker, containerd, etc. please specify)
  • or a combination, please be explicit
  • jails if it is FreeBSD

Steps to Reproduce the behavior
users.sls

junos-users:
    netusers.managed:
         - users:
            admin:
                level: 15
                password: $1$knmhgPPv$g8745biu4rb.Zf.IT.F/U1
                sshkeys: []
            restricted:
                level: 1
                password: $1$j34j5k4b$4d5SVjTiz1l.Zf.IT.F/K7

/srv/pillar/juniper.sls

proxy:
  proxytype: napalm
  driver: junos
  ip: xx.xx.xx.xx
  username: user
  password: passwd

Expected behavior
Add/remove users from juniper config

Screenshots
If applicable, add screenshots to help explain your problem.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3004.1
 
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: 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, Apr 12 2022, 06:55:39)
  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: rocky 8.5 Green Obsidian
        locale: UTF-8
       machine: x86_64
       release: 4.18.0-348.7.1.el8_5.x86_64
        system: Linux
       version: Rocky Linux 8.5 Green Obsidian

Additional context
Add any other context about the problem here.

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!

if replace common_users parameter in /usr/lib/python3.6/site-packages/salt/states/netusers.py

def _expand_users(device_users, common_users):

  # common_users is None
    """Creates a longer list of accepted users on the device."""
    common_users = {}
    expected_users = copy.deepcopy(common_users)
    expected_users.update(device_users)

    return expected_users

from None to empty dict

----------
          ID: junos-users
    Function: netusers.managed
      Result: False
     Comment: Cannot configure new users: Local file source set_users does not existCannot remove users: Local file source delete_users does not exist
     Started: 09:55:18.028058
    Duration: 751.266 ms
     Changes:   
              ----------
              added:
                  ----------
                  admin:
                      ----------
                      level:
                          15
                      password:
                          $1$knmhgPPv$g8745biu4rb.Zf.IT.F/U1
                      sshkeys:
                  restricted:
                      ----------
                      level:
                          1
                      password:
                          $1$j34j5k4b$4d5SVjTiz1l.Zf.IT.F/K7
              removed:
                  ----------
                  gaijinadmin:
                      ----------
                      level:
                          15
                      password:
                          $1$PLdFvi96$HggZzwtFDEhjTfREc1xOL0
                      sshkeys:
                  root:
                      ----------
                      level:
                          20
                      password:
                          $1$tPa/egY0$vcYrkv8zcEMcqVpQ4a4mo1
                      sshkeys:
              updated:
                  ----------

Summary for router1
------------
Succeeded: 0 (changed=1)
Failed:    1
------------
Total states run:     1
Total run time: 751.266 ms
ERROR: Minions returned with non-zero exit code

@mirceaulinic can you take a look at this? It has been plaguing me on Arista as well for over a year, with the exact same behavior on all revisions up to the 3005.1 which I am currently testing.