Update Netbox execution module#48916
Conversation
salt/modules/netbox.py
Outdated
There was a problem hiding this comment.
instead of using salt.utils.args.clean_kwargs, it is already injected in these modules, just use __utils__['args.clean_kwargs'](**kwargs)
There was a problem hiding this comment.
I've updated this, but this breaks the unit tests:
Traceback (most recent call last):
File "/Users/tstrickx/Library/Python/2.7/lib/python/site-packages/mock/mock.py", line 1305, in patched
return func(*args, **keywargs)
File "/Users/tstrickx/Documents/Projects/salt/tests/unit/modules/test_netbox.py", line 86, in test_token_present
netbox.get_('dcim', 'devices', name='test')
File "/Users/tstrickx/Documents/Projects/salt/salt/modules/netbox.py", line 191, in get_
return _dict(_get(app, endpoint, id=id, auth_required=True if app in AUTH_ENDPOINTS else False, **kwargs))
File "/Users/tstrickx/Documents/Projects/salt/salt/modules/netbox.py", line 128, in _get
kwargs = __utils__['args.clean_kwargs'](**kwargs)
KeyError: u'args.clean_kwargs'
There was a problem hiding this comment.
Are you using this on 2017.7 or older? because the args.py file was added starting in 2018.3.
There was a problem hiding this comment.
you would need to include the args.py in your salt://_utils as well for older versions.
There was a problem hiding this comment.
This happened while running the unit tests using ./runtests.py --name=unit.modules.test_netbox. Not sure how that relates to which version of Salt I'm running.
Maybe this is relevant?
pytest-salt (2018.2.2) - Pytest Salt Plugin
INSTALLED: 2018.2.2 (latest)
salt/modules/netbox.py
Outdated
There was a problem hiding this comment.
__utils__['dictupdate.update']()
salt/modules/netbox.py
Outdated
There was a problem hiding this comment.
We like to avoid the use of **kwargs because it's unclear to the end user what it supposed to be passed here. We either need this made into an explicit variable or an explanation of what's expected here inserted into the function documentation, please.
salt/modules/netbox.py
Outdated
There was a problem hiding this comment.
This is duplicated in a few places. Can we refactor it into a single location?
There was a problem hiding this comment.
What do you mean exactly?
There was a problem hiding this comment.
From what I understood, you want to refactor the "does this object exist in netbox" checks to a single location. Most of these checks are single use, except for the device one, which I guess could be put in a function. Is this what you meant?
salt/modules/netbox.py
Outdated
salt/modules/netbox.py
Outdated
There was a problem hiding this comment.
Should we just make the empty strings the keyword defaults?
bf22380 to
10b9ec5
Compare
Add multiple functions to interact with the Netbox API.
|
I have made the requested changes, and updated the tests to function. Please let me know if there's anything else that needs to be done before merging. |
rallytime
left a comment
There was a problem hiding this comment.
This looks good to me. Thanks for updating this.
|
I changed the branch to Fluorine. CC @rallytime |
|
Thanks @Ichabond! And congrats on your first Salt PR! |
What does this PR do?
Add multiple functions to interact with the Netbox API.
New Behavior
This PR adds more functions to the Netbox execution module. This further expands the functionality by allowing deletion and creation of Netbox objects as well.
Tests written?
No
Commits signed with GPG?
No
CC: @zachmoody @mirceaulinic