def ready(self): # By default, the software selection spoke is not ready. We have to # wait until the installation source spoke is completed. This could be # because the user filled something out, or because we're done fetching # repo metadata from the mirror list, or we detected a DVD/CD. return bool(not threadMgr.get(constants.THREAD_SOFTWARE_WATCHER) and not threadMgr.get(constants.THREAD_PAYLOAD) and not threadMgr.get(constants.THREAD_CHECK_SOFTWARE) and self.payload.base_repo is not None)
def _check_discover(self): """ After the DASD discover thread runs, check to see whether a valid device was discovered. Display an error message if not. If the discover is not done, return True to indicate that the check has to be run again, otherwise check the discovery and return False. """ # Discovery is not done, return True. if threadMgr.get(constants.THREAD_DASD_DISCOVER): return True # Discovery has finished, run the check. self._spinner.stop() if self._discoveryError: # Failure, display a message and leave the user on the dialog so # they can try again (or cancel) self._errorLabel.set_text(self._discoveryError) self._discoveryError = None self._deviceEntry.set_sensitive(True) self._conditionNotebook.set_current_page(2) else: # Great success. Since DASDs go under local disks, update dialog to # show users that's where they'll be self._okButton.set_sensitive(True) self._conditionNotebook.set_current_page(3) self._cancelButton.set_sensitive(True) # Discovery and the check have finished, return False. return False
def restart_thread(self, storage, ksdata, payload, fallback=False, checkmount=True, onlyOnChange=False): """Start or restart the payload thread. This method starts a new thread to restart the payload thread, so this method's return is not blocked by waiting on the previous payload thread. If there is already a payload thread restart pending, this method has no effect. :param pyanaconda.storage.InstallerStorage storage: The blivet storage instance :param kickstart.AnacondaKSHandler ksdata: The kickstart data instance :param payload.Payload payload: The payload instance :param bool fallback: Whether to fall back to the default repo in case of error :param bool checkmount: Whether to check for valid mounted media :param bool onlyOnChange: Restart thread only if existing repositories changed. This won't restart thread even when a new repository was added!! """ log.debug("Restarting payload thread") # If a restart thread is already running, don't start a new one if threadMgr.get(THREAD_PAYLOAD_RESTART): return thread_args = (storage, ksdata, payload, fallback, checkmount, onlyOnChange) # Launch a new thread so that this method can return immediately threadMgr.add(AnacondaThread(name=THREAD_PAYLOAD_RESTART, target=self._restart_thread, args=thread_args))
def refresh(self, args=None): super().refresh(args) self._container = ListColumnContainer(1, columns_width=78, spacing=1) # check if the storage refresh thread is running if threadMgr.get(THREAD_STORAGE_WATCHER): # storage refresh is running - just report it # so that the user can refresh until it is done # TODO: refresh once the thread is done ? message = _(PAYLOAD_STATUS_PROBING_STORAGE) self.window.add_with_separator(TextWidget(message)) # check if there are any mountable devices if self._mountable_devices: for d in self._mountable_devices: self._container.add(TextWidget(d[1]), callback=self._select_mountable_device, data=d[0]) self.window.add_with_separator(self._container) else: message = _("No mountable devices found") self.window.add_with_separator(TextWidget(message))
def _check_discover(self, *args): if threadMgr.get(constants.THREAD_ISCSI_DISCOVER): return True # When iscsi discovery is done, update the UI. We don't need to worry # about the user escaping from the dialog because all the buttons are # marked insensitive. spinner = self.builder.get_object("waitSpinner") spinner.stop() if self._discoveryError: # Failure. Display some error message and leave the user on the # dialog to try again. self.builder.get_object("discoveryErrorLabel").set_text( self._discoveryError) self._discoveryError = None self._conditionNotebook.set_current_page(2) self._set_configure_sensitive(True) else: # Success. Now populate the node store and kick the user on over to # that subscreen. self._add_nodes(self._discoveredNodes) self._iscsiNotebook.set_current_page(1) # If some form of login credentials were used for discovery, # default to using the same for login. if self._authTypeCombo.get_active() != 0: self._loginAuthTypeCombo.set_active(3) # We always want to enable this button, in case the user's had enough. self._cancelButton.set_sensitive(True) return False
def restart_thread(self, payload, fallback=False, checkmount=True, onlyOnChange=False): """Start or restart the payload thread. This method starts a new thread to restart the payload thread, so this method's return is not blocked by waiting on the previous payload thread. If there is already a payload thread restart pending, this method has no effect. :param payload.Payload payload: The payload instance :param bool fallback: Whether to fall back to the default repo in case of error :param bool checkmount: Whether to check for valid mounted media :param bool onlyOnChange: Restart thread only if existing repositories changed. This won't restart thread even when a new repository was added!! """ log.debug("Restarting payload thread") # If a restart thread is already running, don't start a new one if threadMgr.get(THREAD_PAYLOAD_RESTART): return # Launch a new thread so that this method can return immediately threadMgr.add( AnacondaThread(name=THREAD_PAYLOAD_RESTART, target=self._restart_thread, args=(payload, fallback, checkmount, onlyOnChange)))
def wait_and_fetch_net_data(url, out_file, ca_certs=None): """ Function that waits for network connection and starts a thread that fetches data over network. :see: org_fedora_oscap.data_fetch.fetch_data :return: the name of the thread running fetch_data :rtype: str """ # get thread that tries to establish a network connection nm_conn_thread = threadMgr.get(constants.THREAD_WAIT_FOR_CONNECTING_NM) if nm_conn_thread: # NM still connecting, wait for it to finish nm_conn_thread.join() if not nm.nm_is_connected(): raise OSCAPaddonNetworkError("Network connection needed to fetch data.") fetch_data_thread = AnacondaThread(name=THREAD_FETCH_DATA, target=fetch_data, args=(url, out_file, ca_certs), fatal=False) # register and run the thread threadMgr.add(fetch_data_thread) return THREAD_FETCH_DATA
def refresh(self, args=None): NormalTUISpoke.refresh(self, args) # check if the storage refresh thread is running if threadMgr.get(THREAD_STORAGE_WATCHER): # storage refresh is running - just report it # so that the user can refresh until it is done # TODO: refresh once the thread is done ? message = _(PAYLOAD_STATUS_PROBING_STORAGE) self._window += [TextWidget(message), ""] return True # check if there are any mountable devices if self._mountable_devices: def _prep(i, w): """ Mangle our text to make it look pretty on screen. """ number = TextWidget("%2d)" % (i + 1)) return ColumnWidget([(4, [number]), (None, [w])], 1) devices = [TextWidget(d[1]) for d in self._mountable_devices] # gnarl and mangle all of our widgets so things look pretty on # screen choices = [_prep(i, w) for i, w in enumerate(devices)] displayed = ColumnWidget([(78, choices)], 1) self._window += [displayed, ""] else: message = _("No mountable devices found") self._window += [TextWidget(message), ""] return True
def _check_discover(self, *args): """ After the zFCP discover thread runs, check to see whether a valid device was discovered. Display an error message if not. If the discover is not done, return True to indicate that the check has to be run again, otherwise check the discovery and return False. """ # Discovery is not done, return True. if threadMgr.get(constants.THREAD_ZFCP_DISCOVER): return True # Discovery has finished, run the check. self._spinner.stop() if self._discoveryError: # Failure, display a message and leave the user on the dialog so # they can try again (or cancel) self._errorLabel.set_text(self._discoveryError) self._discoveryError = None self._conditionNotebook.set_current_page(2) self._set_configure_sensitive(True) else: # Great success. Just return to the advanced storage window and let the # UI update with the newly-added device self.window.response(1) return False self._cancelButton.set_sensitive(True) # Discovery and the check have finished, return False. return False
def is_service_available(self, timeout=RHSM_SERVICE_TIMEOUT): """Return if RHSM service is available or wait if startup is ongoing.""" if self.is_running: # Wait up to defined timeout for the service to startup # by joining the thread running the task. We specify a timeout when # joining to prevent a deadlocked task blocking this method forever. thread = threadMgr.get(self._thread_name) if thread: log.debug("subscription: waiting for RHSM service to start for up to %f seconds.", timeout) thread.join(timeout) else: log.error("subscription: RHSM startup task is running but no thread found.") return False # now check again if the task is still running if self.is_running: # looks like we timed out log.debug("subscription: RHSM service not available after waiting for %f seconds.", timeout) return False else: # If we got this far, the task has finished running. If the result is True # it was able to successfully start the systemd unit and connect to the DBus API. # If the result is False, then the service failed to start. try: result = self.get_result() except NoResultError: # if the task fails in weird ways, there could apparently be no result log.error("subscription: got no result from StartRHSMTask") result = False return result
def wait_and_fetch_net_data(url, out_file, ca_certs=None): """ Function that waits for network connection and starts a thread that fetches data over network. :see: org_fedora_oscap.data_fetch.fetch_data :return: the name of the thread running fetch_data :rtype: str """ # get thread that tries to establish a network connection nm_conn_thread = threadMgr.get(constants.THREAD_WAIT_FOR_CONNECTING_NM) if nm_conn_thread: # NM still connecting, wait for it to finish nm_conn_thread.join() network_proxy = NETWORK.get_proxy() if not network_proxy.Connected(): raise OSCAPaddonNetworkError("Network connection needed to fetch data.") fetch_data_thread = AnacondaThread(name=THREAD_FETCH_DATA, target=fetch_data, args=(url, out_file, ca_certs), fatal=False) # register and run the thread threadMgr.add(fetch_data_thread) return THREAD_FETCH_DATA
def _check_discover(self, *args): if threadMgr.get(constants.THREAD_ISCSI_DISCOVER): return True # When iscsi discovery is done, update the UI. We don't need to worry # about the user escaping from the dialog because all the buttons are # marked insensitive. spinner = self.builder.get_object("waitSpinner") spinner.stop() if self._discoveryError: # Failure. Display some error message and leave the user on the # dialog to try again. self.builder.get_object("discoveryErrorLabel").set_text(self._discoveryError) self._discoveryError = None self._conditionNotebook.set_current_page(2) self._set_configure_sensitive(True) else: # Success. Now populate the node store and kick the user on over to # that subscreen. self._add_nodes(self._discoveredNodes) self._iscsiNotebook.set_current_page(1) # If some form of login credentials were used for discovery, # default to using the same for login. if self._authTypeCombo.get_active() != 0: self._loginAuthTypeCombo.set_active(3) # We always want to enable this button, in case the user's had enough. self._cancelButton.set_sensitive(True) return False
def ready(self): """The subscription spoke is ready once its initialization thread finishes. We do this to avoid the Subscription spoke being set mandatory in cases where the current installation source is the CDN, but payload refresh is still running and it might change to CDROM later one. We achieve this by waiting for tha payload refresh thread to finish in the Subscription spoke initialization thread. """ return not threadMgr.get(THREAD_SUBSCRIPTION_SPOKE_INIT)
def completed(self): processing_done = bool(not threadMgr.get(constants.THREAD_CHECK_SOFTWARE) and not threadMgr.get(constants.THREAD_PAYLOAD) and not self._error_msgs and self.txid_valid) # * we should always check processing_done before checking the other variables, # as they might be inconsistent until processing is finished # * we can't let the installation proceed until a valid environment has been set if processing_done: if self._selection.environment: # if we have environment it needs to be valid return self.is_environment_valid(self._selection.environment) # if we don't have environment we need to at least have the %packages # section in kickstart elif self._kickstarted: return True # no environment and no %packages section -> manual intervention is needed else: return False else: return False
def refresh(self): """Refresh location info.""" # check if a refresh is already in progress if threadMgr.get(constants.THREAD_GEOLOCATION_REFRESH): log.debug("Geoloc: refresh already in progress") else: # wait for Internet connectivity if network.wait_for_connectivity(): threadMgr.add( AnacondaThread(name=constants.THREAD_GEOLOCATION_REFRESH, target=self._provider.refresh)) else: log.error("Geolocation refresh failed" " - no connectivity")
def completed(self): processingDone = bool(not threadMgr.get(constants.THREAD_CHECK_SOFTWARE) and not threadMgr.get(constants.THREAD_PAYLOAD) and not self._errorMsgs and self.txid_valid) # * we should always check processingDone before checking the other variables, # as they might be inconsistent until processing is finished # * we can't let the installation proceed until a valid environment has been set if processingDone: if self.environment is not None: # if we have environment it needs to be valid return self.environment_valid # if we don't have environment we need to at least have the %packages # section in kickstart elif self._kickstarted: return True # no environment and no %packages section -> manual intervention is needed else: return False else: return False
def refresh(self): """Refresh location info.""" # check if a refresh is already in progress if threadMgr.get(constants.THREAD_GEOLOCATION_REFRESH): log.debug("Geoloc: refresh already in progress") else: # wait for Internet connectivity if network.wait_for_connectivity(): threadMgr.add(AnacondaThread( name=constants.THREAD_GEOLOCATION_REFRESH, target=self._provider.refresh)) else: log.error("Geolocation refresh failed" " - no connectivity")
def _initialize(self): # a bit hacky way, but should return the translated strings for i in range(1, 32): day = datetime.date(2000, 1, i).strftime(self._day_format) self.add_to_store_idx(self._daysStore, i, day) for i in range(1, 13): month = datetime.date(2000, i, 1).strftime(self._month_format) self.add_to_store_idx(self._monthsStore, i, month) for i in range(1990, 2051): year = datetime.date(i, 1, 1).strftime(self._year_format) self.add_to_store_idx(self._yearsStore, i, year) cities = set() xlated_regions = ((region, get_xlated_timezone(region)) for region in self._regions_zones.keys()) for region, xlated in sorted( xlated_regions, key=functools.cmp_to_key(_compare_regions)): self.add_to_store_xlated(self._regionsStore, region, xlated) for city in self._regions_zones[region]: cities.add((city, get_xlated_timezone(city))) for city, xlated in sorted(cities, key=functools.cmp_to_key(_compare_cities)): self.add_to_store_xlated(self._citiesStore, city, xlated) self._update_datetime_timer = None kickstart_timezone = self._timezone_module.proxy.Timezone if is_valid_timezone(kickstart_timezone): self._set_timezone(kickstart_timezone) elif not flags.flags.automatedInstall: log.warning( "%s is not a valid timezone, falling back to default (%s)", kickstart_timezone, DEFAULT_TZ) self._set_timezone(DEFAULT_TZ) self._timezone_module.proxy.SetTimezone(DEFAULT_TZ) time_init_thread = threadMgr.get(constants.THREAD_TIME_INIT) if time_init_thread is not None: hubQ.send_message(self.__class__.__name__, _("Restoring hardware time...")) threadMgr.wait(constants.THREAD_TIME_INIT) hubQ.send_ready(self.__class__.__name__, False) # report that we are done self.initialize_done()
def _initialize(self): # a bit hacky way, but should return the translated strings for i in range(1, 32): day = datetime.date(2000, 1, i).strftime(self._day_format) self.add_to_store_idx(self._daysStore, i, day) for i in range(1, 13): month = datetime.date(2000, i, 1).strftime(self._month_format) self.add_to_store_idx(self._monthsStore, i, month) for i in range(1990, 2051): year = datetime.date(i, 1, 1).strftime(self._year_format) self.add_to_store_idx(self._yearsStore, i, year) cities = set() xlated_regions = ((region, get_xlated_timezone(region)) for region in self._regions_zones.keys()) for region, xlated in sorted(xlated_regions, key=functools.cmp_to_key(_compare_regions)): self.add_to_store_xlated(self._regionsStore, region, xlated) for city in self._regions_zones[region]: cities.add((city, get_xlated_timezone(city))) for city, xlated in sorted(cities, key=functools.cmp_to_key(_compare_cities)): self.add_to_store_xlated(self._citiesStore, city, xlated) self._update_datetime_timer = None kickstart_timezone = self._timezone_module.proxy.Timezone if is_valid_timezone(kickstart_timezone): self._set_timezone(kickstart_timezone) elif not flags.flags.automatedInstall: log.warning("%s is not a valid timezone, falling back to default (%s)", kickstart_timezone, DEFAULT_TZ) self._set_timezone(DEFAULT_TZ) self._timezone_module.proxy.SetTimezone(DEFAULT_TZ) time_init_thread = threadMgr.get(constants.THREAD_TIME_INIT) if time_init_thread is not None: hubQ.send_message(self.__class__.__name__, _("Restoring hardware time...")) threadMgr.wait(constants.THREAD_TIME_INIT) hubQ.send_ready(self.__class__.__name__, False) # report that we are done self.initialize_done()
def _check_login(self, *args): if threadMgr.get(constants.THREAD_ISCSI_LOGIN): return True spinner = self.builder.get_object("loginSpinner") spinner.stop() spinner.hide() if self._loginError: self.builder.get_object("loginErrorLabel").set_text( self._loginError) self._loginError = None self._loginConditionNotebook.set_current_page(1) self._cancelButton.set_sensitive(True) self._loginButton.set_sensitive(True) else: anyLeft = False self._loginConditionNotebook.set_current_page(0) # Select the now-first target for the user in case they want to # log into another one. for row in self._store: if row[1]: row[0] = True anyLeft = True # And make the login button sensitive if there are any more # nodes to login to. self._loginButton.set_sensitive(True) break self._okButton.set_sensitive(True) # Once a node has been logged into, it doesn't make much sense to let # the user cancel. Cancel what, exactly? self._cancelButton.set_sensitive(False) if not anyLeft: self.window.response(1) self._set_login_sensitive(True) return False
def _check_login(self, *args): if threadMgr.get(constants.THREAD_ISCSI_LOGIN): return True spinner = self.builder.get_object("loginSpinner") spinner.stop() spinner.hide() if self._loginError: self.builder.get_object("loginErrorLabel").set_text(self._loginError) self._loginError = None self._loginConditionNotebook.set_current_page(1) self._cancelButton.set_sensitive(True) self._loginButton.set_sensitive(True) else: anyLeft = False self._loginConditionNotebook.set_current_page(0) # Select the now-first target for the user in case they want to # log into another one. for row in self._store: if row[1]: row[0] = True anyLeft = True # And make the login button sensitive if there are any more # nodes to login to. self._loginButton.set_sensitive(True) break self._okButton.set_sensitive(True) # Once a node has been logged into, it doesn't make much sense to let # the user cancel. Cancel what, exactly? self._cancelButton.set_sensitive(False) if not anyLeft: self.window.response(1) self._set_login_sensitive(True) return False
def one_time_sync_async(server, callback=None): """ Asynchronously synchronize the system time with a given NTP server. This function is non-blocking it starts a new thread for synchronization and returns. Use callback argument to specify the function called when the new thread finishes if needed. :param server: NTP server :param callback: callback function to run after sync or failure :type callback: a function taking one boolean argument (success) """ thread_name = "%s_%s" % (THREAD_SYNC_TIME_BASENAME, server) if threadMgr.get(thread_name): #syncing with the same server running return threadMgr.add(AnacondaThread(name=thread_name, target=one_time_sync, args=(server, callback)))
def _check_rescan(self, *args): if threadMgr.get(constants.THREAD_STORAGE): self._elapsed += 1 # If more than five seconds has elapsed since the rescan started, # give the user the option to return to the hub. if self._elapsed >= 5: self._notebook.set_current_page(2) return True # Seems a little silly to have this warning text still displayed # when everything is done. box = self.builder.get_object("warningBox") box.set_visible(False) self._cancel_button.set_sensitive(False) self._ok_button.set_sensitive(True) self._notebook.set_current_page(3) return False
def _software_is_ready(self): # FIXME: Would be nicer to just ask the spoke if it's ready. return (not threadMgr.get(constants.THREAD_PAYLOAD) and not threadMgr.get(constants.THREAD_SOFTWARE_WATCHER) and not threadMgr.get(constants.THREAD_CHECK_SOFTWARE) and self.payload.is_ready())
def ready(self): return self._ready and threadMgr.get(ADD_LAYOUTS_INITIALIZE_THREAD) is None
def ready(self): """ Check if the spoke is ready. """ return (self._ready and not threadMgr.get(THREAD_PAYLOAD) and not threadMgr.get(THREAD_CHECK_SOFTWARE))
def ready(self): return not threadMgr.get("AnaDateTimeThread")
def ready(self): # By default, the storage spoke is not ready. We have to wait until # storageInitialize is done. return self._ready and not threadMgr.get(THREAD_STORAGE_WATCHER)
def ready(self): return self._ready and threadMgr.get( ADD_LAYOUTS_INITIALIZE_THREAD) is None
def ready(self): """ If we're ready to move on. """ return (not threadMgr.get(THREAD_PAYLOAD) and not threadMgr.get(THREAD_CHECK_SOFTWARE) and not threadMgr.get(THREAD_SOFTWARE_WATCHER))
def _processing_data(self): """Is the spoke processing data?""" return threadMgr.get(THREAD_SOFTWARE_WATCHER) \ or threadMgr.get(THREAD_PAYLOAD) \ or threadMgr.get(THREAD_CHECK_SOFTWARE)