All,

    I have developed the attached, rather small, yum plugin that I
intend to distribute as part of firmware-tools. I would like some review
on this before I start enabling it to ensure that it is completely sane
and using the yum api's properly.

Description:
    Firmware-tools is a package meant to provide infrastructure to do
firmware upgrades. It needs to have a set of machine and
hardware-dependent RPMs installed representing the firmware for that
hardware.

    I use a 'bootstrap' process currently to figure out the list of
firmware RPMs to install. This consists of converting the local
machine's lspci output to a standardized RPM virtual provides name, and
then searching the yum repos for RPMs with that virtual provides. The
current way this is done is like: "yum install $(bootstrap_firmware)",
where bootstrap_firmware is the command that creates the virtual
provides names.

    The intent of this yum plugin is to eliminate this bootstrap as a
separate step. The intent is that whenever the user does a yum upgrade,
that if there are any new firmware packages in the repository that were
not previously on their system, they will get automatically
bootstrapped.

Questions:
  -- I currently use exclude_hook as that seems to run about where I
need. The only other hook that runs about when I want is the
postreposetup_hook.

  -- will this work with yum 2.4 as distributed in Centos 4? I dont have
a test machine handy and need to support back to yum 2.4.

  -- The plugin can be tested with mock input by setting the
DEBUG_BOOTSTRAP environment variable before running yum, and can provide
tracing by setting the DEBUG environment variable. Is this acceptable?
--
Michael

# vim:tw=0:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:
"""
Yum plugin to automatically bootstrap packages.

The purpose of this plugin is to automatically always add firmware-tools
bootstrap to the yum transaction. Before this was done by an explicit added
step. The instructions used to say:

# yum install $(bootstrap_firmware)

Normal bootstrap_firmware output looks like this:

# bootstrap_firmware 
pci_firmware(ven_0x10de_dev_0x00e1)
pci_firmware(ven_0x10de_dev_0x00e0_subven_0x10de_subdev_0x0c11)
pci_firmware(ven_0x10de_dev_0x00e4_subven_0x10de_subdev_0x0c11)
pci_firmware(ven_0x10de_dev_0x00e7_subven_0x10de_subdev_0x0c11)
... cut ...

The yum install command would effectively look up each pci_firmware(...) line
and look for RPM packages that had "Provides:" tags for the corresponding
firmware.

The purpose of this plugin is to remove that additional step. Now anytime the
user says "yum upgrade", they will automatically get the latest bootstrap
packages installed on their system.
"""

from yum.plugins import TYPE_CORE
import yum.Errors

version="1.5.7"
requires_api_version = '2.1'
plugin_type = TYPE_CORE

import ConfigParser
import os
import sys

global firmwaretools
import firmwaretools.clifuncs
import firmwaretools.trace_decorator as trace_decorator

if os.environ.get('DEBUG_BOOTSTRAP') == "1":
    # provide a made-up set of bootstrap packages rather than real one.
    # useful for testing.
    import firmwaretools.mockpackage

if os.environ.get('DEBUG'):
    # activate function tracing
    trace_decorator.debug["__main__"] = 9

def exclude_hook(conduit):
    ini = ConfigParser.ConfigParser()
    firmwaretools.clifuncs.getConfig(ini, 
firmwaretools.clifuncs.configLocations)
    for pkg in firmwaretools.clifuncs.runBootstrapInventory(ini):
        # see if it is a normal package name
        try:
            conduit._base.install(name=pkg.name)
            continue
        except yum.Errors.InstallError, e:
            pass

        # isnt a straight name, need to see if it is a dep
        try:
            mypkg = conduit._base.returnPackageByDep(pkg.name)
            conduit._base.install(mypkg)
        except yum.Errors.YumBaseError, e:
            pass

# this decorates all functions in this module to provide tracing if it is 
enabled.
trace_decorator.decorateAllFunctions(sys.modules[__name__])
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel

Reply via email to