summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Sprygada <privateip@users.noreply.github.com>2016-10-10 12:37:21 -0400
committerGitHub <noreply@github.com>2016-10-10 12:37:21 -0400
commite6c039872f553c6cca9e6fc77716f2dda3670215 (patch)
treea425719c74a17fc515815eb1de60bfa94f7f15aa
parentf5c204005f5463f91eac0e8a800a453fd027f461 (diff)
downloadansible-modules-core-e6c039872f553c6cca9e6fc77716f2dda3670215.tar.gz
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
-rw-r--r--network/junos/junos_config.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/network/junos/junos_config.py b/network/junos/junos_config.py
index 80cfc39a..5e2ead6a 100644
--- a/network/junos/junos_config.py
+++ b/network/junos/junos_config.py
@@ -214,18 +214,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`')
-
- 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)
+ 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('delete'):
+ for entry in config:
+ if entry.startswith(item[7:]) and item not in visited:
+ updates.append(item)
+ visited.add(item)
return updates