From 5e82468eb77c03c3929a19508b103889b6cb06b6 Mon Sep 17 00:00:00 2001 From: Brendan Tobolaski Date: Sun, 19 Apr 2020 13:51:59 -0500 Subject: [PATCH 1/3] Make empty diffs work Without these, empty diffs would result in an error instead of empty diffs --- napalm_ruckus_fastiron/FastIron.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/napalm_ruckus_fastiron/FastIron.py b/napalm_ruckus_fastiron/FastIron.py index 26942d0..ef20c6b 100644 --- a/napalm_ruckus_fastiron/FastIron.py +++ b/napalm_ruckus_fastiron/FastIron.py @@ -491,6 +491,7 @@ def __creates_config_block(list_1): @staticmethod def __compare_blocks(cb_1, config_blocks_2, cmd, symbol): temp_list = list() + stat = False for cb_2 in config_blocks_2: # grabs a single config block if cmd == cb_2[0]: # checks cmd not found stat = True @@ -510,6 +511,7 @@ def __comparing_list(list_1, list_2, symbol): for cb_1 in config_blocks_1: # Grabs a single config block is_found = False + temp_list = list() if cb_1 not in config_blocks_2: # checks if config block already exisit cmd = cb_1[0] # grabs first cmd of config block From d9ddf2492722f9f2391a9f27cc33edc571534b0c Mon Sep 17 00:00:00 2001 From: Brendan Tobolaski Date: Sun, 19 Apr 2020 13:53:57 -0500 Subject: [PATCH 2/3] Switch diff direction Previous if you added something to the replace candidate, it would appear in the diff output with a - prefix instead of a plus --- napalm_ruckus_fastiron/FastIron.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/napalm_ruckus_fastiron/FastIron.py b/napalm_ruckus_fastiron/FastIron.py index ef20c6b..72fd809 100644 --- a/napalm_ruckus_fastiron/FastIron.py +++ b/napalm_ruckus_fastiron/FastIron.py @@ -659,8 +659,8 @@ def compare_config(self): # optimize implementatio else: return -1 # No configuration was found - diff_1 = FastIronDriver.__comparing_list(rc, stored_conf, "+") - diff_2 = FastIronDriver.__comparing_list(stored_conf, rc, "-") + diff_1 = FastIronDriver.__comparing_list(rc, stored_conf, "-") + diff_2 = FastIronDriver.__comparing_list(stored_conf, rc, "+") str_diff1 = FastIronDriver.__compare_away(diff_1, diff_2) str_diff2 = FastIronDriver.__compare_vice(diff_2, diff_1) @@ -683,9 +683,9 @@ def commit_config(self): for sentence in my_temp: - if sentence[0] == '-': + if sentence[0] == '+': sentence = sentence[1:len(sentence)] - elif sentence[0] == '+': + elif sentence[0] == '-': sentence = 'no' + sentence[1:len(sentence)] replace_list.append(sentence) From 71847848f70d724b2fb436613cdef6de2c13aba2 Mon Sep 17 00:00:00 2001 From: Brendan Tobolaski Date: Sun, 19 Apr 2020 13:59:00 -0500 Subject: [PATCH 3/3] Strip trailing whitespace when comparing blocks My text editor removes trailing whitespace automatically and it appears that the running config has trailing whitespace in it. This resulted in the diff being greater than the actual changes. --- napalm_ruckus_fastiron/FastIron.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/napalm_ruckus_fastiron/FastIron.py b/napalm_ruckus_fastiron/FastIron.py index 72fd809..c7d26e2 100644 --- a/napalm_ruckus_fastiron/FastIron.py +++ b/napalm_ruckus_fastiron/FastIron.py @@ -21,7 +21,7 @@ from netmiko import ConnectHandler import socket import sys -# import re +import re # local modules # import napalm.base.exceptions @@ -488,17 +488,23 @@ def __creates_config_block(list_1): return config_block + @staticmethod + def __strip_trailing_whitespace(cmd): + strip = re.compile(r"(\s*([^\s]*[\s]*[^\s+]+)+)\s*$") + return strip.match(cmd).group(1) + @staticmethod def __compare_blocks(cb_1, config_blocks_2, cmd, symbol): temp_list = list() stat = False for cb_2 in config_blocks_2: # grabs a single config block - if cmd == cb_2[0]: # checks cmd not found + if FastIronDriver.__strip_trailing_whitespace(cmd) == FastIronDriver.__strip_trailing_whitespace(cb_2[0]): # checks cmd not found stat = True for single_cmd in cb_1: # iterates through cmd of config block - if single_cmd == cmd: # if this is first command add as base + if FastIronDriver.__strip_trailing_whitespace(single_cmd) == FastIronDriver.__strip_trailing_whitespace(cmd): # if this is first command add as base temp_list.append(single_cmd) # add to list with no changes - elif single_cmd not in cb_2: + elif FastIronDriver.__strip_trailing_whitespace(single_cmd) not in list(map(FastIronDriver.__strip_trailing_whitespace, cb_2)): + print(list(map(FastIronDriver.__strip_trailing_whitespace, cb_2))) temp_list.append(symbol + " " + single_cmd) return temp_list, stat