yum repos has a delete() function. But it doesn't clear the cache.

yum also has a cache it uses for listEnabled(), but the cache isn't
invalidated when a repo is deleted it any following metadata update
will fail because it is still using the deleted repo.

We are forced to use the heavy hammer on a yum private variable yet
again to force the cache to be cleared so that it won't crash.
This commit is contained in:
Brian C. Lane 2018-06-01 16:43:15 -07:00
parent 2e95b56508
commit a5eaebeefc
1 changed files with 7 additions and 1 deletions

View File

@ -1478,10 +1478,13 @@ def v0_api(api):
# Cleanup the mess, if loading it failed we don't want to leave it in memory
with api.config["YUMLOCK"].lock:
yb = api.config["YUMLOCK"].yb
repos = list(r.id for r in yb.repos.listEnabled())
log.info("BCL: repos = %s", repos)
if source["name"] in repos:
yb = api.config["YUMLOCK"].yb
yb.repos.delete(source["name"])
# delete doesn't remove it from the cache used by listEnabled so we have to force it
yb.repos._cache_enabled_repos = None
log.info("Updating repository metadata after adding %s failed", source["name"])
update_metadata(yb)
@ -1508,6 +1511,9 @@ def v0_api(api):
repos = list(r.id for r in yb.repos.listEnabled())
if source_name in repos:
yb.repos.delete(source_name)
# delete doesn't remove it from the cache used by listEnabled so we have to force it
yb.repos._cache_enabled_repos = None
log.info("Updating repository metadata after removing %s", source_name)
update_metadata(yb)