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
8 changes: 5 additions & 3 deletions tests/common/helpers/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def generate_ips(num, prefix, exclude_ips):
exclude_ips.append(prefix.network)
available_ips = list(prefix)

if len(available_ips) - len(exclude_ips)< num:
if len(available_ips) - len(exclude_ips) < num:
raise Exception("Not enough available IPs")

generated_ips = []
Expand Down Expand Up @@ -41,14 +41,16 @@ def route_through_default_routes(host, ip_addr):
return ret


def generate_ip_through_default_route(host):
def generate_ip_through_default_route(host, exclude_ips=None):
"""
@summary: Generate a random IP address routed through default routes
@param host: The duthost
@param exclude_ips: IPs to exclude, default None
@return: A str, on None if non ip is found in given range
"""
exclude_ips = exclude_ips if exclude_ips is not None else []
for leading in range(11, 255):
ip_addr = generate_ips(1, "{}.0.0.1/24".format(leading), [])[0]
ip_addr = generate_ips(1, "{}.0.0.1/24".format(leading), exclude_ips)[0]
if route_through_default_routes(host, ip_addr):
return ip_addr
return None
42 changes: 41 additions & 1 deletion tests/generic_config_updater/test_bgpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def bgpmon_tc1_add_duplicate(duthost, bgpmon_setup_info):
finally:
delete_tmpfile(duthost, tmpfile)

def bgpmon_tc1_admin_change(duthost):
def bgpmon_tc1_admin_change(duthost, bgpmon_setup_info):
""" Test to admin down bgpmon config
"""
peer_addr, _, _ = bgpmon_setup_info
Expand All @@ -162,6 +162,44 @@ def bgpmon_tc1_admin_change(duthost):
finally:
delete_tmpfile(duthost, tmpfile)

def bgpmon_tc1_ip_change(duthost, bgpmon_setup_info):
""" Test to replace bgpmon ip address
"""
peer_addr, local_addr, bgp_asn = bgpmon_setup_info
peer_addr_replaced = generate_ip_through_default_route(duthost, [IPNetwork(peer_addr).ip])
peer_addr_replaced = str(IPNetwork(peer_addr_replaced).ip)
json_patch = [
{
"op": "remove",
"path": "/BGP_MONITORS/{}".format(peer_addr)
},
{
"op": "add",
"path": "/BGP_MONITORS/{}".format(peer_addr_replaced),
"value": {
"admin_status": "up",
"asn": bgp_asn,
"holdtime": "180",
"keepalive": "60",
"local_addr": local_addr,
"name": "BGPMonitor",
"nhopself": "0",
"rrclient": "0"
}
}
]

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

try:
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
expect_op_success(duthost, output)

check_bgpmon_with_addr(duthost, peer_addr_replaced)
finally:
delete_tmpfile(duthost, tmpfile)

def bgpmon_tc1_remove(duthost):
""" Test to remove bgpmon config
"""
Expand Down Expand Up @@ -194,4 +232,6 @@ def test_bgpmon_tc1_add_and_remove(duthost, bgpmon_setup_info):
"""
bgpmon_tc1_add_init(duthost, bgpmon_setup_info)
bgpmon_tc1_add_duplicate(duthost, bgpmon_setup_info)
bgpmon_tc1_admin_change(duthost, bgpmon_setup_info)
bgpmon_tc1_ip_change(duthost, bgpmon_setup_info)
bgpmon_tc1_remove(duthost)