fixes bug with junos_config module not properly loading config (#5213)

This fixes two issues.  First, it fixes an issue with the junos_config
module not properly recognizing a file with set commands.  The second
bug would cause the diff_config() function to raise an exception due
to a blank line when splitting the config
This commit is contained in:
Peter Sprygada 2016-10-10 12:37:21 -04:00 committed by Matt Clay
parent 5a8ebf5953
commit 4dc09e19ea

View file

@ -217,18 +217,19 @@ def diff_commands(commands, config):
updates = list()
visited = set()
for item in commands:
if not item.startswith('set') and not item.startswith('delete'):
raise ValueError('line must start with either `set` or `delete`')
for item in commands.split('\n'):
if len(item) > 0:
if not item.startswith('set') and not item.startswith('delete'):
raise ValueError('line must start with either `set` or `delete`')
elif item.startswith('set') and item[4:] not in config:
updates.append(item)
elif item.startswith('set') and item[4:] not in config:
updates.append(item)
elif item.startswith('delete'):
for entry in config:
if entry.startswith(item[7:]) and item not in visited:
updates.append(item)
visited.add(item)
elif item.startswith('delete'):
for entry in config:
if entry.startswith(item[7:]) and item not in visited:
updates.append(item)
visited.add(item)
return updates