From f8c4a38ffee337d97538a28603652d75fe9ee3ac Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Tue, 11 Feb 2020 04:47:58 +0530 Subject: [PATCH] Backport PR to fix the duplication of IPV6 address with replace state in ios_l3_interfaces module (#66680) * fix 66530 (#66654) (cherry picked from commit 0c4f167b82e8c898dd8e6d5b00fcd76aa483d875) * changelog * Update 66654-fix-ipv6-duplication-for-replace-state-ios-l3-interfaces.yaml Co-authored-by: Matt Davis --- ...tion-for-replace-state-ios-l3-interfaces.yaml | 2 ++ .../module_utils/network/ios/utils/utils.py | 16 ++++++++++++++-- .../ios_l3_interfaces/tests/cli/replaced.yaml | 2 ++ .../targets/ios_l3_interfaces/vars/main.yaml | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/66654-fix-ipv6-duplication-for-replace-state-ios-l3-interfaces.yaml diff --git a/changelogs/fragments/66654-fix-ipv6-duplication-for-replace-state-ios-l3-interfaces.yaml b/changelogs/fragments/66654-fix-ipv6-duplication-for-replace-state-ios-l3-interfaces.yaml new file mode 100644 index 00000000000..fe4c4b120cf --- /dev/null +++ b/changelogs/fragments/66654-fix-ipv6-duplication-for-replace-state-ios-l3-interfaces.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ios_ - Fix bug where IPV6 was duplicated for replace state (https://github.com/ansible/ansible/pull/66654) diff --git a/lib/ansible/module_utils/network/ios/utils/utils.py b/lib/ansible/module_utils/network/ios/utils/utils.py index b7cd63580ba..e8d0ef1d1c2 100644 --- a/lib/ansible/module_utils/network/ios/utils/utils.py +++ b/lib/ansible/module_utils/network/ios/utils/utils.py @@ -62,24 +62,36 @@ def dict_to_set(sample_dict): def filter_dict_having_none_value(want, have): # Generate dict with have dict value which is None in want dict test_dict = dict() - test_key_dict = dict() name = want.get('name') if name: test_dict['name'] = name diff_ip = False - want_ip = '' for k, v in iteritems(want): if isinstance(v, dict): for key, value in iteritems(v): + test_key_dict = dict() if value is None: dict_val = have.get(k).get(key) test_key_dict.update({key: dict_val}) + elif k == 'ipv6' and value.lower() != have.get(k)[0].get(key).lower(): + # as multiple IPV6 address can be configured on same + # interface, for replace state in place update will + # actually create new entry, which isn't as expected + # for replace state, so in case of IPV6 address + # every time 1st delete the existing IPV6 config and + # then apply the new change + dict_val = have.get(k)[0].get(key) + test_key_dict.update({key: dict_val}) test_dict.update({k: test_key_dict}) if isinstance(v, list): for key, value in iteritems(v[0]): + test_key_dict = dict() if value is None: dict_val = have.get(k).get(key) test_key_dict.update({key: dict_val}) + elif k == 'ipv6' and value.lower() != have.get(k)[0].get(key).lower(): + dict_val = have.get(k)[0].get(key) + test_key_dict.update({key: dict_val}) test_dict.update({k: test_key_dict}) # below conditions checks are added to check if # secondary IP is configured, if yes then delete diff --git a/test/integration/targets/ios_l3_interfaces/tests/cli/replaced.yaml b/test/integration/targets/ios_l3_interfaces/tests/cli/replaced.yaml index 1a389044f1b..7e6e4de24d9 100644 --- a/test/integration/targets/ios_l3_interfaces/tests/cli/replaced.yaml +++ b/test/integration/targets/ios_l3_interfaces/tests/cli/replaced.yaml @@ -18,6 +18,8 @@ - address: 198.51.100.1/24 secondary: True - address: 198.51.100.2/24 + ipv6: + - address: 2001:db8:1:1::/64 state: replaced register: result diff --git a/test/integration/targets/ios_l3_interfaces/vars/main.yaml b/test/integration/targets/ios_l3_interfaces/vars/main.yaml index 024880dc104..b85a3c2ae54 100644 --- a/test/integration/targets/ios_l3_interfaces/vars/main.yaml +++ b/test/integration/targets/ios_l3_interfaces/vars/main.yaml @@ -63,6 +63,7 @@ replaced: - "no ipv6 address" - "ip address 198.51.100.1 255.255.255.0 secondary" - "ip address 198.51.100.2 255.255.255.0" + - "ipv6 address 2001:db8:1:1::/64" after: - name: loopback888 @@ -77,6 +78,8 @@ replaced: - address: 198.51.100.1 255.255.255.0 secondary: true - address: 198.51.100.2 255.255.255.0 + ipv6: + - address: 2001:db8:1:1::/64 name: GigabitEthernet0/2 overridden: