def regen_channel_db(channels=(), clean_db=False): """Inserts into the database the taskomatic jobs. requires to be run on the satellite or import will fail""" global satver global rhnConfig global rhnSQL global rhnChannel 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: print "satellite version %s, switching to api" % (satver) key = session_init("baseorg", {}) regen_channel(key, True, label) print "channel " + label + " has been queued for regeneration" rhnSQL.commit() #moving needed cache cleaning to another option print "Finished queueing the new jobs into the database" print "Restart taskomatic and schedule the 'channel-repodata-bunch' task once to continue" print "Clear the needed cache if your systems display incorrect update counts afterwards (option --cleancache)"
def regen_channel_db(channels=(), clean_db=False): """Inserts into the database the taskomatic jobs. requires to be run on the satellite or import will fail""" global satver; global rhnConfig global rhnSQL global rhnChannel 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: print "satellite version %s, switching to api" % (satver) key = session_init("baseorg", {}) regen_channel(key, True, label) print "channel "+label+" has been queued for regeneration" rhnSQL.commit(); #moving needed cache cleaning to another option print "Finished queueing the new jobs into the database" print "Restart taskomatic and schedule the 'channel-repodata-bunch' task once to continue" print "Clear the needed cache if your systems display incorrect update counts afterwards (option --cleancache)"
def select_channels_db(): """returns all the channels that have a checksum type""" global rhnConfig global rhnSQL global rhnChannel h = rhnSQL.prepare("SELECT label FROM rhnchannel WHERE checksum_type_id IS NOT NULL") h.execute() channels = [] for entry in h.fetchall_dict(): channels.append(entry['label']) return channels
def select_channels_db(): """returns all the channels that have a checksum type""" global rhnConfig global rhnSQL global rhnChannel h = rhnSQL.prepare( "SELECT label FROM rhnchannel WHERE checksum_type_id IS NOT NULL") h.execute() channels = [] for entry in h.fetchall_dict(): channels.append(entry['label']) return channels
def main(): setup_db() print "=================" print "Updating Symbolic Links" q = """select cr.id as rev_id, ccon.id as content_id, ccon.contents, cr.CONFIG_INFO_ID as info_id, cf.id as file_id, cc.org_id, wc.name as org_name, ci.SELINUX_CTX as selinux, cfn.path as path, ci.SYMLINK_TARGET_FILENAME_ID as info_target, nvl( (select path from rhnCOnfigFileName where id = ci.SYMLINK_TARGET_FILENAME_ID), 'None') as name_target from rhnConfigContent ccon inner join rhnConfigRevision cr on cr.config_content_id = ccon.id inner join rhnConfigFile cf on cr.CONFIG_FILE_ID = cf.id inner join rhnConfigFileName cfn on cfn.id = cf.config_file_name_id inner join rhnConfigInfo ci on ci.id = cr.CONFIG_INFO_ID inner join rhnConfigChannel cc on cf.CONFIG_CHANNEL_ID = cc.id inner join web_customer wc on cc.org_id = wc.id where cr.CONFIG_FILE_TYPE_ID in (select id from rhnConfigFileType where label='symlink')""" h = rhnSQL.prepare(q) h.execute() results = h.fetchall_dict() if not results: print "Update completed." print "=================" return contents = [] for row in results: contents.append( dict(revision_id = row["rev_id"], file_id = row ["file_id"], info_id = row ["info_id"], content_id = row ["content_id"], path = row['path'], info_target = row['info_target'], name_target = row['name_target'], selinux = row['selinux'], org_id = row['org_id'], org_name = row['org_name'], symlink_target = rhnSQL.read_lob(row["contents"]))) update_query = """update rhnConfigRevision set config_info_id = lookup_config_info(null, null, null, :selinux, lookup_config_filename(:symlink_target)) where id = :revision_id""" null_symlink_update_query = """update rhnConfigRevision set config_info_id = lookup_config_info(null, null, null, :selinux, null) where id = :revision_id""" update_cr = """ update rhnConfigRevision set config_content_id = null where id = :revision_id""" delete_content = """ delete from rhnConfigContent where id = :content_id""" format = """ Path: [%(path)s] Symbolic link:[%(symlink_target)s] Update URL: https://<FQDN>/rhn/configuration/file/FileDetails.do?cfid=%(file_id)d&crid=%(revision_id)d Organization Id : [%(org_id)d] Organization Name : [%(org_name)s] """ bad_items = list() for item in contents: if item['symlink_target'] is None: bad_items.append(item) rhnSQL.prepare(null_symlink_update_query).execute(**item) else: if not isabs(item['symlink_target']) or len(item['symlink_target']) >= 1024: bad_items.append(item) item['symlink_target'] = item['symlink_target'][:1024] rhnSQL.prepare(update_query).execute(**item) rhnSQL.prepare(update_cr).execute(**item) rhnSQL.prepare(delete_content).execute(**item) print format % item rhnSQL.commit() rhnSQL.closeDB() print "%d rows updated." % len(contents) print "Update completed" print "=================" msg = """ The following symbolic link paths are either null or not absolute or above 1024 characters in length. While entries have been added in the DB, the values have to be updated for them in the Web UI. Please go to the provided url, logging in as a user with config admin/org admin role in the specified organization and update the target path value accordingly. """ if bad_items: print msg for item in bad_items: print format % item
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