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

The ios_l2_interface vlan_range_to_list function may not cast a null variable in integer #43878

Closed
clementtrebuchet opened this issue Aug 9, 2018 · 3 comments · Fixed by #43879
Assignees
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. cisco Cisco technologies ios Cisco IOS community module This issue/PR relates to a module. networking Network category support:network This issue/PR relates to code supported by the Ansible Network Team. traceback This issue/PR includes a traceback.

Comments

@clementtrebuchet
Copy link
Contributor

SUMMARY

In our infrastructure we can have devices configured with a list of vlans whose string ends with a comma.

When splitting the string, the last element is then equal to None which can not be cast to integer

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ios_l2_interface

ANSIBLE VERSION
(zion_ansible)[ta-admin-ng5898b@rac group_vars]$ ansible --version
ansible 2.6.2
 config file = /etc/ansible/ansible.cfg
 configured module search path = [u'/usr/share/ansible']
 ansible python module location = /dns/development/ctrebuchet_sandbox/zion_ansible/lib/python2.7/site-packages/ansible
 executable location = /dns/development/ctrebuchet_sandbox/zion_ansible/bin/ansible
 python version = 2.7.8 (default, Oct  9 2014, 10:48:46) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
CONFIGURATION
OS / ENVIRONMENT

Red Hat Enterprise Linux Server release 6.9 (Santiago)

STEPS TO REPRODUCE

having in the configuration a string of vlan like : "228-230,370,378,379,381,385,500,501,580-584,600,646,"

>>> def vlan_range_to_list(vlans):
...     result = []
...     if vlans:
...         for part in vlans.split(','):
...             if part.lower() == 'none':
...                 break
...             if '-' in part:
...                 start, stop = (int(i) for i in part.split('-'))
...                 result.extend(range(start, stop + 1))
...             else:
...                 result.append(int(part))
...     return sorted(result)
... 
>>> vlans = "228-230,370,378,379,381,385,500,501,580-584,600,646,"
>>> vlan_range_to_list(vlans)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 11, in vlan_range_to_list
ValueError: invalid literal for int() with base 10: ''
>>> vlans = "228-230,370,378,379,381,385,500,501,580-584,600,646"
>>> vlan_range_to_list(vlans)
[228, 229, 230, 370, 378, 379, 381, 385, 500, 501, 580, 581, 582, 583, 584, 600, 646]
>>> 
EXPECTED RESULTS

The vlan string is parsed correctly and the function handle all the cases.

>>> def vlan_range_to_list(vlans):
...     result = []
...     if vlans:
...         for part in vlans.split(','):
...             if part.lower() == 'none':
...                 break
...             if part:
...                 if '-' in part:
...                     start, stop = (int(i) for i in part.split('-'))
...                     result.extend(range(start, stop + 1))
...                 else:
...                     result.append(int(part))
...     return sorted(result)
... 
>>> vlans = "228-230,370,378,379,381,385,500,501,580-584,600,646,"
>>> vlan_range_to_list(vlans)
[228, 229, 230, 370, 378, 379, 381, 385, 500, 501, 580, 581, 582, 583, 584, 600, 646]
ACTUAL RESULTS
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 11, in vlan_range_to_list
ValueError: invalid literal for int() with base 10: ''
@ansibot
Copy link
Contributor

ansibot commented Aug 9, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Aug 9, 2018

@ansibot
Copy link
Contributor

ansibot commented Aug 9, 2018

Hi @clementtrebuchet,

Thank you for the issue, just so you are aware we have a dedicated Working Group for network.
You can find other people interested in this in #ansible-network on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

@ansibot ansibot added affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. networking Network category support:network This issue/PR relates to code supported by the Ansible Network Team. traceback This issue/PR includes a traceback. labels Aug 9, 2018
clementtrebuchet added a commit to clementtrebuchet/ansible that referenced this issue Aug 9, 2018
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Aug 13, 2018
mattclay pushed a commit that referenced this issue Aug 21, 2018
* FIX ISSUE:#43878 when the vlans string have a final comma. (#43879)

(cherry picked from commit 401c453)

* Added changelog
@dagwieers dagwieers added ios Cisco IOS community cisco Cisco technologies labels Mar 5, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. cisco Cisco technologies ios Cisco IOS community module This issue/PR relates to a module. networking Network category support:network This issue/PR relates to code supported by the Ansible Network Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants