From 3cf514436f2830ca53eb1f65e7244b7b9cb96ac5 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Fri, 19 Feb 2021 15:07:04 +1300 Subject: [PATCH] do not stop listening to curtin events the instant the curtin process exits --- subiquity/journald.py | 14 ++++++++++++++ subiquity/server/controllers/install.py | 25 ++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/subiquity/journald.py b/subiquity/journald.py index 872d0da8..cf21e2b0 100644 --- a/subiquity/journald.py +++ b/subiquity/journald.py @@ -15,6 +15,8 @@ from systemd import journal +from subiquitycore import contextlib38 + def journald_listen(loop, identifiers, callback, seek=False): reader = journal.Reader() @@ -33,3 +35,15 @@ def journald_listen(loop, identifiers, callback, seek=False): callback(event) loop.add_reader(reader.fileno(), watch) return reader.fileno() + + +@contextlib38.contextmanager +def journald_subscriptions(loop, ids_callbacks): + fds = set() + for id, callback in ids_callbacks: + fds.add(journald_listen(loop, [id], callback)) + try: + yield + finally: + for fd in fds: + loop.remove_reader(fd) diff --git a/subiquity/server/controllers/install.py b/subiquity/server/controllers/install.py index c9ae2762..c8a028ec 100644 --- a/subiquity/server/controllers/install.py +++ b/subiquity/server/controllers/install.py @@ -46,7 +46,7 @@ from subiquity.server.controller import ( from subiquity.common.types import ( ApplicationState, ) -from subiquity.journald import journald_listen +from subiquity.journald import journald_subscriptions log = logging.getLogger("subiquity.server.controllers.install") @@ -188,23 +188,11 @@ class InstallController(SubiquityController): log.debug('curtin_install') self.curtin_event_contexts[''] = context - loop = self.app.aio_loop - - fds = [ - journald_listen(loop, [self.app.log_syslog_id], self.log_event), - journald_listen(loop, [self._event_syslog_id], self.curtin_event), - ] - curtin_cmd = self._get_curtin_command() log.debug('curtin install cmd: {}'.format(curtin_cmd)) - try: - cp = await arun_command( - self.logged_command(curtin_cmd), check=True) - finally: - for fd in fds: - loop.remove_reader(fd) + cp = await arun_command(self.logged_command(curtin_cmd), check=True) log.debug('curtin_install completed: %s', cp.returncode) @@ -228,15 +216,18 @@ class InstallController(SubiquityController): await self.unmount_target( context=context, target=self.model.target) - await self.curtin_install(context=context) + with journald_subscriptions( + self.app.aio_loop, + [(self.app.log_syslog_id, self.log_event), + (self._event_syslog_id, self.curtin_event)]): + await self.curtin_install(context=context) + await self.drain_curtin_events(context=context) self.app.update_state(ApplicationState.POST_WAIT) await asyncio.wait( {e.wait() for e in self.model.postinstall_events}) - await self.drain_curtin_events(context=context) - self.app.update_state(ApplicationState.POST_RUNNING) await self.postinstall(context=context)