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
24 changes: 15 additions & 9 deletions tests/stress/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
import pytest
import time

import pytest

from tests.common.utilities import wait_until
from utils import get_crm_resources, check_queue_status, sleep_to_wait
from utils import get_crm_resource_status, check_queue_status, sleep_to_wait

CRM_POLLING_INTERVAL = 1
CRM_DEFAULT_POLL_INTERVAL = 300
Expand All @@ -18,7 +19,8 @@ def get_function_conpleteness_level(pytestconfig):


@pytest.fixture(scope="module", autouse=True)
def set_polling_interval(duthost):
def set_polling_interval(duthosts, enum_rand_one_per_hwsku_frontend_hostname):
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
wait_time = 2
duthost.command("crm config polling interval {}".format(CRM_POLLING_INTERVAL))
logger.info("Waiting {} sec for CRM counters to become updated".format(wait_time))
Expand All @@ -32,7 +34,12 @@ def set_polling_interval(duthost):


@pytest.fixture(scope='module')
def withdraw_and_announce_existing_routes(duthost, localhost, tbinfo):
def withdraw_and_announce_existing_routes(duthosts, localhost, tbinfo, enum_rand_one_per_hwsku_frontend_hostname,
enum_rand_one_frontend_asic_index):
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
asichost = duthost.asic_instance(enum_rand_one_frontend_asic_index)
namespace = asichost.namespace

ptf_ip = tbinfo["ptf_ip"]
topo_name = tbinfo["topo"]["name"]

Expand All @@ -41,8 +48,8 @@ def withdraw_and_announce_existing_routes(duthost, localhost, tbinfo):

wait_until(MAX_WAIT_TIME, CRM_POLLING_INTERVAL, 0, lambda: check_queue_status(duthost, "inq") == True)
sleep_to_wait(CRM_POLLING_INTERVAL * 100)
ipv4_route_used_before = get_crm_resources(duthost, "ipv4_route", "used")
ipv6_route_used_before = get_crm_resources(duthost, "ipv6_route", "used")
ipv4_route_used_before = get_crm_resource_status(duthost, "ipv4_route", "used", namespace)
ipv6_route_used_before = get_crm_resource_status(duthost, "ipv6_route", "used", namespace)
logger.info("ipv4 route used {}".format(ipv4_route_used_before))
logger.info("ipv6 route used {}".format(ipv6_route_used_before))

Expand All @@ -53,6 +60,5 @@ def withdraw_and_announce_existing_routes(duthost, localhost, tbinfo):

wait_until(MAX_WAIT_TIME, CRM_POLLING_INTERVAL, 0, lambda: check_queue_status(duthost, "outq") == True)
sleep_to_wait(CRM_POLLING_INTERVAL * 5)
logger.info("ipv4 route used {}".format(get_crm_resources(duthost, "ipv4_route", "used")))
logger.info("ipv6 route used {}".format(get_crm_resources(duthost, "ipv6_route", "used")))

logger.info("ipv4 route used {}".format(get_crm_resource_status(duthost, "ipv4_route", "used", namespace)))
logger.info("ipv6 route used {}".format(get_crm_resource_status(duthost, "ipv6_route", "used", namespace)))
30 changes: 18 additions & 12 deletions tests/stress/test_stress_routes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python

import logging

import pytest

from tests.common.helpers.assertions import pytest_assert
from tests.common.utilities import wait_until
from utils import get_crm_resources, check_queue_status, sleep_to_wait, LOOP_TIMES_LEVEL_MAP
from utils import get_crm_resource_status, check_queue_status, sleep_to_wait, LOOP_TIMES_LEVEL_MAP

ALLOW_ROUTES_CHANGE_NUMS = 5
CRM_POLLING_INTERVAL = 1
Expand All @@ -14,33 +15,38 @@
logger = logging.getLogger(__name__)

pytestmark = [
pytest.mark.topology('t0', 't1', 'm0', 'mx')
pytest.mark.topology('t0', 't1', 'm0', 'mx', 't2')
]


def announce_withdraw_routes(duthost, localhost, ptf_ip, topo_name):
def announce_withdraw_routes(duthost, namespace, localhost, ptf_ip, topo_name):
logger.info("announce ipv4 and ipv6 routes")
localhost.announce_routes(topo_name=topo_name, ptf_ip=ptf_ip, action="announce", path="../ansible/")

