def start_reboot_if_required_and_time_available()

in src/core/src/core_logic/RebootManager.py [0:0]


    def start_reboot_if_required_and_time_available(self, current_time_available):
        # type: (int) -> any
        """ Starts a reboot if required. Happens only at the end of the run if required. """
        reboot_pending = self.is_reboot_pending()

        # Log a special-case message if the package manager is forcing a reboot that's not normally visible on the machine (encoded into is_reboot_pending())
        if self.package_manager.force_reboot:
            self.composite_logger.log("[RM] A reboot is pending as the package manager required it.")

        # No-op - return false if config says never reboot
        if self.__reboot_setting_sanitized == Constants.REBOOT_NEVER:
            if reboot_pending:
                self.composite_logger.log_warning('[RM][!] Reboot is pending but BLOCKED by the customer configuration ({0}).'.format(str(Constants.REBOOT_NEVER)))
            else:
                self.composite_logger.log_debug('[RM] No reboot pending, and reboot is blocked regardless by the customer configuration ({0}).'.format(str(Constants.REBOOT_NEVER)))
            return False

        # No-op - return if system doesn't require it (and only reboot if it does)
        if self.__reboot_setting_sanitized == Constants.REBOOT_IF_REQUIRED and not reboot_pending:
            self.composite_logger.log_debug("[RM] No reboot pending detected. Reboot skipped as per customer configuration ({0}).".format(str(Constants.REBOOT_IF_REQUIRED)))
            return False

        # No-op - prevent repeated reboots
        if self.__reboot_setting_sanitized == Constants.REBOOT_ALWAYS and not reboot_pending and self.status_handler.get_installation_reboot_status() == Constants.RebootStatus.COMPLETED:
            self.composite_logger.log_debug("[RM] At least one reboot has occurred, and there's no reboot pending, so the conditions for the 'Reboot Always' setting is fulfilled and reboot won't be repeated.")
            return False

        # Try to reboot - if enough time is available
        if self.__reboot_setting_sanitized == Constants.REBOOT_ALWAYS or (self.__reboot_setting_sanitized == Constants.REBOOT_IF_REQUIRED and reboot_pending):
            if self.is_reboot_time_available(current_time_available):
                self.composite_logger.log_debug('[RM] Reboot is being scheduled, as per customer configuration ({0}). [RebootPending={1}][CurrentTimeAvailable={2}]'.format(str(self.__reboot_setting_sanitized), str(reboot_pending), str(current_time_available)))
                self.__start_reboot(maintenance_window_available_time_in_minutes=current_time_available)
                return True
            else:
                # Maintenance window will be marked exceeded as reboot is required and not enough time is available
                error_msg = '[RM][!] Insufficient time to schedule a required reboot ({0}). [RebootPending={1}][CurrentTimeAvailable={2}]'.format(str(self.__reboot_setting_sanitized), str(reboot_pending), str(current_time_available))
                self.composite_logger.log_error(error_msg)
                self.status_handler.add_error_to_status(str(error_msg), Constants.PatchOperationErrorCodes.DEFAULT_ERROR)
                self.__maintenance_window_exceeded_flag = True
                return False

        # No-op - This code should never be reached. If seen, it indicates a bug in the code.
        self.composite_logger.log_error('[RM] Bug-check: Unexpected code branch reached. [RebootSetting={0}][RebootPending={1}]'.format(str(self.__reboot_setting_sanitized), str(reboot_pending)))
        return False