From 1ad9da8a7882a643ca28fedbdc614f1855e3669a Mon Sep 17 00:00:00 2001 From: Patrick Venture Date: Mon, 19 Aug 2019 12:25:54 -0700 Subject: drop entity YAML in favor of json provided file Step 5 of moving from entity map from YAML to JSON drops support for a built-in YAML mapping of the entity containers. Tested: Not tested. No platform upstream updates this YAML file in their builds. Signed-off-by: Patrick Venture Change-Id: Ic2918f568f5a6f4a9f9135990889b3bb84a0c81d --- Makefile.am | 6 +- entity_map_json.cpp | 14 +--- scripts/entity-example.md | 153 +++++++++++++++++++++++++++++++++++++++++++ scripts/entity-example.yaml | 127 ----------------------------------- scripts/entity_gen.py | 60 ----------------- scripts/writeentity.mako.cpp | 40 ----------- test/Makefile.am | 2 +- 7 files changed, 157 insertions(+), 245 deletions(-) create mode 100644 scripts/entity-example.md delete mode 100644 scripts/entity-example.yaml delete mode 100755 scripts/entity_gen.py delete mode 100644 scripts/writeentity.mako.cpp diff --git a/Makefile.am b/Makefile.am index bcac808..cd0b64e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,8 +25,7 @@ ipmid_SOURCES = \ libipmi20_BUILT_LIST = \ sensor-gen.cpp \ inventory-sensor-gen.cpp \ - fru-read-gen.cpp \ - entity-gen.cpp + fru-read-gen.cpp BUILT_SOURCES = \ ipmiwhitelist.cpp \ @@ -79,9 +78,6 @@ inventory-sensor-gen.cpp: scripts/inventorysensor.mako.cpp scripts/inventory-sen fru-read-gen.cpp: scripts/readfru.mako.cpp scripts/fru_gen.py @FRU_YAML_GEN@ $(AM_V_GEN)@FRUGEN@ -o $(top_builddir) generate-cpp -entity-gen.cpp: scripts/writeentity.mako.cpp scripts/entity_gen.py @ENTITY_YAML_GEN@ - $(AM_V_GEN)@ENTITYGEN@ -o $(top_builddir) generate-cpp - providers_LTLIBRARIES += libipmi20.la libipmi20_la_SOURCES = \ app/channel.cpp \ diff --git a/entity_map_json.cpp b/entity_map_json.cpp index c0b836c..7b4e0bf 100644 --- a/entity_map_json.cpp +++ b/entity_map_json.cpp @@ -13,8 +13,6 @@ namespace ipmi namespace sensor { -extern const EntityInfoMap entities; - EntityInfoMapContainer* EntityInfoMapContainer::getContainer() { static std::unique_ptr instance; @@ -25,16 +23,8 @@ EntityInfoMapContainer* EntityInfoMapContainer::getContainer() * the first thread to hit it would set it up. */ EntityInfoMap builtEntityMap = buildEntityMapFromFile(); - if (!builtEntityMap.empty()) - { - instance = std::unique_ptr( - new EntityInfoMapContainer(builtEntityMap)); - } - else - { - instance = std::unique_ptr( - new EntityInfoMapContainer(entities)); - } + instance = std::unique_ptr( + new EntityInfoMapContainer(builtEntityMap)); } return instance.get(); diff --git a/scripts/entity-example.md b/scripts/entity-example.md new file mode 100644 index 0000000..98dbade --- /dev/null +++ b/scripts/entity-example.md @@ -0,0 +1,153 @@ +If your platform requires the entity container map, you can provide a json file of the format: + +``` +[ + { + "id" : 1, + "containerEntityId" : 2, + "containerEntityInstance" : 3, + "isList" : false, + "isLinked" : false, + "entities" : [ + {"id" : 1, "instance" : 2}, + {"id" : 1, "instance" : 3}, + {"id" : 1, "instance" : 4}, + {"id" : 1, "instance" : 5} + ] + } +] +``` + +as part of your `phosphor-ipmi-config` + +The above json is identical to the original YAML documented below: + +``` +# This record has: +# Container Entity Id and Container Entity Instance = (0x13, 0x81) +# Contained Entity Id and Contained Entity Instance = (0x0A, 0x1), +# (0x0A, 0x3), (0x0A, 0x5), (0x0A, 0x7) +# Entity Record id is the key +0x01: + # Container entity contains other entities + # Entity Id and entity Instance for the container entity + containerEntityId: 0x13 + containerEntityInstance: 0x81 + # A record can have contained entities as a four entry list or as upto + # two ranges of entity instances; this record has contained entities + # as a four entry list + isList: "true" + # Records can be linked if necessary to extend the number of contained + # entities within a container entity; this record is not linked + isLinked: "false" + entityId1: 0x0A + entityInstance1: 0x1 + entityId2: 0x0A + entityInstance2: 0x3 + entityId3: 0x0A + entityInstance3: 0x5 + entityId4: 0x0A + entityInstance4: 0x7 + +# The below two records have: +# Container Entity Id and Container Entity Instance = (0x18, 0x2) +# Contained Entity Id and Contained Entity Instance = (0x1D, 0x1), +# (0x1D, 0x4), (0x1D, 0x6), (0x2B, 0x1), (0x2B, 0x3), (0x0F, 0x1), +# (0x0F, 0x3), (0x10, 0x5) +0x02: + containerEntityId: 0x18 + containerEntityInstance: 0x2 + # This record has contained entities as a four entry list + isList: "true" + # This record is linked with the below record; this record and the + # below record have the same container entity Id and container entity + # instance; + isLinked: "true" + entityId1: 0x1D + entityInstance1: 0x1 + entityId2: 0x1D + entityInstance2: 0x4 + entityId3: 0x1D + entityInstance3: 0x6 + entityId4: 0x2B + entityInstance4: 0x1 + +0x03: + containerEntityId: 0x18 + containerEntityInstance: 0x2 + # This record has contained entities as a four entry list + isList: "true" + # This record is linked with the above record; this record and the + # above record have the same container entity Id and container entity + # instance + isLinked: "true" + entityId1: 0x2B + entityInstance1: 0x3 + entityId2: 0x0F + entityInstance2: 0x1 + entityId3: 0x0F + entityInstance3: 0x3 + entityId4: 0x10 + entityInstance4: 0x5 + +# This record has: +# Container Entity Id and Container Entity Instance = (0x1E, 0x1) +# Contained Entity Id and Contained Entity Instance = (0x20, 0x1), +# (0x20, 0x2), (0x20, 0x3), (0x20, 0x7), (0x20, 0x8), (0x20, 0x9) +0x04: + containerEntityId: 0x1E + containerEntityInstance: 0x1 + # This record has contained entities as two ranges of entity instances + isList: "false" + # This record is not linked + isLinked: "false" + entityId1: 0x20 + entityInstance1: 0x1 + entityId2: 0x20 + entityInstance2: 0x3 + entityId3: 0x20 + entityInstance3: 0x7 + entityId4: 0x20 + entityInstance4: 0x9 + +# The below two records have: +# Container Entity Id and Container Entity Instance = (0x1E, 0x3) +# Contained Entity Id and Contained Entity Instance = (0x20, 0x1), +# (0x20, 0x2), (0x20, 0x3), (0x20, 0x6), (0x20, 0x7), (0x20, 0x8), +# (0x20, 0xA), (0x20, 0xB), (0x20, 0xD), (0x20, 0xE), (0x20, 0xF) +0x05: + containerEntityId: 0x1E + containerEntityInstance: 0x03 + # This record has contained entities as two ranges of entity instances + isList: "false" + # This record is linked with the below record; this record and the + # below record have the same container entity Id and container entity + # instance; + isLinked: "true" + entityId1: 0x20 + entityInstance1: 0x1 + entityId2: 0x20 + entityInstance2: 0x3 + entityId3: 0x20 + entityInstance3: 0x6 + entityId4: 0x20 + entityInstance4: 0x8 + +0x06: + containerEntityId: 0x1E + containerEntityInstance: 0x03 + # This record has contained entities as two ranges of entity instances + isList: "false" + # This record is linked with the above record; this record and the + # above record have the same container entity Id and container entity + # instance; + isLinked: "true" + entityId1: 0x20 + entityInstance1: 0xA + entityId2: 0x20 + entityInstance2: 0xB + entityId3: 0x20 + entityInstance3: 0xD + entityId4: 0x20 + entityInstance4: 0xF +``` diff --git a/scripts/entity-example.yaml b/scripts/entity-example.yaml deleted file mode 100644 index 2db14cc..0000000 --- a/scripts/entity-example.yaml +++ /dev/null @@ -1,127 +0,0 @@ -# This record has: -# Container Entity Id and Container Entity Instance = (0x13, 0x81) -# Contained Entity Id and Contained Entity Instance = (0x0A, 0x1), -# (0x0A, 0x3), (0x0A, 0x5), (0x0A, 0x7) -# Entity Record id is the key -0x01: - # Container entity contains other entities - # Entity Id and entity Instance for the container entity - containerEntityId: 0x13 - containerEntityInstance: 0x81 - # A record can have contained entities as a four entry list or as upto - # two ranges of entity instances; this record has contained entities - # as a four entry list - isList: "true" - # Records can be linked if necessary to extend the number of contained - # entities within a container entity; this record is not linked - isLinked: "false" - entityId1: 0x0A - entityInstance1: 0x1 - entityId2: 0x0A - entityInstance2: 0x3 - entityId3: 0x0A - entityInstance3: 0x5 - entityId4: 0x0A - entityInstance4: 0x7 - -# The below two records have: -# Container Entity Id and Container Entity Instance = (0x18, 0x2) -# Contained Entity Id and Contained Entity Instance = (0x1D, 0x1), -# (0x1D, 0x4), (0x1D, 0x6), (0x2B, 0x1), (0x2B, 0x3), (0x0F, 0x1), -# (0x0F, 0x3), (0x10, 0x5) -0x02: - containerEntityId: 0x18 - containerEntityInstance: 0x2 - # This record has contained entities as a four entry list - isList: "true" - # This record is linked with the below record; this record and the - # below record have the same container entity Id and container entity - # instance; - isLinked: "true" - entityId1: 0x1D - entityInstance1: 0x1 - entityId2: 0x1D - entityInstance2: 0x4 - entityId3: 0x1D - entityInstance3: 0x6 - entityId4: 0x2B - entityInstance4: 0x1 - -0x03: - containerEntityId: 0x18 - containerEntityInstance: 0x2 - # This record has contained entities as a four entry list - isList: "true" - # This record is linked with the above record; this record and the - # above record have the same container entity Id and container entity - # instance - isLinked: "true" - entityId1: 0x2B - entityInstance1: 0x3 - entityId2: 0x0F - entityInstance2: 0x1 - entityId3: 0x0F - entityInstance3: 0x3 - entityId4: 0x10 - entityInstance4: 0x5 - -# This record has: -# Container Entity Id and Container Entity Instance = (0x1E, 0x1) -# Contained Entity Id and Contained Entity Instance = (0x20, 0x1), -# (0x20, 0x2), (0x20, 0x3), (0x20, 0x7), (0x20, 0x8), (0x20, 0x9) -0x04: - containerEntityId: 0x1E - containerEntityInstance: 0x1 - # This record has contained entities as two ranges of entity instances - isList: "false" - # This record is not linked - isLinked: "false" - entityId1: 0x20 - entityInstance1: 0x1 - entityId2: 0x20 - entityInstance2: 0x3 - entityId3: 0x20 - entityInstance3: 0x7 - entityId4: 0x20 - entityInstance4: 0x9 - -# The below two records have: -# Container Entity Id and Container Entity Instance = (0x1E, 0x3) -# Contained Entity Id and Contained Entity Instance = (0x20, 0x1), -# (0x20, 0x2), (0x20, 0x3), (0x20, 0x6), (0x20, 0x7), (0x20, 0x8), -# (0x20, 0xA), (0x20, 0xB), (0x20, 0xD), (0x20, 0xE), (0x20, 0xF) -0x05: - containerEntityId: 0x1E - containerEntityInstance: 0x03 - # This record has contained entities as two ranges of entity instances - isList: "false" - # This record is linked with the below record; this record and the - # below record have the same container entity Id and container entity - # instance; - isLinked: "true" - entityId1: 0x20 - entityInstance1: 0x1 - entityId2: 0x20 - entityInstance2: 0x3 - entityId3: 0x20 - entityInstance3: 0x6 - entityId4: 0x20 - entityInstance4: 0x8 - -0x06: - containerEntityId: 0x1E - containerEntityInstance: 0x03 - # This record has contained entities as two ranges of entity instances - isList: "false" - # This record is linked with the above record; this record and the - # above record have the same container entity Id and container entity - # instance; - isLinked: "true" - entityId1: 0x20 - entityInstance1: 0xA - entityId2: 0x20 - entityInstance2: 0xB - entityId3: 0x20 - entityInstance3: 0xD - entityId4: 0x20 - entityInstance4: 0xF diff --git a/scripts/entity_gen.py b/scripts/entity_gen.py deleted file mode 100755 index b558a44..0000000 --- a/scripts/entity_gen.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -import yaml -import argparse -from mako.template import Template - - -def generate_cpp(entity_yaml, output_dir): - with open(entity_yaml, 'r') as f: - ifile = yaml.safe_load(f) - if not isinstance(ifile, dict): - ifile = {} - - # Render the mako template - - t = Template(filename=os.path.join( - script_dir, - "writeentity.mako.cpp")) - - output_cpp = os.path.join(output_dir, "entity-gen.cpp") - with open(output_cpp, 'w') as fd: - fd.write(t.render(entityDict=ifile)) - - -def main(): - - valid_commands = { - 'generate-cpp': generate_cpp - } - parser = argparse.ArgumentParser( - description="IPMI Entity record parser and code generator") - - parser.add_argument( - '-i', '--entity_yaml', dest='entity_yaml', - default='example.yaml', help='input entity yaml file to parse') - - parser.add_argument( - "-o", "--output-dir", dest="outputdir", - default=".", - help="output directory") - - parser.add_argument( - 'command', metavar='COMMAND', type=str, - choices=valid_commands.keys(), - help='Command to run.') - - args = parser.parse_args() - - if (not (os.path.isfile(args.entity_yaml))): - sys.exit("Can not find input yaml file " + args.entity_yaml) - - function = valid_commands[args.command] - function(args.entity_yaml, args.outputdir) - - -if __name__ == '__main__': - script_dir = os.path.dirname(os.path.realpath(__file__)) - main() diff --git a/scripts/writeentity.mako.cpp b/scripts/writeentity.mako.cpp deleted file mode 100644 index 04ea87c..0000000 --- a/scripts/writeentity.mako.cpp +++ /dev/null @@ -1,40 +0,0 @@ -## This file is a template. The comment below is emitted -## into the rendered file; feel free to edit this file. -// !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!! - -#include -#include - -namespace ipmi { -namespace sensor { - -extern const EntityInfoMap entities = { -% for key in entityDict.iterkeys(): -{${key},{ -<% - entity = entityDict[key] - containerEntityId = entity["containerEntityId"] - containerEntityInstance = entity["containerEntityInstance"] - isList = entity["isList"] - isLinked = entity["isLinked"] - entityId1 = entity["entityId1"] - entityInstance1 = entity["entityInstance1"] - entityId2 = entity["entityId2"] - entityInstance2 = entity["entityInstance2"] - entityId3 = entity["entityId3"] - entityInstance3 = entity["entityInstance3"] - entityId4 = entity["entityId4"] - entityInstance4 = entity["entityInstance4"] -%> - ${containerEntityId},${containerEntityInstance},${isList},${isLinked},{ - std::make_pair(${entityId1}, ${entityInstance1}), - std::make_pair(${entityId2}, ${entityInstance2}), - std::make_pair(${entityId3}, ${entityInstance3}), - std::make_pair(${entityId4}, ${entityInstance4}) } - -}}, -% endfor -}; - -} // namespace sensor -} // namespace ipmi diff --git a/test/Makefile.am b/test/Makefile.am index 7d3d6fc..e4ff261 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -27,7 +27,7 @@ check_PROGRAMS = TESTS = $(check_PROGRAMS) entitymap_json_unittest_SOURCES = entitymap_json_unittest.cpp -entitymap_json_unittest_LDADD = $(top_builddir)/entity_map_json.o -lgmock $(top_builddir)/entity-gen.o +entitymap_json_unittest_LDADD = $(top_builddir)/entity_map_json.o -lgmock check_PROGRAMS += entitymap_json_unittest -- cgit v1.2.1