Skip to content

Commit

Permalink
Merge pull request #624 from mwhudson/refactor-exiting
Browse files Browse the repository at this point in the history
refactor how subiquity is exited after install
  • Loading branch information
mwhudson committed Jan 23, 2020
2 parents a18d6b6 + 963cbaa commit ac40a37
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
23 changes: 8 additions & 15 deletions subiquity/controllers/installprogress.py
Expand Up @@ -295,9 +295,13 @@ async def install(self, context):
except Exception:
self.curtin_error()

await self.reboot_clicked.wait()

self.reboot()
async def move_on(self):
await asyncio.wait(
{self.reboot_clicked.wait(), self.install_task})
self.app.reboot_on_exit = True
if not self.opts.dry_run and platform.machine() == 's390x':
run_command(["chreipl", "/target/boot"])
self.app.next_screen()

async def drain_curtin_events(self, context):
waited = 0.0
Expand Down Expand Up @@ -403,18 +407,6 @@ async def copy_logs_to_target(self, context):
except Exception:
log.exception("saving journal failed")

def reboot(self):
if self.opts.dry_run:
log.debug('dry-run enabled, skipping reboot, quitting instead')
self.app.exit()
else:
# TODO Possibly run this earlier, to show a warning; or
# switch to shutdown if chreipl fails
if platform.machine() == 's390x':
run_command(["chreipl", "/target/boot"])
# Should probably run curtin -c $CONFIG unmount -t TARGET first.
run_command(["/sbin/reboot"])

async def _click_reboot(self):
if self.uu_running:
await self.stop_uu()
Expand All @@ -435,6 +427,7 @@ def start_ui(self):
self.progress_view.title = (
_('An error occurred during installation'))
self.ui.set_body(self.progress_view)
schedule_task(self.move_on())


uu_apt_conf = """\
Expand Down
9 changes: 9 additions & 0 deletions subiquity/core.py
Expand Up @@ -26,6 +26,7 @@
schedule_task,
)
from subiquitycore.core import Application
from subiquitycore.utils import run_command

from subiquity.controllers.error import (
ErrorReportKind,
Expand Down Expand Up @@ -114,6 +115,14 @@ def __init__(self, opts, block_log_dir):
self.note_data_for_apport("SnapUpdated", str(self.updated))
self.note_data_for_apport("UsingAnswers", str(bool(self.answers)))

self.reboot_on_exit = False

def exit(self):
if self.reboot_on_exit and not self.opts.dry_run:
run_command(["/sbin/reboot"])
else:
super().exit()

def run(self):
try:
super().run()
Expand Down
8 changes: 6 additions & 2 deletions subiquitycore/core.py
Expand Up @@ -440,9 +440,13 @@ def _move_screen(self, increment):
if old is not None:
old.context.exit("completed")
old.end_ui()
cur_index = self.controllers.index
while True:
self.controllers.index += increment
if self.controllers.out_of_bounds():
if self.controllers.index < 0:
self.controllers.index = cur_index
return
if self.controllers.index >= len(self.controllers.instances):
self.exit()
new = self.controllers.cur
try:
Expand Down Expand Up @@ -480,7 +484,7 @@ def exit(self):
state_path = os.path.join(self.state_dir, 'last-screen')
if os.path.exists(state_path):
os.unlink(state_path)
raise urwid.ExitMainLoop()
self.aio_loop.stop()

def run_scripts(self, scripts):
# run_scripts runs (or rather arranges to run, it's all async)
Expand Down

0 comments on commit ac40a37

Please sign in to comment.