Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/bgp/test_bgp_bbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from tests.common.utilities import wait_until, delete_running_config
from tests.common.gu_utils import apply_patch, expect_op_success
from tests.common.gu_utils import generate_tmpfile, delete_tmpfile
from tests.common.gu_utils import format_json_patch_for_multiasic


pytestmark = [
Expand Down Expand Up @@ -75,6 +76,7 @@ def add_bbr_config_to_running_config(duthost, status):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand All @@ -97,6 +99,7 @@ def config_bbr_by_gcu(duthost, status):
"value": "{}".format(status)
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down
3 changes: 3 additions & 0 deletions tests/bgp/test_bgp_bbr_default_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from tests.common.utilities import delete_running_config
from tests.common.gu_utils import apply_patch, expect_op_success
from tests.common.gu_utils import generate_tmpfile, delete_tmpfile
from tests.common.gu_utils import format_json_patch_for_multiasic
from tests.common.config_reload import config_reload


Expand Down Expand Up @@ -54,6 +55,7 @@ def add_bbr_config_to_running_config(duthost, status):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
try:
Expand All @@ -73,6 +75,7 @@ def config_bbr_by_gcu(duthost, status):
"value": "{}".format(status)
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
try:
Expand Down
3 changes: 3 additions & 0 deletions tests/bgp/test_bgp_dual_asn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from tests.generic_config_updater.test_bgp_speaker import get_bgp_speaker_runningconfig
from tests.common.gu_utils import apply_patch, expect_op_success
from tests.common.gu_utils import generate_tmpfile, delete_tmpfile
from tests.common.gu_utils import format_json_patch_for_multiasic
from tests.common.gu_utils import (
create_checkpoint,
delete_checkpoint,
Expand Down Expand Up @@ -367,6 +368,7 @@ def bgp_peer_range_add_config(
}
]

json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))

