mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
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:
committed by
GitHub
parent
38eb388154
commit
604a38cac1
@@ -62,9 +62,9 @@ class AnsibleFailJson(Exception):
|
||||
class TestEosModule(unittest.TestCase):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None,
|
||||
sort=True, defaults=False):
|
||||
sort=True, defaults=False, transport='cli'):
|
||||
|
||||
self.load_fixtures(commands)
|
||||
self.load_fixtures(commands, transport=transport)
|
||||
|
||||
if failed:
|
||||
result = self.failed()
|
||||
@@ -108,6 +108,6 @@ class TestEosModule(unittest.TestCase):
|
||||
self.assertEqual(result['changed'], changed, result)
|
||||
return result
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
pass
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -36,7 +36,7 @@ class TestEosCommandModule(TestEosModule):
|
||||
def tearDown(self):
|
||||
self.mock_run_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
def load_from_file(*args, **kwargs):
|
||||
module, commands = args
|
||||
output = list()
|
||||
|
||||
@@ -41,7 +41,7 @@ class TestEosConfigModule(TestEosModule):
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.get_config.return_value = load_fixture('eos_config_config.cfg')
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class TestEosEapiModule(TestEosModule):
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_fixtures(self, commands=None, transport='eapi'):
|
||||
def run_commands(module, commands, **kwargs):
|
||||
output = list()
|
||||
for cmd in commands:
|
||||
|
||||
@@ -40,7 +40,7 @@ class TestEosSystemModule(TestEosModule):
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.get_config.return_value = load_fixture('eos_system_config.cfg')
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class TestEosUserModule(TestEosModule):
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.get_config.return_value = load_fixture('eos_user_config.cfg')
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user