[Yum-devel] [RFC] hardware specific repo + disable repo if 404

Michael E Brown Michael_E_Brown at dell.com
Tue Mar 27 22:01:53 UTC 2007


All,
    I am looking for feedback on the code below. Thanks.

    I am writing a yum plugin that will set up a hardware-specific yum
repo. Basically, this is just a repo with a baseurl or mirrorlist like
this: 
    baseurl=http://linux.dell.com/repo/hardware/system-$dellsysid

    The problem I have is that I will not have a repo for each and every
Dell system ever made... some system ids will come back as http 404.
This is not an error in this case because everything is just fine. But,
yum considers this an error and will not continue.

    My proposed solution to this is to have the following option in the
*.repo file:
    disable_if_404={1,0}

    Then, in my plugin, I wrap the _loadRepoXML() method and call
.disable() if it throws an exception. The current code is below.
Everything appears to work just fine with one minor output detail that I
want to fix.

1) Does anybody have any objections to doing it this way? Is this the
best way to do this?

2) How do I supress the urlgrabber error output? I still get the
following error output even though everything appears to complete
successfully:

----======----
http://linux.dell.com/yum/hardware/system-MAGIC/repodata/repomd.xml:
[Errno 14] HTTP Error 404: Date: Tue, 27 Mar 2007 21:46:14 GMT
Server: Apache
Content-Length: 243
Content-Type: text/html; charset=iso-8859-1

Trying other mirror.
----======----


=============================================
def init_hook(conduit):
    """ 
    Plugin initialization hook.
    """

    conf = conduit.getConf()
    conf.yumvar["dellsysid"] = "MAGIC"   # replaced by a lib call in my production version...

    repos = conduit.getRepos()
    for repo in repos.findRepos('*'):
        repo.yumvar.update(conf.yumvar)


    #Here we check all of the repos for "disable_if_404" option. For all
    # that have this option, we set up an alternate .check() function
    # that just disables the repo instead of erroring out.
    import new
    import yum.yumRepo
    import yum.Errors
    def wrapLoad(self, text=None):
        try:
            self.old_loadRepoXML(text)
        except  yum.Errors.RepoError, e:
            self.disable()
            pass # dont propogate exception upwards

    for repo in repos.listEnabled():
        try:
            if repo.cfg.has_option(repo.id, "disable_if_404"):
                di4 = repo.cfg.get(repo.id, "disable_if_404")
                if di4:
                    repo.old_loadRepoXML = repo._loadRepoXML
                    repo._loadRepoXML = new.instancemethod(wrapLoad, repo, yum.yumRepo.YumRepository)
        except AttributeError:
            continue
=============================================



More information about the Yum-devel mailing list