def test_empty_manage_repos_int_37(self): manage_repos_enabled = repofile.manage_repos_enabled() # Should fail, and return default of 1 self.assertEqual(manage_repos_enabled, True)
def __init__(self, cache_only=False, apply_overrides=True): self.identity = inj.require(inj.IDENTITY) # These should probably move closer their use self.ent_dir = inj.require(inj.ENT_DIR) self.prod_dir = inj.require(inj.PROD_DIR) self.ent_source = ent_cert.EntitlementDirEntitlementSource() self.cp_provider = inj.require(inj.CP_PROVIDER) self.uep = self.cp_provider.get_consumer_auth_cp() self.manage_repos = 1 self.apply_overrides = apply_overrides self.manage_repos = manage_repos_enabled() self.release = None self.overrides = {} self.override_supported = False try: self.override_supported = bool( self.identity.is_valid() and self.uep and self.uep.supports_resource('content_overrides')) except (socket.error, connection.ConnectionException) as e: # swallow the error to fix bz 1298327 log.exception(e) pass self.written_overrides = WrittenOverrideCache() # FIXME: empty report at the moment, should be changed to include # info about updated repos self.report = RepoActionReport() self.report.name = "Repo updates" # If we are not registered, skip trying to refresh the # data from the server if not self.identity.is_valid(): return # NOTE: if anything in the RepoActionInvoker init blocks, and it # could, yum could still block. The closest thing to an # event loop we have is the while True: sleep() in lock.py:Lock.acquire() # Only attempt to update the overrides if they are supported # by the server. if self.override_supported: self.written_overrides.read_cache_only() try: override_cache = inj.require(inj.OVERRIDE_STATUS_CACHE) except KeyError: override_cache = OverrideStatusCache() if cache_only: status = override_cache.read_cache_only() else: status = override_cache.load_status(self.uep, self.identity.uuid) for item in status or []: # Don't iterate through the list if item['contentLabel'] not in self.overrides: self.overrides[item['contentLabel']] = {} self.overrides[item['contentLabel']][ item['name']] = item['value']
def test_empty_manage_repos(self): manage_repos_enabled = repofile.manage_repos_enabled() self.assertEqual(manage_repos_enabled, True)
def test_empty_manage_repos_zero(self): manage_repos_enabled = repofile.manage_repos_enabled() self.assertEqual(manage_repos_enabled, False)
def test(self): # default stub config, no manage_repo defined, uses default manage_repos_enabled = repofile.manage_repos_enabled() self.assertEqual(manage_repos_enabled, True)
def __init__(self, cache_only=False, apply_overrides=True): log.debug("Updating repo triggered with following attributes: cache_only=%s, apply_overrides=%s" % (str(cache_only), str(apply_overrides))) self.identity = inj.require(inj.IDENTITY) # These should probably move closer their use self.ent_dir = inj.require(inj.ENT_DIR) self.prod_dir = inj.require(inj.PROD_DIR) self.ent_source = ent_cert.EntitlementDirEntitlementSource() self.cp_provider = inj.require(inj.CP_PROVIDER) self.manage_repos = 1 self.apply_overrides = apply_overrides self.manage_repos = manage_repos_enabled() self.release = None self.overrides = {} self.override_supported = False if not cache_only: self.uep = self.cp_provider.get_consumer_auth_cp() else: self.uep = None if self.identity.is_valid(): supported_resources = ServerCache.get_supported_resources(self.identity.uuid, self.uep) self.override_supported = 'content_overrides' in supported_resources self.written_overrides = WrittenOverrideCache() # FIXME: empty report at the moment, should be changed to include # info about updated repos self.report = RepoActionReport() self.report.name = "Repo updates" # If we are not registered, skip trying to refresh the # data from the server if not self.identity.is_valid(): log.debug("The system is not registered. Skipping refreshing data from server.") return # NOTE: if anything in the RepoActionInvoker init blocks, and it # could, yum could still block. The closest thing to an # event loop we have is the while True: sleep() in lock.py:Lock.acquire() # Only attempt to update the overrides if they are supported # by the server. if self.override_supported: self.written_overrides.read_cache_only() try: override_cache = inj.require(inj.OVERRIDE_STATUS_CACHE) except KeyError: override_cache = OverrideStatusCache() if cache_only: status = override_cache.read_cache_only() else: status = override_cache.load_status(self.uep, self.identity.uuid) for item in status or []: # Don't iterate through the list if item['contentLabel'] not in self.overrides: self.overrides[item['contentLabel']] = {} self.overrides[item['contentLabel']][item['name']] = item['value']
def _do_command(self): self._validate_options() # Abort if not registered self.assert_should_be_registered() supported_resources = get_supported_resources() if "content_overrides" not in supported_resources: system_exit( os.EX_UNAVAILABLE, _("Error: The 'repo-override' command is not supported by the server." )) # update entitlement certificates if necessary. If we do have new entitlements # CertLib.update() will call RepoActionInvoker.update(). self.entcertlib.update() # make sure the EntitlementDirectory singleton is refreshed self._request_validity_check() overrides = Overrides() if not manage_repos_enabled(): print(_("Repositories disabled by configuration.")) if self.options.list: results = overrides.get_overrides(self.identity.uuid) if results: self._list(results, self.options.repos) else: print( _("This system does not have any content overrides applied to it." )) return if self.options.additions: repo_ids = [ repo.id for repo in overrides.repo_lib.get_repos(apply_overrides=False) ] to_add = [ Override(repo, name, value) for repo in self.options.repos for name, value in list(self.options.additions.items()) ] try: results = overrides.add_overrides(self.identity.uuid, to_add) except connection.RestlibException as ex: if ex.code == 400: # blocklisted overrides specified. # Print message and return a less severe code. mapped_message: str = ExceptionMapper().get_message(ex) system_exit(1, mapped_message) else: raise ex # Print out warning messages if the specified repo does not exist in the repo file. for repo in self.options.repos: if repo not in repo_ids: print( _("Repository '{repo}' does not currently exist, but the override has been added." ).format(repo=repo)) if self.options.removals: to_remove = [ Override(repo, item) for repo in self.options.repos for item in self.options.removals ] results = overrides.remove_overrides(self.identity.uuid, to_remove) if self.options.remove_all: results = overrides.remove_all_overrides(self.identity.uuid, self.options.repos) # Update the cache and refresh the repo file. overrides.update(results)
def _do_command(self): self._reconcile_list_options() rc = 0 if not manage_repos_enabled(): print(_("Repositories disabled by configuration.")) return rc # Pull down any new entitlements and refresh the entitlements directory if self.identity.is_valid(): cert_action_client = ActionClient(skips=[PackageProfileActionInvoker]) cert_action_client.update() self._request_validity_check() if self.is_registered(): supported_resources = get_supported_resources() self.use_overrides = "content_overrides" in supported_resources else: self.use_overrides = False # specifically, yum repos, for now. rl = RepoActionInvoker() repos = rl.get_repos() if self.options.repo_actions is not None: rc = self._set_repo_status(repos, rl, self.options.repo_actions) if self.identity.is_valid(): profile_action_client = ProfileActionClient() profile_action_client.update() if self.list: if len(repos): # TODO: Perhaps this should be abstracted out as well...? def filter_repos(repo): disabled_values = ["false", "0"] repo_enabled = repo["enabled"].lower() show_enabled = self.list_enabled and repo_enabled not in disabled_values show_disabled = self.list_disabled and repo_enabled in disabled_values return show_enabled or show_disabled repos = list(filter(filter_repos, repos)) if len(repos): print("+----------------------------------------------------------+") print(_(" Available Repositories in {file}").format(file=rl.get_repo_file())) print("+----------------------------------------------------------+") for repo in repos: print( columnize( REPOS_LIST, echo_columnize_callback, repo.id, repo["name"], repo["baseurl"], repo["enabled"], ) + "\n" ) else: print(_("There were no available repositories matching the specified criteria.")) else: print(_("This system has no repositories available through subscriptions.")) return rc
def __init__(self, cache_only=False, apply_overrides=True): log.debug( "Updating repo triggered with following attributes: cache_only=%s, apply_overrides=%s" % (str(cache_only), str(apply_overrides))) self.identity = inj.require(inj.IDENTITY) # These should probably move closer their use self.ent_dir = inj.require(inj.ENT_DIR) self.prod_dir = inj.require(inj.PROD_DIR) self.ent_source = ent_cert.EntitlementDirEntitlementSource() self.cp_provider = inj.require(inj.CP_PROVIDER) self.manage_repos = 1 self.apply_overrides = apply_overrides self.manage_repos = manage_repos_enabled() self.release = None self.overrides = {} self.override_supported = False if not cache_only: self.uep = self.cp_provider.get_consumer_auth_cp() else: self.uep = None if self.identity.is_valid(): supported_resources = ServerCache.get_supported_resources( self.identity.uuid, self.uep) self.override_supported = 'content_overrides' in supported_resources self.written_overrides = WrittenOverrideCache() # FIXME: empty report at the moment, should be changed to include # info about updated repos self.report = RepoActionReport() self.report.name = "Repo updates" # If we are not registered, skip trying to refresh the # data from the server if not self.identity.is_valid(): log.debug( "The system is not registered. Skipping refreshing data from server." ) return # NOTE: if anything in the RepoActionInvoker init blocks, and it # could, yum could still block. The closest thing to an # event loop we have is the while True: sleep() in lock.py:Lock.acquire() # Only attempt to update the overrides if they are supported # by the server. if self.override_supported: self.written_overrides.read_cache_only() try: override_cache = inj.require(inj.OVERRIDE_STATUS_CACHE) except KeyError: override_cache = OverrideStatusCache() if cache_only: status = override_cache.read_cache_only() else: status = override_cache.load_status(self.uep, self.identity.uuid) for item in status or []: # Don't iterate through the list if item['contentLabel'] not in self.overrides: self.overrides[item['contentLabel']] = {} self.overrides[item['contentLabel']][ item['name']] = item['value']