From cb0ee517121e694c77634825a36eb09616984e0f Mon Sep 17 00:00:00 2001 From: hexdump0x0200 <43333029+hexdump0x0200@users.noreply.github.com> Date: Fri, 18 Oct 2019 22:55:45 +0700 Subject: [PATCH] ios_bgp: fixes #57666 (#57667) * ios_bgp: fixes #57666 * ios_bgp: add integration tests --- .../ios/providers/cli/config/bgp/process.py | 3 +- lib/ansible/modules/network/ios/ios_bgp.py | 2 +- .../targets/ios_bgp/tests/cli/basic.yaml | 56 +++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/network/ios/providers/cli/config/bgp/process.py b/lib/ansible/module_utils/network/ios/providers/cli/config/bgp/process.py index 32bc7c6c19e..d74cf92773c 100644 --- a/lib/ansible/module_utils/network/ios/providers/cli/config/bgp/process.py +++ b/lib/ansible/module_utils/network/ios/providers/cli/config/bgp/process.py @@ -25,7 +25,8 @@ class Provider(CliProvider): existing_as = None if config: match = re.search(r'router bgp (\d+)', config, re.M) - existing_as = match.group(1) + if match: + existing_as = match.group(1) operation = self.params['operation'] diff --git a/lib/ansible/modules/network/ios/ios_bgp.py b/lib/ansible/modules/network/ios/ios_bgp.py index 1b6d88db981..604033486fe 100644 --- a/lib/ansible/modules/network/ios/ios_bgp.py +++ b/lib/ansible/modules/network/ios/ios_bgp.py @@ -419,7 +419,7 @@ def main(): supports_check_mode=True) try: - result = module.edit_config(config_filter='| section bgp') + result = module.edit_config(config_filter='| section ^router bgp') except Exception as exc: module.fail_json(msg=to_text(exc)) diff --git a/test/integration/targets/ios_bgp/tests/cli/basic.yaml b/test/integration/targets/ios_bgp/tests/cli/basic.yaml index fa0f8b20b7a..8dd0bfe3ab0 100644 --- a/test/integration/targets/ios_bgp/tests/cli/basic.yaml +++ b/test/integration/targets/ios_bgp/tests/cli/basic.yaml @@ -6,6 +6,62 @@ ignore_errors: yes - block: + + - name: Add fake config with 'bgp' string + ios_config: + match: none + replace: block + lines: + - "no ip access-list extended BGP_ACL" + - "ip access-list extended BGP_ACL" + - "permit tcp any any eq bgp" + + - name: Try delete fake bgp config + register: result + ios_bgp: + operation: delete + + - assert: + that: + - 'result.changed == false' + + - name: Clean fake config with 'bgp' string + ios_config: + match: none + replace: block + lines: + - "no ip access-list extended BGP_ACL" + + - name: Add fake bgp-like config + ios_config: + match: none + replace: block + lines: + - "no ip access-list extended BGP_ACL_2" + - "ip access-list extended BGP_ACL_2" + - "remark router bgp 64496" + - "remark neighbor 192.0.2.10 remote-as 64496" + - "remark neighbor 192.0.2.10 shutdown" + - "remark address-family ipv4" + - "remark neighbor 192.0.2.10 activate" + - "remark exit-address-family" + - "permit tcp any any eq bgp" + + - name: Try delete fake bgp-like config + register: result + ios_bgp: + operation: delete + + - assert: + that: + - 'result.changed == false' + + - name: Clean fake bgp-like config + ios_config: + match: none + replace: block + lines: + - "no ip access-list extended BGP_ACL_2" - name: Configure BGP with AS 64496 and a router-id ios_bgp: &config