From: Daniel Walton Date: Thu, 17 Sep 2015 14:24:21 +0000 (-0700) Subject: 'service quagga reload' should not dump so much output to the log file. X-Git-Tag: frr-2.0-rc1~1253 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=c50aceeeee3944f6c229b08e31e2354d037a3ab1;p=matthieu%2Ffrr.git 'service quagga reload' should not dump so much output to the log file. It should also check that quagga is running before attempting to do any work. Signed-off-by: Daniel Walton Reviewed-by: Donald Sharp Ticket: CM-7486 Reviewed By: Donald Sharp Testing Done: Verified that 'service quagga reload' exits cleanly if quagga is not running. Also verified that it produces a minimal amount of log output by default. The user can enable --debug in /etc/init.d/quagga if they would like to enable debug output. --- diff --git a/tools/quagga-reload.py b/tools/quagga-reload.py index 1744a13365..cc3910760d 100755 --- a/tools/quagga-reload.py +++ b/tools/quagga-reload.py @@ -73,7 +73,7 @@ class Config(object): The internal representation has been marked appropriately by passing it through vtysh with the -m parameter """ - logger.debug('Loading Config object from file %s', filename) + logger.info('Loading Config object from file %s', filename) try: file_output = subprocess.check_output(['vtysh', '-m', '-f', filename]) @@ -98,7 +98,7 @@ class Config(object): The internal representation has been marked appropriately by passing it through vtysh with the -m parameter """ - logger.debug('Loading Config object from vtysh show running') + logger.info('Loading Config object from vtysh show running') try: config_text = subprocess.check_output("vtysh -c 'show run' | tail -n +4 | vtysh -m -f -", shell=True) @@ -441,14 +441,14 @@ if __name__ == '__main__': # For --test log to stdout # For --reload log to /var/log/quagga/quagga-reload.log if args.test: - logging.basicConfig(level=logging.DEBUG, + logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)5s: %(message)s') elif args.reload: if not os.path.isdir('/var/log/quagga/'): os.makedirs('/var/log/quagga/') logging.basicConfig(filename='/var/log/quagga/quagga-reload.log', - level=logging.DEBUG, + level=logging.INFO, format='%(asctime)s %(levelname)5s: %(message)s') # argparse should prevent this from happening but just to be safe... @@ -483,6 +483,17 @@ if __name__ == '__main__': print "'service integrated-vtysh-config' is not configured, this is required for 'service quagga reload'" sys.exit(1) + status_error = int(subprocess.call('service quagga status', shell=True)) + + if status_error: + print "quagga is not running" + sys.exit(1) + + if args.debug: + logger.setLevel(logging.DEBUG) + + logger.info('Called via "%s"', str(args)) + # Create a Config object from the config generated by newconf newconf = Config() newconf.load_from_file(args.filename) @@ -528,8 +539,7 @@ if __name__ == '__main__': elif args.reload: - logger.debug('Called via "%s"', str(args)) - logger.info('New Quagga Config\n%s', newconf.get_lines()) + logger.debug('New Quagga Config\n%s', newconf.get_lines()) # This looks a little odd but we have to do this twice...here is why # If the user had this running bgp config: @@ -556,7 +566,7 @@ if __name__ == '__main__': for x in range(2): running = Config() running.load_from_show_running() - logger.info('Running Quagga Config (Pass #%d)\n%s', x, running.get_lines()) + logger.debug('Running Quagga Config (Pass #%d)\n%s', x, running.get_lines()) (lines_to_add, lines_to_del, restart_bgp) = compare_context_objects(newconf, running) @@ -583,9 +593,6 @@ if __name__ == '__main__': # quagga(config-if)# while True: - - logger.info(cmd) - try: _ = subprocess.check_output(cmd) @@ -595,7 +602,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 - logger.info('%s failed', str(cmd)) + logger.warning('Failed to execute %s', ' '.join(cmd)) last_arg = cmd[-1].split(' ') if len(last_arg) <= 2: @@ -605,7 +612,7 @@ if __name__ == '__main__': new_last_arg = last_arg[0:-1] cmd[-1] = ' '.join(new_last_arg) else: - logger.info('%s worked', str(cmd)) + logger.info('Executed "%s"', ' '.join(cmd)) break @@ -616,7 +623,7 @@ if __name__ == '__main__': continue cmd = line_to_vtysh_conft(ctx_keys, line, False) - logger.debug(cmd) + logger.info(' '.join(cmd)) subprocess.call(cmd) if restart_bgp: