def parseKickstart(handler, f, strict_mode=False, pass_to_boss=False): # preprocessing the kickstart file has already been handled in initramfs. ksparser = AnacondaKSParser(handler) kswarnings = [] showwarning = warnings.showwarning def ksshowwarning(message, category, filename, lineno, file=None, line=None): # Print the warning with default function. showwarning(message, category, filename, lineno, file, line) # Collect pykickstart warnings. if issubclass(category, KickstartParseWarning): kswarnings.append(message) try: # Process warnings differently in this part. with warnings.catch_warnings(): # Set up the warnings module. warnings.showwarning = ksshowwarning warnings.simplefilter("always", category=KickstartParseWarning) # Parse the kickstart file in DBus modules. if pass_to_boss: boss = BOSS.get_proxy() report = KickstartReport.from_structure( boss.ReadKickstartFile(f) ) for warn in report.warning_messages: warnings.warn(warn.message, KickstartParseWarning) if not report.is_valid(): message = "\n\n".join(map(str, report.error_messages)) raise KickstartError(message) # Parse the kickstart file in anaconda. ksparser.readKickstart(f) # Process pykickstart warnings in the strict mode: if strict_mode and kswarnings: raise KickstartError("Please modify your kickstart file to fix the warnings " "or remove the `ksstrict` option.") except KickstartError as e: # We do not have an interface here yet, so we cannot use our error # handling callback. parsing_log.error(e) # Print kickstart warnings in the strict mode. if strict_mode and kswarnings: print(_("\nSome warnings occurred during reading the kickstart file:")) for w in kswarnings: print(str(w).strip()) # Print an error and terminate. print(_("\nAn error occurred during reading the kickstart file:" "\n%s\n\nThe installer will now terminate.") % str(e).strip()) util.ipmi_report(IPMI_ABORTED) time.sleep(10) sys.exit(1)
def _installation_done(self): log.debug("The installation has finished.") util.ipmi_report(IPMI_FINISHED) if conf.license.eula: self.set_warning( _("Use of this product is subject to the license agreement " "found at %s") % conf.license.eula) self.window.show_all() # Show the reboot message. self._progressNotebook.set_current_page(1) # Enable the continue button. self.window.set_may_continue(True) # Hide the quit button. quit_button = self.window.get_quit_button() quit_button.hide() # kickstart install, continue automatically if reboot or shutdown selected if flags.automatedInstall and self.data.reboot.action in [ KS_REBOOT, KS_SHUTDOWN ]: self.window.emit("continue-clicked")
def show_all(self): super().show_all() from pyanaconda.installation import doInstall, doConfiguration from pyanaconda.threading import threadMgr, AnacondaThread thread_args = (self.storage, self.payload, self.data, self.instclass) threadMgr.add( AnacondaThread(name=THREAD_INSTALL, target=doInstall, args=thread_args)) # This will run until we're all done with the install thread. self._update_progress() threadMgr.add( AnacondaThread(name=THREAD_CONFIGURATION, target=doConfiguration, args=thread_args)) # This will run until we're all done with the configuration thread. self._update_progress() util.ipmi_report(IPMI_FINISHED) # kickstart install, continue automatically if reboot or shutdown selected if flags.automatedInstall and self.data.reboot.action in [ KS_REBOOT, KS_SHUTDOWN ]: # Just pretend like we got input, and our input doesn't care # what it gets, it just quits. raise ExitMainLoop()
def show_all(self): super().show_all() from pyanaconda.installation import doInstall, doConfiguration from pyanaconda.threading import threadMgr, AnacondaThread thread_args = (self.storage, self.payload, self.data, self.instclass) threadMgr.add(AnacondaThread(name=THREAD_INSTALL, target=doInstall, args=thread_args)) # This will run until we're all done with the install thread. self._update_progress() threadMgr.add(AnacondaThread(name=THREAD_CONFIGURATION, target=doConfiguration, args=thread_args)) # This will run until we're all done with the configuration thread. self._update_progress() util.ipmi_report(IPMI_FINISHED) if self.instclass.eula_path: # Notify user about the EULA (if any). print(_("Installation complete")) print('') print(_("Use of this product is subject to the license agreement found at:")) print(self.instclass.eula_path) print('') # kickstart install, continue automatically if reboot or shutdown selected if flags.automatedInstall and self.data.reboot.action in [KS_REBOOT, KS_SHUTDOWN]: # Just pretend like we got input, and our input doesn't care # what it gets, it just quits. raise ExitMainLoop()
def show_all(self): super().show_all() from pyanaconda.installation import run_installation from pyanaconda.threading import threadMgr, AnacondaThread threadMgr.add(AnacondaThread( name=THREAD_INSTALL, target=run_installation, args=(self.payload, self.data)) ) # This will run until we're all done with the install thread. self._update_progress() util.ipmi_report(IPMI_FINISHED) if conf.license.eula: # Notify user about the EULA (if any). print(_("Installation complete")) print('') print(_("Use of this product is subject to the license agreement found at:")) print(conf.license.eula) print('') # kickstart install, continue automatically if reboot or shutdown selected if flags.automatedInstall and self.data.reboot.action in [KS_REBOOT, KS_SHUTDOWN]: # Just pretend like we got input, and our input doesn't care # what it gets, it just quits. raise ExitMainLoop()
def prompt_for_ssh(options): """Prompt the user to ssh to the installation environment on the s390. :param options: Anaconda command line/boot options :return: True if the prompt is printed, otherwise False """ if not blivet.arch.is_s390(): return False if not conf.target.is_hardware: return False if 'TMUX' in os.environ: return False if options.ksfile: return False if options.vnc: return False # Do some work here to get the ip addr / hostname to pass # to the user. import socket ip = network.get_first_ip_address() if not ip: stdout_log.error("No IP addresses found, cannot continue installation.") util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) ipstr = ip name = None try: hinfo = socket.gethostbyaddr(ipstr) except socket.herror as e: stdout_log.debug("Exception caught trying to get host name of %s: %s", ipstr, e) name = socket.gethostname() else: if len(hinfo) == 3: name = hinfo[0] if ip.find(':') != -1: ipstr = "[%s]" % (ip,) if (name is not None) and (not name.startswith('localhost')) and (ipstr is not None): connxinfo = "%s (%s)" % (socket.getfqdn(name=name), ipstr,) elif ipstr is not None: connxinfo = "%s" % (ipstr,) else: connxinfo = None if connxinfo: stdout_log.info(_("Please ssh install@%s to begin the install."), connxinfo) else: stdout_log.info(_("Please ssh install@HOSTNAME to continue installation.")) return True
def check_kickstart_error(): try: yield except KickstartError as e: # We do not have an interface here yet, so we cannot use our error # handling callback. print(e) util.ipmi_report(IPMI_ABORTED) sys.exit(1)
def check_kickstart_error(): try: yield except KickstartError as e: # We do not have an interface here yet, so we cannot use our error # handling callback. print(e) util.ipmi_report(IPMI_ABORTED) sys.exit(1)
def showError(self, message): dlg = ErrorDialog(None) with self.mainWindow.enlightbox(dlg.window): dlg.refresh(message) dlg.run() dlg.window.destroy() # the dialog has the only button -- "Exit installer", so just do so util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1)
def run(self, chroot): """ Run the kickstart script @param chroot directory path to chroot into before execution """ if self.inChroot: scriptRoot = chroot else: scriptRoot = "/" (fd, path) = tempfile.mkstemp("", "ks-script-", scriptRoot + "/tmp") os.write(fd, self.script.encode("utf-8")) os.close(fd) os.chmod(path, 0o700) # Always log stdout/stderr from scripts. Using --log just lets you # pick where it goes. The script will also be logged to program.log # because of execWithRedirect. if self.logfile: if self.inChroot: messages = "%s/%s" % (scriptRoot, self.logfile) else: messages = self.logfile d = os.path.dirname(messages) if not os.path.exists(d): os.makedirs(d) else: # Always log outside the chroot, we copy those logs into the # chroot later. messages = "/tmp/%s.log" % os.path.basename(path) with open(messages, "w") as fp: rc = util.execWithRedirect(self.interp, ["/tmp/%s" % os.path.basename(path)], stdout=fp, root=scriptRoot) if rc != 0: script_log.error( "Error code %s running the kickstart script at line %s", rc, self.lineno) if self.errorOnFail: err = "" with open(messages, "r") as fp: err = "".join(fp.readlines()) # Show error dialog even for non-interactive flags.ksprompt = True errorHandler.cb(ScriptError(self.lineno, err)) util.ipmi_report(IPMI_ABORTED) sys.exit(0)
def postWriteHook(self, dump_info): # See if there is a /root present in the root path and put exception there as well if os.access(conf.target.system_root + "/root", os.X_OK): try: dest = conf.target.system_root + "/root/%s" % os.path.basename(self.exnFile) shutil.copyfile(self.exnFile, dest) except (shutil.Error, OSError): log.error("Failed to copy %s to %s/root", self.exnFile, conf.target.system_root) # run kickstart traceback scripts (if necessary) self._run_kickstart_scripts(dump_info) util.ipmi_report(IPMI_FAILED)
def parse_kickstart(options, addon_paths, pass_to_boss=False): """Parse the input kickstart. If we were given a kickstart file, parse (but do not execute) that now. Otherwise, load in defaults from kickstart files shipped with the installation media. Pick up any changes from interactive-defaults.ks that would otherwise be covered by the dracut KS parser. :param options: command line/boot options :param dict addon_paths: addon paths dictionary :returns: kickstart parsed to a data model """ ksdata = None if options.ksfile and not options.liveinst: if not os.path.exists(options.ksfile): stdout_log.error("Kickstart file %s is missing.", options.ksfile) util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) flags.automatedInstall = True flags.eject = False ks_files = [options.ksfile] elif os.path.exists("/run/install/ks.cfg") and not options.liveinst: # this is to handle such cases where a user has pre-loaded a # ks.cfg onto an OEMDRV labeled device flags.automatedInstall = True flags.eject = False ks_files = ["/run/install/ks.cfg"] else: ks_files = [ "/tmp/updates/interactive-defaults.ks", "/usr/share/anaconda/interactive-defaults.ks" ] for ks in ks_files: if not os.path.exists(ks): continue kickstart.preScriptPass(ks) log.info("Parsing kickstart: " + ks) ksdata = kickstart.parseKickstart(ks, options.ksstrict) if pass_to_boss: distribute_kickstart_with_boss(ks) # Only load the first defaults file we find. break if not ksdata: ksdata = kickstart.AnacondaKSHandler(addon_paths["ks"]) return ksdata
def run(self, chroot): """ Run the kickstart script @param chroot directory path to chroot into before execution """ if self.inChroot: scriptRoot = chroot else: scriptRoot = "/" (fd, path) = tempfile.mkstemp("", "ks-script-", scriptRoot + "/tmp") os.write(fd, self.script.encode("utf-8")) os.close(fd) os.chmod(path, 0o700) # Always log stdout/stderr from scripts. Using --log just lets you # pick where it goes. The script will also be logged to program.log # because of execWithRedirect. if self.logfile: if self.inChroot: messages = "%s/%s" % (scriptRoot, self.logfile) else: messages = self.logfile d = os.path.dirname(messages) if not os.path.exists(d): os.makedirs(d) else: # Always log outside the chroot, we copy those logs into the # chroot later. messages = "/tmp/%s.log" % os.path.basename(path) with open(messages, "w") as fp: rc = util.execWithRedirect(self.interp, ["/tmp/%s" % os.path.basename(path)], stdout=fp, root=scriptRoot) if rc != 0: script_log.error("Error code %s running the kickstart script at line %s", rc, self.lineno) if self.errorOnFail: err = "" with open(messages, "r") as fp: err = "".join(fp.readlines()) # Show error dialog even for non-interactive flags.ksprompt = True errorHandler.cb(ScriptError(self.lineno, err)) util.ipmi_report(IPMI_ABORTED) sys.exit(0)
def _configuration_done(self): # Configuration done, remove ransom notes timer # and switch to the Reboot page self._cycle_rnotes_timer.cancel() self._progressNotebook.set_current_page(1) self.window.set_may_continue(True) util.ipmi_report(IPMI_FINISHED) # kickstart install, continue automatically if reboot or shutdown selected if flags.automatedInstall and self.data.reboot.action in [ KS_REBOOT, KS_SHUTDOWN ]: self.window.emit("continue-clicked")
def parse_kickstart(options, addon_paths, pass_to_boss=False): """Parse the input kickstart. If we were given a kickstart file, parse (but do not execute) that now. Otherwise, load in defaults from kickstart files shipped with the installation media. Pick up any changes from interactive-defaults.ks that would otherwise be covered by the dracut KS parser. :param options: command line/boot options :param dict addon_paths: addon paths dictionary :returns: kickstart parsed to a data model """ ksdata = None if options.ksfile and not options.liveinst: if not os.path.exists(options.ksfile): stdout_log.error("Kickstart file %s is missing.", options.ksfile) util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) flags.automatedInstall = True flags.eject = False ks_files = [options.ksfile] elif os.path.exists("/run/install/ks.cfg") and not options.liveinst: # this is to handle such cases where a user has pre-loaded a # ks.cfg onto an OEMDRV labeled device flags.automatedInstall = True flags.eject = False ks_files = ["/run/install/ks.cfg"] else: ks_files = ["/tmp/updates/interactive-defaults.ks", "/usr/share/anaconda/interactive-defaults.ks"] for ks in ks_files: if not os.path.exists(ks): continue kickstart.preScriptPass(ks) log.info("Parsing kickstart: %s", ks) ksdata = kickstart.parseKickstart(ks, options.ksstrict, pass_to_boss) # Only load the first defaults file we find. break if not ksdata: ksdata = kickstart.AnacondaKSHandler(addon_paths["ks"]) return ksdata
def prompt_for_ssh(): """Prompt the user to ssh to the installation environment on the s390.""" # Do some work here to get the ip addr / hostname to pass # to the user. import socket ip = network.get_first_ip_address() if not ip: stdout_log.error( "No IP addresses found, cannot continue installation.") util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) ipstr = ip try: hinfo = socket.gethostbyaddr(ipstr) except socket.herror as e: stdout_log.debug("Exception caught trying to get host name of %s: %s", ipstr, e) name = network.get_hostname() else: if len(hinfo) == 3: name = hinfo[0] if ip.find(':') != -1: ipstr = "[%s]" % (ip, ) if (name is not None) and (not name.startswith('localhost')) and ( ipstr is not None): connxinfo = "%s (%s)" % ( socket.getfqdn(name=name), ipstr, ) elif ipstr is not None: connxinfo = "%s" % (ipstr, ) else: connxinfo = None if connxinfo: stdout_log.info(_("Please ssh install@%s to begin the install."), connxinfo) else: stdout_log.info( _("Please ssh install@HOSTNAME to continue installation."))
def _configuration_done(self): # Configuration done, remove ransom notes timer # and switch to the Reboot page self._cycle_rnotes_timer.cancel() self._progressNotebook.set_current_page(1) self.window.set_may_continue(True) util.ipmi_report(IPMI_FINISHED) if self.instclass.eula_path: self.set_warning(_("Use of this product is subject to the license agreement found at %s") % self.instclass.eula_path) self.window.show_all() # kickstart install, continue automatically if reboot or shutdown selected if flags.automatedInstall and self.data.reboot.action in [KS_REBOOT, KS_SHUTDOWN]: self.window.emit("continue-clicked")
def _configuration_done(self): # Configuration done, remove ransom notes timer # and switch to the Reboot page self._cycle_rnotes_timer.cancel() self._progressNotebook.set_current_page(1) self.window.set_may_continue(True) util.ipmi_report(IPMI_FINISHED) if self.instclass.eula_path: self.set_warning(_("Use of this product is subject to the license agreement found at %s") % self.instclass.eula_path) self.window.show_all() # kickstart install, continue automatically if reboot or shutdown selected if flags.automatedInstall and self.data.reboot.action in [KS_REBOOT, KS_SHUTDOWN]: self.window.emit("continue-clicked")
def postWriteHook(self, dump_info): anaconda = dump_info.object # See if there is a /root present in the root path and put exception there as well if os.access(conf.target.system_root + "/root", os.X_OK): try: dest = conf.target.system_root + "/root/%s" % os.path.basename(self.exnFile) shutil.copyfile(self.exnFile, dest) except (shutil.Error, IOError): log.error("Failed to copy %s to %s/root", self.exnFile, conf.target.system_root) # run kickstart traceback scripts (if necessary) try: util.runOnErrorScripts(anaconda.ksdata.scripts) kickstart.runTracebackScripts(anaconda.ksdata.scripts) # pylint: disable=bare-except except: pass util.ipmi_report(IPMI_FAILED)
def postWriteHook(self, dump_info): anaconda = dump_info.object # See if there is a /root present in the root path and put exception there as well if os.access(util.getSysroot() + "/root", os.X_OK): try: dest = util.getSysroot() + "/root/%s" % os.path.basename(self.exnFile) shutil.copyfile(self.exnFile, dest) except (shutil.Error, IOError): log.error("Failed to copy %s to %s/root", self.exnFile, util.getSysroot()) # run kickstart traceback scripts (if necessary) try: util.runOnErrorScripts(anaconda.ksdata.scripts) kickstart.runTracebackScripts(anaconda.ksdata.scripts) # pylint: disable=bare-except except: pass util.ipmi_report(IPMI_FAILED)
def _main_loop_handleException(self, dump_info): """ Helper method with one argument only so that it can be registered with run_in_loop to run on idle or called from a handler. :type dump_info: an instance of the meh.DumpInfo class """ ty = dump_info.exc_info.type value = dump_info.exc_info.value if (issubclass(ty, blivet.errors.StorageError) and value.hardware_fault) \ or (issubclass(ty, OSError) and value.errno == errno.EIO): # hardware fault or '[Errno 5] Input/Output error' hw_error_msg = _("The installation was stopped due to what " "seems to be a problem with your hardware. " "The exact error message is:\n\n%s.\n\n " "The installer will now terminate.") % str(value) self.intf.messageWindow(_("Hardware error occurred"), hw_error_msg) self._run_kickstart_scripts(dump_info) util.ipmi_report(IPMI_FAILED) sys.exit(1) elif isinstance(value, UnusableStorageError): self._run_kickstart_scripts(dump_info) util.ipmi_report(IPMI_FAILED) sys.exit(1) elif isinstance(value, NonInteractiveError): self._run_kickstart_scripts(dump_info) util.ipmi_report(IPMI_FAILED) sys.exit(1) else: # This will call postWriteHook. super().handleException(dump_info) return False
def find_kickstart(options): """Find a kickstart to parse. If we were given a kickstart file, return that one. Otherwise, return a default kickstart file shipped with the installation media. Pick up any changes from interactive-defaults.ks that would otherwise be covered by the dracut kickstart parser. :param options: command line/boot options :returns: a path to a kickstart file or None """ if options.ksfile and not options.liveinst: if not os.path.exists(options.ksfile): stdout_log.error("Kickstart file %s is missing.", options.ksfile) util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) flags.automatedInstall = True flags.eject = False ks_files = [options.ksfile] elif os.path.exists("/run/install/ks.cfg") and not options.liveinst: # this is to handle such cases where a user has pre-loaded a # ks.cfg onto an OEMDRV labeled device flags.automatedInstall = True flags.eject = False ks_files = ["/run/install/ks.cfg"] else: ks_files = [ "/tmp/updates/interactive-defaults.ks", "/usr/share/anaconda/interactive-defaults.ks" ] for ks in ks_files: if not os.path.exists(ks): continue return ks return None
def prompt_for_ssh(): """Prompt the user to ssh to the installation environment on the s390.""" # Do some work here to get the ip addr / hostname to pass # to the user. import socket ip = network.getFirstRealIP() if not ip: stdout_log.error("No IP addresses found, cannot continue installation.") util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) ipstr = ip try: hinfo = socket.gethostbyaddr(ipstr) except socket.herror as e: stdout_log.debug("Exception caught trying to get host name of %s: %s", ipstr, e) name = network.getHostname() else: if len(hinfo) == 3: name = hinfo[0] if ip.find(':') != -1: ipstr = "[%s]" % (ip,) if (name is not None) and (not name.startswith('localhost')) and (ipstr is not None): connxinfo = "%s (%s)" % (socket.getfqdn(name=name), ipstr,) elif ipstr is not None: connxinfo = "%s" % (ipstr,) else: connxinfo = None if connxinfo: stdout_log.info(_("Please ssh install@%s to begin the install."), connxinfo) else: stdout_log.info(_("Please ssh install@HOSTNAME to continue installation."))
def _on_installation_done(self): log.debug("The installation has finished.") # Print a new line after the last step. if self._stepped: print('') # Finish the installation task. Re-raise tracebacks if any. self._task.finish() util.ipmi_report(IPMI_FINISHED) if conf.license.eula: # Notify user about the EULA (if any). print(_("Installation complete")) print('') print( _("Use of this product is subject to the license agreement found at:" )) print(conf.license.eula) print('') loop = App.get_event_loop() loop.enqueue_signal(ScreenReadySignal(self))
def input(self, args, key): """Call IPMI ABORTED. Everything else will be done by original implementation.""" util.ipmi_report(constants.IPMI_ABORTED) super().input(args, key)
startup_utils.prompt_for_ssh() sys.exit(0) log.info("%s %s", sys.argv[0], startup_utils.get_anaconda_version_string(build_time_version=True)) if os.path.exists("/tmp/updates"): log.info("Using updates in /tmp/updates/ from %s", opts.updateSrc) # TODO: uncomment this when we're sure that we're doing the right thing # with flags.cmdline *everywhere* it appears... #for arg in depr: # stdout_log.warn("Boot argument '%s' is deprecated. " # "In the future, use 'inst.%s'.", arg, arg) from pyanaconda import isys util.ipmi_report(constants.IPMI_STARTED) if (opts.images or opts.dirinstall) and opts.liveinst: stdout_log.error("--liveinst cannot be used with --images or --dirinstall") util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) if opts.images and opts.dirinstall: stdout_log.error("--images and --dirinstall cannot be used at the same time") util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) from pyanaconda import vnc from pyanaconda import kickstart from pyanaconda import ntp from pyanaconda import keyboard
def _earlyExceptionHandler(ty, value, traceback): util.ipmi_report(constants.IPMI_FAILED) util.vtActivate(1) return sys.__excepthook__(ty, value, traceback)
sys.exit(0) log.info("%s %s", sys.argv[0], util.get_anaconda_version_string(build_time_version=True)) if os.path.exists("/tmp/updates"): log.info("Using updates in /tmp/updates/ from %s", opts.updateSrc) # TODO: uncomment this when we're sure that we're doing the right thing # with flags.cmdline *everywhere* it appears... #for arg in depr: # stdout_log.warn("Boot argument '%s' is deprecated. " # "In the future, use 'inst.%s'.", arg, arg) from pyanaconda import isys util.ipmi_report(constants.IPMI_STARTED) if (opts.images or opts.dirinstall) and opts.liveinst: stdout_log.error( "--liveinst cannot be used with --images or --dirinstall") util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) if opts.images and opts.dirinstall: stdout_log.error( "--images and --dirinstall cannot be used at the same time") util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) from pyanaconda import vnc from pyanaconda import kickstart
def _earlyExceptionHandler(ty, value, traceback): util.ipmi_report(constants.IPMI_FAILED) util.vtActivate(1) return sys.__excepthook__(ty, value, traceback)
def parseKickstart(f, strict_mode=False, pass_to_boss=False): # preprocessing the kickstart file has already been handled in initramfs. addon_paths = collect_addon_paths(ADDON_PATHS) handler = AnacondaKSHandler(addon_paths["ks"]) ksparser = AnacondaKSParser(handler) kswarnings = [] ksmodule = "pykickstart" kscategories = (UserWarning, SyntaxWarning, DeprecationWarning) showwarning = warnings.showwarning def ksshowwarning(message, category, filename, lineno, file=None, line=None): # Print the warning with default function. showwarning(message, category, filename, lineno, file, line) # Collect pykickstart warnings. if ksmodule in filename and issubclass(category, kscategories): kswarnings.append(message) try: # Process warnings differently in this part. with warnings.catch_warnings(): # Set up the warnings module. warnings.showwarning = ksshowwarning for category in kscategories: warnings.filterwarnings(action="always", module=ksmodule, category=category) # Parse the kickstart file in DBus modules. if pass_to_boss: boss = BOSS.get_proxy() boss.SplitKickstart(f) errors = boss.DistributeKickstart() if errors: message = "\n\n".join("{error_message}".format_map(e) for e in errors) raise KickstartError(message) # Parse the kickstart file in anaconda. ksparser.readKickstart(f) # Process pykickstart warnings in the strict mode: if strict_mode and kswarnings: raise KickstartError( "Please modify your kickstart file to fix the warnings " "or remove the `ksstrict` option.") except (KickstartError, SplitKickstartError) as e: # We do not have an interface here yet, so we cannot use our error # handling callback. parsing_log.error(e) # Print kickstart warnings in the strict mode. if strict_mode and kswarnings: print( _("\nSome warnings occurred during reading the kickstart file:" )) for w in kswarnings: print(str(w).strip()) # Print an error and terminate. print( _("\nAn error occurred during reading the kickstart file:" "\n%s\n\nThe installer will now terminate.") % str(e).strip()) util.ipmi_report(IPMI_ABORTED) time.sleep(10) sys.exit(1) return handler
def tui_quit_callback(data): ipmi_report(IPMI_ABORTED)
def tui_quit_callback(data): ipmi_report(IPMI_ABORTED)
def parseKickstart(f, strict_mode=False, pass_to_boss=False): # preprocessing the kickstart file has already been handled in initramfs. addon_paths = collect_addon_paths(ADDON_PATHS) handler = AnacondaKSHandler(addon_paths["ks"]) ksparser = AnacondaKSParser(handler) # So that drives onlined by these can be used in the ks file blivet.iscsi.iscsi.startup() # Note we do NOT call dasd.startup() here, that does not online drives, but # only checks if they need formatting, which requires zerombr to be known kswarnings = [] ksmodule = "pykickstart" kscategories = (UserWarning, SyntaxWarning, DeprecationWarning) showwarning = warnings.showwarning def ksshowwarning(message, category, filename, lineno, file=None, line=None): # Print the warning with default function. showwarning(message, category, filename, lineno, file, line) # Collect pykickstart warnings. if ksmodule in filename and issubclass(category, kscategories): kswarnings.append(message) try: # Process warnings differently in this part. with warnings.catch_warnings(): # Set up the warnings module. warnings.showwarning = ksshowwarning for category in kscategories: warnings.filterwarnings(action="always", module=ksmodule, category=category) # Parse the kickstart file in DBus modules. if pass_to_boss: boss = BOSS.get_proxy() boss.SplitKickstart(f) errors = boss.DistributeKickstart() if errors: message = "\n\n".join("{error_message}".format_map(e) for e in errors) raise KickstartError(message) # Parse the kickstart file in anaconda. ksparser.readKickstart(f) # Process pykickstart warnings in the strict mode: if strict_mode and kswarnings: raise KickstartError("Please modify your kickstart file to fix the warnings " "or remove the `ksstrict` option.") except (KickstartError, SplitKickstartError) as e: # We do not have an interface here yet, so we cannot use our error # handling callback. parsing_log.error(e) # Print kickstart warnings in the strict mode. if strict_mode and kswarnings: print(_("\nSome warnings occurred during reading the kickstart file:")) for w in kswarnings: print(str(w).strip()) # Print an error and terminate. print(_("\nAn error occurred during reading the kickstart file:" "\n%s\n\nThe installer will now terminate.") % str(e).strip()) util.ipmi_report(IPMI_ABORTED) time.sleep(10) sys.exit(1) return handler
def check_memory(anaconda, options, display_mode=None): """Check is the system has enough RAM for installation. :param anaconda: instance of the Anaconda class :param options: command line/boot options :param display_mode: a display mode to use for the check (graphical mode usually needs more RAM, etc.) """ from pyanaconda import isys reason_strict = _("%(product_name)s requires %(needed_ram)s MB of memory to " "install, but you only have %(total_ram)s MB on this machine.\n") reason_graphical = _("The %(product_name)s graphical installer requires %(needed_ram)s " "MB of memory, but you only have %(total_ram)s MB\n.") reboot_extra = _('\n' 'Press [Enter] to reboot your system.\n') livecd_title = _("Not enough RAM") livecd_extra = _(" Try the text mode installer by running:\n\n" "'/usr/bin/liveinst -T'\n\n from a root terminal.") nolivecd_extra = _(" Starting text mode.") # skip the memory check in rescue mode if options.rescue: return if not display_mode: display_mode = anaconda.display_mode reason = reason_strict total_ram = int(isys.total_memory() / 1024) needed_ram = int(isys.MIN_RAM) graphical_ram = int(isys.MIN_GUI_RAM) # count the squashfs.img in if it is kept in RAM if not util.persistent_root_image(): needed_ram += isys.SQUASHFS_EXTRA_RAM graphical_ram += isys.SQUASHFS_EXTRA_RAM log.info("check_memory(): total:%s, needed:%s, graphical:%s", total_ram, needed_ram, graphical_ram) if not options.memcheck: log.warning("CHECK_MEMORY DISABLED") return reason_args = {"product_name": product.productName, "needed_ram": needed_ram, "total_ram": total_ram} if needed_ram > total_ram: if options.liveinst: # pylint: disable=logging-not-lazy stdout_log.warning(reason % reason_args) gtk_warning(livecd_title, reason % reason_args) else: reason += reboot_extra print(reason % reason_args) print(_("The installation cannot continue and the system will be rebooted")) print(_("Press ENTER to continue")) input() util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) # override display mode if machine cannot nicely run X if display_mode != constants.DisplayModes.TUI and not flags.usevnc: needed_ram = graphical_ram reason_args["needed_ram"] = graphical_ram reason = reason_graphical if needed_ram > total_ram: if options.liveinst: reason += livecd_extra # pylint: disable=logging-not-lazy stdout_log.warning(reason % reason_args) title = livecd_title gtk_warning(title, reason % reason_args) util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) else: reason += nolivecd_extra # pylint: disable=logging-not-lazy stdout_log.warning(reason % reason_args) anaconda.display_mode = constants.DisplayModes.TUI time.sleep(2)
def handleException(self, dump_info): """ Our own handleException method doing some additional stuff before calling the original python-meh's one. :type dump_info: an instance of the meh.DumpInfo class :see: python-meh's ExceptionHandler.handleException """ log.debug("running handleException") exception_lines = traceback.format_exception(*dump_info.exc_info) log.critical("\n".join(exception_lines)) ty = dump_info.exc_info.type value = dump_info.exc_info.value try: gi.require_version("Gtk", "3.0") from gi.repository import Gtk # XXX: Gtk stopped raising RuntimeError if it fails to # initialize. Horay! But will it stay like this? Let's be # cautious and raise the exception on our own to work in both # cases initialized = Gtk.init_check(None)[0] if not initialized: raise RuntimeError() # Attempt to grab the GUI initializing lock, do not block if not self._gui_lock.acquire(False): # the graphical interface is running, don't crash it by # running another one potentially from a different thread log.debug( "Gtk running, queuing exception handler to the main loop") run_in_loop(self._main_loop_handleException, dump_info) else: log.debug( "Gtk not running, starting Gtk and running exception handler in it" ) self._main_loop_handleException(dump_info) except (RuntimeError, ImportError, ValueError): log.debug("Gtk cannot be initialized") # X not running (Gtk cannot be initialized) if threadMgr.in_main_thread(): log.debug("In the main thread, running exception handler") if issubclass(ty, NonInteractiveError) or not self._interactive: if issubclass(ty, NonInteractiveError): cmdline_error_msg = _( "\nThe installation was stopped due to an " "error which occurred while running in " "non-interactive cmdline mode. Since there " "cannot be any questions in cmdline mode, edit " "your kickstart file and retry installation. " "\nThe exact error message is: \n\n%s. \n\nThe " "installer will now terminate.") % str(value) else: cmdline_error_msg = _( "\nRunning in cmdline mode, no interactive " "debugging allowed.\nThe exact error message is: " "\n\n%s.\n\nThe installer will now terminate." ) % str(value) # since there is no UI in cmdline mode and it is completely # non-interactive, we can't show a message window asking the user # to acknowledge the error; instead, print the error out and sleep # for a few seconds before exiting the installer print(cmdline_error_msg, flush=True) self._run_kickstart_scripts(dump_info) util.ipmi_report(IPMI_FAILED) time.sleep(180) sys.exit(1) else: print("\nAn unknown error has occured, look at the " "/tmp/anaconda-tb* file(s) for more details") # in the main thread, run exception handler self._main_loop_handleException(dump_info) else: log.debug( "In a non-main thread, sending a message with exception data" ) # not in the main thread, just send message with exception # data and let message handler run the exception handler in # the main thread exc_info = dump_info.exc_info # new Simpleline package is now used in TUI. Look if Simpleline is # initialized or if this is some fallback from GTK or other stuff. if App.is_initialized(): # if Simpleline is initialized enqueue exception there loop = App.get_event_loop() loop.enqueue_signal( ExceptionSignal(App.get_scheduler(), exception_info=exc_info)) else: hubQ.send_exception( (exc_info.type, exc_info.value, exc_info.stack))
def check_memory(anaconda, options, display_mode=None): """Check is the system has enough RAM for installation. :param anaconda: instance of the Anaconda class :param options: command line/boot options :param display_mode: a display mode to use for the check (graphical mode usually needs more RAM, etc.) """ from pyanaconda import isys reason_strict = _( "%(product_name)s requires %(needed_ram)s MB of memory to " "install, but you only have %(total_ram)s MB on this machine.\n") reason_graphical = _( "The %(product_name)s graphical installer requires %(needed_ram)s " "MB of memory, but you only have %(total_ram)s MB.\n") reboot_extra = _('\n' 'Press [Enter] to reboot your system.\n') livecd_title = _("Not enough RAM") livecd_extra = _(" Try the text mode installer by running:\n\n" "'/usr/bin/liveinst -T'\n\n from a root terminal.") nolivecd_extra = _(" Starting text mode.") # skip the memory check in rescue mode if options.rescue: return if not display_mode: display_mode = anaconda.display_mode reason = reason_strict total_ram = int(isys.total_memory() / 1024) needed_ram = int(isys.MIN_RAM) graphical_ram = int(isys.MIN_GUI_RAM) # count the squashfs.img in if it is kept in RAM if not util.persistent_root_image(): needed_ram += isys.SQUASHFS_EXTRA_RAM graphical_ram += isys.SQUASHFS_EXTRA_RAM log.info("check_memory(): total:%s, needed:%s, graphical:%s", total_ram, needed_ram, graphical_ram) if not options.memcheck: log.warning("CHECK_MEMORY DISABLED") return reason_args = { "product_name": product.productName, "needed_ram": needed_ram, "total_ram": total_ram } if needed_ram > total_ram: if options.liveinst: # pylint: disable=logging-not-lazy stdout_log.warning(reason % reason_args) gtk_warning(livecd_title, reason % reason_args) else: reason += reboot_extra print(reason % reason_args) print( _("The installation cannot continue and the system will be rebooted" )) print(_("Press ENTER to continue")) input() util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) # override display mode if machine cannot nicely run X if display_mode != constants.DisplayModes.TUI and not flags.usevnc: needed_ram = graphical_ram reason_args["needed_ram"] = graphical_ram reason = reason_graphical if needed_ram > total_ram: if options.liveinst: reason += livecd_extra # pylint: disable=logging-not-lazy stdout_log.warning(reason % reason_args) title = livecd_title gtk_warning(title, reason % reason_args) util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) else: reason += nolivecd_extra # pylint: disable=logging-not-lazy stdout_log.warning(reason % reason_args) anaconda.display_mode = constants.DisplayModes.TUI time.sleep(2)
def input(self, args, key): """Call IPMI ABORTED. Everything else will be done by original implementation.""" util.ipmi_report(constants.IPMI_ABORTED) super().input(args, key)