def apply_table_cfg(etree_table, stage, prio): table_name = etree_table.attrib['tag'] dbg_print("Creating table stage = ", stage, "prio = ", prio) t = nas_acl.TableCPSObj(table_id=table_name, stage=stage, priority=int(prio)) for field in etree_table.findall('allow-match'): dbg_print("Add allow filter ", field.text) t.add_allow_filter(field.text) for field in etree_table.findall('allow-action'): dbg_print("Add allow action ", field.text) t.add_allow_action(field.text) dbg_print(t.data()) cps_upd = ('create', t.data()) ret = cps_utils.CPSTransaction([cps_upd]).commit() if ret == False: raise RuntimeError("ACL INIT - Table creation failed: " + table_name) t = nas_acl.TableCPSObj(cps_data=ret[0]) table_id = t.extract_id() dbg_print("Created Table " + table_name + "-" + str(table_id)) return table_id
def __get_table(type, fields): _table_id = nas_acl.create_table(stage=type,\ prio=_default_table_prio, allow_filters=fields,only_if_not_exist=True) out = [] if cps.get([nas_acl.TableCPSObj(table_id=_table_id).data()], out) == True: if out: return nas_acl.TableCPSObj(cps_data=out[0]) return None
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"
def __create_table(): if _args['table_stage'] == None or _args[ 'table_priority'] == None or _args['table_match'] == None: print('Missing manditory attributes to create table') sys.exit(1) _table_id = nas_acl.create_table(stage=_args['table_stage'],prio=_args['table_priority'],\ allow_filters=_args['table_match'],only_if_not_exist=True) _table = nas_acl.TableCPSObj(table_id=_table_id) out = [] if cps.get([_table.data()], out) == True: for t_cps in out: t = nas_acl.TableCPSObj(cps_data=t_cps) _table = t return _table
def test_check_entry(): ret_tlist = [] tid = 1 eid = "ospfv3-all-dr" filt = nas_acl.TableCPSObj(table_id=tid) if not cps.get([filt.data()], ret_tlist): print "Error in Table Get" exit() print "" print "Finding Entry in Table " filt = nas_acl.EntryCPSObj(table_id=tid, entry_id=eid) ret_elist = [] if not cps.get([filt.data()], ret_elist): print "Error in Entry Get" for entry in ret_elist: e = nas_acl.EntryCPSObj(cps_data=entry) cps_data = e.data() print "The Entry ID is:" + str(e.extract_attr(cps_data, 'id')) assert e.extract_attr(cps_data, 'match/IP_PROTOCOL_VALUE/data') == 89
for child in value: elem_val[child.tag] = child.text dbg_print("Add type ", elem_type, "val = ", elem_val) return elem_type, elem_val def dbg_print(*args): if dbg_on: print(args) if __name__ == '__main__': if 'DN_ACL_CFG_PATH' in os.environ.keys(): acl_cfg_path = os.environ['DN_ACL_CFG_PATH'] else: acl_cfg_path = target_cfg_path t = nas_acl.TableCPSObj() r = [] while cps.get([t.data()], r) == False: time.sleep(1) try: table_detail_map, entry_detail_map = load_detail_list() load_master_list(table_detail_map, entry_detail_map) except RuntimeError as r: print "Runtime Error: " + str(r) sys.exit(1)
# See the Apache Version 2.0 License for specific language governing # permissions and limitations under the License. import sys import nas_acl import cps tid = None eid = None ret_tlist = [] if len(sys.argv) > 1: tid = sys.argv[1] if len(sys.argv) > 2: eid = sys.argv[2] filt = nas_acl.TableCPSObj(table_id=tid) if not cps.get([filt.data()], ret_tlist): print "Error in Table Get" exit() for table in ret_tlist: t = nas_acl.TableCPSObj(cps_data=table) print "" print "TABLE " t.print_obj() print "" print "Entries in Table " filt = nas_acl.EntryCPSObj(table_id=t.extract_id(), entry_id=eid) ret_elist = [] if not cps.get([filt.data()], ret_elist):
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() for t_cps in out_table: t = nas_acl.TableCPSObj(cps_data=t_cps) tid = t.extract_id() print "Deleting table ", tid t1 = nas_acl.TableCPSObj(tid) cps_delete(t1) else: t = nas_acl.TableCPSObj(table_id=tid) print "Deleting table ", tid cps_delete(t)