Skip to content

Commit eb92044

Browse files
committed
RBMC: Add failover support to rbmctool
Add --failover and --force-failover options to rbmctool. It calls the StartFailover method on the Failover interface on /xyz/openbmc_project/state/bmc0. The new help text: ``` [Option Group: Starting failovers] Options: -f,--failover Excludes: --force-failover Start a failover -r,--force-failover Excludes: --failover Start a forced failover. Only for emergencies. ``` Tested: Note, failovers aren't implemented yet and always return an error. ``` $ ./rbmctool --failover <6> Initiating failover Error: Failover cannot be started now (see journal for details) $ ./rbmctool --force-failover <6> Initiating forced failover Error: Failover cannot be started now (see journal for details) ``` Change-Id: I91f62ba40d7ab133d4ba79147abd7bf613c8a9cf Signed-off-by: Matt Spinler <[email protected]>
1 parent 40c9f06 commit eb92044

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

redundant-bmc/src/rbmc_tool.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "sibling_reset_impl.hpp"
77

88
#include <CLI/CLI.hpp>
9-
#include <xyz/openbmc_project/ObjectMapper/client.hpp>
9+
#include <xyz/openbmc_project/Control/Failover/client.hpp>
1010
#include <xyz/openbmc_project/Software/Version/client.hpp>
1111
#include <xyz/openbmc_project/State/BMC/Redundancy/client.hpp>
1212
#include <xyz/openbmc_project/State/BMC/client.hpp>
@@ -19,6 +19,7 @@ using Redundancy =
1919
sdbusplus::client::xyz::openbmc_project::state::bmc::Redundancy<>;
2020
using BMCState = sdbusplus::client::xyz::openbmc_project::state::BMC<>;
2121
using Role = Redundancy::Role;
22+
using Failover = sdbusplus::client::xyz::openbmc_project::control::Failover<>;
2223
using Heartbeat =
2324
sdbusplus::client::xyz::openbmc_project::state::decorator::Heartbeat<>;
2425
using Version = sdbusplus::client::xyz::openbmc_project::software::Version<>;
@@ -295,6 +296,53 @@ sdbusplus::async::task<> modifyRedundancyOverride(
295296
}
296297
}
297298

299+
// NOLINTNEXTLINE
300+
sdbusplus::async::task<> startFailover(sdbusplus::async::context& ctx,
301+
bool force)
302+
{
303+
using FailoverOptions = std::map<std::string, std::variant<bool>>;
304+
FailoverOptions options;
305+
306+
try
307+
{
308+
if (force)
309+
{
310+
lg2::info("Initiating forced failover");
311+
options.emplace(
312+
Failover::convertOptionsToString(Failover::Options::Force),
313+
force);
314+
}
315+
else
316+
{
317+
lg2::info("Initiating failover");
318+
}
319+
320+
auto path =
321+
sdbusplus::message::object_path{Redundancy::namespace_path::value} /
322+
Redundancy::namespace_path::bmc;
323+
324+
co_await Failover(ctx)
325+
.service(Redundancy::interface)
326+
.path(path.str)
327+
.start_failover(options);
328+
}
329+
catch (const sdbusplus::exception_t& e)
330+
{
331+
if (std::string{"xyz.openbmc_project.Common.Error.Unavailable"} ==
332+
e.name())
333+
{
334+
std::cout
335+
<< "Error: Failover cannot be started now (see journal for details)\n";
336+
}
337+
else
338+
{
339+
std::cout << "Unexpected error: " << e.what() << '\n';
340+
}
341+
342+
exit(EXIT_FAILURE);
343+
}
344+
}
345+
298346
int main(int argc, char** argv)
299347
{
300348
CLI::App app{"RBMC Tool"};
@@ -303,6 +351,8 @@ int main(int argc, char** argv)
303351
bool resetSibling{};
304352
bool disableRedundancy{};
305353
bool enableRedundancy{};
354+
bool failover{};
355+
bool forceFailover{};
306356
sdbusplus::async::context ctx;
307357

308358
auto* displayGroup = app.add_option_group("Display RBMC information");
@@ -326,6 +376,14 @@ int main(int argc, char** argv)
326376
resetGroup->add_flag("--reset-sibling", resetSibling,
327377
"Reset the sibling BMC");
328378

379+
auto* failoverGroup = app.add_option_group("Starting failovers");
380+
auto* fo =
381+
failoverGroup->add_flag("-f, --failover", failover, "Start a failover");
382+
failoverGroup
383+
->add_flag("-r, --force-failover", forceFailover,
384+
"Start a forced failover. Only for emergencies.")
385+
->excludes(fo);
386+
329387
app.require_option(1);
330388

331389
CLI11_PARSE(app, argc, argv);
@@ -346,6 +404,10 @@ int main(int argc, char** argv)
346404
{
347405
ctx.spawn(modifyRedundancyOverride(ctx, false));
348406
}
407+
else if (failover || forceFailover)
408+
{
409+
ctx.spawn(startFailover(ctx, forceFailover));
410+
}
349411
else
350412
{
351413
std::cout << app.help();

0 commit comments

Comments
 (0)