mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
allow empty line in src template file (#42493)
This commit is contained in:
parent
940d4a0e89
commit
cf7a42b4f4
3 changed files with 12 additions and 4 deletions
|
@ -146,12 +146,17 @@ CONFIG_FILTERS = [
|
||||||
def get_candidate(module):
|
def get_candidate(module):
|
||||||
contents = module.params['src'] or module.params['lines']
|
contents = module.params['src'] or module.params['lines']
|
||||||
|
|
||||||
if module.params['lines']:
|
if module.params['src']:
|
||||||
contents = '\n'.join(contents)
|
contents = format_commands(contents.splitlines())
|
||||||
|
|
||||||
|
contents = '\n'.join(contents)
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
|
|
||||||
|
def format_commands(commands):
|
||||||
|
return [line for line in commands if len(line.strip()) > 0]
|
||||||
|
|
||||||
|
|
||||||
def diff_config(commands, config):
|
def diff_config(commands, config):
|
||||||
config = [str(c).replace("'", '') for c in config.splitlines()]
|
config = [str(c).replace("'", '') for c in config.splitlines()]
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
set system host-name foo
|
set system host-name foo
|
||||||
|
|
||||||
delete interfaces ethernet eth0 address
|
delete interfaces ethernet eth0 address
|
||||||
set interfaces ethernet eth1 address '6.7.8.9/24'
|
set interfaces ethernet eth1 address '6.7.8.9/24'
|
||||||
set interfaces ethernet eth1 description 'test string'
|
set interfaces ethernet eth1 description 'test string'
|
||||||
|
|
|
@ -75,15 +75,17 @@ class TestVyosConfigModule(TestVyosModule):
|
||||||
def test_vyos_config_src(self):
|
def test_vyos_config_src(self):
|
||||||
src = load_fixture('vyos_config_src.cfg')
|
src = load_fixture('vyos_config_src.cfg')
|
||||||
set_module_args(dict(src=src))
|
set_module_args(dict(src=src))
|
||||||
|
candidate = '\n'.join(self.module.format_commands(src.splitlines()))
|
||||||
commands = ['set system host-name foo', 'delete interfaces ethernet eth0 address']
|
commands = ['set system host-name foo', 'delete interfaces ethernet eth0 address']
|
||||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, self.running_config))
|
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config))
|
||||||
self.execute_module(changed=True, commands=commands)
|
self.execute_module(changed=True, commands=commands)
|
||||||
|
|
||||||
def test_vyos_config_src_brackets(self):
|
def test_vyos_config_src_brackets(self):
|
||||||
src = load_fixture('vyos_config_src_brackets.cfg')
|
src = load_fixture('vyos_config_src_brackets.cfg')
|
||||||
set_module_args(dict(src=src))
|
set_module_args(dict(src=src))
|
||||||
|
candidate = '\n'.join(self.module.format_commands(src.splitlines()))
|
||||||
commands = ['set interfaces ethernet eth0 address 10.10.10.10/24', 'set system host-name foo']
|
commands = ['set interfaces ethernet eth0 address 10.10.10.10/24', 'set system host-name foo']
|
||||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, self.running_config))
|
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config))
|
||||||
self.execute_module(changed=True, commands=commands)
|
self.execute_module(changed=True, commands=commands)
|
||||||
|
|
||||||
def test_vyos_config_backup(self):
|
def test_vyos_config_backup(self):
|
||||||
|
|
Loading…
Reference in a new issue