bmcweb: Update to use delay-reset not async timer

The old patch used an async timer, which left the state in bmcweb.
This new patch uses a delay-reset service that handles the state.

Tested:

curl http://localhost:80/redfish/v1/Systems/system/ResetActionInfo/
{
  "@odata.id": "/redfish/v1/Systems/system/ResetActionInfo",
  "@odata.type": "#ActionInfo.v1_1_2.ActionInfo",
  "Id": "ResetActionInfo",
  "Name": "Reset Action Info",
  "Parameters": [
    {
      "AllowableValues": [
        "On",
        "ForceOff",
        "ForceOn",
        "ForceRestart",
        "GracefulRestart",
        "GracefulShutdown",
        "PowerCycle",
        "Nmi"
      ],
      "DataType": "String",
      "Delay": "Number",
      "Name": "ResetType",
      "Required": true
    }
 ]
}

curl http://localhost:80/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/ -d "{\"ResetType\": \"ForceOn\", \"Delay\": 5 }"
{
  "@Message.ExtendedInfo": [
    {
      "@odata.type": "#Message.v1_1_1.Message",
      "Message": "The request completed successfully.",
      "MessageArgs": [],
      "MessageId": "Base.1.13.0.Success",
      "MessageSeverity": "OK",
      "Resolution": "None"
    }
  ]
}

journalctl
systemd[1]: Starting Delay power off...
(5 seconds later)
systemd[1]: Started Delay power off.
curl[11898]:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
curl[11898]:                                  Dload  Upload   Total   Spent    Left  Speed
curl[11898]: [158B blob data]
curl[11898]: {
curl[11898]:   "@Message.ExtendedInfo": [
curl[11898]:     {
curl[11898]:       "@odata.type": "#Message.v1_1_1.Message",
curl[11898]:       "Message": "The request completed successfully.",
curl[11898]:       "MessageArgs": [],
curl[11898]:       "MessageId": "Base.1.13.0.Success",
curl[11898]:       "MessageSeverity": "OK",
curl[11898]:       "Resolution": "None"
curl[11898]:     }
curl[11898]:   ]
bmcweb[11842]: W0210 19:17:45.846359   11842 grpc_server.h:81] Received request; |url|=/redfish/v1/Systems/system/Memory/dimm10/MemoryMetrics; |method|=GET
systemd[1]: delay-reset@5.service: Deactivated successfully.
curl[11898]: }

$ curl http://localhost:80/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/ -d "{\"ResetType\": \"ForceOn\", \"Delay\": 123}"
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "@odata.type": "#Message.v1_1_1.Message",
        "Message": "The value '120' for the property Delay is not in the supported range of acceptable values.",
        "MessageArgs": [
          "120",
          "Delay"
        ],
        "MessageId": "Base.1.13.0.PropertyValueOutOfRange",
        "MessageSeverity": "Warning",
        "Resolution": "Correct the value for the property in the request body and resubmit the request if the operation failed."
      }
    ],
    "code": "Base.1.13.0.PropertyValueOutOfRange",
    "message": "The value '120' for the property Delay is not in the supported range of acceptable values."
  }
}
$ curl http://localhost:80/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/ -d "{\"ResetType\": \"ForceOff\", \"Delay\": 5}"
{
  "resetType@Message.ExtendedInfo": [
    {
      "@odata.type": "#Message.v1_1_1.Message",
      "Message": "The value 'ForceOff' for the property resetType is not in the list of acceptable values.",
      "MessageArgs": [
        "ForceOff",
        "resetType"
      ],
      "MessageId": "Base.1.13.0.PropertyValueNotInList",
      "MessageSeverity": "Warning",
      "Resolution": "Choose a value from the enumeration list that the implementation can support and resubmit the request if the operation failed."
    }
  ]
}

Patch tracking info stays the same.

