Beispiel #1
0
def setup_db():
    initCFG('server.satellite')
    db_backend = CFG.DB_BACKEND
    db_host = CFG.DB_HOST
    db_port = CFG.DB_PORT
    db_user = CFG.DB_user
    db_password = CFG.DB_PASSWORD
    database = CFG.DB_NAME
    rhnSQL.initDB(backend=db_backend, host=db_host, port=db_port,
                        username=db_user, password=db_password, database=database)
def db_init():
    """initializes the db connection"""
    #global access - not a good idea but that'll have to do for now.
    global rhnSQL
    global rhnChannel
    global rhnConfig
    global satver
    import sys
    sys.path.append('/usr/share/rhn/')
    #TODO: replace this by a file read test
    #TODO: use the taskomatic module instead to do the db operation
    try:
        #import server.repomd.repository as repository
        import server.rhnChannel as rhnChannel
        import common.rhnConfig as rhnConfig
        import server.rhnSQL as rhnSQL
    except ImportError:
        # this changed for 5.5
        import spacewalk.server.rhnChannel as rhnChannel
        import spacewalk.common.rhnConfig as rhnConfig
        import spacewalk.server.rhnSQL as rhnSQL
    rhnConfig.initCFG("web")
    rhnSQL.initDB()
    satver = rhnConfig.CFG.VERSION
def db_init():
    """initializes the db connection"""
    #global access - not a good idea but that'll have to do for now.
    global rhnSQL;
    global rhnChannel;
    global rhnConfig;
    global satver;
    import sys
    sys.path.append('/usr/share/rhn/')
    #TODO: replace this by a file read test
    #TODO: use the taskomatic module instead to do the db operation
    try:
        #import server.repomd.repository as repository
        import server.rhnChannel as rhnChannel
        import common.rhnConfig as rhnConfig
        import server.rhnSQL as rhnSQL
    except ImportError:
        # this changed for 5.5
        import spacewalk.server.rhnChannel as rhnChannel
        import spacewalk.common.rhnConfig as rhnConfig
        import spacewalk.server.rhnSQL as rhnSQL
    rhnConfig.initCFG("web")
    rhnSQL.initDB()
    satver = rhnConfig.CFG.VERSION
def regen_channel_db(key,channels=(), clean_db=False):
    """Inserts into the database the taskomatic jobs. requires to be run on the satellite or import will fail"""
    global satver;
    import sys
    sys.path.append('/usr/share/rhn/')
    #TODO: replace this by a file read test
    #TODO: use the taskomatic module instead to do the db operation
    try:
        #import server.repomd.repository as repository
        import server.rhnChannel as rhnChannel
        import common.rhnConfig as rhnConfig
        import server.rhnSQL as rhnSQL
    except ImportError:
        # this changed for 5.5
        import spacewalk.server.rhnChannel as rhnChannel
        import spacewalk.common.rhnConfig as rhnConfig
        import spacewalk.server.rhnSQL as rhnSQL

    rhnConfig.initCFG()
    rhnSQL.initDB()
    try:
        backend = rhnConfig.CFG.DB_BACKEND
    except:
        backend = 'oracle'
    if clean_db:
        h = rhnSQL.prepare("DELETE FROM rhnRepoRegenQueue")
        h.execute()
        rhnSQL.commit();
        #this part should only run on 5.4.0 versions (it will fail on others)
    #only execute g if need to be cleaned and on 5.4.0 minimum
    g = rhnSQL.prepare("DELETE FROM rhnPackageRepodata WHERE package_id IN (SELECT  a.package_id FROM rhnChannelPackage a, rhnChannel b WHERE a.channel_id = b.id AND b.label like :channel)")
    #this should choose the sql to use between either postgresql or oracle. problem is the way to use sequences changes from one another
    if backend != 'postgresql':
        h = rhnSQL.prepare("INSERT INTO rhnRepoRegenQueue (id, CHANNEL_LABEL, REASON, BYPASS_FILTERS, FORCE) VALUES (rhn_repo_regen_queue_id_seq.nextval, :channel , 'repodata regeneration script','Y', 'Y')")
    else:
        h = rhnSQL.prepare("INSERT INTO rhnRepoRegenQueue (id, CHANNEL_LABEL, REASON, BYPASS_FILTERS, FORCE) VALUES (nextval('rhn_repo_regen_queue_id_seq'), :channel , 'repodata regeneration script','Y', 'Y')")
    if satver in ('5.4.0','5.4.1', '5.5.0', '5.6.0'):
        #this is a satellite of at least version 5.4.0, 5.5.0 or 5.6.0
        for label in channels:
            if clean_db:
                g.execute(channel=label) 
                status = "channel "+label+" has been queued for regeneration, previous repodata were cleaned from the database"
            else:
                status =  "channel "+label+" has been queued for regeneration"
            h.execute(channel=label)
            print status
    elif satver in ('5.3.0', None):
        #satellite 5.3.0 and older
        for label in channels:
            h.execute(channel=label)
            print "channel "+label+" has been queued for regeneration"
    else:
        #satellite after 5.6.0
        #default action : use the api instead. this should be hit when satellite 5.x isn't tested and on test it should have its own version added to either the first function or a new function be created.
        for label in channels:
            regen_channel(key,True,label)
            print "channel "+label+" has been queued for regeneration"
    rhnSQL.commit();
    #now clean the needed cache to make sure all systems see their updates properly
    try:
        client.channel.software.regenerateNeededCache(key)
        print "The needed cache has been regenerated for all systems"
    except:
        sys.stderr.write("an exception occured durring the regenerateNeededCache call!")
        raise 
    pass