Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding test case to test telemetry service "osversion/build" query. #2578

Merged
merged 4 commits into from
Dec 15, 2020
Merged
Changes from 2 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
36 changes: 36 additions & 0 deletions tests/telemetry/test_telemetry.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,16 @@
logger = logging.getLogger(__name__)

TELEMETRY_PORT = 50051
mode_subscribe = "subscribe"
mode_get = "get"

subscribe_mode_stream = 0
subscribe_mode_once = 1
subscribe_mode_poll = 2

submode_targetdefined=0
submode_onchange=1
submode_sample=2

# Helper functions
def get_dict_stdout(gnmi_out, certs_out):
@@ -45,6 +54,21 @@ def setup_telemetry_forpyclient(duthost):
else:
logger.info('client auth is false. No need to restart telemetry')

def generate_client_cli(duthost, mode=mode_get, xpath="COUNTERS/Ethernet0", target="COUNTERS_DB", subscribe_mode=subscribe_mode_stream, submode=submode_sample, intervalms=0, update_count=3):
"""Generate the py_gnmicli command line based on the given params.
"""
cmdFormat = 'python /gnxi/gnmi_cli_py/py_gnmicli.py -g -t {0} -p {1} -m {2} -x {3} -xt {4} -o {5}'
cmd = cmdFormat.format(duthost.mgmt_ip, TELEMETRY_PORT, mode, xpath, target, "ndastreamingservertest")

if mode == mode_subscribe:
cmd += " --subscribe_mode {0} --submode {1} --interval {2} --update_count {3}".format(subscribe_mode, submode, intervalms, update_count)
return cmd

def assert_equal(actual, expected, message):
"""Helper method to compare an expected value vs the actual value.
"""
pytest_assert(actual == expected, "{0}. Expected {1} vs actual {2}".format(message, expected, actual))

def verify_telemetry_dockerimage(duthost):
"""If telemetry docker is available in image then return true
"""
@@ -133,3 +157,15 @@ def test_telemetry_ouput(duthosts, rand_one_dut_hostname, ptfhost, localhost):
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_osbuild_version(duthosts, rand_one_dut_hostname, ptfhost, localhost):
""" Test osbuild/version query.
"""
duthost = duthosts[rand_one_dut_hostname]
cmd = generate_client_cli(duthost=duthost, mode=mode_get, target="OTHERS", xpath="osversion/build")
logger.info("Command to run: {0}".format(cmd))
show_gnmi_out = ptfhost.shell(cmd)['stdout']
logger.info(show_gnmi_out)
result = str(show_gnmi_out)

assert_equal(len(re.findall('"build_version": "sonic', result)), 1, "build_version value")