wait_until(MAX_WAIT_TIME, CRM_POLLING_INTERVAL, 0, lambda: check_queue_status(duthost, "outq") is True)

logger.info("ipv4 route used {}".format(get_crm_resources(duthost, "ipv4_route", "used")))
logger.info("ipv6 route used {}".format(get_crm_resources(duthost, "ipv6_route", "used")))
logger.info("ipv4 route used {}".format(get_crm_resource_status(duthost, "ipv4_route", "used", namespace)))
logger.info("ipv6 route used {}".format(get_crm_resource_status(duthost, "ipv6_route", "used", namespace)))
sleep_to_wait(CRM_POLLING_INTERVAL * 5)

logger.info("withdraw ipv4 and ipv6 routes")
localhost.announce_routes(topo_name=topo_name, ptf_ip=ptf_ip, action="withdraw", path="../ansible/")

wait_until(MAX_WAIT_TIME, CRM_POLLING_INTERVAL, 0, lambda: check_queue_status(duthost, "inq") is True)
sleep_to_wait(CRM_POLLING_INTERVAL * 5)
logger.info("ipv4 route used {}".format(get_crm_resources(duthost, "ipv4_route", "used")))
logger.info("ipv6 route used {}".format(get_crm_resources(duthost, "ipv6_route", "used")))
logger.info("ipv4 route used {}".format(get_crm_resource_status(duthost, "ipv4_route", "used", namespace)))
logger.info("ipv6 route used {}".format(get_crm_resource_status(duthost, "ipv6_route", "used", namespace)))


def test_announce_withdraw_route(duthost, localhost, tbinfo, get_function_conpleteness_level,
withdraw_and_announce_existing_routes, loganalyzer):
def test_announce_withdraw_route(duthosts, localhost, tbinfo, get_function_conpleteness_level,
withdraw_and_announce_existing_routes, loganalyzer,
enum_rand_one_per_hwsku_frontend_hostname, enum_rand_one_frontend_asic_index):
ptf_ip = tbinfo["ptf_ip"]
topo_name = tbinfo["topo"]["name"]
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
asichost = duthost.asic_instance(enum_rand_one_frontend_asic_index)
namespace = asichost.namespace

if loganalyzer:
ignoreRegex = [
".*ERR route_check.py:.*",
Expand All @@ -57,13 +63,13 @@ def test_announce_withdraw_route(duthost, localhost, tbinfo, get_function_conple
loop_times = LOOP_TIMES_LEVEL_MAP[normalized_level]

while loop_times > 0:
announce_withdraw_routes(duthost, localhost, ptf_ip, topo_name)
announce_withdraw_routes(duthost, namespace, localhost, ptf_ip, topo_name)
loop_times -= 1

sleep_to_wait(CRM_POLLING_INTERVAL * 100)

ipv4_route_used_after = get_crm_resources(duthost, "ipv4_route", "used")
ipv6_route_used_after = get_crm_resources(duthost, "ipv6_route", "used")
ipv4_route_used_after = get_crm_resource_status(duthost, "ipv4_route", "used", namespace)
ipv6_route_used_after = get_crm_resource_status(duthost, "ipv6_route", "used", namespace)

pytest_assert(abs(ipv4_route_used_after - ipv4_route_used_before) < ALLOW_ROUTES_CHANGE_NUMS,
"ipv4 route used after is not equal to it used before")
Expand Down
6 changes: 4 additions & 2 deletions tests/stress/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import time

from tests.common.helpers.constants import DEFAULT_NAMESPACE

TOPO_FILENAME_TEMPLATE = 'topo_{}.yml'
SHOW_BGP_SUMMARY_CMD = "show ip bgp summary"
Expand All @@ -12,8 +13,9 @@
'diagnose': 200
}

def get_crm_resources(duthost, resource, status):
return duthost.get_crm_resources().get("main_resources").get(resource).get(status)

def get_crm_resource_status(duthost, resource, status, namespace=DEFAULT_NAMESPACE):
return duthost.get_crm_resources(namespace).get("main_resources").get(resource).get(status)

def check_queue_status(duthost, queue):
bgp_neighbors = duthost.show_and_parse(SHOW_BGP_SUMMARY_CMD)
Expand Down