adds integration tests cases for nxos_feature (#21966)

This commit is contained in:
Peter Sprygada 2017-02-26 08:12:57 -05:00 committed by GitHub
parent 10b23f3a00
commit 4c354c9c70
10 changed files with 224 additions and 63 deletions

View file

@ -65,54 +65,25 @@ EXAMPLES = '''
''' '''
RETURN = ''' RETURN = '''
proposed: commands:
description: proposed feature state description: The set of commands to be sent to the remote device
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
returned: always returned: always
type: list type: list
sample: ["no feature eigrp"] sample: ['nv overlay evpn']
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"
''' '''
import re 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.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): def check_args(module, warnings):
new_dict = {} nxos_check_args(module, warnings)
for key, value in table.items():
new_key = key_map.get(key) for key in ('include_defaults', 'config', 'save'):
if new_key: if module.params[key] is not None:
value = table.get(key) warnings.append('argument %s is no longer supported, ignoring value' % key)
if value:
new_dict[new_key] = str(value)
else:
new_dict[new_key] = value
return new_dict
def get_available_features(feature, module): def get_available_features(feature, module):
@ -121,6 +92,7 @@ def get_available_features(feature, module):
command = 'show feature' command = 'show feature'
command = {'command': command, 'output': 'text'} command = {'command': command, 'output': 'text'}
body = run_commands(module, [command]) body = run_commands(module, [command])
split_body = body[0].splitlines() split_body = body[0].splitlines()
@ -212,11 +184,12 @@ def validate_feature(module, mode='show'):
def main(): def main():
argument_spec = dict( argument_spec = dict(
feature=dict(type='str', required=True), feature=dict(type='str', required=True),
state=dict(choices=['enabled', 'disabled'], default='enabled', state=dict(choices=['enabled', 'disabled'], default='enabled'),
required=False),
include_defaults=dict(default=False), # deprecated in Ans2.3
include_defaults=dict(),
config=dict(), config=dict(),
save=dict(type='bool', default=False) save=dict()
) )
argument_spec.update(nxos_argument_spec) argument_spec.update(nxos_argument_spec)
@ -227,7 +200,6 @@ def main():
warnings = list() warnings = list()
check_args(module, warnings) check_args(module, warnings)
feature = validate_feature(module) feature = validate_feature(module)
state = module.params['state'].lower() state = module.params['state'].lower()
@ -248,25 +220,15 @@ def main():
cmds = get_commands(proposed, existing, state, module) cmds = get_commands(proposed, existing, state, module)
if cmds: if cmds:
if module.check_mode: if not module.check_mode:
module.exit_json(changed=True, commands=cmds)
else:
load_config(module, cmds) load_config(module, cmds)
changed = True 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 = {
results['proposed'] = proposed 'commands': cmds,
results['existing'] = existing 'changed': changed,
results['end_state'] = end_state 'warnings': warnings
results['updates'] = cmds }
results['changed'] = changed
results['warnings'] = warnings
results['feature'] = module.params['feature']
module.exit_json(**results) module.exit_json(**results)

View file

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

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,3 @@
---
- { include: cli.yaml, tags: ['cli'] }
- { 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,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"

View file

@ -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"

View file

@ -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"

View file

@ -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"