Implement eos_banner for EAPI (#22609)

On EAPI, the multi-line commands are expected to be a dict,
with key/value pairs 'cmd'/'input' .
This change implements that behaviour and fixes the idempotency
on EAPI as well.

Fixes #22494
This commit is contained in:
Ricardo Carrillo Cruz 2017-03-14 21:00:17 +01:00 committed by GitHub
commit 604a38cac1
8 changed files with 51 additions and 20 deletions

View file

@ -39,22 +39,42 @@ class TestEosBannerModule(TestEosModule):
self.mock_run_commands.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None):
self.run_commands.return_value = [load_fixture('eos_banner_show_banner.txt').strip()]
def load_fixtures(self, commands=None, transport='cli'):
if transport == 'cli':
self.run_commands.return_value = [load_fixture('eos_banner_show_banner.txt').strip()]
else:
self.run_commands.return_value = [{'loginBanner': load_fixture('eos_banner_show_banner.txt').strip()}]
self.load_config.return_value = dict(diff=None, session='session')
def test_eos_banner_create(self):
set_module_args(dict(banner='login', text='test\nbanner\nstring'))
def test_eos_banner_create_with_cli_transport(self):
set_module_args(dict(banner='login', text='test\nbanner\nstring',
transport='cli'))
commands = ['banner login', 'test', 'banner', 'string', 'EOF']
self.execute_module(changed=True, commands=commands)
def test_eos_banner_remove(self):
set_module_args(dict(banner='login', state='absent'))
def test_eos_banner_create_with_eapi_transport(self):
set_module_args(dict(banner='login', text='test\nbanner\nstring',
transport='eapi'))
commands = [{'cmd': 'banner login', 'input': 'test\nbanner\nstring'}]
self.execute_module(changed=True, commands=commands, transport='eapi')
def test_eos_banner_remove_with_cli_transport(self):
set_module_args(dict(banner='login', state='absent', transport='cli'))
commands = ['no banner login']
self.execute_module(changed=True, commands=commands)
def test_eos_banner_nochange(self):
def test_eos_banner_remove_with_eapi_transport(self):
set_module_args(dict(banner='login', state='absent', transport='eapi'))
commands = ['no banner login']
self.execute_module(changed=True, commands=commands, transport='eapi')
def test_eos_banner_nochange_with_cli_transport(self):
banner_text = load_fixture('eos_banner_show_banner.txt').strip()
set_module_args(dict(banner='login', text=banner_text))
set_module_args(dict(banner='login', text=banner_text, transport='cli'))
self.execute_module()
def test_eos_banner_nochange_with_eapi_transport(self):
banner_text = load_fixture('eos_banner_show_banner.txt').strip()
set_module_args(dict(banner='login', text=banner_text, transport='eapi'))
self.execute_module(transport='eapi')