Skip to content

[masic] test_cacl_application.py: Fix argument issue in verify_cacl #6170

Merged
wenyiz2021 merged 9 commits intosonic-net:masterfrom
wenyiz2021:cacl_appl
Aug 17, 2022
Merged

[masic] test_cacl_application.py: Fix argument issue in verify_cacl #6170
wenyiz2021 merged 9 commits intosonic-net:masterfrom
wenyiz2021:cacl_appl

Conversation

@wenyiz2021
Copy link
Contributor

Signed-off-by: Wenyi Zhang [email protected]

Description of PR

PR #5895 introduced 2 fixture which should be intended to work for dualtor, while it added argument in verify_cacl, which is also used for test_multiasic_cacl_application, failing to add this argument in this test leads to an argument misleading at runtime, between expected_dhcp_rules_for_standby and enum_frontend_asic_index

Summary:
Fixes # (issue)

Type of change

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

Back port request

  • 201911
  • 202012

Approach

What is the motivation for this PR?

Fix issue seen on multi-asic seen after above PR merged

How did you do it?

Add argument expected_dhcp_rules_for_standby in test_cacl_application_dualtor, as the fixture take fixture duthost_dualtor that for non-dualtor, there is only 1 active_tor and returns empty list.

How did you verify/test it?

Before:
30/07/2022 07:12:07 init._log_sep_line L0160 INFO | ==================== cacl/test_cacl_application.py::test_multiasic_cacl_application[3] call ====================
30/07/2022 07:12:07 init.pytest_runtest_call L0040 ERROR | Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/_pytest/python.py", line 1464, in runtest
self.ihook.pytest_pyfunc_call(pyfuncitem=self)
File "/usr/local/lib/python2.7/dist-packages/pluggy/hooks.py", line 286, in call
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/usr/local/lib/python2.7/dist-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/usr/local/lib/python2.7/dist-packages/pluggy/manager.py", line 87, in
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/usr/local/lib/python2.7/dist-packages/pluggy/callers.py", line 208, in _multicall
return outcome.get_result()
File "/usr/local/lib/python2.7/dist-packages/pluggy/callers.py", line 81, in get_result
_reraise(*ex) # noqa
File "/usr/local/lib/python2.7/dist-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/python.py", line 174, in pytest_pyfunc_call
testfunction(**testargs)
File "/azp/agent/_work/2/s/sonic-mgmt-int/tests/cacl/test_cacl_application.py", line 838, in test_multiasic_cacl_application
verify_cacl(duthost, localhost, creds, docker_network, enum_frontend_asic_index)
File "/azp/agent/_work/2/s/sonic-mgmt-int/tests/cacl/test_cacl_application.py", line 745, in verify_cacl
expected_iptables_rules, expected_ip6tables_rules = generate_expected_rules(duthost, docker_network, asic_index, expected_dhcp_rules_for_standby)
File "/azp/agent/_work/2/s/sonic-mgmt-int/tests/cacl/test_cacl_application.py", line 416, in generate_expected_rules
iptables_rules.extend(expected_dhcp_rules_for_standby)
TypeError: 'int' object is not iterable

After:
cacl/test_cacl_application.py::test_cacl_application_nondualtor PASSED [ 7%]
cacl/test_cacl_application.py::test_cacl_application_dualtor[active_tor] SKIPPED [ 15%]
cacl/test_cacl_application.py::test_cacl_application_dualtor[standby_tor] SKIPPED [ 23%]
cacl/test_cacl_application.py::test_multiasic_cacl_application[active_tor-0] PASSED [ 30%]
cacl/test_cacl_application.py::test_multiasic_cacl_application[standby_tor-0] PASSED [ 38%]
cacl/test_cacl_application.py::test_multiasic_cacl_application[active_tor-1] PASSED [ 46%]
cacl/test_cacl_application.py::test_multiasic_cacl_application[standby_tor-1] PASSED [ 53%]
cacl/test_cacl_application.py::test_multiasic_cacl_application[active_tor-2] PASSED [ 61%]
cacl/test_cacl_application.py::test_multiasic_cacl_application[standby_tor-2] PASSED [ 69%]
cacl/test_cacl_application.py::test_multiasic_cacl_application[active_tor-3] PASSED [ 76%]
cacl/test_cacl_application.py::test_multiasic_cacl_application[standby_tor-3] PASSED [ 84%]
cacl/test_cacl_application.py::test_cacl_scale_rules_ipv4 PASSED [ 92%]
cacl/test_cacl_application.py::test_cacl_scale_rules_ipv6 PASSED [100%]

--------------------------------------------------------------------------------------------- generated xml file: /var/src/sonic-mgmt-int/tests/logs/tr.xml ----------------------------------------------------------------------------------------------
================================================================================================================ short test summary info =================================================================================================================
SKIPPED [2] cacl/test_cacl_application.py: test_cacl_application_dualtor is only supported on dualtor topology
========================================================================================================= 11 passed, 2 skipped in 895.93 seconds =========================================================================================================

Any platform specific information?

Fix for multi-asic

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

Documentation

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 15, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@wenyiz2021 wenyiz2021 requested a review from ZhaohuiS August 15, 2022 20:11
@wenyiz2021
Copy link
Contributor Author

/easycla

1 similar comment
@wenyiz2021
Copy link
Contributor Author

/easycla

commit b1cd519
Author: Wenyi Zhang <[email protected]>
Date:   Mon Aug 15 20:09:12 2022 +0000

    Fix argument in test_multiasic_cacl_application

    Signed-off-by: Wenyi Zhang <[email protected]>
@wenyiz2021
Copy link
Contributor Author

/easycla

@wenyiz2021
Copy link
Contributor Author

/easycla

1 similar comment
@wenyiz2021
Copy link
Contributor Author

/easycla

"""
duthost = duthosts[rand_one_dut_hostname]
verify_cacl(duthost, tbinfo, localhost, creds, docker_network, enum_frontend_asic_index)
verify_cacl(duthost, tbinfo, localhost, creds, docker_network, expected_dhcp_rules_for_standby, enum_frontend_asic_index)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the expectation from the changes in #5895 is that, if it is not dualtor, then we have to keep expected_dhcp_rules_for_standby as None in verify_cacl.
So for mulit-asic platform, in

def test_multiasic_cacl_application, 
verify_cacl(duthost, tbinfo, localhost, creds, docker_network, None, enum_frontend_asic_index)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the expectation is None/empty-list.
fixture expected_dhcp_rules_for_standby will return empty list for non-dualtor scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SuvarnaMeenakshi think you are right, passing None makes code cleaner. Changed in this way.

@bingwang-ms
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

verify_cacl(duthost_dualtor, tbinfo, localhost, creds, docker_network, expected_dhcp_rules_for_standby)

def test_multiasic_cacl_application(duthosts, tbinfo, rand_one_dut_hostname, localhost, creds,docker_network, enum_frontend_asic_index):
def test_multiasic_cacl_application(duthosts, tbinfo, rand_one_dut_hostname, localhost, creds, docker_network, expected_dhcp_rules_for_standby, enum_frontend_asic_index):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wenyiz2021 Thank you for your hard work to fix this issue. I think your solution is better, should we add expected_dhcp_rules_for_standby for test_cacl_application_nondualtor as well, even it works fine based on current code.
One wired thing is in the traceback of test_cacl_application_nondualtor, expected_dhcp_rules_for_standby is 1, that's the reason why this case failed. I verified test_cacl_application_nondualtor, the expected_dhcp_rules_for_standby is null. What's the difference for these 2 cases, I didn't figure out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZhaohuiS I didn't change for test_cacl_application_nondualtor, because it is calling verify_cacl this way:
verify_cacl(duthost, localhost, creds, docker_network, None)
where def is:
def verify_cacl(duthost, localhost, creds, docker_network, expected_dhcp_rules_for_standby, asic_index = None)

so it is passing None to expected_dhcp_rules_for_standby, and leave asic_index = None, so it should be good.

may I know where you find "traceback of test_cacl_application_nondualtor, expected_dhcp_rules_for_standby is 1"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, I gave default None to expected_dhcp_rules_for_standby at verify_cacl() definition.

So that only test_multiasic_cacl_application that called verify_cacl with an asic_index need to specifically pass None to expected_dhcp_rules_for_standby.
test_cacl_application_dualtor can pass its expected_dhcp_rules_for_standby.

Other callers don't need to specify for the 2 arguments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wenyiz2021 I got it, this the difference, if I put expected_dhcp_rules_for_standby behind asic_index, it should be fine. As you said, it's correct to set it to None. Thank you for fixing this.

the log of "traceback of test_cacl_application_nondualtor, expected_dhcp_rules_for_standby is 1" is here:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZhaohuiS yeah, that traceback comes from test_multiasic_cacl_application(), where the integer comes from asic_index iso intending for expected_dhcp_rules_for_standby .

of expected_dhcp_rules is list before adding it to the iptables_rules
@lgtm-com
Copy link

lgtm-com bot commented Aug 16, 2022

This pull request introduces 1 alert and fixes 2 when merging 50711ad into 55b23fd - view on LGTM.com

new alerts:

  • 1 for Syntax error

fixed alerts:

  • 2 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Aug 16, 2022

This pull request introduces 1 alert and fixes 2 when merging d76799a into 55b23fd - view on LGTM.com

new alerts:

  • 1 for Syntax error

fixed alerts:

  • 2 for Unused import

@wenyiz2021 wenyiz2021 merged commit 6738170 into sonic-net:master Aug 17, 2022
@wenyiz2021 wenyiz2021 deleted the cacl_appl branch August 17, 2022 17:24
wangxin pushed a commit that referenced this pull request Aug 22, 2022
…6170)

* Fix argument in test_multiasic_cacl_application

Signed-off-by: Wenyi Zhang <[email protected]>

* Squashed commit of the following:

commit b1cd519
Author: Wenyi Zhang <[email protected]>
Date:   Mon Aug 15 20:09:12 2022 +0000

    Fix argument in test_multiasic_cacl_application

    Signed-off-by: Wenyi Zhang <[email protected]>

* Squash commit with new signature

Signed-off-by: wenyiz2021 <[email protected]>

* Add pytest_assert to ensure type

of expected_dhcp_rules is list before adding it to the iptables_rules

* Change expected_dhcp.. to None if not needed

* add backslash

* Fix syntax

Signed-off-by: Wenyi Zhang <[email protected]>
Signed-off-by: wenyiz2021 <[email protected]>
allen-xf pushed a commit to allen-xf/sonic-mgmt that referenced this pull request Oct 28, 2022
…onic-net#6170)

* Fix argument in test_multiasic_cacl_application

Signed-off-by: Wenyi Zhang <[email protected]>

* Squashed commit of the following:

commit b1cd519
Author: Wenyi Zhang <[email protected]>
Date:   Mon Aug 15 20:09:12 2022 +0000

    Fix argument in test_multiasic_cacl_application

    Signed-off-by: Wenyi Zhang <[email protected]>

* Squash commit with new signature

Signed-off-by: wenyiz2021 <[email protected]>

* Add pytest_assert to ensure type

of expected_dhcp_rules is list before adding it to the iptables_rules

* Change expected_dhcp.. to None if not needed

* add backslash

* Fix syntax

Signed-off-by: Wenyi Zhang <[email protected]>
Signed-off-by: wenyiz2021 <[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.

5 participants