rpm-software-management / yum

[DEPRECATED] YUM package manager
GNU General Public License v2.0
125 stars 85 forks source link

"Repository listed more than once" when also using Spacewalk (RHN) #50

Closed wschaft closed 6 years ago

wschaft commented 7 years ago

When the yum library is called on a server with both RHN (Spacewalk in my case) and local repository files configured, it outputs that some repositories more than once:

python -c 'import yum ; yb = yum.YumBase() ; print [(r.id + "=" + str(r.gpgcheck)) for r in yb.repos.listEnabled()]' | grep "^\[" | tr -d '[] ' | tr -d "'" | sed 's/,/ /g'
Repository dell-system-update_independent is listed more than once in the configuration
Repository dell-system-update_dependent is listed more than once in the configuration
Repository dell-omsa-indep is listed more than once in the configuration
Repository dell-omsa-specific is listed more than once in the configuration
centos7=False centos_7-repos=False dell-system-update_dependent=False dell-system-update_independent=False epel_7=False spacewalk_client-el7=False zabbix-el7=False

This isn't the case when the yum command itself is executed. Maybe the output is filtered out?

The Dell repositories are locally configured, the rest if coming from Spacewalk.

This happens on both CentOS 6 and 7. Version of the yum-rhn-plugin: yum-rhn-plugin-2.5.5-1

dmnks commented 6 years ago

Hi,

This turned out pretty confusing, but here's the culprit: yb.getReposFromConfig() is invoked twice in your script. What happens is, when

1) yb.repos is touched, it calls 2) yb._getRepos() which touches 3) yb.conf which goes to the init hook of yum-rhn-plugin which touches 4) yb.repos itself which calls 5) yb._getRepos() again which touches 6) yb.conf again (this time it only returns the already initialized yb._conf) which calls 7) yb.getReposFromConfig(), reading in all the repo config files.

Later, when execution returns to the topmost stack frame, the _getRepos() function continues past the just returned yb.conf to getReposFromConfig() again, which causes the error messages.

Luckily, this is trivial to resolve: you have to touch yb.conf first, before yb.repos, so that the latter yb.repos doesn't get into the same recursion that caused the double repo configuration. So the fixed script looks like this: python -c 'import yum ; yb = yum.YumBase() ; yb.conf ; print [(r.id + "=" + str(r.gpgcheck)) for r in yb.repos.listEnabled()]' | grep "^\[" | tr -d '[] ' | tr -d "'" | sed 's/,/ /g'

BTW, this is also why this doesn't happen if you run the yum binary; the code path is different, with the conf object being touched first.