Make banner detection non-greedy in ios_banner (#63092)

* Make banner detection non-greedy in ios_banner

* Added ios_banner unit test to detect bug #63091

* Corrected PEP8 errors

* Added integration test

* Corrected typo in integration test
This commit is contained in:
kalimsshar 2019-10-25 20:20:00 +02:00 committed by GomathiselviS
parent 9d91e6275e
commit 01a92f0191
4 changed files with 86 additions and 1 deletions

View file

@ -123,7 +123,7 @@ def map_config_to_obj(module):
'show running-config | begin banner %s'
% module.params['banner'])
if out:
output = re.search(r'\^C(.*)\^C', out, re.S).group(1).strip()
output = re.search(r'\^C(.*?)\^C', out, re.S).group(1).strip()
else:
output = None
obj = {'banner': module.params['banner'], 'state': 'absent'}

View file

@ -0,0 +1,55 @@
---
- name: Setup - set login and exec
ios_banner:
banner: "{{ item }}"
text: |
this is my login banner
that as a multiline
string
state: present
provider: "{{ cli }}"
loop:
- login
- exec
- name: Set login
ios_banner:
banner: "login"
text: |
this is my login banner
that as a multiline
string
state: present
provider: "{{ cli }}"
register: result
- debug:
msg: "{{ result }}"
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"
- name: Set exec
ios_banner:
banner: "exec"
text: |
this is my login banner
that as a multiline
string
state: present
provider: "{{ cli }}"
register: result
- debug:
msg: "{{ result }}"
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"

View file

@ -0,0 +1,15 @@
banner exec ^C
this is a sample
mulitline banner
used for testing
^C
banner login ^C
this is a sample
mulitline banner
used for testing
^C
!
dummy
end
of
config

View file

@ -60,3 +60,18 @@ class TestIosBannerModule(TestIosModule):
banner_text = load_fixture('ios_banner_show_banner.txt').strip()
set_module_args(dict(banner='login', text=banner_text))
self.execute_module()
class TestIosBannerIos12Module(TestIosBannerModule):
def load_fixtures(self, commands):
show_banner_return_value = (1, '', None)
show_running_config_return_value = \
(0, load_fixture('ios_banner_show_running_config_ios12.txt').strip(), None)
self.exec_command.side_effect = [show_banner_return_value,
show_running_config_return_value]
def test_ios_banner_nochange(self):
banner_text = load_fixture('ios_banner_show_banner.txt').strip()
set_module_args(dict(banner='exec', text=banner_text))
self.execute_module()