forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[asic_sensors] Generate the asic_sensors polling configuration based …
…on the platform.json (sonic-net#20826) For any platform which supports the asic_sensors pulling, it requires the configuration files (config_db#.json) contain the following configuration to trigger the system to poll the ASIC sensors temperature. Fixes Nokia-ION/ndk#48 Adding Yang model support to fixes sonic-net#20633 --------- Signed-off-by: mlok <marty.lok@nokia.com>
- Loading branch information
1 parent
0729297
commit d0536d5
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
import sys | ||
import portconfig | ||
from sonic_py_common import device_info | ||
|
||
try: | ||
if os.environ["CFGGEN_UNIT_TESTING"] == "2": | ||
modules_path = os.path.join(os.path.dirname(__file__), ".") | ||
tests_path = os.path.join(modules_path, "tests") | ||
sys.path.insert(0, modules_path) | ||
sys.path.insert(0, tests_path) | ||
import mock_tables.dbconnector | ||
mock_tables.dbconnector.load_namespace_config() | ||
|
||
except KeyError: | ||
pass | ||
|
||
ASIC_SENSORS_KEY = "asic_sensors" | ||
|
||
|
||
def get_asic_sensors_config(): | ||
config = {} | ||
if os.environ.get("CFGGEN_UNIT_TESTING") == "2": | ||
json_file = os.path.join(tests_path, "data", "asic_sensors", "platform.json") | ||
else: | ||
platform_path = device_info.get_path_to_platform_dir() | ||
json_file = os.path.join(platform_path, device_info.PLATFORM_JSON_FILE) | ||
|
||
if not os.path.exists(json_file): | ||
return config | ||
|
||
platform_json = portconfig.readJson(json_file) | ||
if not platform_json: | ||
return config | ||
|
||
if ASIC_SENSORS_KEY in platform_json: | ||
config["ASIC_SENSORS"] = {"ASIC_SENSORS_POLLER_INTERVAL": {"interval": platform_json[ASIC_SENSORS_KEY]["poll_interval"]}, | ||
"ASIC_SENSORS_POLLER_STATUS": {"admin_status": platform_json[ASIC_SENSORS_KEY]["poll_admin_status"]} | ||
} | ||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/sonic-config-engine/tests/data/asic_sensors/platform.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"asic_sensors": { | ||
"poll_interval": "10", | ||
"poll_admin_status": "enable" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters