[Yum-devel] [Yum] prereposetup_hook() vs. checkEnabledRepo()

Miroslav Suchý msuchy at redhat.com
Thu Apr 28 12:48:08 UTC 2011


On 04/27/2011 07:01 PM, James Antill wrote:
> Miroslav Suchý <msuchy at redhat.com> writes:
> 
>> I have interested situation with yum-rhn-plugin:
> 
>  FYI. you probably want the yum-devel ML.

True... Continuing on yum-devel only.

> 
>> In yum-rhn-plugin in init_hook we look for cached information of
>> channels and create dummy repos pointing to conduit.getConf().cachedir
>>
>> In prereposetup_hook we connect to Spacewalk/Satellite and replace those
>> dummy repos with repos pointing to channels on Spacewalk/Satellite.
>>
>> So far so good.
>>
>> But when you have only rhnplugin and no other repo and you do:
>>  rm -rf /var/cache/yum/*
>>  yum update # or any other command
>> I get:
>>  There are no enabled repos.
>>  Run "yum repolist all" to see the repos you have.
>>
>> This is because we have no cached repo (we deleted it, but same
>> situation will be just after kickstart) and the function
>> checkEnabledRepo() is called before prereposetup_hook.
>>
>> My question is: what is semantics of prereposetup_hook? Is it intended
>> to setup the repo, or just to configure them?
>>
>> In documentation is stated:
>> prereposetup
>>     Called just before Yum initialises its repository information.
>>
>> I tend to think that checkEnabledRepo() should be called *after*
>> prereposetup...
> 
>  This is probably just confusing terminology, and movements within
> core to do as little as possible until absolutely required. Plus
> RHNplugin's kind of unusual requirements :)

Yeah, rhnplugin is taking it to the edge :) But having one liner
documentation for every plugin is IMHO not enough.
I would very welcome if you can enhance:
  http://yum.baseurl.org/wiki/WritingYumPlugins#SlotsandHooks
And define which variable are defined in each stage and what is expected
from each plugin to do.
And how many time it is called :) For example I find very confusing that
prereposetup hook is called twice during groupinstall. Once during Sack
setup and second during Groups setup.


>  There are multiple stages for a "normal" repo:
> 
> 1. Existing on disk, but yum hasn't loaded anything.
> 
> 2. Loaded from disk. At his point it's in yb.repos has all it's
> configuration etc. (is enabled/disabled).
> 
> 3. "Activated", so that repomd.xml for the repo. is now valid etc.
> 
> ... prereposetup/postreposetup are done around #3, and a number of
> things (like checkEnabledRepo()) don't need that level of info. ... so
> just ask for #2 (basically calling yb.repos calls _getRepos() and gets
> you #2).
> 
>  I'm pretty sure you want to convert to "real" repos. at #3 time
> (aka. prereposetup). 
Yeah, we convert it in prereposetup, but checkEnabledRepo (introduced in
commit 169a9787 for BZ 620802) is called before this step.
checkEnabledRepo() is called in doCheck() which is called at the end of
parseCommands().
I really do not think it is best place. I would love to see this check
after prereposetup hook.

>  Other stuff, like auto-update-debuginfo, use prereposetup ... which
> is somewhat wrong, but they are pretty much guaranteed to have other
> repos. around to fake out the code between #2 and #3.
> to work around it would be to always add a fake "rhn" repo. ... this
> might be considered horrible though :).

I tried it. It looked promising (beside it ugliness :)), but the problem
is when you have no base channel (i.e. no repo at all) it will try to
use the dummy repo.

I put at the end of init_hook():

    if not repos.listEnabled():
       repo = YumRepository('dummy-yum-rhn-pluggin')
        repo.basecachedir = cachedir
        repo.name = 'Dummy yum-rhn-pluggin repository'
        repo.enable()
        repos.add(repo)

and at the beggining of prereposetup_hook() I put:

    repos = conduit.getRepos()
    if repos.findRepos('dummy-yum-rhn-pluggin'):
        repos.delete('dummy-yum-rhn-pluggin')

and when I have no channel (even not base) I got:
Error: Cannot retrieve repository metadata (repomd.xml) for repository:
dummy-yum-rhn-pluggin. Please verify its path and try again

Which is strange because I delete this repo at very beggining of
prereposetup_hook - and yes that code is called and the repo is indeed
removed. So I'm confused why yum use it later after this part of code..?

-- 
Miroslav Suchy
Red Hat Satellite Engineering


More information about the Yum-devel mailing list