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
5 changes: 4 additions & 1 deletion ansible/roles/test/tasks/sensors_check.yml
22 changes: 17 additions & 5 deletions tests/common/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,34 @@ def _get_npu_info(self):
self._get_critical_services_for_multi_npu


def _platform_info(self):
def get_platform_info(self):
"""
@summary: Get the platform information of the SONiC switch.
@return: Returns a dictionary containing preperties of the platform information, for example:
{
"platform": "",
"hwsku": "",
"asic_type": ""
}
"""
platform_info = self.command("show platform summary")["stdout_lines"]
result = {}
for line in platform_info:
if line.startswith("Platform:"):
self.facts["platform"] = line.split(":")[1].strip()
result["platform"] = line.split(":")[1].strip()
elif line.startswith("HwSKU:"):
self.facts["hwsku"] = line.split(":")[1].strip()
result["hwsku"] = line.split(":")[1].strip()
elif line.startswith("ASIC:"):
self.facts["asic_type"] = line.split(":")[1].strip()
result["asic_type"] = line.split(":")[1].strip()
return result

def gather_facts(self):
"""
@summary: Gather facts of the SONiC switch and store the gathered facts in the dict type 'facts' attribute.
"""
self.facts = {}
self._platform_info()
platform_info = self.get_platform_info()
self.facts.update(platform_info)
self._get_npu_info()
logging.debug("SonicHost facts: %s" % json.dumps(self.facts))

Expand Down
21 changes: 21 additions & 0 deletions tests/test_sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
import logging

from common.helpers.assertions import pytest_assert

def test_sensors(duthost, creds):
# Get platform name
platform = duthost.get_platform_info()['platform']

# Prepare check list
sensors_checks = creds['sensors_checks']

# Gather sensors
if platform not in sensors_checks.keys():
pytest.skip("Skip test due to not support check sensors for current platform({})".format(platform))

sensors_facts = duthost.sensors_facts(checks=sensors_checks[platform])['ansible_facts']

pytest_assert(not sensors_facts['sensors']['alarm'], "sensors facts: {}".format(sensors_facts))
if sensors_facts['sensors']['warning']:
logging.debug("Show warnings: %s" % sensors_facts['sensors']['warning'])