diff --git a/ansible/roles/test/tasks/sensors_check.yml b/ansible/roles/test/tasks/sensors_check.yml index a0436103e08..28dcc2fcaf0 120000 --- a/ansible/roles/test/tasks/sensors_check.yml +++ b/ansible/roles/test/tasks/sensors_check.yml @@ -1 +1,4 @@ -../../sonic-common/tasks/sensors_check.yml \ No newline at end of file +- name: run test + include_tasks: roles/test/tasks/pytest_runner.yml + vars: + test_node: test_sensors.py \ No newline at end of file diff --git a/tests/common/devices.py b/tests/common/devices.py index f93656d3f43..9a4c394d707 100644 --- a/tests/common/devices.py +++ b/tests/common/devices.py @@ -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)) diff --git a/tests/test_sensors.py b/tests/test_sensors.py new file mode 100644 index 00000000000..286af88d22b --- /dev/null +++ b/tests/test_sensors.py @@ -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']) \ No newline at end of file