sensor_yaml_config.py: Parse rpt file
Parse rpt file into a list of RtpSensor, check the sensor ids to find
which sensors are missing in the yaml file.
Tested: Using Romulus rpt, verify the sensors in rpt file is
correctly parsed into the RptSensor structure in python.
Change-Id: Iafb0ec1845db8802c4fac20abe2bdcaf51a876e9
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/leiyu/obmc-utils/sensor_yaml_config.py b/leiyu/obmc-utils/sensor_yaml_config.py
index a5aa222..249e4c0 100755
--- a/leiyu/obmc-utils/sensor_yaml_config.py
+++ b/leiyu/obmc-utils/sensor_yaml_config.py
@@ -3,6 +3,19 @@
import yaml
import argparse
+from typing import NamedTuple
+
+
+class RptSensor(NamedTuple):
+ name: str
+ entityId: int
+ typeId: int
+ evtType: int
+ sensorId: int
+ fru: int
+ targetPath: str
+
+
entityIds = {
'dimm': 32,
'core': 208,
@@ -68,6 +81,27 @@
return instanceId
+def loadRpt(rptFile):
+ sensors = []
+ with open(rptFile) as f:
+ next(f)
+ next(f)
+ for line in f:
+ fields = line.strip().split('|')
+ fields = list(map(str.strip, fields))
+ sensor = RptSensor(
+ fields[0],
+ int(fields[2], 16) if fields[2] else None,
+ int(fields[3], 16) if fields[3] else None,
+ int(fields[4], 16) if fields[4] else None,
+ int(fields[5], 16) if fields[5] else None,
+ int(fields[7], 16) if fields[7] else None,
+ fields[9])
+ # print(sensor)
+ sensors.append(sensor)
+ return sensors
+
+
def main():
parser = argparse.ArgumentParser(
description='Yaml tool for updating ipmi sensor yaml config')
@@ -87,12 +121,18 @@
parser.print_help()
exit(1)
-# TODO: read rtp and generate the whole config yaml
-# if args['rpt']:
-# pass
-
y = openYaml(args['input'])
+ sensorIds = list(y.keys())
+ if args['rpt']:
+ rptSensors = loadRpt(args['rpt'])
+ for s in rptSensors:
+ if s.sensorId is not None and s.sensorId not in sensorIds:
+ print("Sensor ID:", s.sensorId,
+ " not in yaml, path", s.targetPath)
+ # TODO: add new items in yaml with missing sensors
+ return
+
if args['entity']:
# Fix entities
for i in y: