topology: Add powered_by topology
bmcweb already support the power supply command, refer to
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/57668
Use "PowerPort" to add the powered_by association for upstream port, so
that the PowerSupplyCollection in redfish can get the power supply
information.
Tested:
Add the following config in mobo.json:
```
{
"Name": "Mobo Upstream Port",
"Type": "Mobo Upstream Port"
},
```
Add the following config in PSU.json:
```
{
"ConnectsToType": "Mobo Upstream Port",
"Name": "PSU $BUS Downstream Port",
"Type": "DownstreamPort",
"PowerPort": true
},
```
Result for association:
```
{
"type" : "as",
"data" : [
[
"/xyz/openbmc_project/inventory/system/board/PSU_1"
]
]
}
```
Result in bmcweb:
```
$ curl -s -k -H "X-Auth-Token: $token" http://${bmc}/redfish/v1/Chassis/Mobo | jq .Links.Contains
[
{
"@odata.id": "/redfish/v1/Chassis/PSU_1"
}
]
$ curl -k -H "X-Auth-Token: $token" http://${bmc}/redfish/v1/Chassis/Mobo/PowerSubsystem/PowerSupplies/PSU_1
{
"@odata.id": "/redfish/v1/Chassis/Mobo/PowerSubsystem/PowerSupplies/PSU_1",
"@odata.type": "#PowerSupply.v1_5_0.PowerSupply",
...
}
```
Run unitest for test_topology is PASSED.
Change-Id: Iad10e61417437a41628cf311cdd7893725a5dcde
Signed-off-by: Jeff Lin <JeffLin2@quantatw.com>
diff --git a/src/topology.cpp b/src/topology.cpp
index f2ee22b..94389b9 100644
--- a/src/topology.cpp
+++ b/src/topology.cpp
@@ -29,6 +29,11 @@
downstreamPorts[connectsTo].emplace_back(path);
boardTypes[path] = boardType;
+ auto findPoweredBy = exposesItem.find("PowerPort");
+ if (findPoweredBy != exposesItem.end())
+ {
+ powerPaths.insert(path);
+ }
}
else if (exposesType.ends_with("Port"))
{
@@ -65,6 +70,11 @@
{
result[downstream].emplace_back("contained_by",
"containing", upstream);
+ if (powerPaths.find(downstream) != powerPaths.end())
+ {
+ result[upstream].emplace_back(
+ "powered_by", "powering", downstream);
+ }
}
}
}