Roll forward cl/707228705

The unit test had a typo resulting in malformed json. It looks like the test wasn't added to the test list in meson.build.

Automated g4 rollback of changelist 707697181.

*** Reason for rollback ***

Rolling forward with fixed tests

*** Original change description ***

Automated g4 rollback of changelist 707228705.

*** Reason for rollback ***

Failing https://tap.corp.google.com/node_os

*** Original change description ***

#gpowerd - Add build target for register_actions

***

***

PiperOrigin-RevId: 715497339
Change-Id: I6dc063506ab169e09206d10dee446407dec7adc6
diff --git a/bmc/register_actions_bmc.cc b/bmc/register_actions_bmc.cc
index c394477..f5097ec 100644
--- a/bmc/register_actions_bmc.cc
+++ b/bmc/register_actions_bmc.cc
@@ -1,23 +1,29 @@
 #include "bmc/register_actions_bmc.h"
 
-#include <nlohmann/json.hpp>
-#include <safepower_agent.h>
-#include <safepower_agent.pb.h>
-#include <safepower_agent_config.pb.h>
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <string_view>
+#include <utility>
+#include <vector>
 
+#include "action_context.h"
+#include "bmc/http_connection.h"
 #include "absl/functional/any_invocable.h"
+#include "absl/log/log.h"
 #include "absl/status/status.h"
 #include "absl/status/statusor.h"
 #include "absl/strings/str_split.h"
+#include "absl/strings/string_view.h"
 
-#include "bmc/http_connection.h"
+// NOLINTBEGIN(readability/boost)
+#include "boost/asio/ip/tcp.hpp"
+#include "boost/beast/core.hpp"
+#include "boost/beast/http.hpp"
+// NOLINTEND(readability/boost)
 
-#include "action_context.h"
-#include "bmc/redfish.h"
-
-#include "boost/asio/ip/tcp.hpp"  // NOLINT
-#include "boost/beast/core.hpp"  // NOLINT
-#include "boost/beast/http.hpp"  // NOLINT
+#include "nlohmann/json.hpp"
+#include "nlohmann/json_fwd.hpp"
 
 namespace safepower_agent {
 
@@ -49,36 +55,31 @@
     return absl::OkStatus();
   } else {
     LOG(ERROR) << "Failed to power off :" << *message_id;
-    return absl::NotFoundError("Failed to power off :"
-                                 + message_id->dump());
+    return absl::NotFoundError("Failed to power off :" + message_id->dump());
   }
 }
 
 // runs when then action is called, perform the action
 inline void GenericRedfishPowerOperation(
-    absl::string_view uri, nlohmann::json body,
-    std::string_view ip, uint16_t port,
-    absl::AnyInvocable<void(absl::Status) &&> cb,
-    const safepower_agent_proto::Action& )
-  {
+    absl::string_view uri, nlohmann::json body, std::string_view ip,
+    uint16_t port, absl::AnyInvocable<void(absl::Status) &&> cb,
+    const safepower_agent_proto::Action&) {
   LOG(INFO) << "Redfish action " << ip << ":" << port << "  " <<
       uri << " " << body;
   auto connection = std::make_shared<HttpConnection>();
-  connection->PerformConnection(http::verb::post,
-                               uri,
-                               [callback = std::move(cb)]
-                               (absl::StatusOr<nlohmann::json> js) mutable {
-                                 absl::Status status = GenericRedfishParser(js);
-                                 std::move(callback)(status);
-                                   }, body,
-                               ip, port);
-  }
+  connection->PerformConnection(
+      http::verb::post, uri,
+      [callback = std::move(cb)](absl::StatusOr<nlohmann::json> js) mutable {
+        absl::Status status = GenericRedfishParser(js);
+        std::move(callback)(status);
+      },
+      body, ip, port);
+}
 
 // runs at startup to register all actions from the config
 absl::Status RegisterActionFromConfig(
     ActionContextManager* action_context_manager,
-    const SafePowerAgentConfig& config)
-  {
+    const SafePowerAgentConfig& config) {
   for (const auto& action_config : config.action_configs()) {
     safepower_agent_proto::Action action_to_register = action_config.action();
     // The config will map actions to redfish (uris and body)
@@ -90,11 +91,11 @@
       LOG(ERROR) << "Failed to parse json body: " <<
           action_config.redfish().json_body();
       return absl::InvalidArgumentError("Failed to parse json body: " +
-                              action_config.redfish().json_body());
+                                        action_config.redfish().json_body());
     }
     std::string uri = action_config.redfish().uri();
     uint32_t port = action_config.redfish().port();
