Skip to content

Commit a723f8f

Browse files
authored
Fix pre-commit failures
1 parent 9b8bafe commit a723f8f

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

tests/dash/test_eni_based_fowarding.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
from ptf.mask import Mask
1212
from dash_utils import render_template_to_host, apply_swssconfig_file
1313
from tests.dash.conftest import get_interface_ip
14-
SONIC_MGMT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
15-
sys.path.insert(0, os.path.join(SONIC_MGMT_ROOT, 'ansible', 'module_utils'))
16-
from smartswitch_utils import smartswitch_hwsku_config
1714
from tests.common.helpers.assertions import pytest_assert
1815
from tests.common.utilities import wait_until
1916
from tests.common.platform.interface_utils import get_dpu_npu_ports_from_hwsku
2017
from packets import generate_inner_packet, set_do_not_care_layer
2118
from tests.common import config_reload
22-
from constants import *
19+
from constants import * # noqa: F403
20+
SONIC_MGMT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
21+
sys.path.insert(0, os.path.join(SONIC_MGMT_ROOT, 'ansible', 'module_utils'))
22+
from smartswitch_utils import smartswitch_hwsku_config # noqa: E402
2323

2424
pytestmark = [
2525
pytest.mark.topology('t1'),
@@ -38,6 +38,7 @@
3838
dataplane_logger = logging.getLogger("dataplane")
3939
dataplane_logger.setLevel(logging.ERROR)
4040

41+
4142
@pytest.fixture(scope="module", autouse=True)
4243
def setup_gnmi_server():
4344
"""Override the conftest autouse fixture to skip it, this test does not use gNMI"""
@@ -81,7 +82,7 @@ def update_peer_route(duthost, loopback_ips, dash_pl_config):
8182

8283
@pytest.fixture(scope="module")
8384
def apply_config_db(duthost, dpu_num, mock_pa_ipv4, loopback_ips,
84-
dash_pl_config, vdpus_info, apply_peer_route): # noqa: F811
85+
dash_pl_config, vdpus_info, apply_peer_route): # noqa: F811
8586
loopback0_ip, peer_loopback0_ip = loopback_ips
8687
template_name = "eni_based_forwarding_config_db.j2"
8788
dest_path = "/tmp/eni_based_forwarding_config_db.json"
@@ -99,7 +100,7 @@ def apply_config_db(duthost, dpu_num, mock_pa_ipv4, loopback_ips,
99100
}
100101
render_template_to_host(template_name, duthost, dest_path, **config_db_params)
101102
rendered_config = duthost.shell(f"cat {dest_path}")['stdout']
102-
logger.info(f"Apply configrations to config_db:\n {rendered_config}")
103+
logger.info(f"Apply configrations to config_db: \n{rendered_config}")
103104
duthost.shell(f"config load {dest_path} -y")
104105

105106
yield
@@ -130,17 +131,17 @@ def loopback_ips(duthost):
130131

131132

132133
@pytest.fixture(scope="module")
133-
def apply_appl_db_and_check_acl_rules(duthost, vdpus_info, apply_config_db, mock_pa_ipv4, loopback_ips): # noqa: F811
134+
def apply_appl_db_and_check_acl_rules(duthost, vdpus_info, apply_config_db, mock_pa_ipv4, loopback_ips): # noqa: F811
134135
_, peer_loopback0_ip = loopback_ips
135136
apply_dash_eni_forward_table(duthost, vdpus_info, active_eni_mac=ENI1_MAC, standby_eni_mac=ENI2_MAC)
136137
logger.info("Check the ENI forwarding ACL rules are applied correctly.")
137138
pytest_assert(
138139
wait_until(10, 5, 0, check_acl_table_and_type_tables, duthost),
139140
"ACL table and type tables are not applied correctly.")
140-
pytest_assert(
141-
wait_until(10, 5, 0, check_acl_rules, duthost, mock_pa_ipv4, peer_loopback0_ip,
142-
active_eni_mac=ENI1_MAC, standby_eni_mac=ENI2_MAC),
143-
"ACL rules are not applied correctly.")
141+
pytest_assert(wait_until(
142+
10, 5, 0, check_acl_rules, duthost, mock_pa_ipv4, peer_loopback0_ip,
143+
active_eni_mac=ENI1_MAC, standby_eni_mac=ENI2_MAC),
144+
"ACL rules are not applied correctly.")
144145

145146

146147
def apply_dash_eni_forward_table(
@@ -161,7 +162,7 @@ def apply_dash_eni_forward_table(
161162
}
162163
render_template_to_host(template_name, duthost, dest_path, **appl_db_params)
163164
rendered_config = duthost.shell(f"cat {dest_path}")['stdout']
164-
logger.info(f"Apply configrations to appl_db:\n {rendered_config}")
165+
logger.info(f"Apply configrations to appl_db: \n{rendered_config}")
165166
apply_swssconfig_file(duthost, dest_path)
166167

167168

@@ -186,15 +187,17 @@ def check_acl_table_and_type_tables(duthost):
186187
"BIND_POINTS": "PORT,PORTCHANNEL"
187188
}
188189
}
189-
logger.info(f"Expected ACL tables for ENI based forwarding:\n {expected_tables}")
190+
logger.info(f"Expected ACL tables for ENI based forwarding: \n{expected_tables}")
190191
for table, table_fields in expected_tables.items():
191192
actual_table = json.loads(duthost.shell(f"redis-cli --json -n 0 HGETALL {table}")['stdout'])
192193
logger.info(f"Actual table for key {table}: {actual_table}")
193194
if not actual_table == table_fields:
194-
logger.error(f"ACL table {table} is not applied correctly. Expected: {table_fields}, Actual: {actual_table}")
195+
logger.error(
196+
f"ACL table {table} is not applied correctly. Expected: {table_fields}, Actual: {actual_table}")
195197
return False
196198
return True
197199

200+
198201
def check_acl_rules(duthost, mock_pa_ipv4, peer_loopback0_ip,
199202
active_eni_mac=ENI1_MAC, standby_eni_mac=ENI2_MAC,
200203
non_existing_eni_mac=NON_EXISTING_ENI_MAC):
@@ -232,7 +235,8 @@ def check_acl_rules(duthost, mock_pa_ipv4, peer_loopback0_ip,
232235
"REDIRECT_ACTION": f"{peer_loopback0_ip}@tunnel_v4,{VNI}"
233236
}
234237
}
235-
logger.info(f"3 ENIs are configured in this test, expected {len(expected_rules.keys())} ACL rules:\n {expected_rules}")
238+
logger.info(
239+
f"3 ENIs are configured in this test, expected {len(expected_rules.keys())} ACL rules: \n{expected_rules}")
236240
actual_rule_num = int(duthost.shell("redis-cli -n 0 keys 'ACL_RULE_TABLE:ENI*' | grep 'ACL' | wc -l")['stdout'])
237241
if not actual_rule_num == len(expected_rules):
238242
logger.error(f"Expected {len(expected_rules)} ENI forwarding ACL rules, but got {actual_rule_num}")
@@ -241,13 +245,14 @@ def check_acl_rules(duthost, mock_pa_ipv4, peer_loopback0_ip,
241245
actual_rule = json.loads(duthost.shell(f"redis-cli --json -n 0 HGETALL {rule_name}")['stdout'])
242246
logger.info(f"Actual rule for key {rule_name}: {actual_rule}")
243247
if not actual_rule == rule_fields:
244-
logger.error(f"ACL rule {rule_name} is not applied correctly. Expected: {rule_fields}, Actual: {actual_rule}")
248+
logger.error(
249+
f"ACL rule {rule_name} is not applied correctly. Expected: {rule_fields}, Actual: {actual_rule}")
245250
return False
246251
return True
247252

248253

249254
@pytest.fixture(scope="module", autouse=True)
250-
def common_setup_teardown(duthost, apply_appl_db_and_check_acl_rules, dpu_num): # noqa: F811
255+
def common_setup_teardown(duthost, apply_appl_db_and_check_acl_rules, dpu_num): # noqa: F811
251256

252257
yield
253258

@@ -363,18 +368,20 @@ def test_eni_based_forwarding_non_existing_eni(ptfadapter, dash_pl_config, loopb
363368
testutils.verify_packet_any_port(ptfadapter, expected_packet, dash_pl_config[REMOTE_PTF_RECV_INTF])
364369

365370

366-
def test_eni_based_forwarding_eni_state_change(duthost, ptfadapter, dash_pl_config, vdpus_info, loopback_ips, mock_pa_ipv4):
371+
def test_eni_based_forwarding_eni_state_change(
372+
duthost, ptfadapter, dash_pl_config, vdpus_info, loopback_ips, mock_pa_ipv4
373+
):
367374
"""
368375
Validate when the ENI state changes, the ACL rules are updated correctly.
369376
"""
370377
_, peer_loopback0_ip = loopback_ips
371378
try:
372379
logger.info("Change the active ENI to standby ENI and vice versa.")
373380
apply_dash_eni_forward_table(duthost, vdpus_info, active_eni_mac=ENI2_MAC, standby_eni_mac=ENI1_MAC)
374-
pytest_assert(
375-
wait_until(10, 5, 0, check_acl_rules, duthost, mock_pa_ipv4, peer_loopback0_ip,
376-
active_eni_mac=ENI2_MAC, standby_eni_mac=ENI1_MAC),
377-
"ACL rules are not applied correctly.")
381+
pytest_assert(wait_until(
382+
10, 5, 0, check_acl_rules, duthost, mock_pa_ipv4, peer_loopback0_ip,
383+
active_eni_mac=ENI2_MAC, standby_eni_mac=ENI1_MAC),
384+
"ACL rules are not applied correctly.")
378385
logger.info("Send a packet of the original standby ENI to VIP and expect"
379386
" to receive it on the mock local DPU dataplane interface.")
380387
packet, expected_packet = generate_packet(dash_pl_config, ENI2_MAC, 'active')
@@ -390,10 +397,10 @@ def test_eni_based_forwarding_eni_state_change(duthost, ptfadapter, dash_pl_conf
390397
finally:
391398
logger.info("Restore the ENI to their original states.")
392399
apply_dash_eni_forward_table(duthost, vdpus_info, active_eni_mac=ENI1_MAC, standby_eni_mac=ENI2_MAC)
393-
pytest_assert(
394-
wait_until(10, 5, 0, check_acl_rules, duthost, mock_pa_ipv4, peer_loopback0_ip,
395-
active_eni_mac=ENI1_MAC, standby_eni_mac=ENI2_MAC),
396-
"ACL rules are not applied correctly.")
400+
pytest_assert(wait_until(
401+
10, 5, 0, check_acl_rules, duthost, mock_pa_ipv4, peer_loopback0_ip,
402+
active_eni_mac=ENI1_MAC, standby_eni_mac=ENI2_MAC),
403+
"ACL rules are not applied correctly.")
397404

398405

399406
def test_eni_based_forwarding_tunnel_termination(

0 commit comments

Comments
 (0)