Skip to content

[action] [PR:9208] [tests/crm] Fix python3 syntax error in test_acl_entry#9338

Merged
mssonicbld merged 1 commit intosonic-net:202305from
mssonicbld:cherry/202305/9208
Aug 9, 2023
Merged

[action] [PR:9208] [tests/crm] Fix python3 syntax error in test_acl_entry#9338
mssonicbld merged 1 commit intosonic-net:202305from
mssonicbld:cherry/202305/9208

Conversation

@mssonicbld
Copy link
Copy Markdown
Collaborator

Description of PR

Summary:
Testcase crm/test_crm.py::test_acl_entry hit below error in Python3 env:

 def test_acl_entry(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_frontend_asic_index, collector, tbinfo):
 duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
 asichost = duthost.asic_instance(enum_frontend_asic_index)
 asic_collector = collector[asichost.asic_index]

 if duthost.facts["asic_type"] == "marvell":
 # Remove DATA ACL Table and add it again with ports in same port group
 mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
 tmp_ports = mg_facts["minigraph_ports"].keys()
> tmp_ports.sort(key=lambda x: int(x[8:]))
E AttributeError: 'dict_keys' object has no attribute 'sort'

The root cause is, in python2 dict.keys() returns a list object, but in python3 it returns a dict_keys object which is not sortable.

Use sorted() function instead of dict.keys().sort(). sorted() function can put the keys of a dict in a list in sorted order, and it has same action in Python2 and Python3.

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 201911
  • 202012
  • 202205

Approach

What is the motivation for this PR?

Fix a python3 syntax error in testcase crm/test_crm.py::test_acl_entry.

How did you do it?

Use sorted() function instead of dict.keys().sort(). sorted() function can put the keys of a dict in a list in sorted order, and it has same action in Python2 and Python3.

How did you verify/test it?

Verified by running testcase on Marvell testbed.

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

)

What is the motivation for this PR?
Fix a python3 syntax error in testcase crm/test_crm.py::test_acl_entry. In python2 dict.keys() returns a list object, but in python3 it returns a dict_keys object which is not sortable.

How did you do it?
Use sorted() function instead of dict.keys().sort(). sorted() function can put the keys of a dict in a list in sorted order, and it has same action in Python2 and Python3.

How did you verify/test it?
Verified by running testcase on Marvell testbed.

Signed-off-by: Zhijian Li <[email protected]>
@mssonicbld
Copy link
Copy Markdown
Collaborator Author

Original PR: #9208

@mssonicbld mssonicbld merged commit aa9cb6a into sonic-net:202305 Aug 9, 2023
@mssonicbld mssonicbld deleted the cherry/202305/9208 branch February 4, 2024 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants