Exemple #1
0
def test_independent_tags():

    ddb = DefectsDB(TEST_DATABASE, read_only=False)

    # Create two defects
    create_defect_type(ddb, 0)
    create_defect_type(ddb, 1)
    create_defect_type(ddb, 2)

    ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "")
    ddb.insert("DQD_TEST_DEFECT_1", 100, 200, "", "")
    ddb.insert("DQD_TEST_DEFECT_2", 200, 300, "", "")

    dtag1 = ddb.new_defects_tag("dqd-test", "New iov tag")

    ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "", present=False)

    dtag2 = ddb.new_defects_tag("dqd-test-2", "New iov tag")

    # Make a virtual defect whose result is the combination of the above
    ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "",
                           "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")

    ltag1 = ddb.new_logics_tag()

    ddb.update_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
                              "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_2")

    ltag2 = ddb.new_logics_tag()

    iovs = DefectsDB(
        TEST_DATABASE,
        tag=("HEAD", ltag1)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
    assert iov_ranges(iovs) == [(100, 200)], str(iov_ranges(iovs))

    iovs = DefectsDB(
        TEST_DATABASE,
        tag=("HEAD", ltag2)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
    assert iov_ranges(iovs) == [(200, 300)], str(iov_ranges(iovs))

    iovs = DefectsDB(
        TEST_DATABASE,
        tag=(dtag1, ltag1)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
    assert iov_ranges(iovs) == [(0, 100), (100, 200)], str(iov_ranges(iovs))

    iovs = DefectsDB(
        TEST_DATABASE,
        tag=(dtag2, ltag2)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
    assert iov_ranges(iovs) == [(200, 300)], str(iov_ranges(iovs))

    htag = ddb.new_hierarchical_tag(dtag2, ltag2)

    iovs = DefectsDB(TEST_DATABASE,
                     tag=(htag,
                          htag)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
    assert iov_ranges(iovs) == [(200, 300)], str(iov_ranges(iovs))

    iovs = DefectsDB(TEST_DATABASE,
                     tag=htag).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
    assert iov_ranges(iovs) == [(200, 300)], str(iov_ranges(iovs))
Exemple #2
0
def test_update_virtual_defect():

    ddb = DefectsDB(TEST_DATABASE, read_only=False)

    # Create two defects
    create_defect_type(ddb, 0)
    create_defect_type(ddb, 1)
    create_defect_type(ddb, 2)

    ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "")
    ddb.insert("DQD_TEST_DEFECT_1", 100, 200, "", "")
    ddb.insert("DQD_TEST_DEFECT_2", 200, 300, "", "")

    defects_tag = ddb.new_defects_tag("dqd-test", "New iov tag")

    # Make a virtual defect whose result is the combination of the above
    ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "",
                           "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")

    original_tag = ddb.new_logics_tag()
    original_htag = ddb.new_hierarchical_tag(defects_tag, original_tag)

    ddb.update_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
                              "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_2")

    new_tag = ddb.new_logics_tag()
    new_htag = ddb.new_hierarchical_tag(defects_tag, new_tag)

    what = {"channels": ["DQD_TEST_VIRTUAL_DEFECT"]}

    orig_iovs = DefectsDB(TEST_DATABASE, tag=original_htag).retrieve(**what)
    new_iovs = DefectsDB(TEST_DATABASE, tag=new_htag).retrieve(**what)
    head_iovs = DefectsDB(TEST_DATABASE).retrieve(**what)

    assert head_iovs == new_iovs
    assert head_iovs != orig_iovs

    assert len(head_iovs) == 2
    assert (head_iovs[0].since, head_iovs[0].until) == (0, 100)
    assert (head_iovs[1].since, head_iovs[1].until) == (200, 300)

    from DQUtils.db import Databases
    db3 = Databases.get_instance(TEST_DATABASE, read_only=True)
    pfs = db3.getFolderSet('/GLOBAL/DETSTATUS')
    assert pfs.tagDescription(
        new_htag) != '', 'Hierarchical tag description not created'
            print 'ERROR: Problem parsing file', f
            print str(e)
            sys.exit(1)
        if not tmp_indict:
            print 'NOTICE: No definitions in file', f
            continue
        interset = set(tmp_indict) & set(indict)
        if len(interset) > 0:
            for k in interset:
                print 'WARNING: Redefinition of defect', k, 'in file', f
                if not opts.ignore_redef:
                    sys.exit(1)
        indict.update(tmp_indict)

    #print '\n'.join(map(str,tocreate))
    from DQDefects import DefectsDB
    from DQDefects.exceptions import DefectUnknownError
    ddb = DefectsDB(opts.db, create=opts.create, read_only=False,
                    tag=opts.tag)

    print 'Now updating defects on', opts.db
    with ddb.storage_buffer:
        for defect, clause in indict.items():
            print defect, clause
            try:
                ddb.update_virtual_defect(defect, ' '.join(clause))
            except DefectUnknownError:
                ddb.new_virtual_defect(defect, '', ' '.join(clause))
                #print 'ERROR: defect', defect, 'not present in DB, unable to update'
                #sys.exit(1)
    print 'Reading in definitions...'
    inclauses = indb.virtual_defect_logics
    print '%d virtual defects retrieved from input database' % len(inclauses)
    inchannels = set(channels if channels is not None else inclauses.keys())
    outchannels = set(outdb.virtual_defect_names)
    missingchannels = inchannels - outchannels
    with outdb.storage_buffer:
        if len(missingchannels) != 0:
            if not opts.createdefects:
                print 'Missing virtual defect(s) in target database:'
                print list(missingchannels)
                print 'Rerun with a restricted virtual defect list (--defects) or with --createdefects'
                sys.exit(1)
            else:
                print 'Creating missing virtual defects on output database...'
                descriptions = indb.get_virtual_channel_descriptions(
                    missingchannels)
                for channel in missingchannels:
                    outdb.new_virtual_defect(
                        channel, descriptions[channel],
                        ' '.join(inclauses[channel].clauses))
                print 'Done'

        print 'Updating existing virtual defects...'
        for channel in inchannels - missingchannels:
            outdb.update_virtual_defect(channel,
                                        ' '.join(inclauses[channel].clauses))

        print 'Done.'