]> git.proxmox.com Git - mirror_frr.git/blobdiff - tools/frr-reload.py
tools: reload handle removal of entire address-family section under BGP
[mirror_frr.git] / tools / frr-reload.py
index 80d2d6a2a321b7742cdad45f37cddbf5a8aff071..1ef6920d0698f25874749c1d45c618304cbda695 100755 (executable)
@@ -346,6 +346,7 @@ end
                                 "debug ",
                                 "dump ",
                                 "enable ",
+                                "frr ",
                                 "hostname ",
                                 "ip ",
                                 "ipv6 ",
@@ -813,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))
@@ -888,11 +897,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 +922,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 +935,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 +1045,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 +1080,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)