vyos_config bug fix #66110 (#66122)

Signed-off-by: rohitthakur2590 <rohitthakur2590@outlook.com>
This commit is contained in:
Rohit 2020-01-03 17:35:37 +05:30 committed by GitHub
parent 5493ea590c
commit 2f996fc6e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 2 deletions

View file

@ -208,7 +208,13 @@ def get_candidate(module):
def format_commands(commands):
return [line for line in commands if len(line.strip()) > 0]
"""
This function format the input commands and removes the prepend white spaces
for command lines having 'set' or 'delete' and it skips empty lines.
:param commands:
:return: list of commands
"""
return [line.strip() if line.split()[0] in ('set', 'delete') else line for line in commands if len(line.strip()) > 0]
def diff_config(commands, config):

View file

@ -0,0 +1,3 @@
set service lldp
set protocols static

View file

@ -25,6 +25,30 @@
that:
- "result.changed == false"
- name: Configuring when commands starts with whitespaces
vyos_config:
src: "{{ role_path }}/tests/cli/config.cfg"
register: result
- assert:
that:
- "result.changed == true"
- '"set service lldp" in result.commands'
- '"set protocols static" in result.commands'
- name: Delete description
vyos_config:
lines:
- delete service lldp
- delete protocols static
register: result
- assert:
that:
- "result.changed == true"
- '"delete service lldp" in result.commands'
- '"delete protocols static" in result.commands'
- name: teardown
vyos_config:
lines: set system host-name {{ inventory_hostname_short }}

View file

@ -2,5 +2,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'
set interfaces ethernet eth1 description 'test string'
set interfaces ethernet eth1 disable