Fix for nxos_pim issues (#35103)

* fix nxos_pim issues

* unused line removed

* unused line removed

* remove unnecessary files
pull/35053/head
saichint 7 years ago committed by Trishna Guha
parent d0a257efad
commit 4bc22be614

@ -34,7 +34,8 @@ options:
ssm_range: ssm_range:
description: description:
- Configure group ranges for Source Specific Multicast (SSM). - Configure group ranges for Source Specific Multicast (SSM).
Valid values are multicast addresses or the keyword 'none'. Valid values are multicast addresses or the keyword 'none'
or keyword 'default'
required: true required: true
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -75,7 +76,9 @@ def get_existing(module, args):
value = '' value = ''
if has_command: if has_command:
value = has_command.group('value') value = has_command.group('value')
existing[arg] = value if value == '232.0.0.0/8':
value = '' # remove the reserved value
existing[arg] = value.split()
return existing return existing
@ -93,8 +96,13 @@ def get_commands(module, existing, proposed, candidate):
proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed) proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed)
for key, value in proposed_commands.items(): for key, value in proposed_commands.items():
command = '{0} {1}'.format(key, value) if key == 'ip pim ssm range' and value == 'default':
commands.append(command) # no cmd needs a value but the actual value does not matter
command = 'no ip pim ssm range none'
commands.append(command)
else:
command = '{0} {1}'.format(key, value)
commands.append(command)
if commands: if commands:
candidate.add(commands, parents=[]) candidate.add(commands, parents=[])
@ -102,7 +110,7 @@ def get_commands(module, existing, proposed, candidate):
def main(): def main():
argument_spec = dict( argument_spec = dict(
ssm_range=dict(required=True, type='str'), ssm_range=dict(required=True, type='list'),
) )
argument_spec.update(nxos_argument_spec) argument_spec.update(nxos_argument_spec)
@ -114,16 +122,29 @@ def main():
check_args(module, warnings) check_args(module, warnings)
result = {'changed': False, 'commands': [], 'warnings': warnings} result = {'changed': False, 'commands': [], 'warnings': warnings}
splitted_ssm_range = module.params['ssm_range'].split('.') ssm_range_list = module.params['ssm_range']
if len(splitted_ssm_range) != 4 and module.params['ssm_range'] != 'none': for item in ssm_range_list:
module.fail_json(msg="Valid ssm_range values are multicast addresses " splitted_ssm_range = item.split('.')
"or the keyword 'none'.") if len(splitted_ssm_range) != 4 and item != 'none' and item != 'default':
module.fail_json(msg="Valid ssm_range values are multicast addresses "
"or the keyword 'none' or the keyword 'default'.")
args = PARAM_TO_COMMAND_KEYMAP.keys() args = PARAM_TO_COMMAND_KEYMAP.keys()
existing = get_existing(module, args) existing = get_existing(module, args)
proposed = dict((k, v) for k, v in module.params.items() proposed_args = dict((k, v) for k, v in module.params.items() if k in args)
if k in args and v != existing[k])
proposed = {}
for key, value in proposed_args.items():
if key == 'ssm_range':
if value[0] == 'default':
if existing.get(key):
proposed[key] = 'default'
else:
v = sorted(set([str(i) for i in value]))
ex = sorted(set([str(i) for i in existing.get(key)]))
if v != ex:
proposed[key] = ' '.join(str(s) for s in v)
candidate = CustomNetworkConfig(indent=3) candidate = CustomNetworkConfig(indent=3)
get_commands(module, existing, proposed, candidate) get_commands(module, existing, proposed, candidate)

@ -518,6 +518,15 @@
failed_modules: "{{ failed_modules }} + [ 'nxos_overlay_global' ]" failed_modules: "{{ failed_modules }} + [ 'nxos_overlay_global' ]"
test_failed: true test_failed: true
- block:
- include_role:
name: nxos_pim
when: "limit_to in ['*', 'nxos_pim']"
rescue:
- set_fact:
failed_modules: "{{ failed_modules }} + [ 'nxos_pim' ]"
test_failed: true
- block: - block:
- include_role: - include_role:
name: nxos_pim_interface name: nxos_pim_interface

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

@ -0,0 +1,33 @@
---
- name: collect common cli test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
connection: local
register: test_cases
- name: collect cli test cases
find:
paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml"
connection: local
register: cli_cases
- set_fact:
test_cases:
files: "{{ test_cases.files }} + {{ cli_cases.files }}"
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test cases (connection=network_cli)
include: "{{ test_case_to_run }} ansible_connection=network_cli connection={}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run
- name: run test case (connection=local)
include: "{{ test_case_to_run }} ansible_connection=local connection={{ cli }}"
with_first_found: "{{ 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,27 @@
---
- name: collect common nxapi test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
connection: local
register: test_cases
- name: collect nxapi test cases
find:
paths: "{{ role_path }}/tests/nxapi"
patterns: "{{ testcase }}.yaml"
connection: local
register: nxapi_cases
- set_fact:
test_cases:
files: "{{ test_cases.files }} + {{ nxapi_cases.files }}"
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test cases (connection=local)
include: "{{ test_case_to_run }} ansible_connection=local connection={{ nxapi }}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

@ -0,0 +1,74 @@
---
- debug: msg="START connection={{ ansible_connection }} nxos_pim sanity test"
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
- name: "Setup: Disable feature PIM"
nxos_feature: &disable_feature
feature: pim
state: disabled
provider: "{{ connection }}"
- name: "Setup: Enable feature PIM"
nxos_feature:
feature: pim
state: enabled
provider: "{{ connection }}"
- name: "Setup: Configure ssm_range none"
nxos_pim: &none
ssm_range: "none"
provider: "{{ connection }}"
- block:
- name: Configure ssm_range
nxos_pim: &configure
ssm_range:
- "239.128.1.0/24"
- "224.0.0.0/8"
provider: "{{ connection }}"
register: result
- assert: &true
that:
- "result.changed == true"
- name: Check idempotence
nxos_pim: *configure
register: result
- assert: &false
that:
- "result.changed == false"
- name: Configure ssm_range default
nxos_pim: &conf_default
ssm_range: "default"
provider: "{{ connection }}"
register: result
- assert: *true
- name: Check idempotence
nxos_pim: *conf_default
register: result
- assert: *false
- name: Configure ssm_range none
nxos_pim: *none
register: result
- assert: *true
- name: Check idempotence
nxos_pim: *none
register: result
- assert: *false
always:
- name: "Disable feature PIM"
nxos_feature: *disable_feature
- debug: msg="END connection={{ ansible_connection }} nxos_pim sanity test"
Loading…
Cancel
Save