-
Couldn't load subscription status.
- Fork 167
ignore_warning support for junos_install_config #248
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
Conversation
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.
Need to also add a check to ensure that PyEZ >= 2.1.1 is used when ignore_warning is specified.
I suggest just simplifying the PyEZ version check to always requiring PyEZ >= 2.1.1
library/junos_install_config
Outdated
| logging.error(msg) | ||
| module.fail_json(msg=msg) | ||
|
|
||
| if args['ignore_warning'] in BOOLEANS + ["True", "False"]: |
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.
Ansible boolean values are normally case-insensitive, but this is not. Suggest changing to:
if str(args['ignore_warning']).lower() in BOOLEANS + ["true", "false"]:
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 have not defined ignore_warning as a string for few reasons. With the older version of Ansible type will be taken care of. So if I pass in Boolean, string, list it will remain so.
Do you suggest me to make ignore_warning type defined as string?
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.
@stacywsmith I have tested all possible scenarios and dont see any failure case. Can you help me identifying the condition in which we would require this?
|
|
||
| if args['ignore_warning'] in BOOLEANS + ["True", "False"]: | ||
| args['ignore_warning'] = module.boolean(module.params['ignore_warning']) | ||
|
|
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.
It would be helpful to do additional arg type checking here to ensure that args['ignore_warning'] is a string type of list of string types.
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 didnt do that for few reason:
older version of ansible will have it as list itself. with >=2.3 it will be string and in PyEZ we do regular expression check where we loop with all rpc-warning and check if that matches any on in the list.
In this case it will just search/match the warnings in the string of list (for ex "['statment not found', 'xyz']"
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.
@stacywsmith converting string (of list) to list now.
| warning message. If the value is a string, it will ignore | ||
| warning(s) if the message of each warning matches the string. If | ||
| the value is a list of strings, ignore warning(s) if the message of | ||
| each warning matches at least one of the strings in the 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.
Add a line stating:
All warning messages produced when loading, diffing, checking, or committing the configuration are checked against ignore_warning.
Then add code to pass ignore_warning value when diffing or checking the config.
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 dont think we should do it for diff as I never diff function is PyEZ itself doesnt support that and also I never encountered diff giving rpc-error (with severity Warning). I dont see any reason too for getting such error from diff.
commit_check we can do, but for this function PyEZ don't support for now. So we cant do changes as of today.
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.
Actually, we have encountered diff returning a warning.
https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/utils/config.py#L228-L233
We did that before we added ignore_warning to PyEZ.
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.
@stacywsmith Even if we want to do ignore_warning support for diff function then we first need to change the PyEZ diff function itself. Right now it won't accept any extra parameters.
https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/utils/config.py#L208
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.
@vnitinv Yes. Agreed. If we need ignore_warning support for diff, we can add it at a future point.
|
Hi, |
|
@stacywsmith can you please review latest changes to this pull request. We need to check why Ravelo is now failing with ConnectUnknownHostError |
library/junos_install_config
Outdated
| module.fail_json(msg=msg) | ||
|
|
||
| logging.info("connecting to host: {0}@{1}:{2}".format(args['user'], args['host'], args['port'])) | ||
| if args['ignore_warning'] in BOOLEANS + ["True", "False"]: |
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 idea here is to match the exact same things that Ansible would normally interpret as a boolean.
From http://docs.ansible.com/ansible/YAMLSyntax.html:
Ansible doesn’t really use these too much, but you can also specify a boolean value (true/false) in several forms:
create_key: yes
needs_agent: no
knows_oop: True
likes_emacs: TRUE
uses_cvs: false
The current code would not match the string TRUE, for example.
The Ansible code for determining boolean values does a case-insensitive match on the boolean values. You can see this here:
https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py#L2046-L2057
That's why I'm suggesting this line should be:
if str(args['ignore_warning']).lower() in BOOLEANS + "none":
That should match the same values which module.boolean() will actually convert into a boolean value.
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.
@stacywsmith , I have done the below changes only
if str(args['ignore_warning']).lower() in BOOLEANS:Why is + "none" is required here?
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 was recommending + "none" because module.booleans() accepts None as a valid value. However, module.booleans() just returns the unmodified None value in that case, so you are correct that it's not necessary. I'm now fine with the code as it is.
user can now pass ignore_warning as per https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/utils/config.py#L336