From 825be4c27bc165e68ebcb1de8d1beebdbd8c82e9 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 17 May 2017 00:14:37 +0000 Subject: tools: frr-reload.py should exit non-zero when "set src x.x.x.x" fails Signed-off-by: Daniel Walton Reviewed-by: Donald Sharp --- tools/frr-reload.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 80d2d6a2a..0e71eaa04 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -346,6 +346,7 @@ end "debug ", "dump ", "enable ", + "frr ", "hostname ", "ip ", "ipv6 ", @@ -888,11 +889,15 @@ if __name__ == '__main__': # Verify the new config file is valid if not os.path.isfile(args.filename): - print "Filename %s does not exist" % args.filename + msg = "Filename %s does not exist" % args.filename + print msg + log.error(msg) sys.exit(1) if not os.path.getsize(args.filename): - print "Filename %s is an empty file" % args.filename + msg = "Filename %s is an empty file" % args.filename + print msg + log.error(msg) sys.exit(1) # Verify that 'service integrated-vtysh-config' is configured @@ -909,7 +914,9 @@ if __name__ == '__main__': break if not service_integrated_vtysh_config: - print "'service integrated-vtysh-config' is not configured, this is required for 'service frr reload'" + msg = "'service integrated-vtysh-config' is not configured, this is required for 'service frr reload'" + print msg + log.error(msg) sys.exit(1) if args.debug: @@ -920,6 +927,7 @@ if __name__ == '__main__': # Create a Config object from the config generated by newconf newconf = Config() newconf.load_from_file(args.filename) + reload_ok = True if args.test: @@ -1029,7 +1037,7 @@ if __name__ == '__main__': # 'no ip ospf authentication message-digest 1.1.1.1' in # our example above # - Split that last entry by whitespace and drop the last word - log.warning('Failed to execute %s', ' '.join(cmd)) + log.info('Failed to execute %s', ' '.join(cmd)) last_arg = cmd[-1].split(' ') if len(last_arg) <= 2: @@ -1064,9 +1072,25 @@ if __name__ == '__main__': with open(filename, 'w') as fh: for line in lines_to_configure: fh.write(line + '\n') - subprocess.call(['/usr/bin/vtysh', '-f', filename]) + + output = subprocess.check_output(['/usr/bin/vtysh', '-f', filename]) + + # exit non-zero if we see these errors + for x in ('BGP instance name and AS number mismatch', + 'BGP instance is already running', + '% not a local address'): + for line in output.splitlines(): + if x in line: + msg = "ERROR: %s" % x + log.error(msg) + print msg + reload_ok = False + os.unlink(filename) # Make these changes persistent if args.overwrite or args.filename != '/etc/frr/frr.conf': subprocess.call(['/usr/bin/vtysh', '-c', 'write']) + + if not reload_ok: + sys.exit(1) -- cgit v1.2.3 From afa2e8e1870eab4578e19c80cfd23bb443d1adbe Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 17 May 2017 00:16:09 +0000 Subject: tools: reload handle removal of entire address-family section under BGP Signed-off-by: Daniel Walton When an entire address-family section is removed from under BGP, we cannot just issue 'no address-family foo bar' as address-family line doesn't support 'no'. We have to delete the individual lines under the address-family. --- tools/frr-reload.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tools') diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 0e71eaa04..1ef6920d0 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -814,6 +814,14 @@ def compare_context_objects(newconf, running): elif "router bgp" in running_ctx_keys[0] and len(running_ctx_keys) > 1 and delete_bgpd: continue + elif ("router bgp" in running_ctx_keys[0] and + len(running_ctx_keys) > 1 and + running_ctx_keys[1].startswith('address-family')): + # There's no 'no address-family' support and so we have to + # delete each line individually again + for line in running_ctx.lines: + lines_to_del.append((running_ctx_keys, line)) + # Non-global context elif running_ctx_keys and not any("address-family" in key for key in running_ctx_keys): lines_to_del.append((running_ctx_keys, None)) -- cgit v1.2.3 From 970c956816599fe3d58bc45ca3a18b9542467337 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 17 May 2017 00:18:33 +0000 Subject: tools: frr-reload removes "ipv6 nd ra-interval" and "no ipv6 nd supp" Signed-off-by: Daniel Walton --- tools/frr-reload.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 1ef6920d0..f6cb6d991 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -1009,7 +1009,20 @@ if __name__ == '__main__': (lines_to_add, lines_to_del) = compare_context_objects(newconf, running) - if lines_to_del: + # Only do deletes on the first pass. The reason being if we + # configure a bgp neighbor via "neighbor swp1 interface" frr + # will automatically add: + # + # interface swp1 + # ipv6 nd ra-interval 10 + # no ipv6 nd suppress-ra + # ! + # + # but those lines aren't in the config we are reloading against so + # on the 2nd pass they will show up in lines_to_del. This could + # apply to other scenarios as well where configuring FOO adds BAR + # to the config. + if lines_to_del and x == 0: for (ctx_keys, line) in lines_to_del: if line == '!': -- cgit v1.2.3 From 619c4e3acf2077dc16adf6ebd48adaec9365c623 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 17 May 2017 00:22:00 +0000 Subject: frr-reload.py fails on "no debug ospf6 message unknown" Signed-off-by: Daniel Walton --- tools/frr-reload.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/frr-reload.py b/tools/frr-reload.py index f6cb6d991..090937ed2 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -351,6 +351,7 @@ end "ip ", "ipv6 ", "log ", + "no ", "password ", "ptm-enable", "router-id ", -- cgit v1.2.3 From ec3fd9577411a4555a9988f8187e2d1598cd2b00 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 17 May 2017 00:23:38 +0000 Subject: tools: frr-reload.py VtyshMarkException needs to include "vtysh -m" output Signed-off-by: Daniel Walton --- tools/frr-reload.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 090937ed2..11e0bdc68 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -109,9 +109,12 @@ class Config(object): log.info('Loading Config object from file %s', filename) try: - file_output = subprocess.check_output(['/usr/bin/vtysh', '-m', '-f', filename]) + file_output = subprocess.check_output(['/usr/bin/vtysh', '-m', '-f', filename], + stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - raise VtyshMarkException(str(e)) + ve = VtyshMarkException(e) + ve.output = e.output + raise ve for line in file_output.split('\n'): line = line.strip() @@ -134,9 +137,11 @@ class Config(object): try: config_text = subprocess.check_output( "/usr/bin/vtysh -c 'show run' | /usr/bin/tail -n +4 | /usr/bin/vtysh -m -f -", - shell=True) + shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - raise VtyshMarkException(str(e)) + ve = VtyshMarkException(e) + ve.output = e.output + raise ve for line in config_text.split('\n'): line = line.strip() -- cgit v1.2.3 From e80c8c5531635e9df550f11b466f35644668f9f5 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 17 May 2017 00:25:28 +0000 Subject: tools: Allow frr-reload.py to know about agentx Signed-off-by: Daniel Walton Signed-off-by: Donald Sharp --- tools/frr-reload.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 11e0bdc68..a9151e3e7 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -347,6 +347,7 @@ end # the keywords that we know are single line contexts. bgp in this case # is not the main router bgp block, but enabling multi-instance oneline_ctx_keywords = ("access-list ", + "agentx", "bgp ", "debug ", "dump ", -- cgit v1.2.3