Skip to content

Commit

Permalink
Add IPV6 only testcase for telemetry (#12268)
Browse files Browse the repository at this point in the history
## Approach
#### What is the motivation for this PR?

Add testcase for telemetry using mgmt ipv6

#### How did you do it?

Use ipv6 mgmt port for target ip with fixture to make dut ipv6 only
  • Loading branch information
zbud-msft authored Apr 3, 2024
1 parent a0c0c2b commit 7dd677f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 25 deletions.
14 changes: 14 additions & 0 deletions tests/common/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from tests.common.cache import FactsCache
from tests.common.helpers.constants import UPSTREAM_NEIGHBOR_MAP, DOWNSTREAM_NEIGHBOR_MAP
from tests.common.helpers.assertions import pytest_assert
from netaddr import valid_ipv6

logger = logging.getLogger(__name__)
cache = FactsCache()
Expand Down Expand Up @@ -476,6 +477,19 @@ def is_ipv4_address(ip_address):
return False


def get_mgmt_ipv6(duthost):
config_facts = duthost.get_running_config_facts()
mgmt_interfaces = config_facts.get("MGMT_INTERFACE", {})
mgmt_ipv6 = None

for mgmt_interface, ip_configs in mgmt_interfaces.items():
for ip_addr_with_prefix in ip_configs.keys():
ip_addr = ip_addr_with_prefix.split("/")[0]
if valid_ipv6(ip_addr):
mgmt_ipv6 = ip_addr
return mgmt_ipv6


def compare_crm_facts(left, right):
"""Compare CRM facts
Expand Down
38 changes: 24 additions & 14 deletions tests/ip/test_mgmt_ipv6_only.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import re

from netaddr import valid_ipv6
from tests.common.utilities import get_mgmt_ipv6
from tests.common.helpers.assertions import pytest_assert
from tests.tacacs.utils import check_output
from tests.bgp.test_bgp_fact import run_bgp_facts
from tests.test_features import run_show_features
Expand All @@ -10,6 +12,8 @@
from tests.tacacs.conftest import tacacs_creds, check_tacacs_v6 # noqa F401
from tests.syslog.test_syslog import run_syslog, check_default_route # noqa F401
from tests.common.fixtures.duthost_utils import convert_and_restore_config_db_to_ipv6_only # noqa F401
from tests.common.helpers.gnmi_utils import GNMIEnvironment
from tests.telemetry.conftest import setup_streaming_telemetry # noqa F401

pytestmark = [
pytest.mark.disable_loganalyzer,
Expand Down Expand Up @@ -50,19 +54,6 @@ def ignore_expected_loganalyzer_exception(loganalyzer):
loganalyzer[hostname].ignore_regex.extend(ignore_regex)


def get_mgmt_ipv6(duthost):
config_facts = duthost.get_running_config_facts()
mgmt_interfaces = config_facts.get("MGMT_INTERFACE", {})
mgmt_ipv6 = None

for mgmt_interface, ip_configs in mgmt_interfaces.items():
for ip_addr_with_prefix in ip_configs.keys():
ip_addr = ip_addr_with_prefix.split("/")[0]
if valid_ipv6(ip_addr):
mgmt_ipv6 = ip_addr
return mgmt_ipv6


def test_bgp_facts_ipv6_only(duthosts, enum_frontend_dut_hostname, enum_asic_index,
convert_and_restore_config_db_to_ipv6_only): # noqa F811
run_bgp_facts(duthosts, enum_frontend_dut_hostname, enum_asic_index)
Expand Down Expand Up @@ -137,6 +128,25 @@ def test_rw_user_ipv6_only(localhost, duthosts, enum_rand_one_per_hwsku_hostname
check_output(res, 'testadmin', 'remote_user_su')


@pytest.mark.parametrize('setup_streaming_telemetry', [True], indirect=True)
def test_telemetry_output_ipv6_only(duthosts, enum_rand_one_per_hwsku_hostname,
setup_streaming_telemetry, # noqa F811
convert_and_restore_config_db_to_ipv6_only): # noqa F811
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
env = GNMIEnvironment(duthost, GNMIEnvironment.TELEMETRY_MODE)
if duthost.is_supervisor_node():
pytest.skip(
"Skipping test as no Ethernet0 frontpanel port on supervisor")
dut_ip = get_mgmt_ipv6(duthost)
cmd = "~/gnmi_get -xpath_target COUNTERS_DB -xpath COUNTERS/Ethernet0 -target_addr \
[%s]:%s -logtostderr -insecure" % (dut_ip, env.gnmi_port)
show_gnmi_out = duthost.shell(cmd)['stdout']
result = str(show_gnmi_out)
inerrors_match = re.search("SAI_PORT_STAT_IF_IN_ERRORS", result)
pytest_assert(inerrors_match is not None,
"SAI_PORT_STAT_IF_IN_ERRORS not found in gnmi output")


def test_ntp_ipv6_only(duthosts, rand_one_dut_hostname,
convert_and_restore_config_db_to_ipv6_only, setup_ntp): # noqa F811
run_ntp(duthosts, rand_one_dut_hostname, setup_ntp)
18 changes: 13 additions & 5 deletions tests/telemetry/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from tests.common.helpers.assertions import pytest_assert as py_assert
from tests.common.errors import RunAnsibleModuleFail
from tests.common.utilities import wait_until, wait_tcp_connection
from tests.common.utilities import wait_until, wait_tcp_connection, get_mgmt_ipv6
from tests.common.helpers.gnmi_utils import GNMIEnvironment
from telemetry_utils import get_list_stdout, setup_telemetry_forpyclient, restore_telemetry_forpyclient
from tests.telemetry.telemetry_utils import get_list_stdout, setup_telemetry_forpyclient, restore_telemetry_forpyclient

EVENTS_TESTS_PATH = "./telemetry/events"
sys.path.append(EVENTS_TESTS_PATH)
Expand Down Expand Up @@ -86,10 +86,11 @@ def delete_gnmi_config(duthost):


@pytest.fixture(scope="module")
def setup_streaming_telemetry(duthosts, enum_rand_one_per_hwsku_hostname, localhost, ptfhost, gnxi_path):
def setup_streaming_telemetry(request, duthosts, enum_rand_one_per_hwsku_hostname, localhost, ptfhost, gnxi_path):
"""
@summary: Post setting up the streaming telemetry before running the test.
"""
is_ipv6 = request.param
try:
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
has_gnmi_config = check_gnmi_config(duthost)
Expand All @@ -113,11 +114,18 @@ def setup_streaming_telemetry(duthosts, enum_rand_one_per_hwsku_hostname, localh

# Wait until the TCP port was opened
dut_ip = duthost.mgmt_ip
if is_ipv6:
dut_ip = get_mgmt_ipv6(duthost)
wait_tcp_connection(localhost, dut_ip, env.gnmi_port, timeout_s=60)

# pyclient should be available on ptfhost. If it was not available, then fail pytest.
file_exists = ptfhost.stat(path=gnxi_path + "gnmi_cli_py/py_gnmicli.py")
py_assert(file_exists["stat"]["exists"] is True)
if is_ipv6:
cmd = "docker cp %s:/usr/sbin/gnmi_get ~/" % (env.gnmi_container)
ret = duthost.shell(cmd)['rc']
py_assert(ret == 0)
else:
file_exists = ptfhost.stat(path=gnxi_path + "gnmi_cli_py/py_gnmicli.py")
py_assert(file_exists["stat"]["exists"] is True)
except RunAnsibleModuleFail as e:
logger.info("Error happens in the setup period of setup_streaming_telemetry, recover the telemetry.")
restore_telemetry_forpyclient(duthost, default_client_auth)
Expand Down
5 changes: 4 additions & 1 deletion tests/telemetry/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ def validate_yang(duthost, op_file="", yang_file=""):
assert ret["rc"] == 0, "Yang validation failed for {}".format(yang_file)


@pytest.mark.parametrize('setup_streaming_telemetry', [False], indirect=True)
@pytest.mark.disable_loganalyzer
def test_events(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, setup_streaming_telemetry, localhost, gnxi_path,
def test_events(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, setup_streaming_telemetry, gnxi_path,
test_eventd_healthy):
""" Run series of events inside duthost and validate that output is correct
and conforms to YANG schema"""
Expand All @@ -53,6 +54,7 @@ def test_events(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, setup_strea
logger.info("Completed test file: {}".format(os.path.join(EVENTS_TESTS_PATH, file)))


@pytest.mark.parametrize('setup_streaming_telemetry', [False], indirect=True)
@pytest.mark.disable_loganalyzer
def test_events_cache(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, setup_streaming_telemetry, gnxi_path):
"""Create expected o/p file of events with N events. Call event-publisher tool to publish M events (M<N). Publish
Expand Down Expand Up @@ -91,6 +93,7 @@ def test_events_cache(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, setup
verify_counter_increase(duthost, current_published_counter, N, PUBLISHED)


@pytest.mark.parametrize('setup_streaming_telemetry', [False], indirect=True)
@pytest.mark.disable_loganalyzer
def test_events_cache_overflow(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, setup_streaming_telemetry,
gnxi_path):
Expand Down
11 changes: 6 additions & 5 deletions tests/telemetry/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ def test_telemetry_enabledbydefault(duthosts, enum_rand_one_per_hwsku_hostname):
"Telemetry feature is not enabled")


@pytest.mark.parametrize('setup_streaming_telemetry', [False], indirect=True)
def test_telemetry_ouput(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost,
setup_streaming_telemetry, localhost, gnxi_path):
setup_streaming_telemetry, gnxi_path):
"""Run pyclient from ptfdocker and show gnmi server outputself.
"""
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
Expand All @@ -102,7 +103,7 @@ def test_telemetry_ouput(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost,
"SAI_PORT_STAT_IF_IN_ERRORS not found in gnmi_output")