-    if (port > 65535){
+    if (port > 65535) {
       LOG(ERROR) << "Port number is invalid: " << port;
       return absl::InvalidArgumentError("Port number is invalid: " +
                                         std::to_string(port));
@@ -103,20 +104,19 @@
     LOG(INFO) << "registering " << action_config.action_name() << " "
        << ip << ":" << port << "  " << uri << " " << body;
 
-    absl::Status action_status = action_context_manager->
-        RegisterAction(action_to_register,
-                       [uri, body, port, ip]
-                       (const safepower_agent_proto::Action& a,
-          absl::AnyInvocable<void(absl::Status) &&> cb) {
-        GenericRedfishPowerOperation(uri, body, ip, port, std::move(cb), a);
-      });
+    absl::Status action_status = action_context_manager->RegisterAction(
+        action_to_register,
+        [uri, body, port, ip](const safepower_agent_proto::Action& a,
+                              absl::AnyInvocable<void(absl::Status) &&> cb) {
+          GenericRedfishPowerOperation(uri, body, ip, port, std::move(cb), a);
+        });
 
-    if (!action_status.ok()){
-       LOG(ERROR) << "Unable to register action :" << action_status;
-       return action_status;
-      }
+    if (!action_status.ok()) {
+      LOG(ERROR) << "Unable to register action :" << action_status;
+      return action_status;
     }
-    LOG(INFO) << "All actions registered";
-    return absl::OkStatus();
   }
+  LOG(INFO) << "All actions registered";
+  return absl::OkStatus();
+}
 }  // namespace safepower_agent
diff --git a/bmc/register_actions_bmc.h b/bmc/register_actions_bmc.h
index b19f2ca..f8314af 100644
--- a/bmc/register_actions_bmc.h
+++ b/bmc/register_actions_bmc.h
@@ -1,12 +1,10 @@
 #ifndef PRODUCTION_SUSHID_SAFEPOWER_AGENT_BMC_REGISTER_ACTIONS_BMC_H_
 #define PRODUCTION_SUSHID_SAFEPOWER_AGENT_BMC_REGISTER_ACTIONS_BMC_H_
 
-#include <safepower_agent.pb.h>
-#include <safepower_agent_config.pb.h>
-
+#include "action_context.h"
+#include "safepower_agent_config.pb.h"
 #include "absl/functional/any_invocable.h"
 #include "absl/status/status.h"
-#include "action_context.h"
 
 namespace safepower_agent {
 
diff --git a/bmc/register_actions_bmc_test.cc b/bmc/register_actions_bmc_test.cc
index 85b9e98..7ac9aa3 100644
--- a/bmc/register_actions_bmc_test.cc
+++ b/bmc/register_actions_bmc_test.cc
@@ -1,53 +1,55 @@
+
+
 #include "bmc/register_actions_bmc.h"
-#include <safepower_agent.pb.h>
 
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
+#include <cstdlib>
+#include <memory>
+#include <ostream>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
 
-#include "absl/log/log.h"
 #include "action_context.h"
+#include "safepower_agent_config.pb.h"
 #include "state_updater.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include "absl/log/log.h"
 
 namespace safepower_agent {
 
 namespace {
 
-bool isASanEnabled() {
-  return std::getenv("ASAN_OPTIONS") != nullptr;
-}
-using safepower_agent_proto::ActionType;
+bool isASanEnabled() { return std::getenv("ASAN_OPTIONS") != nullptr; }
 using safepower_agent_proto::ActionSeverity;
+using safepower_agent_proto::ActionType;
 
-TEST(RegisterActionsTest, RegisterAction ) {
-    if (isASanEnabled())
-    {
-       LOG(ERROR) << "b/349393089 absl::map insert fails asan" << std::endl;
-       GTEST_SKIP() << "Skipping test in ASan environment.";
-       // TODO b/349393089 absl::map insert fails asan
-       // Error message //https://paste.googleplex.com/6557456877748224
-    }
-    safepower_agent_proto::SystemState initialState;
-    auto reactor =
-        std::make_shared<StateUpdater<safepower_agent_proto::SystemState>>(
-            std::move(initialState), true);
-    auto action_context_manager =
-        std::make_unique<safepower_agent::ActionContextManager>(reactor);
+TEST(RegisterActionsTest, RegisterAction) {
+  if (isASanEnabled()) {
+    LOG(ERROR) << "b/349393089 absl::map insert fails asan" << std::endl;
+    GTEST_SKIP() << "Skipping test in ASan environment.";
+    // TODO b/349393089 absl::map insert fails asan
+    // Error message //https://paste.googleplex.com/6557456877748224
+  }
+  safepower_agent_proto::SystemState initialState;
+  auto reactor =
+      std::make_shared<StateUpdater<safepower_agent_proto::SystemState>>(
+          std::move(initialState), true);
+  auto action_context_manager =
+      std::make_unique<safepower_agent::ActionContextManager>(reactor);
   safepower_agent_config::SafePowerAgentConfig safepower_agent_config;
 
-  std::vector<std::tuple<ActionType,
-                         ActionSeverity, std::string, std::string> > data = {
-      {
-        {safepower_agent_proto::ACTION_TYPE_CYCLE},
-        {safepower_agent_proto::ACTION_SEVERITY_FORCE},
-        {"/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"},
-        {"/{\"ResetType\":\"ForceRestart\"/}"}},
-      {
-        {safepower_agent_proto::ACTION_TYPE_CYCLE},
-        {safepower_agent_proto::ACTION_SEVERITY_GRACEFUL},
-        {"/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"},
-        {"/{\"ResetType\":\"GracefulRestart\"/}"}}
-      };
-    for (auto [action_type, action_severity, uri, json_body] : data) {
+  std::vector<std::tuple<ActionType, ActionSeverity, std::string, std::string>>
+      data = {{{safepower_agent_proto::ACTION_TYPE_CYCLE},
+               {safepower_agent_proto::ACTION_SEVERITY_FORCE},
+               {"/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"},
+               {"{\"ResetType\":\"ForceRestart\"}"}},
+              {{safepower_agent_proto::ACTION_TYPE_CYCLE},
+               {safepower_agent_proto::ACTION_SEVERITY_GRACEFUL},
+               {"/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"},
+               {"{\"ResetType\":\"GracefulRestart\"}"}}};
+  for (auto [action_type, action_severity, uri, json_body] : data) {
     safepower_agent_config::ActionConfig* action_config =
         safepower_agent_config.add_action_configs();
     action_config->mutable_action()->set_action_type(action_type);
@@ -57,20 +59,20 @@
   };
 
   (void)RegisterActionFromConfig(action_context_manager.get(),
-                                       safepower_agent_config);
+                                 safepower_agent_config);
 
   safepower_agent_proto::GetSupportedActionsResponse response;
   action_context_manager->GetSupportedActions(response);
   EXPECT_EQ(response.actions_size(), 2);
   for (const auto& action : response.actions()) {
     EXPECT_EQ(action.action_type(), safepower_agent_proto::ACTION_TYPE_CYCLE);
-    EXPECT_THAT(action.action_severity(), testing::AnyOf(
-              safepower_agent_proto::ACTION_SEVERITY_FORCE,
-              safepower_agent_proto::ACTION_SEVERITY_GRACEFUL));
+    EXPECT_THAT(
+        action.action_severity(),
+        testing::AnyOf(safepower_agent_proto::ACTION_SEVERITY_FORCE,
+                       safepower_agent_proto::ACTION_SEVERITY_GRACEFUL));
   }
 }
 
-
 }  // namespace
 
 }  // namespace safepower_agent