Skip to content

Commit 2a3626c

Browse files
Shuotian Chenglguohan
Shuotian Cheng
authored andcommitted
[test]: Remove duplicate legacy ACL tests (sonic-net#699)
The tests in test_acl.py are duplicate with the ones in the test_acl_portchannel.py, and those legacy tests do not have enough clean up processes while lefting extra things in the database. Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent 8099811 commit 2a3626c

File tree

2 files changed

+46
-187
lines changed

2 files changed

+46
-187
lines changed

tests/test_acl.py

+1-184
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ def clean_up_left_over(self, dvs):
4747
keys = atbl.getKeys()
4848
assert len(keys) == 0
4949

50-
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG")
51-
keys = atbl.getKeys()
52-
for key in keys:
53-
atbl._del(key)
54-
55-
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG")
56-
keys = atbl.getKeys()
57-
assert len(keys) == 0
58-
5950
def verify_acl_group_num(self, adb, expt):
6051
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP")
6152
acl_table_groups = atbl.getKeys()
@@ -68,7 +59,7 @@ def verify_acl_group_num(self, adb, expt):
6859
if fv[0] == "SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE":
6960
assert fv[1] == "SAI_ACL_STAGE_INGRESS"
7061
elif fv[0] == "SAI_ACL_TABLE_GROUP_ATTR_ACL_BIND_POINT_TYPE_LIST":
71-
assert (fv[1] == "1:SAI_ACL_BIND_POINT_TYPE_PORT" or fv[1] == "1:SAI_ACL_BIND_POINT_TYPE_LAG")
62+
assert fv[1] == "1:SAI_ACL_BIND_POINT_TYPE_PORT"
7263
elif fv[0] == "SAI_ACL_TABLE_GROUP_ATTR_TYPE":
7364
assert fv[1] == "SAI_ACL_TABLE_GROUP_TYPE_PARALLEL"
7465
else:
@@ -113,23 +104,6 @@ def verify_acl_port_binding(self, dvs, adb, bind_ports):
113104
assert len(port_groups) == len(bind_ports)
114105
assert set(port_groups) == set(acl_table_groups)
115106

116-
def verify_acl_lag_binding(self, adb, lag_ids):
117-
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP")
118-
acl_table_groups = atbl.getKeys()
119-
assert len(acl_table_groups) == len(lag_ids)
120-
121-
atbl_lag = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG")
122-
port_groups = []
123-
for lag_id in lag_ids:
124-
(status, lagfvs) = atbl_lag.get(lag_id)
125-
for lagfv in lagfvs:
126-
if lagfv[0] == "SAI_LAG_ATTR_INGRESS_ACL":
127-
assert lagfv[1] in acl_table_groups
128-
port_groups.append(lagfv[1])
129-
130-
assert len(port_groups) == len(lag_ids)
131-
assert set(port_groups) == set(acl_table_groups)
132-
133107
def test_AclTableCreation(self, dvs, testlog):
134108
db = swsscommon.DBConnector(4, dvs.redis_sock, 0)
135109
adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)
@@ -1110,160 +1084,3 @@ def test_RulesWithDiffMaskLengths(self, dvs, testlog):
11101084
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE")
11111085
keys = atbl.getKeys()
11121086
assert len(keys) >= 1
1113-
1114-
def test_AclTableCreationOnLAGMember(self, dvs, testlog):
1115-
# prepare db and tables
1116-
self.clean_up_left_over(dvs)
1117-
db = swsscommon.DBConnector(4, dvs.redis_sock, 0)
1118-
adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)
1119-
apldb = swsscommon.DBConnector(0, dvs.redis_sock, 0)
1120-
1121-
# create port channel
1122-
ps = swsscommon.ProducerStateTable(apldb, "LAG_TABLE")
1123-
fvs = swsscommon.FieldValuePairs([("admin", "up"), ("mtu", "1500")])
1124-
ps.set("PortChannel0001", fvs)
1125-
1126-
# create port channel member
1127-
ps = swsscommon.ProducerStateTable(apldb, "LAG_MEMBER_TABLE")
1128-
fvs = swsscommon.FieldValuePairs([("status", "enabled")])
1129-
ps.set("PortChannel0001:Ethernet12", fvs)
1130-
time.sleep(1)
1131-
1132-
# create acl table
1133-
tbl = swsscommon.Table(db, "ACL_TABLE")
1134-
bind_ports = ["Ethernet12"]
1135-
fvs = swsscommon.FieldValuePairs([("policy_desc", "test_negative"), ("type", "L3"), ("ports", ",".join(bind_ports))])
1136-
tbl.set("test_negative", fvs)
1137-
time.sleep(1)
1138-
1139-
# verify test result - ACL table creation should fail
1140-
assert self.verify_if_any_acl_table_created(dvs, adb) == False
1141-
1142-
def test_AclTableCreationOnLAG(self, dvs, testlog):
1143-
# prepare db and tables
1144-
self.clean_up_left_over(dvs)
1145-
db = swsscommon.DBConnector(4, dvs.redis_sock, 0)
1146-
adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)
1147-
apldb = swsscommon.DBConnector(0, dvs.redis_sock, 0)
1148-
1149-
#create port channel
1150-
ps = swsscommon.ProducerStateTable(apldb, "LAG_TABLE")
1151-
fvs = swsscommon.FieldValuePairs([("admin", "up"), ("mtu", "1500")])
1152-
ps.set("PortChannel0002", fvs)
1153-
1154-
# create port channel member
1155-
ps = swsscommon.ProducerStateTable(apldb, "LAG_MEMBER_TABLE")
1156-
fvs = swsscommon.FieldValuePairs([("status", "enabled")])
1157-
ps.set("PortChannel0002:Ethernet16", fvs)
1158-
time.sleep(1)
1159-
1160-
# create acl table
1161-
tbl = swsscommon.Table(db, "ACL_TABLE")
1162-
bind_ports = ["PortChannel0002"]
1163-
fvs = swsscommon.FieldValuePairs([("policy_desc", "test_negative"), ("type", "L3"), ("ports", ",".join(bind_ports))])
1164-
tbl.set("test_LAG", fvs)
1165-
time.sleep(1)
1166-
1167-
# check acl table in asic db
1168-
test_acl_table_id = self.get_acl_table_id(dvs, adb)
1169-
1170-
# check acl table group in asic db
1171-
self.verify_acl_group_num(adb, 1)
1172-
1173-
# get acl table group ids and verify the id numbers
1174-
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP")
1175-
acl_group_ids = atbl.getKeys()
1176-
assert len(acl_group_ids) == 1
1177-
1178-
# check acl table group member
1179-
self.verify_acl_group_member(adb, acl_group_ids, test_acl_table_id)
1180-
1181-
# get lad ids
1182-
atbl_lag = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG")
1183-
lag_ids = atbl_lag.getKeys();
1184-
assert len(lag_ids) == 1
1185-
1186-
# check lag binding
1187-
self.verify_acl_lag_binding(adb, lag_ids)
1188-
1189-
tbl = swsscommon.Table(db, "ACL_TABLE")
1190-
tbl._del("test_LAG")
1191-
1192-
def test_AclTableCreationBeforeLAG(self, dvs, testlog):
1193-
# prepare db and tables
1194-
self.clean_up_left_over(dvs)
1195-
db = swsscommon.DBConnector(4, dvs.redis_sock, 0)
1196-
adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)
1197-
apldb = swsscommon.DBConnector(0, dvs.redis_sock, 0)
1198-
1199-
# create acl table
1200-
tbl = swsscommon.Table(db, "ACL_TABLE")
1201-
bind_ports = ["PortChannel0003"]
1202-
fvs = swsscommon.FieldValuePairs([("policy_desc", "test_negative"), ("type", "L3"), ("ports", ",".join(bind_ports))])
1203-
tbl.set("test_LAG_2", fvs)
1204-
time.sleep(1)
1205-
1206-
# check acl table in asic db
1207-
test_acl_table_id = self.get_acl_table_id(dvs, adb)
1208-
1209-
# check acl table group in asic db
1210-
self.verify_acl_group_num(adb, 0)
1211-
1212-
# get acl table group ids and verify the id numbers
1213-
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP")
1214-
acl_group_ids = atbl.getKeys()
1215-
assert len(acl_group_ids) == 0
1216-
1217-
# check acl table group member
1218-
self.verify_acl_group_member(adb, acl_group_ids, test_acl_table_id)
1219-
1220-
# get lad ids
1221-
atbl_lag = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG")
1222-
lag_ids = atbl_lag.getKeys()
1223-
assert len(lag_ids) == 0
1224-
1225-
# check port binding
1226-
self.verify_acl_lag_binding(adb, lag_ids)
1227-
1228-
# create port channel
1229-
ps = swsscommon.ProducerStateTable(apldb, "LAG_TABLE")
1230-
fvs = swsscommon.FieldValuePairs([("admin", "up"), ("mtu", "1500")])
1231-
ps.set("PortChannel0003", fvs)
1232-
1233-
# create port channel member
1234-
ps = swsscommon.ProducerStateTable(apldb, "LAG_MEMBER_TABLE")
1235-
fvs = swsscommon.FieldValuePairs([("status", "enabled")])
1236-
ps.set("PortChannel0003:Ethernet20", fvs)
1237-
time.sleep(1)
1238-
1239-
# notify aclorch that port channel configured
1240-
stdb = swsscommon.DBConnector(6, dvs.redis_sock, 0)
1241-
tbl = swsscommon.Table(stdb, "LAG_TABLE")
1242-
fvs = swsscommon.FieldValuePairs([("state", "ok")])
1243-
tbl.set("PortChannel0003", fvs)
1244-
time.sleep(1)
1245-
1246-
# check acl table in asic db
1247-
test_acl_table_id = self.get_acl_table_id(dvs, adb)
1248-
1249-
# check acl table group in asic db
1250-
self.verify_acl_group_num(adb, 1)
1251-
1252-
# get acl table group ids and verify the id numbers
1253-
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP")
1254-
acl_group_ids = atbl.getKeys()
1255-
assert len(acl_group_ids) == 1
1256-
1257-
# check acl table group member
1258-
self.verify_acl_group_member(adb, acl_group_ids, test_acl_table_id)
1259-
1260-
# get lad ids
1261-
atbl_lag = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG")
1262-
lag_ids = atbl_lag.getKeys()
1263-
assert len(lag_ids) == 1
1264-
1265-
# check port binding
1266-
self.verify_acl_lag_binding(adb, lag_ids)
1267-
1268-
tbl = swsscommon.Table(db, "ACL_TABLE")
1269-
tbl._del("test_LAG_2")

tests/test_acl_portchannel.py

+45-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ def add_port_channel_members(self, dvs, lag, members):
2727
tbl.set(lag + "|" + member, fvs)
2828
time.sleep(1)
2929

30+
def activate_port_channel_members(self, dvs, lag, members):
31+
tbl = swsscommon.ProducerStateTable(self.pdb, "LAG_MEMBER_TABLE")
32+
fvs = swsscommon.FieldValuePairs([("status", "enabled")])
33+
34+
for member in members:
35+
tbl.set(lag + ":" + member, fvs)
36+
time.sleep(1)
37+
3038
def remove_port_channel_members(self, dvs, lag, members):
3139
tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER")
3240
for member in members:
@@ -59,7 +67,7 @@ def remove_acl_rule(self, dvs, table_name, rule_name):
5967
tbl._del(table_name + "|" + rule_name, fvs)
6068
time.sleep(1)
6169

62-
def check_asic_table(self, dvs):
70+
def check_asic_table_existed(self, dvs):
6371
tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG")
6472
lag = tbl.getKeys()[0]
6573
(status, fvs) = tbl.get(lag)
@@ -106,6 +114,14 @@ def check_asic_table(self, dvs):
106114
(status, fvs) = tbl.get(table_id)
107115
assert status == True
108116

