Move the recursive flushing to the log module.
This commit is contained in:
parent
2c1334460d
commit
64f443aaf9
@ -16,10 +16,10 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from logging import StreamHandler
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from cloudinit import log as logging
|
||||||
from cloudinit import util
|
from cloudinit import util
|
||||||
|
|
||||||
REBOOT_FILE = "/var/run/reboot-required"
|
REBOOT_FILE = "/var/run/reboot-required"
|
||||||
@ -33,17 +33,6 @@ def _multi_cfg_bool_get(cfg, *keys):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _flush_loggers(root):
|
|
||||||
for h in root.handlers:
|
|
||||||
if isinstance(h, (StreamHandler)):
|
|
||||||
try:
|
|
||||||
h.flush()
|
|
||||||
except IOError:
|
|
||||||
pass
|
|
||||||
if root.parent:
|
|
||||||
_flush_loggers(root.parent)
|
|
||||||
|
|
||||||
|
|
||||||
def _fire_reboot(log, wait_attempts=6, initial_sleep=1, backoff=2):
|
def _fire_reboot(log, wait_attempts=6, initial_sleep=1, backoff=2):
|
||||||
util.subp(REBOOT_CMD)
|
util.subp(REBOOT_CMD)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
@ -98,7 +87,7 @@ def handle(_name, cfg, cloud, log, _args):
|
|||||||
try:
|
try:
|
||||||
log.warn("Rebooting after upgrade or install per %s", REBOOT_FILE)
|
log.warn("Rebooting after upgrade or install per %s", REBOOT_FILE)
|
||||||
# Flush the above warning + anything else out...
|
# Flush the above warning + anything else out...
|
||||||
_flush_loggers(log)
|
logging.flushLoggers(log)
|
||||||
_fire_reboot(log)
|
_fire_reboot(log)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
util.logexc(log, "Requested reboot did not happen!")
|
util.logexc(log, "Requested reboot did not happen!")
|
||||||
|
@ -53,6 +53,18 @@ def setupBasicLogging():
|
|||||||
root.setLevel(DEBUG)
|
root.setLevel(DEBUG)
|
||||||
|
|
||||||
|
|
||||||
|
def flushLoggers(root):
|
||||||
|
if not root:
|
||||||
|
return
|
||||||
|
for h in root.handlers:
|
||||||
|
if isinstance(h, (logging.StreamHandler)):
|
||||||
|
try:
|
||||||
|
h.flush()
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
flushLoggers(root.parent)
|
||||||
|
|
||||||
|
|
||||||
def setupLogging(cfg=None):
|
def setupLogging(cfg=None):
|
||||||
# See if the config provides any logging conf...
|
# See if the config provides any logging conf...
|
||||||
if not cfg:
|
if not cfg:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user