def _handle_exception(self, tag, exc): if app.showing_error: return app.showing_error = True track_exception(exc.args[0]) app.ui.show_exception_message(exc) EventLoop.remove_alarms()
async def shutdown_watcher(): app.log.info('Watching for shutdown') try: await Shutdown.wait() except asyncio.CancelledError: pass app.log.info('Shutting down') if app.headless: utils.warning('Shutting down') else: app.ui.show_shutdown_message() try: if app.juju.authenticated: app.log.info('Disconnecting model') await app.juju.client.disconnect() app.log.info('Disconnected') if not app.headless: EventLoop.remove_alarms() for task in asyncio.Task.all_tasks(app.loop): # cancel all other tasks if getattr(task, '_coro', None) is not shutdown_watcher: task.cancel() app.loop.stop() except Exception: app.log.exception('Error in cleanup code') raise
def finish(self, step_model, step_widget, done=False): """ handles processing step with input data Arguments: step_model: step_model returned from widget done: if True continues on to the summary view """ if done: EventLoop.remove_alarms() return controllers.use('summary').render(self.results) # Set next button focus here now that the step is complete. self.view.steps.popleft() if len(self.view.steps) > 0: next_step = self.view.steps[0] next_step.generate_additional_input() self.view.step_pile.focus_position = self.view.step_pile.focus_position + 1 # noqa else: app.log.debug("End of step list setting the view " "summary button in focus.") index = self.view.current_summary_button_index app.log.debug("Next focused button: {}".format(index)) self.view.step_pile.focus_position = index future = async .submit( partial(common.do_step, step_model, step_widget, app.ui.set_footer, gui=True), partial(self.__handle_exception, 'E002')) future.add_done_callback(self.get_result)
def finish(self, step_model, step_widget, done=False): """ handles processing step with input data Arguments: step_model: step_model returned from widget done: if True continues on to the summary view """ if done: EventLoop.remove_alarms() return controllers.use('summary').render(self.results) # Set next button focus here now that the step is complete. self.view.steps.popleft() if len(self.view.steps) > 0: next_step = self.view.steps[0] next_step.generate_additional_input() self.view.step_pile.focus_position = self.view.step_pile.focus_position + 1 # noqa else: app.log.debug( "End of step list setting the view " "summary button in focus.") index = self.view.current_summary_button_index app.log.debug("Next focused button: {}".format(index)) self.view.step_pile.focus_position = index future = async.submit(partial(common.do_step, step_model, step_widget, app.ui.set_footer, gui=True), partial(self.__handle_exception, 'E002')) future.add_done_callback(self.get_result)
async def shutdown_watcher(): app.log.info('Watching for shutdown') try: try: await Shutdown.wait() except asyncio.CancelledError: pass app.log.info('Shutting down') if app.headless: utils.warning('Shutting down') # Store application configuration state await app.save() if app.juju.authenticated: app.log.info('Disconnecting model') await app.juju.client.disconnect() app.log.info('Disconnected') if not app.headless: EventLoop.remove_alarms() for task in asyncio.Task.all_tasks(app.loop): # cancel all other tasks coro = getattr(task, '_coro', None) cr_code = getattr(coro, 'cr_code', None) if cr_code is not shutdown_watcher.__code__: app.log.debug('Cancelling pending task: {}'.format(task)) task.cancel() await asyncio.sleep(0.1) # give tasks a chance to see the cancel except Exception as e: app.log.exception('Error in cleanup code: {}'.format(e)) app.loop.stop()
def show_exception_message(self, ex): errmsg = str(ex) errmsg += ("\n\n" "Review log messages at ~/.cache/conjure-up/conjure-up.log " "If appropriate, please submit a bug here: " "https://github.com/conjure-up/conjure-up/issues/new") async .shutdown() EventLoop.remove_alarms() self.frame.body = ErrorView(errmsg) app.log.debug("Showing dialog for exception: {}".format(ex))
def show_exception_message(self, ex): _cache_dir = Path(app.argv.cache_dir) / 'conjure-up.log' errmsg = str(ex) errmsg += ("\n\n Review log messages at {} " "If appropriate, please submit a bug here: " "https://github.com/conjure-up/conjure-up/issues/new". format(_cache_dir)) async .shutdown() EventLoop.remove_alarms() self.frame.body = ErrorView(errmsg) # ensure error is shown, even if exception was inside urwid EventLoop.redraw_screen() app.log.debug("Showing dialog for exception: {}".format(ex))
def __handle_bootstrap_done(self, future): app.log.debug("handle bootstrap") result = future.result() if result.returncode < 0: # bootstrap killed via user signal, we're quitting return if result.returncode > 0: err = result.stderr.read().decode() app.log.error(err) return self.__handle_exception(Exception("error ")) utils.pollinate(app.session_id, 'J004') EventLoop.remove_alarms() app.ui.set_footer('Bootstrap complete...') self.__post_bootstrap_exec()
def __handle_bootstrap_done(self, future): app.log.debug("handle bootstrap") result = future.result() if result.returncode < 0: # bootstrap killed via user signal, we're quitting return if result.returncode > 0: err = result.stderr.read().decode() app.log.error(err) return self.__handle_exception(Exception("error ")) utils.pollinate(app.session_id, 'J004') EventLoop.remove_alarms() app.ui.set_footer('Bootstrap complete...') juju.switch_controller(app.current_controller) self.__post_bootstrap_exec()
def finish(self, needs_lxd_setup=False, lxdnetwork=None, back=False): """ Processes the new LXD setup and loads the controller to finish bootstrapping the model. Arguments: back: if true loads previous controller needs_lxd_setup: if true prompt user to run lxd init """ if back: return controllers.use('clouds').render() if needs_lxd_setup: EventLoop.remove_alarms() EventLoop.exit(1) if lxdnetwork is None: return app.ui.show_exception_message( Exception("Unable to configure LXD network bridge.")) formatted_network = self.__format_input(lxdnetwork) app.log.debug("LXD Config {}".format(formatted_network)) out = self.__format_conf(formatted_network) with NamedTemporaryFile(mode="w", encoding="utf-8", delete=False) as tempf: app.log.debug("Saving LXD config to {}".format(tempf.name)) utils.spew(tempf.name, out) sh = utils.run('sudo mv {} /etc/default/lxd-bridge'.format( tempf.name), shell=True) if sh.returncode > 0: return app.ui.show_exception_message( Exception("Problem saving config: {}".format( sh.stderr.decode('utf8')))) app.log.debug("Restarting lxd-bridge") utils.run("sudo systemctl restart lxd-bridge.service", shell=True) utils.pollinate(app.session_id, 'L002') controllers.use('newcloud').render( cloud='localhost', bootstrap=True)
def finish(self, needs_lxd_setup=False, lxdnetwork=None, back=False): """ Processes the new LXD setup and loads the controller to finish bootstrapping the model. Arguments: back: if true loads previous controller needs_lxd_setup: if true prompt user to run lxd init """ if back: return controllers.use('clouds').render() if needs_lxd_setup: EventLoop.remove_alarms() EventLoop.exit(1) if lxdnetwork is None: return app.ui.show_exception_message( Exception("Unable to configure LXD network bridge.")) formatted_network = self.__format_input(lxdnetwork) app.log.debug("LXD Config {}".format(formatted_network)) out = self.__format_conf(formatted_network) with NamedTemporaryFile(mode="w", encoding="utf-8", delete=False) as tempf: app.log.debug("Saving LXD config to {}".format(tempf.name)) utils.spew(tempf.name, out) sh = run('sudo mv {} /etc/default/lxd-bridge'.format( tempf.name), shell=True) if sh.returncode > 0: return app.ui.show_exception_message( Exception("Problem saving config: {}".format( sh.stderr.decode('utf8')))) app.log.debug("Restarting lxd-bridge") run("sudo systemctl restart lxd-bridge.service", shell=True) utils.pollinate(app.session_id, 'L002') controllers.use('newcloud').render( cloud='localhost', bootstrap=True)
def __handle_bootstrap_done(self, future): app.log.debug("handle bootstrap") result = future.result() if result.returncode < 0: # bootstrap killed via user signal, we're quitting return if result.returncode > 0: pathbase = os.path.join(app.config['spell-dir'], '{}-bootstrap').format( app.current_controller) with open(pathbase + ".err") as errf: err = "\n".join(errf.readlines()) app.log.error(err) e = Exception("Bootstrap error: {}".format(err)) return self.__handle_exception(e) track_event("Juju Bootstrap", "Done", "") EventLoop.remove_alarms() app.ui.set_footer('Bootstrap complete...') self.__post_bootstrap_exec()
def finish(self, step_model, step_widget, done=False): """ handles processing step with input data Arguments: step_model: step_model returned from widget done: if True continues on to the summary view """ if done: EventLoop.remove_alarms() return controllers.use('summary').render(self.results) if utils.is_linux() and step_model.needs_sudo: password = None if step_widget.sudo_input: password = step_widget.sudo_input.value if not step_model.can_sudo(password): step_widget.set_error( 'Sudo failed. Please check your password and ensure that ' 'your sudo timeout is not set to zero.') step_widget.show_button() return step_widget.clear_error() # Set next button focus here now that the step is complete. self.view.steps.popleft() if len(self.view.steps) > 0: next_step = self.view.steps[0] next_step.generate_additional_input() self.view.step_pile.focus_position = self.view.step_pile.focus_position + 1 # noqa future = async.submit(partial(common.do_step, step_model, step_widget, app.ui.set_footer, gui=True), partial(self.__handle_exception, 'E002')) if future: future.add_done_callback(self.get_result)
from conjureup import async from conjureup.app_config import app from ubuntui.ev import EventLoop import macumba import errno class ConjureUI(Frame): def show_exception_message(self, ex): if isinstance(ex, async.ThreadCancelledException): pass elif isinstance(ex, macumba.errors.ServerError): errmsg = ex.args[1] elif hasattr(ex, 'errno') and ex.errno == errno.ENOENT: # handle oserror errmsg = ex.args[1] else: errmsg = ex.args[0] errmsg += ("\n\n" "Review log messages at /var/log/conjure-up/combined.log " "If appropriate, please submit a bug here: " "https://bugs.launchpad.net/conjure-up/+filebug") self.frame.body = ErrorView(errmsg) app.log.exception("Showing dialog for exception:") EventLoop.remove_alarms() def show_error_message(self, msg): self.frame.body = ErrorView(msg)
def _handle_exception(self, tag, exc): utils.pollinate(app.session_id, tag) app.ui.show_exception_message(exc) self.showing_error = True EventLoop.remove_alarms()
def __handle_exception(self, tag, exc): utils.pollinate(app.session_id, tag) EventLoop.remove_alarms() app.ui.show_exception_message(exc)
def finish(self): EventLoop.remove_alarms() EventLoop.exit(0)
def __handle_exception(self, tag, exc): track_exception(exc.args[0], is_fatal=True) EventLoop.remove_alarms() app.ui.show_exception_message(exc)
from conjureup.app_config import app from ubuntui.ev import EventLoop import macumba import errno class ConjureUI(Frame): def show_exception_message(self, ex): if isinstance(ex, async .ThreadCancelledException): pass elif isinstance(ex, macumba.errors.ServerError): errmsg = ex.args[1] elif hasattr(ex, 'errno') and ex.errno == errno.ENOENT: # handle oserror errmsg = ex.args[1] else: errmsg = ex.args[0] errmsg += ("\n\n" "Review log messages at ~/.cache/conjure-up/conjure-up.log " "If appropriate, please submit a bug here: " "https://github.com/conjure-up/conjure-up/issues/new") async .shutdown() EventLoop.remove_alarms() self.frame.body = ErrorView(errmsg) app.log.debug("Showing dialog for exception: {}".format(ex)) def show_error_message(self, msg): self.frame.body = ErrorView(msg)
def finish(self, future): if not future.exception(): return controllers.use('steps').render() EventLoop.remove_alarms()
def _handle_exception(self, tag, exc): track_exception(exc.args[0]) app.ui.show_exception_message(exc) self.showing_error = True EventLoop.remove_alarms()
def __handle_destroy_done(self, future): if not future.exception(): app.ui.set_footer("") return controllers.use('destroy').render() EventLoop.remove_alarms()
def finish(): EventLoop.remove_alarms()