Fix nxos_interface_ospf idempotence issue (#27783)

* Add tests and fix 27167

* Add modify test
pull/26323/head
Mike Wiebe 7 years ago committed by Nathaniel Case
parent 2571fc061e
commit 65cf31e1ce

@ -285,6 +285,13 @@ def state_present(module, existing, proposed, candidate):
existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing)
for key, value in proposed_commands.items():
if existing_commands.get(key):
if key == 'ip router ospf':
if proposed['area'] == existing['area']:
continue
if existing_commands[key] == proposed_commands[key]:
continue
if value is True:
commands.append(key)
elif value is False:

@ -240,6 +240,15 @@
failed_modules: "{{ failed_modules }} + [ 'nxos_vxlan_vtep' ]"
test_failed: true
- block:
- include_role:
name: nxos_interface_ospf
when: "limit_to in ['*', 'nxos_interface_ospf']"
rescue:
- set_fact:
failed_modules: "{{ failed_modules }} + [ 'nxos_interface_ospf' ]"
test_failed: true
- block:
- include_role:
name: nxos_logging

@ -0,0 +1,2 @@
dependencies:
- prepare_nxos_tests

@ -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'] }

@ -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,4 @@
---
- set_fact: connection="{{ cli }}"
- import_tasks: "{{ role_path }}/tests/common/sanity.yaml"

@ -0,0 +1,119 @@
---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_interface_ospf sanity test"
- set_fact: testint="{{ nxos_int1 }}"
- name: "Setup - Disable feature OSPF"
nxos_feature: &disable
feature: ospf
state: disabled
provider: "{{ connection }}"
ignore_errors: yes
- name: "Setup - Enable feature OSPF"
nxos_feature: &enable
feature: ospf
state: enabled
provider: "{{ connection }}"
ignore_errors: yes
- name: "Put interface into default state"
nxos_config: &intdefault
lines:
- "default interface {{ testint }}"
provider: "{{ connection }}"
ignore_errors: yes
- name: "Remove switchport config"
nxos_config: &removeswitchport
commands:
- no switchport
parents:
- "interface {{ testint }}"
provider: "{{ connection }}"
ignore_errors: yes
- block:
- name: configure ospf interface
nxos_interface_ospf: &configure
interface: "{{ testint }}"
ospf: 1
area: 1
cost: 55
passive_interface: true
hello_interval: 15
dead_interval: 75
state: present
provider: "{{ connection }}"
register: result
- assert: &true
that:
- "result.changed == true"
- name: "Check Idempotence"
nxos_interface_ospf: *configure
register: result
- assert: &false
that:
- "result.changed == false"
- name: Modify properties
nxos_interface_ospf: &modify
interface: "{{ testint }}"
ospf: 1
area: 1
cost: 66
passive_interface: false
hello_interval: 17
dead_interval: 70
state: present
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Check Idempotence"
nxos_interface_ospf: *modify
register: result
- assert: *false
- name: remove ospf interface config
nxos_interface_ospf: &removeconfig
interface: "{{ testint }}"
ospf: 1
area: 1
cost: 55
passive_interface: true
hello_interval: 15
dead_interval: 75
state: absent
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Check Idempotence"
nxos_interface_ospf: *removeconfig
register: result
- assert: *false
- name: "Disable feature OSPF"
nxos_feature: *disable
ignore_errors: yes
- name: "Interface cleanup"
nxos_config: *intdefault
rescue:
- name: "Disable feature OSPF"
nxos_feature: *disable
- name: "Interface cleanup"
nxos_config: *intdefault
always:
- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_interface_ospf sanity test"

@ -0,0 +1,4 @@
---
- set_fact: connection="{{ nxapi }}"
- import_tasks: "{{ role_path }}/tests/common/sanity.yaml"
Loading…
Cancel
Save