def counter_create(table_id, types=[]):
    c = nas_acl.CounterCPSObj(table_id=table_id, types=types)
    upd = ('create', c.data())
    r = cps_utils.CPSTransaction([upd]).commit()

    if r == False:
        raise RuntimeError

    c = nas_acl.CounterCPSObj(cps_data=r[0])
    counter_id = c.extract_id()
    print "Created Counter " + str(counter_id)
    return counter_id
Exemplo n.º 2
0
def acl_ut_entry_delete_rollback(table_id, entry_id, counter_id):
    global total, passed
    total.append(sys._getframe().f_code.co_name)

    # Transaction with multiple updates
    upd = []
    # Delete entry
    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    upd.append(('delete', e.data()))

    # Delete counter
    e = nas_acl.CounterCPSObj(table_id=table_id, counter_id=counter_id)
    upd.append(('delete', e.data()))

    # Delete table
    e = nas_acl.TableCPSObj(table_id=table_id)
    upd.append(('delete', e.data()))

    # Delete entry again - should fail
    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    upd.append(('delete', e.data()))

    print upd
    r = cps_utils.CPSTransaction(upd).commit()
    if r == False:
        print "Error deleting entry twice (Expected) - Should have rolled back to create table, counter and entry again"
        raw_input(
            "Check table and entry is Roll back recreated and Press Enter to continue...")
        passed.append(sys._getframe().f_code.co_name)
    else:
        print "#### Failed - Deleting twice did not give error"
Exemplo n.º 3
0
if len(sys.argv) > 2:
    eid = sys.argv[2]

if eid is None:
    filt = nas_acl.EntryCPSObj(table_id=tid)
    if cps.get([filt.data()], out_entry):
        for e_cps in out_entry:
            e = nas_acl.EntryCPSObj(cps_data=e_cps)
            eid = e.extract_id()
            print "Deleting entry ", eid, "in table ", e.extract('table-id')
            e1 = nas_acl.EntryCPSObj(e.extract('table-id'), eid)
            cps_delete(e1)
    else:
        print "No entries in table"

    filt = nas_acl.CounterCPSObj(table_id=tid)
    if cps.get([filt.data()], out_counter):
        for e_cps in out_counter:
            e = nas_acl.CounterCPSObj(cps_data=e_cps)
            eid = e.extract_id()
            print "Deleting counter ", eid, "in table ", e.extract('table-id')
            e1 = nas_acl.CounterCPSObj(e.extract('table-id'), eid)
            cps_delete(e1)
    else:
        print "No counters in table"

    if tid is None:
        filt = nas_acl.TableCPSObj()
        if not cps.get([filt.data()], out_table):
            print "Table Get failed"
            exit()