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

Voltage and Current sensors CLI tests #10736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bmridul
Copy link
Contributor

@bmridul bmridul commented Nov 14, 2023

Description of PR

Sonic-mgmt tests for CLI introduced as part of Sensormon. HLD - sonic-net/SONiC#1394

Summary:
Added tests for Sensormon supported CLIs for
show platform voltage
show platform current

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • [x ] Test case(new/improvement)

Back port request

  • 201911
  • 202012
  • 202205
  • 202305

Approach

What is the motivation for this PR?

Added first set of sonic mgmt tests for Sensormon feature.

How did you verify/test it?

Ran the tests on the DUT.

Any platform specific information?

Supported testbed topology if it's a new test case?

Any. Should be applicable to all.

Documentation

HLD link provided above.

@bmridul bmridul requested a review from prgeor as a code owner November 14, 2023 17:50
@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Failed
- hook id: check-ast
- exit code: 1

tests/platform_tests/cli/test_show_platform.py: failed parsing with CPython 3.8.10:

Traceback (most recent call last):
File "/home/AzDevOps/.cache/pre-commit/repoc03rpkpp/py_env-python3/lib/python3.8/site-packages/pre_commit_hooks/check_ast.py", line 21, in main
ast.parse(f.read(), filename=filename)
File "/usr/lib/python3.8/ast.py", line 47, in parse
return compile(source, filename, mode, flags,
File "tests/platform_tests/cli/test_show_platform.py", line 368
check_show_platform_sensor_output(cmd, duthost):
^
SyntaxError: invalid syntax
...
[truncated extra lines, please run pre-commit locally to view full check results]

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@cyw233
Copy link
Contributor

cyw233 commented Aug 9, 2024

Hey @bmridul, could you sync this PR with the latest master as it's been here for quite a while, please? It's also a good chance to rerun the PR checks. Thanks!

"""
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
cmd = " ".join([CMD_SHOW_PLATFORM, "voltage"])
check_show_platform_sensor_output(cmd, duthost):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wha is this : for? Is this a typo?

logging.info("Verifying output of '{}' on '{}'...".format(cmd, duthost.hostname))
raw_output_lines = duthost.command(cmd)["stdout_lines"]

pytest_assert(len(raw_output_lines) > 0, "There must be at least one line of output on '{}'".format(hostname))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is hostname here and the ones in below? Should them be duthost.hostname?

@summary: Run and verify output of `show platform [voltage|current]`. Expected output
is "Sensor Not detected" or a table of sensor status data with 8 columns.
"""
num_expected_clos = 8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here, should be num_expected_cols

"""
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
cmd = " ".join([CMD_SHOW_PLATFORM, "current"])
check_show_platform_sensor_output(cmd, duthost):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto the extra :


pytest_assert(len(raw_output_lines) > 0, "There must be at least one line of output on '{}'".format(hostname))
if len(raw_output_lines) == 1:
pytest_assert(raw_output_lines[0].strip() == "Sensor Not detected",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure it's Not with a capital N? I think it'd better if we can lowercase raw_output_lines[0].strip() and then do the comparison, so we don't need to worry about the cases.

second_line = raw_output_lines[1]
field_ranges = util.get_field_range(second_line)
pytest_assert(len(field_ranges) == num_expected_clos, "Output should consist of {} columns on '{}'".
format(num_expected_clos, hostname))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also check that the alarm status for every line of sensor data reads false, indicating no alarm? Perhaps test_thermal.py can instead be copied/expanded for coverage of sensors of other types (voltage, current, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants