Skip to content
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: cnos_vlan and various utility files #21107

Merged
merged 28 commits into from
Feb 16, 2017
Merged

New module: cnos_vlan and various utility files #21107

merged 28 commits into from
Feb 16, 2017

Conversation

dkasberg
Copy link
Contributor

@dkasberg dkasberg commented Feb 7, 2017

First module: cnos_vlan and various utility files. First 1 of 17 CNOS modules

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

cnos_vlan module

ANSIBLE VERSION
ansible 2.3.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
SUMMARY

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 c:module_utils/ community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. networking Network category new_module This PR includes a new module. new_plugin This PR includes a new plugin. test_pull_requests needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Feb 7, 2017
command = command + bgpAFArg1 + " reflection "
elif(bgpAFArg1 == "dampening"):
command = command + bgpAFArg1 + " "
if(bg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failure due to python 2.4 syntax error:

2017-02-08 01:52:26 Compiling ./lib/ansible/module_utils/cnos.py ...
2017-02-08 01:52:26   File "./lib/ansible/module_utils/cnos.py", line 2829
2017-02-08 01:52:26     with open(errorFile, 'r') as f:
2017-02-08 01:52:26             ^
2017-02-08 01:52:26 SyntaxError: invalid syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have fixed this issue that was reported by shippable in cnos.py and have updated the branch. We have not used shippable yet, but have just enabled our repo to have shippable check it, however, still trying to figure out a simple shippable.yml file to have it scan our Python files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can run the tests locally using docker, rather than using Shippable. Take a look at the integration test documentation.

@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label Feb 8, 2017
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. community_review In order to be merged, this PR must follow the community review workflow. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. labels Feb 8, 2017
@dkasberg
Copy link
Contributor Author

dkasberg commented Feb 8, 2017

I'm not able to determine if there is an issue that needs to be fixed based on the check that has failed. Can you help me understand?

@dkasberg
Copy link
Contributor Author

dkasberg commented Feb 8, 2017

I think I found the error now...
2017-02-08 08:29:36 File "./lib/ansible/module_utils/cnos.py", line 2713
2017-02-08 08:29:36 except Exception,e:
2017-02-08 08:29:36 ^
2017-02-08 08:29:36 SyntaxError: invalid syntax
2017-02-08 08:29:36
2017-02-08 08:29:36 ERROR: Command "python3.5 -m compileall -fq -x /.tox/ ./lib/ansible/module_utils/cnos.py ./lib/ansible/module_utils/cnos_devicerules.py ./lib/ansible/module_utils/cnos_errorcodes.py ./lib/ansible/modules/network/cnos/init.py ./lib/ansible/modules/network/cnos/cnos_vlan.py ./lib/ansible/utils/module_docs_fragments/cnos.py" returned exit status 1.

@sivel
Copy link
Member

sivel commented Feb 8, 2017

@dkasak See http://docs.ansible.com/ansible/dev_guide/developing_modules_python3.html#exceptions for using get_exception to properly handle exceptions for py2.4->py3

@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label Feb 8, 2017
@dkasak
Copy link
Contributor

dkasak commented Feb 8, 2017

@sivel, I think you wanted to mention @dkasberg.

@abadger abadger changed the title Cnos part1 New modules: cmos_vlan and cnos_command Feb 8, 2017
@abadger abadger removed the needs_triage Needs a first human triage before being processed. label Feb 8, 2017
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Feb 9, 2017
@ansibot
Copy link
Contributor

ansibot commented Feb 9, 2017

@dkasberg this PR contains the following merge comits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibot ansibot added the merge_commit This PR contains at least one merge commit. Please resolve! label Feb 9, 2017
@dkasberg
Copy link
Contributor Author

We have several modules that share the same set of options so we were advised to move all of them to ansible\lib\ansible\utils\module_docs_fragments\cnos.py. This module has no options specific to it. All the options are defined in the module_docs_fragments\cnos.py.

Please advise how to proceed. Should we move all the common options back into each of the individual module so this passes the 'ansible_doc' check in Shippable?

@dkasberg
Copy link
Contributor Author

Additional comment to the above.

As I mentioned all options for this module have been moved to module_utils since they are in common with all our other modules, but we do have other variables that need to be input to the module. Refer to our documentation from our release last January in the link below As you can see we have an Options section there but also section called "Overloaded Variables". How do we accommodate this in Ansible's documentation guidelines? Should we convert them to the Options format? If that is the case, it may be difficult for the user to understand the various ways to input these variables....

http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_vlan.html

FYI, we will be changing the documentation on our website once our modules are included in the Ansible product.

@gundalow
Copy link
Contributor

Had to dig (I'll update the docs) options: {} is how you add in empty options.

help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fansible_for_
cnos.html)
version_added: "2.3"
Options:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to:
options: {}

cnos.html)
version_added: "2.3"
Options:
- The following is a table depicting how the overloaded variables are used
Copy link
Contributor

@gundalow gundalow Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From here to the end of the DOCUMENTAION block needs deleting

@@ -48,6 +48,8 @@
cnos.html)
version_added: "2.3"
Options:
{}

- The following is a table depicting how the overloaded variables are used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These other lines will not end up in the documentation, so I believe they need removing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about all the lines starting with:
"- The following is a table....
to where the EXAMPLE section starts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. The script that generates the HTML will only look at that the sections defined in docs.ansible.com/ansible/dev_guide/developing_modules_documenting.html

This module uses SSH to manage network device configuration.
The results of the operation can be viewed in results directory.
To know more about this module from Lenovo and customizing them for your
use cases, please visit our [User Guide](http://systemx.lenovofiles.com/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ansibot ansibot added the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. label Feb 15, 2017
@dkasberg
Copy link
Contributor Author

I'm stuck trying to fix this error reported by this check: 'ansible-doc cnos_vlan'
ERROR! module cnos_vlan missing documentation (or could not parse documentation): 'options'
As I mentioned before, this module's options are in the common utils/module_doc_fragments/cnos.py file.

gundalow suggested using:
options: {}

But this fails as well.

@sivel
Copy link
Member

sivel commented Feb 15, 2017

It looks like you specified Options instead of options.

@ansibot ansibot removed the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. label Feb 15, 2017
@mattclay
Copy link
Member

CI failure due to module validation failure:

2017-02-15 22:45:28 ============================================================================
2017-02-15 22:45:28 lib/ansible/modules/network/cnos/cnos_vlan.py
2017-02-15 22:45:28 ============================================================================
2017-02-15 22:45:28 TRACE:
2017-02-15 22:45:28     while scanning a simple key
2017-02-15 22:45:28       in "<string>", line 6, column 3:
2017-02-15 22:45:28           [inventory_hostname]['username'] ... 
2017-02-15 22:45:28           ^
2017-02-15 22:45:28     could not find expected ':'
2017-02-15 22:45:28       in "cnos_vlan.EXAMPLES", line 58, column 35:
2017-02-15 22:45:28           [inventory_hostname]['username']}}  password={{ hostvars[invento ... 
2017-02-15 22:45:28                                           ^
2017-02-15 22:45:28 ERROR: EXAMPLES is not valid YAML. Line 58 column 35

@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label Feb 15, 2017
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Feb 15, 2017
@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. labels Feb 16, 2017
@gundalow gundalow merged commit dbb4521 into ansible:devel Feb 16, 2017
@gundalow
Copy link
Contributor

Merged :)

@dkasberg dkasberg deleted the cnos-part1 branch February 16, 2017 16:38
@dkasberg dkasberg restored the cnos-part1 branch February 16, 2017 16:38
@dkasberg dkasberg deleted the cnos-part1 branch February 16, 2017 16:39
retVal = ""
command = "interface "
newPrompt = prompt
if(interfaceArg1 == "port-aggregation"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many examples of this throughout this PR, however 2 things here:

  1. The parentheses are not needed
  2. There should be a space between if and (

My personal opinion, is that where unnecessary, such as in this example, the parentheses should be removed.

def interfaceLevel2Config(
obj, deviceType, prompt, timeout, interfaceL2Arg1, interfaceL2Arg2,
interfaceL2Arg3, interfaceL2Arg4, interfaceL2Arg5, interfaceL2Arg6,
interfaceL2Arg7):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, all of the args should be indented to the same level as interfaceL2Arg7

Also, I'm not a fan of these variables. They seem pretty poorly named.

This applies throughout the codebase

# EOM


def interfaceLevel2Config(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function, is really untestable. On a McCabe complexity scale, this is a 207, which means it contains at least 207 branches of code that would need to be independently tested. Generally speaking, in most scenarios, something below a 10-12 on a McCabe complexity is preferred.

My recommendation, is that this function needs to be split up, into many smaller functions.

outputfile=./results/test_vlan_{{ inventory_hostname }}_output.txt
vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}'
vlanArg3='{{item.vlanArg3}}'
with_items: "{{test_vlan_data1}}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see here, these EXAMPLES are not valid YAML, and would not be operational if someone were to copy paste them.

They should be laid out in pure/full YAML such as:

- name: Test Vlan - Create a vlan, name it
  cnos_vlan:
    host: "{{ inventory_hostname }}"
    username: "{{ hostvars[inventory_hostname]['username'] }}"

@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 c:module_utils/ module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. networking Network category new_module This PR includes a new module. new_plugin This PR includes a new plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants