Add PowerWatts for EnvironmentMetrics

The EnvironmentMetrics schema[1] provides for efficient retrieval of
environmental metrics by separating them from performance metrics.
EnvironmentMetrics is a property of the Chassis schema since v1_15_0[2].
EnvironmentMetrics was added to Redfish release 2021.2 [3] to be used
instead of the deprecated Power schema.[4]

This commit adds PowerWatts property of the EnvironmentMetrics schema.
PowerWatts has been part of the EnvironmentMetrics schema since v1_1_0.
PowerWatts is a SensorPowerExcerpt[5].

Implementation notes: The new D-Bus interface
"xyz.openbmc_project.Sensor.Purpose" is used to find the sensor with the
"TotalPower" purpose.[6][7] The new utility function
sensor_utils::getSensorsByPurpose() returns a subset of an incoming list
of sensors which implement a specified purpose.

Multiple D-Bus calls are needed to find the sensor providing the
totalPower:
1. Retrieve list of power sensors associated with specified chassis
   which implement the Sensor.Purpose interface using existing
   getAllSensorObjects() function.
2. For each of those power sensors retrieve the actual purpose of the
   sensor to find the sensor implementing totalPower purpose. Expect no
   more than one sensor to implement this purpose. New utility function
   getSensorsByPurpose() is used.
3. If a totalPower sensor is found then retrieve its properties to fill
   in PowerWatts in the response using existing
   sensor_utils::objectExcerptToJson() utility function.

If no sensor has the "TotalPower" purpose then PowerWatts is
not added to EnvironmentMetrics and no error is returned.

[1] https://redfish.dmtf.org/schemas/v1/EnvironmentMetrics.v1_3_2.json
[2] https://redfish.dmtf.org/schemas/v1/Chassis.v1_25_2.json
[3] http://redfish.dmtf.org/schemas/Redfish_Release_History.pdf
[4] https://redfish.dmtf.org/schemas/v1/Power.v1_7_3.json
[5] http://redfish.dmtf.org/schemas/v1/Sensor.v1_9_1.json#/definitions/SensorPowerExcerpt
[6] https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/75943
[7] https://gerrit.openbmc.org/c/openbmc/openpower-occ-control/+/77408

Tested:
 - Updated unit tests for new environmentMetricsNode enum
 - Redfish Service Validator passes (confirmed PowerWatts tested)
```
VERBOSE1 - ServiceRoot -> Chassis -> Members#4 -> EnvironmentMetrics, EnvironmentMetrics.v1_3_0, EnvironmentMetrics
VERBOSE1 - @odata.id                                               PASS
VERBOSE1 - @odata.type                                             PASS
VERBOSE1 - Id                                                      PASS
VERBOSE1 - Name                                                    PASS
VERBOSE1 - PowerWatts                                              PASS
```
 - No "TotalPower" sensor exists (system never powered on).
   PowerWatts is not shown and no error is returned.
```
curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/EnvironmentMetrics
{
  "@odata.id": "/redfish/v1/Chassis/chassis/EnvironmentMetrics",
  "@odata.type": "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics",
  "Id": "EnvironmentMetrics",
  "Name": "Chassis Environment Metrics"
}
```

 - "TotalPower" sensor exists (system powered on)
```
curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Systems/system | grep PowerState
  "PowerState": "On",

curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/EnvironmentMetrics
{
  "@odata.id": "/redfish/v1/Chassis/chassis/EnvironmentMetrics",
  "@odata.type": "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics",
  "Id": "EnvironmentMetrics",
  "Name": "Chassis Environment Metrics",
  "PowerWatts": {
    "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/power_total_power",
    "Reading": 191.0
  }
}
```
   DataSourceUri is a valid sensor:
```
curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/Sensors/power_total_power
{
  "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/power_total_power",
  "@odata.type": "#Sensor.v1_2_0.Sensor",
  "Id": "power_total_power",
  "Name": "total power",
  "Reading": 191.0,
  "ReadingType": "Power",
  "ReadingUnits": "W",
  "Status": {
    "Health": "OK",
    "State": "Enabled"
  }
}
```

 - "TotalPower" sensor exists but null value (system powered off)
```
curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Systems/system | grep PowerState
  "PowerState": "Off",

curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/EnvironmentMetrics
{
  "@odata.id": "/redfish/v1/Chassis/chassis/EnvironmentMetrics",
  "@odata.type": "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics",
  "Id": "EnvironmentMetrics",
  "Name": "Chassis Environment Metrics",
  "PowerWatts": {
    "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/power_total_power",
    "Reading": null
  }
}
```

And again the DataSourceUri points to a valid sensor:
```
curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/Sensors/power_total_power
{
  "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/power_total_power",
  "@odata.type": "#Sensor.v1_2_0.Sensor",
  "Id": "power_total_power",
  "Name": "total power",
  "Reading": null,
  "ReadingType": "Power",
  "ReadingUnits": "W",
  "Status": {
    "Health": "OK",
    "State": "Enabled"
  }
}
```

 - Invalid chassis id ("TotalPower" sensor exists)
```
curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassisBAD/EnvironmentMetrics
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "@odata.type": "#Message.v1_1_1.Message",
        "Message": "The requested resource of type Chassis named 'chassisBAD' was not found.",
        "MessageArgs": [
          "Chassis",
          "chassisBAD"
        ],
        "MessageId": "Base.1.19.ResourceNotFound",
        "MessageSeverity": "Critical",
        "Resolution": "Provide a valid resource identifier and resubmit the request."
      }
    ],
    "code": "Base.1.19.ResourceNotFound",
    "message": "The requested resource of type Chassis named 'chassisBAD' was not found."
  }
}
```

Signed-off-by: George Liu <liuxiwei@inspur.com>
Signed-off-by: Janet Adkins <janeta@us.ibm.com>
Change-Id: Ibe84a5e7fe0d2b232f925e457a094c021ca85d36
4 files changed
tree: 1d0196a001595bff9dce799eeba480c507b9cf71
  1. .github/
  2. config/
  3. docs/
  4. features/
  5. http/
  6. include/
  7. redfish-core/
  8. scripts/
  9. src/
  10. static/
  11. subprojects/
  12. test/
  13. .clang-format
  14. .clang-tidy
  15. .codespell-ignore
  16. .dockerignore
  17. .eslintignore
  18. .gitignore
  19. .markdownlint.yaml
  20. .openbmc-enforce-gitlint
  21. .prettierignore
  22. .shellcheck
  23. DEVELOPING.md
  24. LICENSE
  25. meson.build
  26. meson.options
  27. OWNERS
  28. README.md
  29. run-ci
README.md

OpenBMC webserver

This component attempts to be a "do everything" embedded webserver for OpenBMC.

Features

The webserver implements a few distinct interfaces:

  • DBus event websocket. Allows registering on changes to specific dbus paths, properties, and will send an event from the websocket if those filters match.
  • OpenBMC DBus REST api. Allows direct, low interference, high fidelity access to dbus and the objects it represents.
  • Serial: A serial websocket for interacting with the host serial console through websockets.
  • Redfish: A protocol compliant, DBus to Redfish translator.
  • KVM: A websocket based implementation of the RFB (VNC) frame buffer protocol intended to mate to webui-vue to provide a complete KVM implementation.

Protocols

bmcweb at a protocol level supports http and https. TLS is supported through OpenSSL. Http1 and http2 are supported using ALPN registration for TLS connections and h2c upgrade header for http connections.

AuthX

Authentication

Bmcweb supports multiple authentication protocols:

  • Basic authentication per RFC7617
  • Cookie based authentication for authenticating against webui-vue
  • Mutual TLS authentication based on OpenSSL
  • Session authentication through webui-vue
  • XToken based authentication conformant to Redfish DSP0266

Each of these types of authentication is able to be enabled or disabled both via runtime policy changes (through the relevant Redfish APIs) or via configure time options. All authentication mechanisms supporting username/password are routed to libpam, to allow for customization in authentication implementations.

Authorization

All authorization in bmcweb is determined at routing time, and per route, and conform to the Redfish PrivilegeRegistry.

*Note: Non-Redfish functions are mapped to the closest equivalent Redfish privilege level.

Configuration

bmcweb is configured per the meson build files. Available options are documented in meson_options.txt

Compile bmcweb with default options

meson setup builddir
ninja -C builddir

If any of the dependencies are not found on the host system during configuration, meson will automatically download them via its wrap dependencies mentioned in bmcweb/subprojects.

Use of persistent data

bmcweb relies on some on-system data for storage of persistent data that is internal to the process. Details on the exact data stored and when it is read/written can seen from the persistent_data namespace.

TLS certificate generation

When SSL support is enabled and a usable certificate is not found, bmcweb will generate a self-signed a certificate before launching the server. Please see the bmcweb source code for details on the parameters this certificate is built with.

Compression

bmcweb supports various forms of http compression, including zstd and gzip. Client headers are observed to determine whether compressed payloads are supported.

Redfish Aggregation

bmcweb is capable of aggregating resources from satellite BMCs. Refer to AGGREGATION.md for more information on how to enable and use this feature.