Signed-off-by: John Edward Broadbent <jebr@google.com>
Change-Id: I1855aa618b5e64d671ae5b1c667ee9769f3d1632
(cherry picked from commit 4cc363ca86919535778f462fde69c5e2bb55d6a1)
diff --git a/recipes-phosphor/interfaces/bmcweb/0001-Add-chassis-reset-delay.patch b/recipes-phosphor/interfaces/bmcweb/0001-Add-chassis-reset-delay.patch
index 1d4b07b..2d6325c 100644
--- a/recipes-phosphor/interfaces/bmcweb/0001-Add-chassis-reset-delay.patch
+++ b/recipes-phosphor/interfaces/bmcweb/0001-Add-chassis-reset-delay.patch
@@ -1,10 +1,11 @@
-From b9972de1e621e3128b654f103387d5fc3ca4a6e3 Mon Sep 17 00:00:00 2001
+From 2400c524a1649204d3368abc0af5e19ee0c62ea3 Mon Sep 17 00:00:00 2001
 From: John Edward Broadbent <jebr@google.com>
 Date: Wed, 25 Jan 2023 16:00:50 -0800
 Subject: [PATCH] Add chassis reset delay
 
 Tested:
-curl http://localhost:18080/redfish/v1/Systems/system/ResetActionInfo/
+
+curl http://localhost:80/redfish/v1/Systems/system/ResetActionInfo/
 {
   "@odata.id": "/redfish/v1/Systems/system/ResetActionInfo",
   "@odata.type": "#ActionInfo.v1_1_2.ActionInfo",
@@ -17,9 +18,9 @@
         "ForceOff",
         "ForceOn",
         "ForceRestart",
-	"GracefulRestart",
+        "GracefulRestart",
         "GracefulShutdown",
-	"PowerCycle"
+        "PowerCycle",
         "Nmi"
       ],
       "DataType": "String",
@@ -27,9 +28,10 @@
       "Name": "ResetType",
       "Required": true
     }
-  ]
+ ]
 }
-curl http://localhost:18080/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/ -d "{\"RestType\": \"ForceRestart\", \"Delay\": 60 }"
+
+curl http://localhost:80/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/ -d "{\"ResetType\": \"ForceOn\", \"Delay\": 5 }"
 {
   "@Message.ExtendedInfo": [
     {
@@ -42,7 +44,27 @@
     }
   ]
 }
-resets the host after 60 seconds
+
+journalctl
+systemd[1]: Starting Delay power off...
+(5 seconds later)
+systemd[1]: Started Delay power off.
+curl[11898]:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
+curl[11898]:                                  Dload  Upload   Total   Spent    Left  Speed
+curl[11898]: [158B blob data]
+curl[11898]: {
+curl[11898]:   "@Message.ExtendedInfo": [
+curl[11898]:     {
+curl[11898]:       "@odata.type": "#Message.v1_1_1.Message",
+curl[11898]:       "Message": "The request completed successfully.",
+curl[11898]:       "MessageArgs": [],
+curl[11898]:       "MessageId": "Base.1.13.0.Success",
+curl[11898]:       "MessageSeverity": "OK",
+curl[11898]:       "Resolution": "None"
+curl[11898]:     }
+curl[11898]:   ]
+curl[11898]: }
+systemd[1]: delay-reset@5.service: Deactivated successfully.
 
 Patch Tracking Bug: b/266850782
 Upstream info: This work will have to be replaced by a stable and long term solution.
@@ -54,14 +76,15 @@
 Justification: b/266572626
 
 Google-Bug-Id: b/266572626
-Change-Id: Id9f357a3ed1aaa54171e339ef0aa96465f1c489f
 Signed-off-by: John Edward Broadbent <jebr@google.com>
+
+%% original patch: 0001-Add-chassis-reset-delay.patch
 ---
- redfish-core/lib/systems.hpp | 44 +++++++++++++++++++++++++++++++++++-
- 1 file changed, 43 insertions(+), 1 deletion(-)
+ redfish-core/lib/systems.hpp | 40 ++++++++++++++++++++++++++++++++++--
+ 1 file changed, 38 insertions(+), 2 deletions(-)
 
 diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
-index caf6a292..054dfc07 100644
+index caf6a292..47474ae7 100644
 --- a/redfish-core/lib/systems.hpp
 +++ b/redfish-core/lib/systems.hpp
 @@ -2768,8 +2768,9 @@ inline void requestRoutesSystemActionsReset(App& app)
@@ -75,55 +98,57 @@
          {
              return;
          }
-@@ -2820,7 +2821,47 @@ inline void requestRoutesSystemActionsReset(App& app)
-                                              resetType);
+@@ -2821,6 +2822,41 @@ inline void requestRoutesSystemActionsReset(App& app)
              return;
          }
-+        if (delayTime.has_value())
-+        {
-+            static boost::asio::deadline_timer t(
-+                crow::connections::systemBus->get_io_context());
-+            t.expires_from_now(boost::posix_time::seconds(delayTime.value()));
-+
  
-+            t.async_wait(
-+                [hostCommand, command]
-+                (const boost::system::error_code ec3) {
-+                    if (ec3)
-+                    {
-+                       BMCWEB_LOG_DEBUG << "Got a bad timer for some reason" << ec3;
-+                       return;
-+                    }
-+                    std::string interface, service;
-+                    if (hostCommand){
-+                       interface = "xyz.openbmc_project.State.Host";
-+                       service = "/xyz/openbmc_project/state/host0";
-+                    }
-+                    else{
-+                       interface = "xyz.openbmc_project.State.Chassis";
-+                       service = "/xyz/openbmc_project/state/chassis0";
-+                    }
-+                    crow::connections::systemBus->async_method_call(
-+                         [command](const boost::system::error_code ec) {
-+                       if (ec)
-+                       {
-+                           BMCWEB_LOG_ERROR << "Delay reset error: D-Bus responses error: " << ec;
-+                           return;
-+                       }
-+                    },
-+                    interface, service,
-+                    "org.freedesktop.DBus.Properties", "Set",
-+                    "xyz.openbmc_project.State.Host", "RequestedHostTransition",
-+                    dbus::utility::DbusVariantType{command});
-+           });
++        if (delayTime.has_value() && delayTime.value() > 120)
++        {
++            BMCWEB_LOG_DEBUG << "reset delay timer too large, >120";
++            messages::propertyValueOutOfRange(asyncResp->res, "120", "Delay");
++            return;
++        }
++        if (delayTime.has_value() && resetType != "ForceOn")
++        {
++            BMCWEB_LOG_DEBUG << "reset delay requested with not ForceOn";
++            messages::propertyValueNotInList(asyncResp->res, resetType,
++                                             "resetType");
++            return;
++        }
 +
-+           messages::success(asyncResp->res);
-+           return;
++        if (delayTime.has_value() && delayTime.value() <= 120 &&
++            resetType == "ForceOn")
++        {
++            BMCWEB_LOG_DEBUG << "Seting delayed powerOn ";
++
++            crow::connections::systemBus->async_method_call(
++                [asyncResp](const boost::system::error_code ec) {
++                if (ec)
++                {
++                    BMCWEB_LOG_ERROR << "error in calling delay-reset " << ec;
++                    messages::internalError(asyncResp->res);
++                }
++                BMCWEB_LOG_DEBUG << "delay reset request success";
++                messages::success(asyncResp->res);
++                return;
++                },
++                "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
++                "org.freedesktop.systemd1.Manager", "RestartUnit",
++                "delay-reset@" + std::to_string(delayTime.value()) + ".service",
++                "replace");
 +        }
          if (hostCommand)
          {
              crow::connections::systemBus->async_method_call(
-@@ -3224,6 +3265,7 @@ inline void requestRoutesSystemResetActionInfo(App& app)
+@@ -2895,7 +2931,6 @@ inline void handleComputerSystemCollectionHead(
+  */
+ inline void requestRoutesSystems(App& app)
+ {
+-
+     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/")
+         .privileges(redfish::privileges::headComputerSystem)
+         .methods(boost::beast::http::verb::head)(
+@@ -3224,6 +3259,7 @@ inline void requestRoutesSystemResetActionInfo(App& app)
          parameter["Name"] = "ResetType";
          parameter["Required"] = true;
          parameter["DataType"] = "String";
@@ -132,5 +157,5 @@
          allowableValues.emplace_back("On");
          allowableValues.emplace_back("ForceOff");
 -- 
-2.39.1.456.gfc5497dd1b-goog
+2.39.1.581.gbfd45094c4-goog