adds integration tests cases for nxos_feature (#21966)

pull/21969/head
Peter Sprygada 7 years ago committed by GitHub
parent 10b23f3a00
commit 4c354c9c70

@ -65,54 +65,25 @@ EXAMPLES = '''
'''
RETURN = '''
proposed:
description: proposed feature state
returned: always
type: dict
sample: {"state": "disabled"}
existing:
description: existing state of feature
returned: always
type: dict
sample: {"state": "enabled"}
end_state:
description: feature state after executing module
returned: always
type: dict
sample: {"state": "disabled"}
updates:
description: commands sent to the device
commands:
description: The set of commands to be sent to the remote device
returned: always
type: list
sample: ["no feature eigrp"]
changed:
description: check to see if a change was made on the device
returned: always
type: boolean
sample: true
feature:
description: the feature that has been examined
returned: always
type: string
sample: "vpc"
sample: ['nv overlay evpn']
'''
import re
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec
from ansible.module_utils.nxos import check_args as nxos_check_args
def apply_key_map(key_map, table):
new_dict = {}
for key, value in table.items():
new_key = key_map.get(key)
if new_key:
value = table.get(key)
if value:
new_dict[new_key] = str(value)
else:
new_dict[new_key] = value
return new_dict
def check_args(module, warnings):
nxos_check_args(module, warnings)
for key in ('include_defaults', 'config', 'save'):
if module.params[key] is not None:
warnings.append('argument %s is no longer supported, ignoring value' % key)
def get_available_features(feature, module):
@ -121,6 +92,7 @@ def get_available_features(feature, module):
command = 'show feature'
command = {'command': command, 'output': 'text'}
body = run_commands(module, [command])
split_body = body[0].splitlines()
@ -212,11 +184,12 @@ def validate_feature(module, mode='show'):
def main():
argument_spec = dict(
feature=dict(type='str', required=True),
state=dict(choices=['enabled', 'disabled'], default='enabled',
required=False),
include_defaults=dict(default=False),
state=dict(choices=['enabled', 'disabled'], default='enabled'),
# deprecated in Ans2.3
include_defaults=dict(),
config=dict(),
save=dict(type='bool', default=False)
save=dict()
)
argument_spec.update(nxos_argument_spec)
@ -227,7 +200,6 @@ def main():
warnings = list()
check_args(module, warnings)
feature = validate_feature(module)
state = module.params['state'].lower()
@ -248,25 +220,15 @@ def main():
cmds = get_commands(proposed, existing, state, module)
if cmds:
if module.check_mode:
module.exit_json(changed=True, commands=cmds)
else:
if not module.check_mode:
load_config(module, cmds)
changed = True
updated_features = get_available_features(feature, module)
existstate = updated_features[feature]
end_state = dict(state=existstate)
if 'configure' in cmds:
cmds.pop(0)
results = {}
results['proposed'] = proposed
results['existing'] = existing
results['end_state'] = end_state
results['updates'] = cmds
results['changed'] = changed
results['warnings'] = warnings
results['feature'] = module.params['feature']
changed = True
results = {
'commands': cmds,
'changed': changed,
'warnings': warnings
}
module.exit_json(**results)

@ -14,3 +14,4 @@
- { role: nxos_template, when: "limit_to in ['*', 'nxos_template']" }
- { role: nxos_nxapi, when: "limit_to in ['*', 'nxos_nxapi']" }
- { role: nxos_evpn_global, when: "limit_to in ['*', 'nxos_evpn_global']" }
- { role: nxos_feature, when: "limit_to in ['*', 'nxos_feature']" }

@ -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,3 @@
---
- { include: cli.yaml, tags: ['cli'] }
- { 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,60 @@
---
- debug: msg="START cli/configure.yaml"
- name: setup
nxos_config:
lines: no feature vn-segment-vlan-based
match: none
provider: "{{ cli }}"
- name: enable vn-segment-vlan-based
nxos_feature:
feature: vn-segment-vlan-based
state: enabled
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == true"
- name: verify vn-segment-vlan-based
nxos_feature:
feature: vn-segment-vlan-based
state: enabled
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- name: disable vn-segment-vlan-based
nxos_feature:
feature: vn-segment-vlan-based
state: disabled
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == true"
- name: verify vn-segment-vlan-based
nxos_feature:
feature: vn-segment-vlan-based
state: disabled
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- name: teardown
nxos_config:
lines: no feature vn-segment-vlan-based
match: none
provider: "{{ cli }}"
- debug: msg="END cli/configure.yaml"

@ -0,0 +1,15 @@
---
- debug: msg="START cli/invalid.yaml"
- name: configure invalid feature name
nxos_feature:
feature: invalid
provider: "{{ cli }}"
register: result
ignore_errors: yes
- assert:
that:
- result.failed == true
- debug: msg="END cli/invalid.yaml"

@ -0,0 +1,60 @@
---
- debug: msg="START nxapi/configure.yaml"
- name: setup
nxos_config:
lines: no feature vn-segment-vlan-based
match: none
provider: "{{ nxapi }}"
- name: enable vn-segment-vlan-based
nxos_feature:
feature: vn-segment-vlan-based
state: enabled
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == true"
- name: verify vn-segment-vlan-based
nxos_feature:
feature: vn-segment-vlan-based
state: enabled
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- name: disable vn-segment-vlan-based
nxos_feature:
feature: vn-segment-vlan-based
state: disabled
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == true"
- name: verify vn-segment-vlan-based
nxos_feature:
feature: vn-segment-vlan-based
state: disabled
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- name: teardown
nxos_config:
lines: no feature vn-segment-vlan-based
match: none
provider: "{{ nxapi }}"
- debug: msg="END nxapi/configure.yaml"

@ -0,0 +1,15 @@
---
- debug: msg="START nxapi/invalid.yaml"
- name: configure invalid feature name
nxos_feature:
feature: invalid
provider: "{{ nxapi }}"
register: result
ignore_errors: yes
- assert:
that:
- result.failed == true
- debug: msg="END nxapi/invalid.yaml"
Loading…
Cancel
Save