Skip to content

Commit

Permalink
[asic_sensors] Add asic_sensors configuration
Browse files Browse the repository at this point in the history
Signed-off-by: mlok <[email protected]>
  • Loading branch information
mlok-nokia committed Dec 19, 2024
1 parent 6d876a4 commit a07bd0e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/sonic-config-engine/asic_sensors_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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)
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
3 changes: 2 additions & 1 deletion src/sonic-config-engine/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
'minigraph',
'openconfig_acl',
'portconfig',
'smartswitch_config'
'smartswitch_config',
'asic_sensors_config'
]
if sys.version_info.major == 3:
# Python 3-only modules
Expand Down
11 changes: 10 additions & 1 deletion src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ from portconfig import get_port_config, get_breakout_mode
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id, is_multi_asic
from sonic_py_common import device_info
from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector

import asic_sensors_config

PY3x = sys.version_info >= (3, 0)

Expand Down Expand Up @@ -459,6 +459,15 @@ def main():

deep_update(data, hardware_data)

asic_sensors = {}
if is_multi_asic():
if asic_name is not None:
asic_sensors = asic_sensors_config.get_asic_sensors_config()
else:
asic_sensors = asic_sensors_config.get_asic_sensors_config()
if asic_sensors:
deep_update(data, asic_sensors)

paths = ['/', '/usr/share/sonic/templates']
if args.template_dir:
paths.append(os.path.abspath(args.template_dir))
Expand Down
6 changes: 6 additions & 0 deletions src/sonic-config-engine/tests/data/asic_sensors/platform.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"asic_sensors": {
"poll_interval": "10",
"poll_admin_status": "enable"
}
}
10 changes: 10 additions & 0 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,3 +1155,13 @@ def testsnmp_agent_address_config(self):
self.assertEqual(
utils.liststr_to_dict(output.strip()),
utils.liststr_to_dict("['192.168.200.15|161|', '100.0.0.6|161|', '100.0.0.7|161|', 'fe80::1%Management0|161|']"))

def test_platform_asic_sensors_config(self):
os.environ["PLATFORM"] = "x86_64-kvm_x86_64-r0"
argument = ["-H","--print-data"]
output = self.run_script(argument, check_stderr=False)
config_json = utils.to_dict(output.strip())
os.environ["PLATFORM"] = ""
self.assertEqual(config_json['ASIC_SENSORS'], utils.to_dict("{'ASIC_SENSORS_POLLER_INTERVAL': {'interval': '10'}, 'ASIC_SENSORS_POLLER_STATUS': {'admin_status': 'enable'}}"))


0 comments on commit a07bd0e

Please sign in to comment.