Skip to content

Commit 2044f26

Browse files
added new HA fixtures to programme dash ha scope and ha set tables via… (#22390)
What is the motivation for this PR Not provided in PR description. How did you do it Added new pytest fixtures. How did you verify/test it Ran the tests and verified the DPU Tables HA Scope and HA Set. Signed-off-by: nnelluri-cisco <nnelluri@cisco.com> Signed-off-by: nnelluri <nnelluri@cisco.com>
1 parent 78d6359 commit 2044f26

4 files changed

Lines changed: 496 additions & 15 deletions

File tree

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
{
2-
"DASH_HA_SET_CONFIG_TABLE": {
3-
"ha-set-1001": {
2+
"DASH_HA_SCOPE_CONFIG_TABLE": {
3+
"vdpu0_0:haset0_0": {
44
"version": "1.0",
5-
"vip_v4": "192.168.100.1",
6-
"vip_v6": "fd00::1001",
7-
"vdpu_ids": ["dpu0", "dpu1"],
8-
"scope": "dpu",
9-
"pinned_vdpu_bfd_probe_states": ["up", "down"],
10-
"preferred_vdpu_id": "dpu0",
11-
"preferred_standalone_vdpu_index": 0
5+
"owner": "switch",
6+
"disabled": "false",
7+
"ha_set_id": "haset0_0",
8+
"desired_ha_state": "active",
9+
"approved_pending_operation_ids": ""
10+
},
11+
"vdpu1_0:haset0_0": {
12+
"version": "1.0",
13+
"owner": "switch",
14+
"disabled": "false",
15+
"ha_set_id": "haset0_0",
16+
"desired_ha_state": "standalone",
17+
"approved_pending_operation_ids": ""
1218
}
1319
}
1420
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"DASH_HA_SET_CONFIG_TABLE": {
3+
"haset0_0": {
4+
"version": "1.0",
5+
"vip_v4": "3.2.1.0",
6+
"vip_v6": "3:2::1:0",
7+
"vdpu_ids": ["vdpu0_0", "vdpu1_0"],
8+
"scope": "dpu",
9+
"pinned_vdpu_bfd_probe_states": ["up", "down"],
10+
"preferred_vdpu_id": "vdpu0_0",
11+
"preferred_standalone_vdpu_index": 0
12+
}
13+
}
14+
}

tests/ha/conftest.py

Lines changed: 144 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1+
import logging
12
import pytest
2-
import time
3+
from pathlib import Path
4+
from collections import defaultdict
5+
import os
36
import json
7+
import time
48

59
from tests.common.config_reload import config_reload
6-
from pathlib import Path
7-
from collections import defaultdict
810
from tests.common.helpers.constants import DEFAULT_NAMESPACE
9-
from common.ha.smartswitch_ha_helper import PtfTcpTestAdapter
10-
from common.ha.smartswitch_ha_io import SmartSwitchHaTrafficTest
11-
from common.ha.smartswitch_ha_helper import (
11+
from tests.common.ha.smartswitch_ha_helper import PtfTcpTestAdapter
12+
from tests.common.ha.smartswitch_ha_io import SmartSwitchHaTrafficTest
13+
from tests.common.ha.smartswitch_ha_helper import (
1214
add_port_to_namespace,
1315
remove_namespace,
1416
add_static_route_to_ptf,
1517
add_static_route_to_dut
1618
)
1719

20+
from tests.ha.ha_utils import (
21+
22+
build_dash_ha_scope_args,
23+
wait_for_pending_operation_id,
24+
build_dash_ha_scope_activate_args,
25+
wait_for_ha_state,
26+
build_dash_ha_set_args,
27+
proto_utils_hset
28+
)
29+
30+
logger = logging.getLogger(__name__)
31+
1832

1933
@pytest.fixture(scope="module")
2034
def copy_files(ptfhost):
@@ -408,3 +422,127 @@ def setup_ha_config(duthosts):
408422
final_cfg[f"DUT{switch_id}"] = cfg
409423

410424
return final_cfg
425+
426+
427+
@pytest.fixture(scope="module")
428+
def setup_dash_ha_from_json(duthosts):
429+
current_dir = os.path.dirname(os.path.abspath(__file__))
430+
base_dir = os.path.join(current_dir, "..", "common", "ha")
431+
ha_set_file = os.path.join(base_dir, "dash_ha_set_dpu_config_table.json")
432+
433+
with open(ha_set_file) as f:
434+
ha_set_data = json.load(f)["DASH_HA_SET_CONFIG_TABLE"]
435+
436+
# -------------------------------------------------
437+
# Step 1: Program HA SET on BOTH DUTs
438+
# -------------------------------------------------
439+
for duthost in duthosts:
440+
for key, fields in ha_set_data.items():
441+
proto_utils_hset(
442+
duthost,
443+
table="DASH_HA_SET_CONFIG_TABLE",
444+
key=key,
445+
args=build_dash_ha_set_args(fields),
446+
)
447+
448+
# -------------------------------------------------
449+
# Step 2: Initial HA SCOPE per DUT
450+
# -------------------------------------------------
451+
ha_scope_per_dut = [
452+
(
453+
"vdpu0_0:haset0_0",
454+
{
455+
"version": "1",
456+
"disabled": "true",
457+
"desired_ha_state": "active",
458+
"ha_set_id": "haset0_0",
459+
"owner": "dpu",
460+
},
461+
),
462+
(
463+
"vdpu1_0:haset0_0",
464+
{
465+
"version": "1",
466+
"disabled": "true",
467+
"desired_ha_state": "unspecified",
468+
"ha_set_id": "haset0_0",
469+
"owner": "dpu",
470+
},
471+
),
472+
]
473+
474+
for duthost, (key, fields) in zip(duthosts, ha_scope_per_dut):
475+
proto_utils_hset(
476+
duthost,
477+
table="DASH_HA_SCOPE_CONFIG_TABLE",
478+
key=key,
479+
args=build_dash_ha_scope_args(fields),
480+
)
481+
482+
483+
@pytest.fixture(scope="module")
484+
def activate_dash_ha_from_json(duthosts):
485+
# -------------------------------------------------
486+
# Step 4: Activate Role (using pending_operation_ids)
487+
# -------------------------------------------------
488+
activate_scope_per_dut = [
489+
(
490+
"vdpu0_0:haset0_0",
491+
{
492+
"version": "1",
493+
"disabled": False,
494+
"desired_ha_state": "active",
495+
"ha_set_id": "haset0_0",
496+
"owner": "dpu",
497+
},
498+
),
499+
(
500+
"vdpu1_0:haset0_0",
501+
{
502+
"version": "1",
503+
"disabled": False,
504+
"desired_ha_state": "unspecified",
505+
"ha_set_id": "haset0_0",
506+
"owner": "dpu",
507+
},
508+
),
509+
]
510+
for duthost, (key, fields) in zip(duthosts, activate_scope_per_dut):
511+
proto_utils_hset(
512+
duthost,
513+
table="DASH_HA_SCOPE_CONFIG_TABLE",
514+
key=key,
515+
args=build_dash_ha_scope_args(fields),
516+
)
517+
for idx, (duthost, (key, fields)) in enumerate(zip(duthosts, activate_scope_per_dut)):
518+
pending_id = wait_for_pending_operation_id(
519+
duthost,
520+
scope_key=key,
521+
expected_op_type="activate_role",
522+
timeout=120,
523+
interval=2
524+
)
525+
assert pending_id, (
526+
f"Timed out waiting for active pending_operation_id "
527+
f"for {duthost.hostname} scope {key}"
528+
)
529+
530+
logger.info(f"DASH HA {duthost.hostname} found pending id {pending_id}")
531+
proto_utils_hset(
532+
duthost,
533+
table="DASH_HA_SCOPE_CONFIG_TABLE",
534+
key=key,
535+
args=build_dash_ha_scope_activate_args(fields, pending_id),
536+
)
537+
# Verify HA state using fields
538+
expected_state = "active" if idx == 0 else "standby"
539+
assert wait_for_ha_state(
540+
duthost,
541+
scope_key=key,
542+
expected_state=expected_state,
543+
timeout=120,
544+
interval=5,
545+
), f"HA did not reach expected state {expected_state} for {key} on {duthost.hostname}"
546+
logger.info(f"DASH HA Step-4 Activate Role completed for {duthost.hostname}")
547+
logger.info("DASH HA Step-4 Activate Role completed")
548+
yield

0 commit comments

Comments
 (0)