Skip to content

Commit

Permalink
[pre-commit]Refine the output of conditional mark order check (sonic-…
Browse files Browse the repository at this point in the history
…net#13544)

Description of PR
Summary:
Refine the output of conditional_mark order check.
Print more detailed information so that contributors know where to modify.

Before enhance, only tell there's mis-order, but not how to modify.

check conditional mark sort..............................................Failed
- hook id: check-conditional-mark-sort
- exit code: 1

The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml are not sorted in alphabetic order.
After enhance:

check conditional mark sort..............................................Failed
- hook id: check-conditional-mark-sort
- exit code: 1

The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml are not sorted in alphabetic order.


The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml are not sorted in alphabetic order, please adjust the order before commit
===========================================================================
File: tests\common\plugins\conditional_mark\tests_mark_conditions_skip_traffic_test.yaml
===========================================================================
Conditional marks before sort: ['acl/custom_acl_table/test_custom_acl_table.py', 'acl/null_route/test_null_route_helper.py', 'acl/test_acl.py', 'acl/test_acl_outer_vlan.py', 'acl/test_stress_acl.py', 'arp/test_stress_arp.py', 'arp/test_unknown_mac.py', 'arp/test_wr_arp.py', 'decap/test_decap.py', 'ecmp/inner_hashing/test_inner_hashing.py', 'ecmp/inner_hashing/test_inner_hashing_lag.py', 'ecmp/inner_hashing/test_inner_hashing.py:1', 'ecmp/inner_hashing/test_wr_inner_hashing.py', 'ecmp/inner_hashing/test_wr_inner_hashing_lag.py', 'everflow/test_everflow_ipv6.py', 'everflow/test_everflow_per_interface.py', 'everflow/test_everflow_testbed.py']
Conditional marks after sort: ['acl/custom_acl_table/test_custom_acl_table.py', 'acl/null_route/test_null_route_helper.py', 'acl/test_acl.py', 'acl/test_acl_outer_vlan.py', 'acl/test_stress_acl.py', 'arp/test_stress_arp.py', 'arp/test_unknown_mac.py', 'arp/test_wr_arp.py', 'decap/test_decap.py', 'ecmp/inner_hashing/test_inner_hashing.py', 'ecmp/inner_hashing/test_inner_hashing.py:1', 'ecmp/inner_hashing/test_inner_hashing_lag.py', 'ecmp/inner_hashing/test_wr_inner_hashing.py', 'ecmp/inner_hashing/test_wr_inner_hashing_lag.py', 'everflow/test_everflow_ipv6.py', 'everflow/test_everflow_per_interface.py', 'everflow/test_everflow_testbed.py']
===========================================================================
Mismatch item, before sort: ecmp/inner_hashing/test_inner_hashing_lag.py, after sort: ecmp/inner_hashing/test_inner_hashing.py:1
===========================================================================

Process finished with exit code 1

Approach
What is the motivation for this PR?
Refine the output of conditional_mark order check.
Print more detailed information so that contributors know where to modify.

How did you do it?
Print detailed mis-order item

How did you verify/test it?
Local test

co-authorized by: [email protected]
  • Loading branch information
yejianquan authored Jul 5, 2024
1 parent f2c96e8 commit 2094429
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions .hooks/pre_commit_hooks/check_conditional_mark_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

def main():
stage_files = sys.argv[1:]
retval = 0
for stage_file in stage_files:
if "tests_mark_conditions" in stage_file:
conditions = []
Expand All @@ -17,11 +16,21 @@ def main():
conditions.append(line.strip().rstrip(":"))
sorted_conditions = conditions[:]
sorted_conditions.sort()
if conditions != sorted_conditions:
print("The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml "
"are not sorted in alphabetic order.")
retval = 1
return retval
for i in range(len(conditions)):
if conditions[i] != sorted_conditions[i]:
print("The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml "
"are not sorted in alphabetic order, please adjust the order before commit")
print("===========================================================================")
print("File: {}".format(stage_file))
print("===========================================================================")
print("Conditional marks before sort: {}".format(conditions))
print("Conditional marks after sort: {}".format(sorted_conditions))
print("===========================================================================")
print("Mismatch item, before sort: {}, after sort: {}".format(conditions[i],
sorted_conditions[i]))
print("===========================================================================")
return 1
return 0


if __name__ == "__main__":
Expand Down

0 comments on commit 2094429

Please sign in to comment.