"debug ",
"dump ",
"enable ",
+ "frr ",
"hostname ",
"ip ",
"ipv6 ",
# 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
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:
# Create a Config object from the config generated by newconf
newconf = Config()
newconf.load_from_file(args.filename)
+ reload_ok = True
if args.test:
# '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:
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)