def test_osbuild_version(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhost, gnxi_path):
def test_osbuild_version(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, gnxi_path):
""" Test osbuild/version query.
"""
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
Expand All @@ -118,7 +119,7 @@ def test_osbuild_version(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, lo
0, "invalid build_version value at {0}".format(result))


def test_sysuptime(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhost, gnxi_path):
def test_sysuptime(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, gnxi_path):
"""
@summary: Run pyclient from ptfdocker and test the dataset 'system uptime' to check
whether the value of 'system uptime' was float number and whether the value was
Expand Down Expand Up @@ -167,7 +168,7 @@ def test_sysuptime(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhos
pytest.fail("The value of system uptime was not updated correctly.")


def test_virtualdb_table_streaming(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhost, gnxi_path):
def test_virtualdb_table_streaming(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, gnxi_path):
"""Run pyclient from ptfdocker to stream a virtual-db query multiple times.
"""
logger.info('start virtual db sample streaming testing')
Expand Down Expand Up @@ -196,7 +197,7 @@ def invoke_py_cli_from_ptf(ptfhost, cmd, callback):
callback(ret["stdout"])


def test_on_change_updates(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhost, gnxi_path):
def test_on_change_updates(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, gnxi_path):
logger.info("Testing on change update notifications")

duthost = duthosts[enum_rand_one_per_hwsku_hostname]
Expand Down

0 comments on commit 7dd677f

Please sign in to comment.