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

nxos_acl: some platforms/versions raise when no ACLs are present #55609

Merged
merged 4 commits into from May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/ansible/modules/network/nxos/nxos_acl.py
Expand Up @@ -175,10 +175,10 @@
from ansible.module_utils.basic import AnsibleModule


def execute_show_command(command, module):
def execute_show_command(command, module, check_rc=True):
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
body = run_commands(module, cmds, check_rc=check_rc)
return body


Expand All @@ -188,9 +188,13 @@ def get_acl(module, acl_name, seq_number):
saveme = {}
acl_body = {}

body = execute_show_command(command, module)[0]
if body:
all_acl_body = body['TABLE_ip_ipv6_mac']['ROW_ip_ipv6_mac']
body = execute_show_command(command, module, check_rc=False)
if 'Structured output unsupported' in repr(body):
# Some older versions raise 501 and return a string when no ACLs exist
return {}, []

if body and body[0]:
all_acl_body = body[0]['TABLE_ip_ipv6_mac']['ROW_ip_ipv6_mac']
else:
# no access-lists configured on the device
return {}, []
Expand Down Expand Up @@ -505,7 +509,7 @@ def main():
if existing_core:
commands.append(['no {0}'.format(seq)])
elif state == 'delete_acl':
if acl[0].get('acl') != 'no_entries':
if acl and acl[0].get('acl') != 'no_entries':
commands.append(['no ip access-list {0}'.format(name)])

cmds = []
Expand Down
2 changes: 1 addition & 1 deletion test/integration/targets/nxos_acl/tests/common/sanity.yaml
Expand Up @@ -4,7 +4,7 @@
when: ansible_connection == "local"

- set_fact: time_range="ans-range"
when: not (platform is match("N5K")) and not (platform is match("N35"))
when: platform is not search('N35|N5K|N6K')

- name: "Setup: Cleanup possibly existing acl."
nxos_acl: &remove
Expand Down