Expand Down Expand Up @@ -402,6 +404,7 @@ def bgp_peer_range_delete_config(
{"op": "remove", "path": "/BGP_PEER_RANGE/{}".format(ip_range_name)},
{"op": "remove", "path": "/BGP_PEER_RANGE/{}".format(ipv6_range_name)},
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down
32 changes: 32 additions & 0 deletions tests/common/gu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
FILES_DIR = os.path.join(BASE_DIR, "files")
TMP_DIR = '/tmp'
HOST_NAME = "/localhost"
ASIC_PREFIX = "/asic"


def generate_tmpfile(duthost):
Expand All @@ -33,6 +35,36 @@ def delete_tmpfile(duthost, tmpfile):
duthost.file(path=tmpfile, state='absent')


def format_json_patch_for_multiasic(duthost, json_data, is_asic_specific=False):
if is_asic_specific:
return json_data

json_patch = []
if duthost.is_multi_asic:
num_asic = duthost.facts.get('num_asic')

for operation in json_data:
path = operation["path"]
if path.startswith(HOST_NAME) and ASIC_PREFIX in path:
json_patch.append(operation)
else:
template = {
"op": operation["op"],
"path": "{}{}".format(HOST_NAME, path)
}

if operation["op"] in ["add", "replace", "test"]:
template["value"] = operation["value"]
json_patch.append(template.copy())
for asic_index in range(num_asic):
asic_ns = "{}{}".format(ASIC_PREFIX, asic_index)
template["path"] = "{}{}".format(asic_ns, path)
json_patch.append(template.copy())
json_data = json_patch

return json_data


def apply_patch(duthost, json_data, dest_file):
"""Run apply-patch on target duthost

Expand Down
2 changes: 2 additions & 0 deletions tests/generic_config_updater/gu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import json
from tests.common.gu_utils import apply_patch, generate_tmpfile, delete_tmpfile
from tests.common.gu_utils import format_json_patch_for_multiasic


BASE_DIR = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -39,6 +40,7 @@ def load_and_apply_json_patch(duthost, file_name, setup):
with open(os.path.join(TEMPLATES_DIR, file_name)) as file:
json_patch = json.load(file)

json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
duts_to_apply = [duthost]
outputs = []
if setup["is_dualtor"]:
Expand Down
14 changes: 14 additions & 0 deletions tests/generic_config_updater/test_aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from tests.common.fixtures.tacacs import get_aaa_sub_options_value
from tests.common.gu_utils import apply_patch, expect_op_success, expect_op_failure
from tests.common.gu_utils import generate_tmpfile, delete_tmpfile
from tests.common.gu_utils import format_json_patch_for_multiasic
from tests.common.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload

pytestmark = [
Expand Down Expand Up @@ -168,6 +169,7 @@ def aaa_tc1_add_config(duthost):
"value": aaa_config
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -206,6 +208,7 @@ def aaa_tc1_replace(duthost):
"value": "tacacs+"
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -243,6 +246,7 @@ def aaa_tc1_add_duplicate(duthost):
"value": "tacacs+"
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand All @@ -269,6 +273,7 @@ def aaa_tc1_remove(duthost):
"path": "/AAA"
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -313,6 +318,7 @@ def tacacs_global_tc2_add_config(duthost):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))

Expand Down Expand Up @@ -352,6 +358,7 @@ def tacacs_global_tc2_invalid_input(duthost):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))

Expand All @@ -375,6 +382,7 @@ def tacacs_global_tc2_duplicate_input(duthost):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))

Expand All @@ -400,6 +408,7 @@ def tacacs_global_tc2_remove(duthost):
"path": "/TACPLUS"
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))

Expand Down Expand Up @@ -443,6 +452,7 @@ def tacacs_server_tc3_add_init(duthost):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -481,6 +491,7 @@ def tacacs_server_tc3_add_max(duthost):
}
json_patch.append(patch)

json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))

Expand Down Expand Up @@ -521,6 +532,7 @@ def tacacs_server_tc3_replace_invalid(duthost):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)
tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))

Expand All @@ -542,6 +554,7 @@ def tacacs_server_tc3_add_duplicate(duthost):
"value": TACACS_SERVER_OPTION
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand All @@ -566,6 +579,7 @@ def tacacs_server_tc3_remove(duthost):
"path": "/TACPLUS_SERVER"
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down
5 changes: 5 additions & 0 deletions tests/generic_config_updater/test_bgp_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from tests.common.helpers.assertions import pytest_assert
from tests.common.gu_utils import apply_patch, expect_op_failure, expect_op_success
from tests.common.gu_utils import generate_tmpfile, delete_tmpfile
from tests.common.gu_utils import format_json_patch_for_multiasic
from tests.common.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload

pytestmark = [
Expand Down Expand Up @@ -115,6 +116,7 @@ def bgp_prefix_tc1_add_config(duthost, community, community_table):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -155,6 +157,7 @@ def bgp_prefix_tc1_xfail(duthost, community_table):
"value": prefixes_v4
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -182,6 +185,7 @@ def bgp_prefix_tc1_replace(duthost, community, community_table):
"value": PREFIXES_V4_DUMMY
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -215,6 +219,7 @@ def bgp_prefix_tc1_remove(duthost, community):
"path": "/BGP_ALLOWED_PREFIXES"
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down
5 changes: 5 additions & 0 deletions tests/generic_config_updater/test_bgp_sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tests.common.helpers.assertions import pytest_assert
from tests.common.gu_utils import apply_patch, expect_op_success
from tests.common.gu_utils import generate_tmpfile, delete_tmpfile
from tests.common.gu_utils import format_json_patch_for_multiasic
from tests.common.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload


Expand Down Expand Up @@ -129,6 +130,7 @@ def bgp_sentinel_tc1_add_config(duthost, lo_intf_ips):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -168,6 +170,7 @@ def bgp_sentinel_tc1_add_dummy_ip_range(duthost):
"value": "{}".format(DUMMY_IP_RANGE_V6)
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -201,6 +204,7 @@ def bgp_sentinel_tc1_rm_dummy_ip_range(duthost):
"path": "/BGP_SENTINELS/{}/ip_range/1".format(BGPSENTINEL_V6)
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -235,6 +239,7 @@ def bgp_sentinel_tc1_replace_src_address(duthost):
"value": "{}".format(DUMMY_SRC_ADDRESS_V6)
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down
5 changes: 5 additions & 0 deletions tests/generic_config_updater/test_bgp_speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tests.common.helpers.assertions import pytest_assert
from tests.common.gu_utils import apply_patch, expect_op_success
from tests.common.gu_utils import generate_tmpfile, delete_tmpfile
from tests.common.gu_utils import format_json_patch_for_multiasic
from tests.common.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload

pytestmark = [
Expand Down Expand Up @@ -144,6 +145,7 @@ def bgp_speaker_tc1_add_config(duthost, lo_intf_ips, vlan_intf_ip_ranges):
}
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -183,6 +185,7 @@ def bgp_speaker_tc1_add_dummy_ip_range(duthost):
"value": "{}".format(DUMMY_IP_RANGE_V6)
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -215,6 +218,7 @@ def bgp_speaker_tc1_rm_dummy_ip_range(duthost):
"path": "/BGP_PEER_RANGE/{}/ip_range/1".format(BGPSPEAKER_V6)
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down Expand Up @@ -249,6 +253,7 @@ def bgp_speaker_tc1_replace_src_address(duthost):
"value": "{}".format(DUMMY_SRC_ADDRESS_V6)
}
]
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch)

tmpfile = generate_tmpfile(duthost)
logger.info("tmpfile {}".format(tmpfile))
Expand Down
Loading