117+
def check_asic_table_absent(self, dvs):
118+
tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE")
119+
acl_tables = tbl.getKeys()
120+
for key in dvs.asicdb.default_acl_tables:
121+
assert key in acl_tables
122+
acl_tables = [k for k in acl_tables if k not in dvs.asicdb.default_acl_tables]
123+
124+
assert len(acl_tables) == 0
109125

110126
# Frist create port channel
111127
# Second create ACL table
@@ -119,7 +135,7 @@ def test_PortChannelAfterAcl(self, dvs):
119135
self.create_acl_table(dvs, "LAG_ACL_TABLE", "PortChannel01")
120136

121137
# check ASIC table
122-
self.check_asic_table(dvs)
138+
self.check_asic_table_existed(dvs)
123139

124140
# remove ACL table
125141
self.remove_acl_table(dvs, "LAG_ACL_TABLE")
@@ -139,7 +155,7 @@ def test_PortChannelBeforeAcl(self, dvs):
139155
self.create_port_channel(dvs, "PortChannel01")
140156

141157
# check ASIC table
142-
self.check_asic_table(dvs)
158+
self.check_asic_table_existed(dvs)
143159

144160
# TODO: right now it is not supported to remove port before remove ACL
145161
# table. Will swap the order after having it supported
@@ -148,3 +164,29 @@ def test_PortChannelBeforeAcl(self, dvs):
148164

149165
# remove port channel
150166
self.remove_port_channel(dvs, "PortChannel01")
167+
168+
# ACL table cannot be created upon a member port of a port channel
169+
def test_AclOnPortChannelMember(self, dvs):
170+
self.setup_db(dvs)
171+
172+
# create port channel
173+
self.create_port_channel(dvs, "PortChannel01")
174+
175+
# add port channel member
176+
self.add_port_channel_members(dvs, "PortChannel01", ["Ethernet0", "Ethernet4"])
177+
self.activate_port_channel_members(dvs, "PortChannel01", ["Ethernet0", "Ethernet4"])
178+
179+
# create ACL table
180+
self.create_acl_table(dvs, "LAG_ACL_TABLE", "Ethernet0")
181+
182+
# check ASIC table
183+
self.check_asic_table_absent(dvs)
184+
185+
# remove_acl_table
186+
self.remove_acl_table(dvs, "LAG_ACL_TABLE")
187+
188+
# remove port channel member
189+
self.remove_port_channel_members(dvs, "PortChannel01", ["Ethernet0", "Ethernet4"])
190+
191+
# remove port channel
192+
self.remove_port_channel(dvs, "PortChannel01")

0 commit comments

Comments
 (0)