Example #1
0
def initialize_verify_db(binfo, config=None):
    if not config:
        import uConfig
        config = uConfig.Config()

    progress.do("initializing verify DB")
    config_v = copy.copy(config)
    config_v.database_name = config_v.database_name + '_verify'
    try:
        _cleanup_verify_db(config_v)
    except:
        _recreate_verify_db(config_v)

    progress.done()

    progress.do("migrating verify DB")
    j = binfo.jboss_components
    import imp
    migrateDB = imp.load_source(
        'migrateDB', os.path.join(j.pau_db_migration, 'migrateDB.py'))
    migrateDB.migrate(j.pau_db_migration, migrateDB.INITIAL_VERSION,
                      config_v.database_host, config_v.database_name,
                      config_v.dsn_login, config_v.dsn_passwd)
    progress.done()

    return config_v
Example #2
0
def readTablesFromDB(con):
    progress.do("gathering real database schema")
    tablist = uDBSchema.getTableList(con)
    tables = dict()
    for tname in tablist:
        tables[tname] = uDBSchema.getTable(tname, con)

    progress.done()

    return tables
Example #3
0
def readTablesFromManifestFiles(build_info):
    progress.do("gathering schema information from manifests (from files)")

    manifest_tables = dict()
    for build in build_info.builds:
        for pkg, built_pkg in build.contents.iteritems():
            if isinstance(built_pkg, BuiltPackage):
                xml_text = uManifestParser.unsign_package(
                    built_pkg.manifest_file)
                for table in uPDLDBSchema.getSchemaFromString(xml_text):
                    manifest_tables[table.name] = table

    progress.done()

    return manifest_tables
Example #4
0
def repairDatabase(config, binfo):
    config_v = initialize_verify_db(binfo, config)

    uSysDB.init(config_v)
    con_v = uSysDB.connect()

    uSysDB.init(config)
    con = uSysDB.connect()

    manifest_tables = readTablesFromDB(con_v)
    uSysDB.close(con_v)

    manifest_tables.update(readTablesFromDBManifests(con))
    tables = readTablesFromDB(con)

    validator = DBValidator()
    progress.do("repairing tables")
    errors = validator.repairTables(con, manifest_tables, tables)
    progress.done()

    return errors
Example #5
0
def readTablesFromDBManifests(con):
    progress.do("gathering schema information from manifests (from database)")
    cur = con.cursor()
    cur.execute("""SELECT sc.name, data FROM package_body p
	JOIN components c ON (c.pkg_id = p.pkg_id)
	JOIN sc_instances si ON (si.component_id = c.component_id)
	JOIN service_classes sc ON (sc.sc_id = si.sc_id)
	WHERE sc.name NOT IN ('pleskd', 'vzpemagent')""")

    manifest_tables = dict()
    for row in cur.fetchall():
        data = row[1]
        data = str(data)
        xml_text = uManifestParser.unsign_package(cStringIO.StringIO(data))
        for table in uPDLDBSchema.getSchemaFromString(xml_text):
            manifest_tables[table.name] = table

    # Add tables from ejb's reduced descriptor
    try:
        earFiles = []
        dummy, _mn_plesk_root = uPEM.getMNInfo()
        from u import bootstrap
        for root, subFolders, files in os.walk(
                bootstrap.getJBossDir(_mn_plesk_root) +
                '/standalone/data/content/'):
            for file in files:
                earFiles.append(os.path.join(root, file))

        wDir = tempfile.mkdtemp()
        for earFile in earFiles:
            progress.do("unzip ear file " + earFile + " to " + wDir)
            unzipFile(earFile, wDir)
            progress.done()

        jarFiles = [f for f in os.listdir(wDir) if f.endswith(".jar")]
        for jarFile in jarFiles:
            wDirJar = tempfile.mkdtemp()
            progress.do("unzip jar file " + jarFile + " to " + wDirJar)
            unzipFile(os.path.join(wDir, jarFile), wDirJar)
            progress.done()
            rdFilePath = os.path.join(wDirJar, 'rd.xml')
            if not os.path.isfile(rdFilePath):
                continue
            rdFile = open(rdFilePath, 'r')
            rdContent = rdFile.read()
            rdFile.close()
            for table in uPDLDBSchema.getSchemaFromString(rdContent):
                manifest_tables[table.name] = table

            shutil.rmtree(wDirJar)

        shutil.rmtree(wDir)

    except Exception, e:
        uUtil.logLastException()
        pass
Example #6
0
def validateDatabaseExt(manifest_tables,
                        tables,
                        skip_constraint_names=False,
                        check_triggers=False):
    validator = DBValidator(skip_constraint_names, check_triggers)
    progress.do("checking for missing tables")
    missing = validator.searchMissingTables(manifest_tables, tables)
    progress.done()
    progress.do("checking for redundant tables")
    redundant = validator.searchRedundantTables(manifest_tables, tables)
    progress.done()
    progress.do("validating table structure")
    invalid = validator.validateTables(manifest_tables, tables)
    progress.done()
    return missing, invalid, redundant