allow empty line in src template file (#42493)

pull/42613/head
hitsumabushi 6 years ago committed by Ganesh Nalawade
parent 940d4a0e89
commit cf7a42b4f4

@ -146,12 +146,17 @@ CONFIG_FILTERS = [
def get_candidate(module):
contents = module.params['src'] or module.params['lines']
if module.params['lines']:
contents = '\n'.join(contents)
if module.params['src']:
contents = format_commands(contents.splitlines())
contents = '\n'.join(contents)
return contents
def format_commands(commands):
return [line for line in commands if len(line.strip()) > 0]
def diff_config(commands, config):
config = [str(c).replace("'", '') for c in config.splitlines()]

@ -1,4 +1,5 @@
set system host-name foo
delete interfaces ethernet eth0 address
set interfaces ethernet eth1 address '6.7.8.9/24'
set interfaces ethernet eth1 description 'test string'

@ -75,15 +75,17 @@ class TestVyosConfigModule(TestVyosModule):
def test_vyos_config_src(self):
src = load_fixture('vyos_config_src.cfg')
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']
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)
def test_vyos_config_src_brackets(self):
src = load_fixture('vyos_config_src_brackets.cfg')
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']
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)
def test_vyos_config_backup(self):

Loading…
Cancel
Save