Skip to content

[tests/crm] Fix python3 syntax error in test_acl_entry#9208

Merged
lizhijianrd merged 2 commits intosonic-net:masterfrom
lizhijianrd:fix-crm-test-acl-entry
Aug 1, 2023
Merged

[tests/crm] Fix python3 syntax error in test_acl_entry#9208
lizhijianrd merged 2 commits intosonic-net:masterfrom
lizhijianrd:fix-crm-test-acl-entry

Conversation

@lizhijianrd
Copy link
Copy Markdown
Contributor

@lizhijianrd lizhijianrd commented Aug 1, 2023

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

@lizhijianrd lizhijianrd requested a review from Blueve August 1, 2023 09:00
Blueve
Blueve previously approved these changes Aug 1, 2023
@lizhijianrd lizhijianrd changed the title Fix python3 syntax error in test_acl_entry [tests/crm] Fix python3 syntax error in test_acl_entry Aug 1, 2023
@lizhijianrd lizhijianrd merged commit 1c5b8dd into sonic-net:master Aug 1, 2023
@lizhijianrd lizhijianrd deleted the fix-crm-test-acl-entry branch August 1, 2023 11:26
SuvarnaMeenakshi added a commit to SuvarnaMeenakshi/sonic-mgmt that referenced this pull request Aug 4, 2023
SuvarnaMeenakshi added a commit to SuvarnaMeenakshi/sonic-mgmt that referenced this pull request Aug 4, 2023
@mssonicbld
Copy link
Copy Markdown
Collaborator

Cherry-pick PR to 202305: #9338

mssonicbld pushed a commit to mssonicbld/sonic-mgmt that referenced this pull request Aug 8, 2023
)

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 pushed a commit that referenced this pull request Aug 9, 2023
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]>
AharonMalkin pushed a commit to AharonMalkin/sonic-mgmt that referenced this pull request Jan 25, 2024
)

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]>
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.

3 participants