Merge pull request #898 from mwhudson/lp-1912957

do not stop listening to curtin events when the curtin process exits
This commit is contained in:
Michael Hudson-Doyle 2021-02-22 11:52:04 +13:00 committed by GitHub
commit a76581cd2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 17 deletions

View File

@ -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)

View File

@ -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)