New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New module: management of the Nuage Networks VSP SDN solution (network/nuage/nuage_vspk) #24895
Conversation
- Requires a I(api_version) parameter (example v4_0). | ||
required: true | ||
default: null | ||
choices: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete all occurrences of choices: []
, that's the default, so not needed.
This comment applies to a number of places in this module.
required: true | ||
default: null | ||
choices: [] | ||
aliases: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete all occurrences of aliases: []
, that's the default, so not needed.
This comment applies to a number of places in this module.
default: null | ||
choices: [] | ||
aliases: [] | ||
version_added: "1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only version_added
should be at the top level, the rest can be removed.
This comment applies to a number of places in this module.
This is the Ansible version that the option was changed.
Please see https://docs.ansible.com/ansible/dev_guide/developing_modules_documenting.html for more information
except BambouHTTPError as error: | ||
self.module.fail_json(msg='Unable to connect to the API URL with given username, password and enterprise: {0}'.format(error)) | ||
|
||
def _verify_api(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are going to be a number of modules that need this logic, it may be good to move this into common code module_utils
see https://docs.ansible.com/ansible/dev_guide/developing_modules_in_groups.html for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something we are planning once we move to more modules, we'll split the general functionalities (not only this, but building the connection as well) into a module_util. Currently this is not needed yet, i think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that sounds sensible.
auth: | ||
description: | ||
- Dict with the authentication information required to connect to a Nuage VSP environment. | ||
- Requires a I(api_username) parameter (example csproot). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If some options are required together this can be enforced in the argspec,
See the following draft documentation for examples on this:
https://github.com/gundalow/ansible/blob/docs-argspec/docs/docsite/rst/dev_guide/developing_modules_general.rst#main-and-ansiblemodule-argument-spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks for the tip!
One remark, the doc stipulates the use of ()
brackets, however, that caused issues in some cases, i've used []
everywhere.
Sub options are apparently not available yet in 2.3, as such, i've added them, according to the code in module_utils/basic.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I may have made a mistake in my documentation regarding ()
vs []
, my apologies for any confusion caused, it's not been reviewed yet. I'll make sure that gets updated.
New modules go into devel
which will become the Ansible 2.4 release. What's the comment regarding 2.3 regarding?
if fetcher is None: | ||
self.module.fail_json(msg='No parent specified and root object is not a parent for the type') | ||
|
||
# Verifying state or command is set: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most if not all of this can be removed and replaced with argspec code
match_filter=dict(default=None, required=False, type='str'), | ||
properties=dict(default=None, required=False, type='dict'), | ||
children=dict(default=None, required=False, type='list') | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.properties = module.params['properties'] | ||
|
||
self.children = None | ||
if 'children' in list(module.params.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since children
, properties
and other's are defined as module args, the key will be present in params
and initialized to is a default value. Hence the if
check here and above is not required.
self.children = module.params['children']
is sufficient
auth: | ||
description: | ||
- Dict with the authentication information required to connect to a Nuage VSP environment. | ||
- Requires a I(api_username) parameter (example csproot). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I may have made a mistake in my documentation regarding ()
vs []
, my apologies for any confusion caused, it's not been reviewed yet. I'll make sure that gets updated.
New modules go into devel
which will become the Ansible 2.4 release. What's the comment regarding 2.3 regarding?
auth=dict( | ||
required=True, | ||
type='dict', | ||
no_log=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you are using subboptionsn you only need no_log
on password, & api key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gundalow the comment on 2.3 was that i was testing with 2.3. Which makes me realise that i should be testing directly with the devel branch instead.
I'll have a look and also change the no log to just the password and key (potentially certificate as well, it's not that crucial, but they are stored typically together and both point to files)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gundalow while doing negative tests, i ran into an issue in the current module_utils/basic.py
code, namely:
ansible/lib/ansible/module_utils/basic.py
Line 1739 in 757758c
value = self.params[k] |
value = self.params[k]
This will fail on when doing the check of the sub options, with the following traceback (cause: it is trying to find the sub option in the main params instead of the sub params):
Traceback (most recent call last):
File "/var/folders/7t/j48vp3pd2fzbz30yr8xjxpr00000gq/T/ansible_yoy2Ti/ansible_module_nuage_vspk.py", line 1052, in <module>
main()
File "/var/folders/7t/j48vp3pd2fzbz30yr8xjxpr00000gq/T/ansible_yoy2Ti/ansible_module_nuage_vspk.py", line 1041, in main
supports_check_mode=True
File "/var/folders/7t/j48vp3pd2fzbz30yr8xjxpr00000gq/T/ansible_yoy2Ti/ansible_modlib.zip/ansible/module_utils/basic.py", line 759, in __init__
File "/var/folders/7t/j48vp3pd2fzbz30yr8xjxpr00000gq/T/ansible_yoy2Ti/ansible_modlib.zip/ansible/module_utils/basic.py", line 1759, in _check_argument_types
File "/var/folders/7t/j48vp3pd2fzbz30yr8xjxpr00000gq/T/ansible_yoy2Ti/ansible_modlib.zip/ansible/module_utils/basic.py", line 1739, in _check_argument_types
KeyError: 'api_enterprise'
The code should be:
value = param[k]
(In case you are interested, my negative test cases can be found here: https://github.com/nuagenetworks/vspk-ansible/blob/beccbf3269a3dd5163422814506e9a4b5b244240/roles/nuage-vspk-negative-tests/tasks/main.yml )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gundalow And i also noticed that if i remove the no_log from the auth section and move it to the sub options, it actually will print those values in debug output:
fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"auth": {
"api_enterprise": "csp",
"api_password": "csproot",
"api_url": "https://localhost:8443",
"api_version": "v4_0"
},
"command": "wait_for_job",
"id": "dumy-job-uuid",
"type": "Job"
}
},
"msg": "missing required arguments: api_username"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Can you please raise a bug (or PR if you know the fix) for the
basic.py
issue - suboptions don't (currently) inherit
no_log
, ortype
So you will need to set that explicitly on the sub options as needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gundalow I've made the changes as suggested, however, running this will fail because of the bug mentioned here: #25096 For the no_log of sub options, i created issue #25097 Feel free to run the negative tests, you don't need any Nuage component to do so: |
@pdellaert Looks like #25096 has been fixed in |
All network modules added into 2.4 need to include Unit Tests. So that will need adding before this can be merged. Have a look at
How do the tests in https://github.com/nuagenetworks/vspk-ansible/blob/beccbf3269a3dd5163422814506e9a4b5b244240/roles/nuage-vspk-negative-tests/tasks/main.yml work without having a Nuage device? I see them talking to a web endpoint with credentials. I wonder if we could add them into our CI testing. |
@gundalow For the negative tests, you do not need any system to run, these just verify that all required inputs are met without creating a connection to the Nuage VSP environment. For any other tests, a setup is required. A potential solution could be to use our https://nuagex.io service. If you create an account, please let me know so i can get it activated as soon as possible. I'll look into the unit tests, we do differ from the rest of the network modules with unit tests, it seems. As these modules use CLI commands and output from their respective platforms and we talk to our HTTPS REST API to manage the Nuage solution. Unit tests are still very useful, of course, we already have unit tests in the libraries used by the module, i'll add tests for the module specific. |
Seems like something went wrong with my rebase... i'll create a new branch and push that |
The test
|
-label vmware |
SUMMARY
Adding a new module to manage the Nuage Networks VSP SDN solution through its Python SDK.
ISSUE TYPE
COMPONENT NAME
nuage_vspk
ANSIBLE VERSION