From 361437b042a539307ad0d0dd4fa7a4756618d3a5 Mon Sep 17 00:00:00 2001 From: saichint Date: Mon, 9 Apr 2018 21:05:58 -0700 Subject: [PATCH] fix nxos_igmp issues (#38496) --- lib/ansible/modules/network/nxos/nxos_igmp.py | 13 +++++--- .../nxos_igmp/tests/common/sanity.yaml | 33 ++++++++++++++++--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_igmp.py b/lib/ansible/modules/network/nxos/nxos_igmp.py index 89a30f6472..fc57b3f8e3 100644 --- a/lib/ansible/modules/network/nxos/nxos_igmp.py +++ b/lib/ansible/modules/network/nxos/nxos_igmp.py @@ -132,10 +132,12 @@ def main(): commands.append('no ip igmp enforce-router-alert') elif state == 'present': - if desired['flush_routes'] and not current['flush_routes']: - commands.append('ip igmp flush-routes') - if desired['enforce_rtr_alert'] and not current['enforce_rtr_alert']: - commands.append('ip igmp enforce-router-alert') + ldict = {'flush_routes': 'flush-routes', 'enforce_rtr_alert': 'enforce-router-alert'} + for arg in ['flush_routes', 'enforce_rtr_alert']: + if desired[arg] and not current[arg]: + commands.append('ip igmp {0}'.format(ldict.get(arg))) + elif current[arg] and not desired[arg]: + commands.append('no ip igmp {0}'.format(ldict.get(arg))) result = {'changed': False, 'updates': commands, 'warnings': warnings} @@ -145,7 +147,8 @@ def main(): result['changed'] = True if module.params['restart']: - run_commands(module, 'restart igmp') + cmd = {'command': 'restart igmp', 'output': 'text'} + run_commands(module, cmd) module.exit_json(**result) diff --git a/test/integration/targets/nxos_igmp/tests/common/sanity.yaml b/test/integration/targets/nxos_igmp/tests/common/sanity.yaml index da8bce3c88..5689d996bd 100644 --- a/test/integration/targets/nxos_igmp/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_igmp/tests/common/sanity.yaml @@ -3,6 +3,9 @@ - debug: msg="Using provider={{ connection.transport }}" when: ansible_connection == "local" +- set_fact: restart="true" + when: platform is not match("N35") + - block: - name: Configure igmp with non-default values @@ -26,23 +29,45 @@ that: - "result.changed == false" - - name: Configure igmp with default values + - name: Configure igmp defaults nxos_igmp: &default + flush_routes: false + enforce_rtr_alert: false + restart: "{{restart|default(omit)}}" + state: present + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Check Idempotence - Configure igmp with defaults" + nxos_igmp: *default + register: result + + - assert: *false + + - name: Configure igmp non-defaults again + nxos_igmp: *non-default + register: result + + - name: Configure igmp state as values + nxos_igmp: &sdefault state: default provider: "{{ connection }}" register: result - assert: *true - - name: "Check Idempotence - Configure igmp with default values" - nxos_igmp: *default + - name: "Check Idempotence - Configure igmp with state default" + nxos_igmp: *sdefault register: result - assert: *false always: - name: Configure igmp with default values - nxos_igmp: *default + nxos_igmp: *sdefault register: result + ignore_errors: yes - debug: msg="END connection={{ ansible_connection }} nxos_igmp sanity test"