fix for nxos_ospf_vrf invalid cmd and ntp errors (#27977)

* fix for nxos_ospf_vrf invalid cmd

* fix for nxos_ntp issues
This commit is contained in:
saichint 2017-08-14 13:09:16 -07:00 committed by Nathaniel Case
parent 19a6000d97
commit 9d84a4e530
20 changed files with 271 additions and 13 deletions

View file

@ -135,16 +135,16 @@ import re
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
output = 'json'
else:
output = 'text'
return body
commands = [{
'command': command,
'output': output,
}]
return run_commands(module, commands)
def flatten_list(command_lists):
@ -170,7 +170,7 @@ def get_ntp_source(module):
else:
source_type = 'source'
source = output[0].split()[2].lower()
except AttributeError:
except (AttributeError, IndexError):
source_type = None
source = None
@ -327,7 +327,6 @@ def main():
warnings = list()
check_args(module, warnings)
server = module.params['server'] or None
peer = module.params['peer'] or None
key_id = module.params['key_id']

View file

@ -146,7 +146,6 @@ from ansible.module_utils.netcfg import CustomNetworkConfig
PARAM_TO_COMMAND_KEYMAP = {
'vrf': 'vrf',
'ospf': 'ospf',
'router_id': 'router-id',
'default_metric': 'default-metric',
'log_adjacency': 'log-adjacency-changes',

View file

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

View file

@ -0,0 +1,2 @@
---
testcase: "*"

View file

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

View 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

View file

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

View 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 }}"

View file

@ -0,0 +1,4 @@
---
- set_fact: connection="{{ cli }}"
- import_tasks: targets/nxos_ntp/tests/common/sanity.yaml

View file

@ -0,0 +1,56 @@
---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_ntp sanity test"
- name: Setup - Remove ntp if configured
nxos_ntp: &remove
server: 1.2.3.4
key_id: 32
prefer: disabled
vrf_name: management
source_addr: 5.5.5.5
state: absent
provider: "{{ connection }}"
ignore_errors: yes
- block:
- name: Configure ntp
nxos_ntp: &config
server: 1.2.3.4
key_id: 32
prefer: enabled
vrf_name: management
source_addr: 5.5.5.5
state: present
provider: "{{ connection }}"
register: result
- assert: &true
that:
- "result.changed == true"
- name: Idempotence Check
nxos_ntp: *config
register: result
- assert: &false
that:
- "result.changed == false"
- name: Remove ntp config
nxos_ntp: *remove
register: result
- assert: *true
- name: Remove Idempotence Check
nxos_ntp: *remove
register: result
- assert: *false
always:
- name: Remove ntp config
nxos_ntp: *remove
- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_ntp sanity test"

View file

@ -0,0 +1,4 @@
---
- set_fact: connection="{{ nxapi }}"
- import_tasks: targets/nxos_ntp/tests/common/sanity.yaml

View file

@ -0,0 +1,2 @@
---
testcase: "*"

View file

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

View 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

View file

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

View 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 }}"

View file

@ -0,0 +1,4 @@
---
- set_fact: connection="{{ cli }}"
- import_tasks: targets/nxos_ospf_vrf/tests/common/sanity.yaml

View file

@ -0,0 +1,64 @@
---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_ospf_vrf sanity test"
- name: "Enable feature OSPF"
nxos_feature:
feature: ospf
state: enabled
provider: "{{ connection }}"
ignore_errors: yes
- block:
- name: Configure ospf vrf
nxos_ospf_vrf: &config
ospf: 1
router_id: 1.1.1.1
timer_throttle_spf_start: 50
timer_throttle_spf_hold: 1000
timer_throttle_spf_max: 2000
timer_throttle_lsa_start: 60
timer_throttle_lsa_hold: 1100
timer_throttle_lsa_max: 3000
vrf: test
state: present
provider: "{{ connection }}"
register: result
- assert: &true
that:
- "result.changed == true"
- name: "Check Idempotence"
nxos_ospf_vrf: *config
register: result
- assert: &false
that:
- "result.changed == false"
rescue:
- name: "Disable feature OSPF"
nxos_feature:
feature: ospf
state: disabled
provider: "{{ connection }}"
ignore_errors: yes
always:
- name: Unconfigure ospf vrf
nxos_ospf_vrf: &unconfig
ospf: 1
vrf: test
state: absent
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Check Idempotence"
nxos_ospf_vrf: *unconfig
register: result
- assert: *false
- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_ospf_vrf sanity test"

View file

@ -0,0 +1,4 @@
---
- set_fact: connection="{{ nxapi }}"
- import_tasks: targets/nxos_ospf_vrf/tests/common/sanity.yaml

View file

@ -59,7 +59,6 @@ class TestNxosOspfVrfModule(TestNxosModule):
sorted(['router ospf 1',
'vrf test',
'timers throttle lsa 60 1100 3000',
'ospf 1',
'timers throttle spf 50 1000 2000',
'vrf test']))