mirceaulinic / salt-sproxy

Salt plugin to automate the management and configuration of (network) devices at scale, without running (Proxy) Minions.
https://salt-sproxy.readthedocs.io/en/latest/
Apache License 2.0
117 stars 19 forks source link

Updated netbox 'filters' persists when using reactor. #258

Open n-holmstedt opened 3 years ago

n-holmstedt commented 3 years ago

Describe the bug This only occurs when using a reactor with the runner.proxy.execute.

The variable 'netbox_filter' in the targets-function of the netbox roster is a reference to the netbox filters in the global master options. When targeting a single device or using grains-filters, the global option object is updated and stored when name or levels is set.

Example: 1: Netbox filter in master config

netbox:
  token: <token>
  url: <url>
  filters:
    role: mwtransmission

2: Reactor executing targets a single device (tgt='mw-1') the 'netbox_filter' will be

[DEBUG   ] Querying NetBox with the following filters
[DEBUG   ] {'role': 'mwtransmission', name':'mw-1'}

3: Reactor executing globbing the devices (tgt='mw*') the 'netbox_filter will still be

[DEBUG   ] Querying NetBox with the following filters
[DEBUG   ] {'role': 'mwtransmission', name':'mw-1'}

Expected behavior The netbox filter should have the starting values of the initial master config every time the 'targets'-function of the roster interface is called.

Versions Report

Salt Version:
           Salt: 3001.7
    Salt SProxy: 2021.6.1

Dependency Versions:
        Ansible: Not Installed
           cffi: 1.14.6
       dateutil: 2.8.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 3.0.1
     junos-eznc: 2.6.3
       jxmlease: Not Installed
        libgit2: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 1.0.2
         NAPALM: 3.2.0
       ncclient: 0.6.9
        Netmiko: 3.4.0
       paramiko: 2.8.0
      pycparser: 2.20
       pycrypto: Not Installed
   pycryptodome: 3.10.1
         pyeapi: 0.8.4
         pygit2: Not Installed
       PyNetBox: 6.1.3
          PyNSO: Not Installed
         Python: 3.7.10 (default, Apr 15 2021, 05:35:41)
   python-gnupg: Not Installed
         PyYAML: 5.4.1
          PyZMQ: 19.0.2
            scp: 0.14.1
          smmap: Not Installed
        textfsm: 1.1.0
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.2

System Versions:
           dist: alpine 3.12.7
         locale: UTF-8
        machine: x86_64
        release: 4.18.0-147.5.1.el8_1.x86_64
         system: Linux
        version: Alpine Linux 3.12.7

Additional context Copying/de-referencing the options solves the issue.

netbox_filters = __opts__.get('netbox', {}).get('filters', {}).copy()
mirceaulinic commented 2 years ago

This also sounds like a bug, thanks for reporting @n-holmstedt. And yes, your solution sounds appropriate!