Skip to content

Commit

Permalink
Update black and isort, and hardcode click packages for prettify (#515)
Browse files Browse the repository at this point in the history
* Update black and isort, and hardcode click packages for prettify

* Use proxy for docker registry

* Use sudo to set proxy

* Test

* Test

* Remove change to Jenkinsfile
  • Loading branch information
daniele-moro authored Apr 15, 2022
1 parent 385bb26 commit 157f011
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
python3 -m venv .venv
# shellcheck disable=SC1091
source .venv/bin/activate
python3 -m pip install black==19.10b0 isort==5.6.4
python3 -m pip install black==21.12b0 isort==5.10.1 click==8.0.4
black --config .github/linters/.python-black .
isort --sp .github/linters/.isort.cfg .
deactivate
20 changes: 16 additions & 4 deletions ptf/tests/common/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,8 @@ def verify_multicast_group(self, group_id, expected_multicast_group):
pre_entry = entity.packet_replication_engine_entry
if pre_entry.HasField("multicast_group_entry"):
self.verify_p4runtime_entity(
pre_entry.multicast_group_entry, expected_multicast_group,
pre_entry.multicast_group_entry,
expected_multicast_group,
)

def verify_direct_counter(
Expand Down Expand Up @@ -1093,7 +1094,12 @@ def verify_direct_counter(
return None

def verify_indirect_counter(
self, c_name, c_index, typ, expected_byte_count=0, expected_packet_count=0,
self,
c_name,
c_index,
typ,
expected_byte_count=0,
expected_packet_count=0,
):
# Check counter type with P4Info
counter = self.get_counter(c_name)
Expand Down Expand Up @@ -1150,7 +1156,10 @@ def verify_indirect_counter(
return None

def verify_register(
self, register_name, register_index, expected_value,
self,
register_name,
register_index,
expected_value,
):
req = self.get_new_read_request()
entity = req.entities.add()
Expand Down Expand Up @@ -1347,7 +1356,10 @@ def handle(*args, **kwargs):
finally:
if test.generate_tv:
tv_folder = os.path.join(
os.getcwd(), "testvectors", test.__class__.__name__, sub_dir,
os.getcwd(),
"testvectors",
test.__class__.__name__,
sub_dir,
)
tvutils.write_to_file(
test.tv, tv_folder, tv_name, create_tv_sub_dir=False
Expand Down
139 changes: 110 additions & 29 deletions ptf/tests/common/fabric_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,14 @@ def pkt_add_gtp(
):
gtp_pkt = (
Ether(src=pkt[Ether].src, dst=pkt[Ether].dst)
/ IP(src=out_ipv4_src, dst=out_ipv4_dst, tos=0, id=0x1513, flags=0, frag=0,)
/ IP(
src=out_ipv4_src,
dst=out_ipv4_dst,
tos=0,
id=0x1513,
flags=0,
frag=0,
)
/ UDP(sport=sport, dport=dport, chksum=0)
/ GTP_U_Header(gtp_type=255, teid=teid)
)
Expand Down Expand Up @@ -1200,10 +1207,14 @@ def set_up_recirc_ports(self):
)
self.set_egress_vlan(port, DEFAULT_VLAN, push_vlan=False)
self.set_forwarding_type(
port, ethertype=ETH_TYPE_IPV4, fwd_type=FORWARDING_TYPE_UNICAST_IPV4,
port,
ethertype=ETH_TYPE_IPV4,
fwd_type=FORWARDING_TYPE_UNICAST_IPV4,
)
self.set_forwarding_type(
port, ethertype=ETH_TYPE_MPLS_UNICAST, fwd_type=FORWARDING_TYPE_MPLS,
port,
ethertype=ETH_TYPE_MPLS_UNICAST,
fwd_type=FORWARDING_TYPE_MPLS,
)

def add_bridging_entry(
Expand Down Expand Up @@ -1346,15 +1357,24 @@ def add_forwarding_acl_set_clone_session_id(
)

def add_forwarding_acl_drop(
self, ipv4_src=None, ipv4_dst=None, ip_proto=None, l4_sport=None, l4_dport=None,
self,
ipv4_src=None,
ipv4_dst=None,
ip_proto=None,
l4_sport=None,
l4_dport=None,
):
# Send only if the match keys are not empty
matches = self.build_acl_matches(
ipv4_src, ipv4_dst, ip_proto, l4_sport, l4_dport
)
if matches:
self.send_request_add_entry_to_action(
"acl.acl", matches, "acl.drop", [], DEFAULT_PRIORITY,
"acl.acl",
matches,
"acl.drop",
[],
DEFAULT_PRIORITY,
)

def build_acl_matches(
Expand Down Expand Up @@ -1569,7 +1589,9 @@ def add_next_mpls(self, next_id, label):
"pre_next.next_mpls",
[self.Exact("next_id", next_id_)],
"pre_next.set_mpls_label",
[("label", label_),],
[
("label", label_),
],
)

# next_hops is a list of tuples (egress_port, smac, dmac)
Expand All @@ -1590,7 +1612,11 @@ def add_next_mpls_and_routing_group(self, next_id, grp_id, next_hops=None):
actions.append(
[
"next.routing_hashed",
[("port_num", egress_port_), ("smac", smac_), ("dmac", dmac_),],
[
("port_num", egress_port_),
("smac", smac_),
("dmac", dmac_),
],
]
)
self.add_next_hashed_group_action(next_id, grp_id, actions)
Expand Down Expand Up @@ -1647,7 +1673,10 @@ def delete_clone_group(self, clone_id, ports, store=True):
def add_next_hashed_group_member(self, action_name, params):
mbr_id = self.get_next_mbr_id()
return self.send_request_add_member(
"FabricIngress.next.hashed_profile", mbr_id, action_name, params,
"FabricIngress.next.hashed_profile",
mbr_id,
action_name,
params,
)

def add_next_hashed_group(self, grp_id, mbr_ids):
Expand All @@ -1660,7 +1689,10 @@ def add_next_hashed_group(self, grp_id, mbr_ids):

def modify_next_hashed_group(self, grp_id, mbr_ids, grp_size):
return self.send_request_modify_group(
"FabricIngress.next.hashed_profile", grp_id, grp_size, mbr_ids,
"FabricIngress.next.hashed_profile",
grp_id,
grp_size,
mbr_ids,
)

def read_next_hashed_group_member(self, mbr_id):
Expand Down Expand Up @@ -2455,8 +2487,7 @@ def runPacketInTest(self, pkt, eth_type, tagged=False, vlan_id=10):


class SlicingTest(FabricTest):
"""Mixin class with methods to manipulate QoS entities
"""
"""Mixin class with methods to manipulate QoS entities"""

def set_default_tc(self, slice_id=None, tc=None):
matches = [
Expand Down Expand Up @@ -2507,7 +2538,12 @@ def add_slice_tc_meter(self, slice_id, tc, committed_bps, peak_bps):
pir = int(peak_bps / 8)
pburst = int(pir * BURST_DURATION_MS * 0.001)
self.configure_slice_tc_meter(
slice_id=slice_id, tc=tc, cir=cir, cburst=cburst, pir=pir, pburst=pburst,
slice_id=slice_id,
tc=tc,
cir=cir,
cburst=cburst,
pir=pir,
pburst=pburst,
)

def add_queue_entry(self, slice_id, tc, qid=None, color=None):
Expand Down Expand Up @@ -2563,7 +2599,9 @@ def _add_upf_iface(
self.Exact("gtpu_is_valid", stringify(int(gtpu_valid))),
],
"FabricIngress.upf." + iface_type,
[("slice_id", stringify(slice_id)),],
[
("slice_id", stringify(slice_id)),
],
)
self.write_request(req)

Expand Down Expand Up @@ -2646,7 +2684,9 @@ def setup_app_filtering(
"FabricIngress.upf.applications",
match_fields,
"FabricIngress.upf.set_app_id",
[("app_id", stringify(app_id)),],
[
("app_id", stringify(app_id)),
],
priority=priority,
)
self.write_request(req)
Expand Down Expand Up @@ -2841,7 +2881,9 @@ def add_gtp_tunnel_peer(
"FabricIngress.upf.ig_tunnel_peers",
[self.Exact("tun_peer_id", stringify(tunnel_peer_id))],
"FabricIngress.upf.set_routing_ipv4_dst",
[("tun_dst_addr", ipv4_to_binary(tunnel_dst_addr)),],
[
("tun_dst_addr", ipv4_to_binary(tunnel_dst_addr)),
],
)
self.write_request(req)

Expand Down Expand Up @@ -2914,7 +2956,10 @@ def setup_downlink(

def enable_encap_with_psc(self):
self.send_request_add_entry_to_action(
"FabricEgress.upf.gtpu_encap", None, "FabricEgress.upf.gtpu_with_psc", [],
"FabricEgress.upf.gtpu_encap",
None,
"FabricEgress.upf.gtpu_with_psc",
[],
)

def reset_upf_counters(self, ctr_idx):
Expand All @@ -2932,15 +2977,23 @@ def verify_upf_counters(
exp_ingress_pkts,
exp_egress_pkts,
):
""" Verify that the UPF ingress and egress counters for index 'ctr_idx' are now
'exp_ingress_bytes', 'exp_ingress_pkts' and 'exp_egress_bytes',
'exp_egress_pkts' respectively upon reading.
"""Verify that the UPF ingress and egress counters for index 'ctr_idx' are now
'exp_ingress_bytes', 'exp_ingress_pkts' and 'exp_egress_bytes',
'exp_egress_pkts' respectively upon reading.
"""
self.verify_indirect_counter(
UPF_COUNTER_INGRESS, ctr_idx, "BOTH", exp_ingress_bytes, exp_ingress_pkts,
UPF_COUNTER_INGRESS,
ctr_idx,
"BOTH",
exp_ingress_bytes,
exp_ingress_pkts,
)
self.verify_indirect_counter(
UPF_COUNTER_EGRESS, ctr_idx, "BOTH", exp_egress_bytes, exp_egress_pkts,
UPF_COUNTER_EGRESS,
ctr_idx,
"BOTH",
exp_egress_bytes,
exp_egress_pkts,
)

def runUplinkTest(
Expand Down Expand Up @@ -3009,7 +3062,9 @@ def runUplinkTest(
)
if meter_drop:
self.enable_policing(
slice_id, tc, V1MODEL_COLOR_RED if is_v1model() else COLOR_RED,
slice_id,
tc,
V1MODEL_COLOR_RED if is_v1model() else COLOR_RED,
)
app_meter_idx = DEFAULT_APP_METER_IDX
if app_max_bps is not None:
Expand Down Expand Up @@ -3291,7 +3346,9 @@ def runDownlinkTest(
)
if meter_drop:
self.enable_policing(
slice_id, tc, V1MODEL_COLOR_RED if is_v1model() else COLOR_RED,
slice_id,
tc,
V1MODEL_COLOR_RED if is_v1model() else COLOR_RED,
)
app_meter_idx = DEFAULT_APP_METER_IDX
if app_max_bps is not None:
Expand Down Expand Up @@ -3696,7 +3753,11 @@ def set_up_watchlist_flow(
matches.append(self.Range("l4_dport", dport_low, dport_high))

self.send_request_add_entry_to_action(
"watchlist", matches, action, [], priority=DEFAULT_PRIORITY,
"watchlist",
matches,
action,
[],
priority=DEFAULT_PRIORITY,
)

def truncate_packet(self, pkt, size):
Expand Down Expand Up @@ -3746,7 +3807,9 @@ def build_int_local_report(
/ UDP(sport=0, chksum=0)
/ INT_L45_REPORT_FIXED(nproto=2, f=f_flag, q=q_flag, hw_id=(eg_port >> 7))
/ INT_L45_LOCAL_REPORT(
switch_id=sw_id, ingress_port_id=ig_port, egress_port_id=eg_port,
switch_id=sw_id,
ingress_port_id=ig_port,
egress_port_id=eg_port,
)
/ inner_packet
)
Expand Down Expand Up @@ -4809,7 +4872,14 @@ def set_line_map(self, s_tag, c_tag, line_id):
)

def setup_line_v4(
self, s_tag, c_tag, line_id, ipv4_addr, mac_src, pppoe_session_id, enabled=True,
self,
s_tag,
c_tag,
line_id,
ipv4_addr,
mac_src,
pppoe_session_id,
enabled=True,
):
assert s_tag != 0
assert c_tag != 0
Expand Down Expand Up @@ -4907,7 +4977,10 @@ def runUpstreamV4Test(self, pkt, tagged2, is_next_hop_spine, line_enabled=True):

# Input is the given packet with double VLAN tags and PPPoE headers.
pppoe_pkt = pkt_add_pppoe(
pkt, type=1, code=PPPOE_CODE_SESSION_STAGE, session_id=pppoe_session_id,
pkt,
type=1,
code=PPPOE_CODE_SESSION_STAGE,
session_id=pppoe_session_id,
)
pppoe_pkt = pkt_add_vlan(pppoe_pkt, vlan_vid=vlan_id_inner)
pppoe_pkt = pkt_add_vlan(pppoe_pkt, vlan_vid=vlan_id_outer)
Expand Down Expand Up @@ -5030,7 +5103,10 @@ def runDownstreamV4Test(self, pkt, in_tagged, line_enabled):
# Build expected packet from the input one, we expect it to be routed
# and encapsulated in double VLAN tags and PPPoE.
exp_pkt = pkt_add_pppoe(
pkt, type=1, code=PPPOE_CODE_SESSION_STAGE, session_id=pppoe_session_id,
pkt,
type=1,
code=PPPOE_CODE_SESSION_STAGE,
session_id=pppoe_session_id,
)
exp_pkt = pkt_add_vlan(exp_pkt, vlan_vid=vlan_id_outer)
exp_pkt = pkt_add_inner_vlan(exp_pkt, vlan_vid=vlan_id_inner)
Expand Down Expand Up @@ -5135,7 +5211,12 @@ def verify_stats_counter(
"Counter is not same as expected.\
\nActual packet count: %d, Expected packet count: %d\
\nActual byte count: %d, Expected byte count: %d\n"
% (actual_pkt_count, pkt_count, actual_byte_count, byte_count,)
% (
actual_pkt_count,
pkt_count,
actual_byte_count,
byte_count,
)
)

def add_stats_table_entry(self, gress, stats_flow_id, ports, **ftuple):
Expand Down
Loading

0 comments on commit 157f011

Please sign in to comment.