entity-manager: add support for replacement while including
This commit enhances the feature by adding replacement of keyword
support while including json.
```
Let’s say, we have the following include json where we can see two
template parameters %%BOARD_NAME%% and %%SYSTEM_NAME%%.
// include/association_template.json
{
"Description": [
"This file has some keywords that needs to be replaced.",
"%%SYSTEM_NAME%%: the system name the mobo associated to.",
"%%BOARD_NAME%%: the board name the mobo and the system associated to.",
],
"xyz.openbmc_project.Association.Definitions": {
"Associations": [
{
"Forward": "contained_by",
"Path": "/xyz/openbmc_project/inventory/system/board/%%BOARD_NAME%%/%%SYSTEM_NAME%%",
"Reverse": "containing"
}
]
}
...
}
```
```
Normally in existing platforms we use `sed` to replace them and create a
new file. But since we are using include directive, we can pass the
value of these parameters and include feature will replace them while
generating the configuration. Here is an example of how we can use this
// mobo.json
{
"Description": [...],
"include": {
"path": "association_template.json",
"replace": [
{
"search": "%%BOARD_NAME%%",
"replace_with": "mobo_1"
},
{
"search": "%%SYSTEM_NAME%%",
"replace_with": "system1"
}
]
}
...
}
```
Best practices for templates:
* Always name the json file with `_template` suffix so that everyone knows it has a template.
* It is always good to have a similar kind of description in the include file to quickly understand what needs to be done to include this template.
* Keep consistent with the keywords throughout the configurations i.e use the same template parameter name %%SYSTEM_NAME%% in all templates instead of creating different template parameter names for the same purpose.
Fusion-Link:
platform11: https://fusion2.corp.google.com/25866add-0dbc-35a4-bade-7e590b173a04
platform5: https://fusion2.corp.google.com/f6fc2926-4463-3e83-a781-50012c9242db
platform15: https://fusion2.corp.google.com/a6b2d8da-c1d9-388a-a760-200ad80f73b9
platform17: https://fusion2.corp.google.com/5122a076-74fd-3cc2-a1b3-0d2eaf228c08
Tested: Unit test passed
Google-Bug-Id: 451442226
Change-Id: Ie3a5bc4be18ce58d19685c0217ad784b7299764e
Signed-off-by: Munawar Hussain <munawarhussain@google.com>
2 files changed