mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* Fixes for #27170, #27172 * Add nxos_ip_interface IT tests * For ipv6 check if ip address configured before doing a no ip address
This commit is contained in:
parent
a01c38756d
commit
b9c3329950
9 changed files with 274 additions and 6 deletions
|
@ -37,6 +37,7 @@ notes:
|
||||||
- C(mask) must be inserted in decimal format (i.e. 24) for
|
- C(mask) must be inserted in decimal format (i.e. 24) for
|
||||||
both IPv6 and IPv4.
|
both IPv6 and IPv4.
|
||||||
- A single interface can have multiple IPv6 configured.
|
- A single interface can have multiple IPv6 configured.
|
||||||
|
- C(tag) is not idempotent for IPv6 addresses and I2 system image.
|
||||||
options:
|
options:
|
||||||
interface:
|
interface:
|
||||||
description:
|
description:
|
||||||
|
@ -168,9 +169,10 @@ def find_same_addr(existing, addr, mask, full=False, **kwargs):
|
||||||
if full:
|
if full:
|
||||||
if kwargs['version'] == 'v4' and int(address['tag']) == kwargs['tag']:
|
if kwargs['version'] == 'v4' and int(address['tag']) == kwargs['tag']:
|
||||||
return address
|
return address
|
||||||
elif kwargs['version'] == 'v6':
|
elif kwargs['version'] == 'v6' and kwargs['tag'] == 0:
|
||||||
# Currently we don't get info about IPv6 address tag
|
# Currently we don't get info about IPv6 address tag
|
||||||
return False
|
# But let's not break idempotence for the default case
|
||||||
|
return address
|
||||||
else:
|
else:
|
||||||
return address
|
return address
|
||||||
return False
|
return False
|
||||||
|
@ -274,7 +276,7 @@ def parse_unstructured_data(body, interface_name, version, module):
|
||||||
address = each_line.strip().split(' ')[0]
|
address = each_line.strip().split(' ')[0]
|
||||||
if address not in address_list:
|
if address not in address_list:
|
||||||
address_list.append(address)
|
address_list.append(address)
|
||||||
interface['prefixes'].append(str(ipaddress.ip_interface(address).network))
|
interface['prefixes'].append(str(ipaddress.ip_interface(u"%s" % address).network))
|
||||||
|
|
||||||
if address_list:
|
if address_list:
|
||||||
for ipv6 in address_list:
|
for ipv6 in address_list:
|
||||||
|
@ -289,7 +291,7 @@ def parse_unstructured_data(body, interface_name, version, module):
|
||||||
if "IP address" in splitted_body[index]:
|
if "IP address" in splitted_body[index]:
|
||||||
regex = '.*IP\saddress:\s(?P<addr>\d{1,3}(?:\.\d{1,3}){3}),\sIP\ssubnet:' + \
|
regex = '.*IP\saddress:\s(?P<addr>\d{1,3}(?:\.\d{1,3}){3}),\sIP\ssubnet:' + \
|
||||||
'\s\d{1,3}(?:\.\d{1,3}){3}\/(?P<mask>\d+)(?:\s(?P<secondary>secondary)\s)?' + \
|
'\s\d{1,3}(?:\.\d{1,3}){3}\/(?P<mask>\d+)(?:\s(?P<secondary>secondary)\s)?' + \
|
||||||
'.+?tag:\s(?P<tag>\d+).*'
|
'(.+?tag:\s(?P<tag>\d+).*)?'
|
||||||
match = re.match(regex, splitted_body[index])
|
match = re.match(regex, splitted_body[index])
|
||||||
if match:
|
if match:
|
||||||
match_dict = match.groupdict()
|
match_dict = match.groupdict()
|
||||||
|
@ -297,6 +299,9 @@ def parse_unstructured_data(body, interface_name, version, module):
|
||||||
match_dict['secondary'] = False
|
match_dict['secondary'] = False
|
||||||
else:
|
else:
|
||||||
match_dict['secondary'] = True
|
match_dict['secondary'] = True
|
||||||
|
if match_dict['tag'] is None:
|
||||||
|
match_dict['tag'] = 0
|
||||||
|
else:
|
||||||
match_dict['tag'] = int(match_dict['tag'])
|
match_dict['tag'] = int(match_dict['tag'])
|
||||||
interface['addresses'].append(match_dict)
|
interface['addresses'].append(match_dict)
|
||||||
prefix = str(ipaddress.ip_interface(u"%(addr)s/%(mask)s" % match_dict).network)
|
prefix = str(ipaddress.ip_interface(u"%(addr)s/%(mask)s" % match_dict).network)
|
||||||
|
@ -349,6 +354,8 @@ def get_remove_ip_config_commands(interface, addr, mask, existing, version):
|
||||||
commands.append('no ip address {0}/{1}'.format(addr, mask))
|
commands.append('no ip address {0}/{1}'.format(addr, mask))
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
for address in existing['addresses']:
|
||||||
|
if address['addr'] == addr:
|
||||||
commands.append('no ipv6 address {0}/{1}'.format(addr, mask))
|
commands.append('no ipv6 address {0}/{1}'.format(addr, mask))
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
|
@ -258,6 +258,15 @@
|
||||||
failed_modules: "{{ failed_modules }} + [ 'nxos_interface_ospf' ]"
|
failed_modules: "{{ failed_modules }} + [ 'nxos_interface_ospf' ]"
|
||||||
test_failed: true
|
test_failed: true
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- include_role:
|
||||||
|
name: nxos_ip_interface
|
||||||
|
when: "limit_to in ['*', 'nxos_ip_interface']"
|
||||||
|
rescue:
|
||||||
|
- set_fact:
|
||||||
|
failed_modules: "{{ failed_modules }} + [ 'nxos_ip_interface' ]"
|
||||||
|
test_failed: true
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- include_role:
|
- include_role:
|
||||||
name: nxos_logging
|
name: nxos_logging
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
testcase: "*"
|
2
test/integration/targets/nxos_ip_interface/meta/main.yml
Normal file
2
test/integration/targets/nxos_ip_interface/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
dependencies:
|
||||||
|
- prepare_nxos_tests
|
15
test/integration/targets/nxos_ip_interface/tasks/cli.yaml
Normal file
15
test/integration/targets/nxos_ip_interface/tasks/cli.yaml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
- name: collect all cli test cases
|
||||||
|
find:
|
||||||
|
paths: "{{ role_path }}/tests/cli"
|
||||||
|
patterns: "{{ testcase }}.yaml"
|
||||||
|
register: test_cases
|
||||||
|
|
||||||
|
- name: set test_items
|
||||||
|
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||||
|
|
||||||
|
- name: run test case
|
||||||
|
include: "{{ test_case_to_run }}"
|
||||||
|
with_items: "{{ test_items }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: test_case_to_run
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
# Use block to ensure that both cli and nxapi tests
|
||||||
|
# will run even if there are failures or errors.
|
||||||
|
- block:
|
||||||
|
- { include: cli.yaml, tags: ['cli'] }
|
||||||
|
always:
|
||||||
|
- { include: nxapi.yaml, tags: ['nxapi'] }
|
28
test/integration/targets/nxos_ip_interface/tasks/nxapi.yaml
Normal file
28
test/integration/targets/nxos_ip_interface/tasks/nxapi.yaml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
- name: collect all nxapi test cases
|
||||||
|
find:
|
||||||
|
paths: "{{ role_path }}/tests/nxapi"
|
||||||
|
patterns: "{{ testcase }}.yaml"
|
||||||
|
register: test_cases
|
||||||
|
|
||||||
|
- name: set test_items
|
||||||
|
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||||
|
|
||||||
|
- name: enable nxapi
|
||||||
|
nxos_config:
|
||||||
|
lines:
|
||||||
|
- feature nxapi
|
||||||
|
- nxapi http port 80
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
|
||||||
|
- name: run test case
|
||||||
|
include: "{{ test_case_to_run }}"
|
||||||
|
with_items: "{{ test_items }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: test_case_to_run
|
||||||
|
|
||||||
|
- name: disable nxapi
|
||||||
|
nxos_config:
|
||||||
|
lines:
|
||||||
|
- no feature nxapi
|
||||||
|
provider: "{{ cli }}"
|
|
@ -0,0 +1,99 @@
|
||||||
|
---
|
||||||
|
- debug: msg="START TRANSPORT:CLI nxos_ip_interface sanity test"
|
||||||
|
|
||||||
|
- set_fact: testint1="{{ nxos_int1 }}"
|
||||||
|
- set_fact: testint2="{{ nxos_int2 }}"
|
||||||
|
|
||||||
|
- name: "Put interface {{testint1}} into default state"
|
||||||
|
nxos_config: &intdefault1
|
||||||
|
lines:
|
||||||
|
- "default interface {{ testint1 }}"
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: "Put interface {{testint2}} into default state"
|
||||||
|
nxos_config: &intdefault2
|
||||||
|
lines:
|
||||||
|
- "default interface {{ testint2 }}"
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: "Make {{testint1}} a layer3 interface"
|
||||||
|
nxos_interface: &l3int1
|
||||||
|
interface: "{{ testint1 }}"
|
||||||
|
mode: layer3
|
||||||
|
description: 'Configured by Ansible - Layer3'
|
||||||
|
admin_state: 'up'
|
||||||
|
state: present
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
|
||||||
|
- name: "Make {{testint2}} a layer3 interface"
|
||||||
|
nxos_interface: &l3int2
|
||||||
|
interface: "{{ testint2 }}"
|
||||||
|
mode: layer3
|
||||||
|
description: 'Configured by Ansible - Layer3'
|
||||||
|
admin_state: 'up'
|
||||||
|
state: present
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
|
||||||
|
# For titanium
|
||||||
|
- name: Clear interface v4
|
||||||
|
nxos_ip_interface:
|
||||||
|
interface: "{{ testint1 }}"
|
||||||
|
version: v4
|
||||||
|
state: absent
|
||||||
|
addr: 20.20.20.20
|
||||||
|
mask: 24
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
|
||||||
|
# For titanium
|
||||||
|
- name: Clear interface v6
|
||||||
|
nxos_ip_interface:
|
||||||
|
interface: "{{ testint2 }}"
|
||||||
|
version: v6
|
||||||
|
state: absent
|
||||||
|
addr: 'fd56:31f7:e4ad:5585::1'
|
||||||
|
mask: 64
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
|
||||||
|
- name: Ensure ipv4 address is configured
|
||||||
|
nxos_ip_interface: &ipv4
|
||||||
|
interface: "{{ testint1 }}"
|
||||||
|
version: v4
|
||||||
|
state: present
|
||||||
|
addr: 20.20.20.20
|
||||||
|
mask: 24
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: &true
|
||||||
|
that:
|
||||||
|
- "result.changed == true"
|
||||||
|
|
||||||
|
- name: "Check Idempotence"
|
||||||
|
nxos_ip_interface: *ipv4
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: &false
|
||||||
|
that:
|
||||||
|
- "result.changed == false"
|
||||||
|
|
||||||
|
- name: Ensure ipv6 address is configured
|
||||||
|
nxos_ip_interface: &ipv6
|
||||||
|
interface: "{{ testint2 }}"
|
||||||
|
version: v6
|
||||||
|
state: present
|
||||||
|
addr: 'fd56:31f7:e4ad:5585::1'
|
||||||
|
mask: 64
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: *true
|
||||||
|
|
||||||
|
- name: "Check Idempotence"
|
||||||
|
nxos_ip_interface: *ipv6
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: *false
|
||||||
|
|
||||||
|
- debug: msg="END TRANSPORT:CLI nxos_ip_interface sanity test"
|
|
@ -0,0 +1,99 @@
|
||||||
|
---
|
||||||
|
- debug: msg="START TRANSPORT:NXAPI nxos_ip_interface sanity test"
|
||||||
|
|
||||||
|
- set_fact: testint1="{{ nxos_int1 }}"
|
||||||
|
- set_fact: testint2="{{ nxos_int2 }}"
|
||||||
|
|
||||||
|
- name: "Put interface {{testint1}} into default state"
|
||||||
|
nxos_config: &intdefault1
|
||||||
|
lines:
|
||||||
|
- "default interface {{ testint1 }}"
|
||||||
|
provider: "{{ nxapi }}"
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: "Put interface {{testint2}} into default state"
|
||||||
|
nxos_config: &intdefault2
|
||||||
|
lines:
|
||||||
|
- "default interface {{ testint2 }}"
|
||||||
|
provider: "{{ nxapi }}"
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: "Make {{testint1}} a layer3 interface"
|
||||||
|
nxos_interface: &l3int1
|
||||||
|
interface: "{{ testint1 }}"
|
||||||
|
mode: layer3
|
||||||
|
description: 'Configured by Ansible - Layer3'
|
||||||
|
admin_state: 'up'
|
||||||
|
state: present
|
||||||
|
provider: "{{ nxapi }}"
|
||||||
|
|
||||||
|
- name: "Make {{testint2}} a layer3 interface"
|
||||||
|
nxos_interface: &l3int2
|
||||||
|
interface: "{{ testint2 }}"
|
||||||
|
mode: layer3
|
||||||
|
description: 'Configured by Ansible - Layer3'
|
||||||
|
admin_state: 'up'
|
||||||
|
state: present
|
||||||
|
provider: "{{ nxapi }}"
|
||||||
|
|
||||||
|
# For titanium
|
||||||
|
- name: Clear interface v4
|
||||||
|
nxos_ip_interface:
|
||||||
|
interface: "{{ testint1 }}"
|
||||||
|
version: v4
|
||||||
|
state: absent
|
||||||
|
addr: 20.20.20.20
|
||||||
|
mask: 24
|
||||||
|
provider: "{{ nxapi }}"
|
||||||
|
|
||||||
|
# For titanium
|
||||||
|
- name: Clear interface v6
|
||||||
|
nxos_ip_interface:
|
||||||
|
interface: "{{ testint2 }}"
|
||||||
|
version: v6
|
||||||
|
state: absent
|
||||||
|
addr: 'fd56:31f7:e4ad:5585::1'
|
||||||
|
mask: 64
|
||||||
|
provider: "{{ nxapi }}"
|
||||||
|
|
||||||
|
- name: Ensure ipv4 address is configured
|
||||||
|
nxos_ip_interface: &ipv4
|
||||||
|
interface: "{{ testint1 }}"
|
||||||
|
version: v4
|
||||||
|
state: present
|
||||||
|
addr: 20.20.20.20
|
||||||
|
mask: 24
|
||||||
|
provider: "{{ nxapi }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: &true
|
||||||
|
that:
|
||||||
|
- "result.changed == true"
|
||||||
|
|
||||||
|
- name: "Check Idempotence"
|
||||||
|
nxos_ip_interface: *ipv4
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: &false
|
||||||
|
that:
|
||||||
|
- "result.changed == false"
|
||||||
|
|
||||||
|
- name: Ensure ipv6 address is configured
|
||||||
|
nxos_ip_interface: &ipv6
|
||||||
|
interface: "{{ testint2 }}"
|
||||||
|
version: v6
|
||||||
|
state: present
|
||||||
|
addr: 'fd56:31f7:e4ad:5585::1'
|
||||||
|
mask: 64
|
||||||
|
provider: "{{ nxapi }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: *true
|
||||||
|
|
||||||
|
- name: "Check Idempotence"
|
||||||
|
nxos_ip_interface: *ipv6
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: *false
|
||||||
|
|
||||||
|
- debug: msg="END TRANSPORT:NXAPI nxos_ip_interface sanity test"
|
Loading…
Reference in a new issue