aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve McIntyre <steve.mcintyre@linaro.org>2018-01-31 17:07:39 +0000
committerSteve McIntyre <steve.mcintyre@linaro.org>2018-01-31 17:10:07 +0000
commit6794088d9f33e585000539f3bbff81ff6337b035 (patch)
tree7d72efb3c85217533fee41aa52849371bdbee30f
parentbc06c935b46da05cd12ce2ebbbbc067071a36e41 (diff)
Shuffle startup order in main process
Initialise the logging code before talking to the database, so we can log things in the database code. Desired so we can see migrations being logged as they happen. Change-Id: I7cd9a01f8390a64669ac5e2efa516401558a48ea
-rwxr-xr-xvland.py50
1 files changed, 21 insertions, 29 deletions
diff --git a/vland.py b/vland.py
index 354c4be..25c854b 100755
--- a/vland.py
+++ b/vland.py
@@ -1,6 +1,6 @@
#! /usr/bin/python
-# Copyright 2014-2016 Linaro Limited
+# Copyright 2014-2018 Linaro Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -57,18 +57,33 @@ if state.config.visualisation.enabled:
util = VlanUtil()
-print 'Connecting to DB...'
+loglevel = util.set_logging_level(state.config.logging.level)
+
+# Should we log to stderr?
+if state.config.logging.filename is None:
+ logging.basicConfig(level = loglevel,
+ format = '%(asctime)s %(levelname)-8s %(message)s')
+else:
+ print "Logging to %s" % state.config.logging.filename
+ logging.basicConfig(level = loglevel,
+ format = '%(asctime)s %(levelname)-8s MAIN %(message)s',
+ datefmt = '%Y-%m-%d %H:%M:%S %Z',
+ filename = state.config.logging.filename,
+ filemode = 'a')
+
+logging.info('%s main daemon starting up', state.banner)
+logging.info('Connecting to DB...')
state.db = VlanDB(db_name=state.config.database.dbname,
username=state.config.database.username, readonly=False)
switches = state.db.all_switches()
-print ' DB knows about %d switches' % len(switches)
+logging.info('DB knows about %d switches', len(switches))
ports = state.db.all_ports()
-print ' DB knows about %d ports' % len(ports)
+logging.info('DB knows about %d ports', len(ports))
vlans = state.db.all_vlans()
-print ' DB knows about %d vlans' % len(vlans)
+logging.info('DB knows about %d vlans', len(vlans))
trunks = state.db.all_trunks()
-print ' DB knows about %d trunks' % len(trunks)
+logging.info('DB knows about %d trunks', len(trunks))
# Initial startup sanity chacking
@@ -90,29 +105,6 @@ if len(switches) != len(state.config.switches):
print 'for each of your switches may help!'
print
-loglevel = util.set_logging_level(state.config.logging.level)
-
-# Should we log to stderr?
-if state.config.logging.filename is None:
- logging.basicConfig(level = loglevel,
- format = '%(asctime)s %(levelname)-8s %(message)s')
-else:
- print "Logging to %s" % state.config.logging.filename
- logging.basicConfig(level = loglevel,
- format = '%(asctime)s %(levelname)-8s MAIN %(message)s',
- datefmt = '%Y-%m-%d %H:%M:%S %Z',
- filename = state.config.logging.filename,
- filemode = 'a')
- logging.info('%s main daemon starting up', state.banner)
- switches = state.db.all_switches()
- logging.info('DB knows about %d switches', len(switches))
- ports = state.db.all_ports()
- logging.info('DB knows about %d ports', len(ports))
- vlans = state.db.all_vlans()
- logging.info('DB knows about %d vlans', len(vlans))
- trunks = state.db.all_trunks()
- logging.info('DB knows about %d trunks', len(trunks))
-
# Now we're done starting up, let the visualisation code talk to the database
if state.config.visualisation.enabled:
logging.info('sending db_ok signal')