Skip to content

Commit

Permalink
ExternalData: Add API for Retrieving Sibling BMC IP
Browse files Browse the repository at this point in the history
- Introduces a framework to retrieve external dependent data, which can be
  hosted on DBus, Filesystem, or other sources by various applications.

- Adds an interface to fetch the Sibling BMC IP, which will be used to obtain
  the corresponding BMC IP.

- External data retrieval happens in parallel during the configuration sync
  phase, ensuring the sync operation starts only after all tasks are completed.
  • Loading branch information
ManishTiwari authored and ManishTiwari committed Jan 10, 2025
1 parent 8199925 commit 8ca9c30
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/external_data_ifaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace data_sync::ext_data
sdbusplus::async::task<> ExternalDataIFaces::startExtDataFetches()
{
// NOLINTNEXTLINE
co_return co_await fetchBMCRedundancyMgrProps();
co_return co_await sdbusplus::async::execution::when_all(
fetchBMCRedundancyMgrProps(), fetchSiblingBmcIP());
}

BMCRole ExternalDataIFaces::bmcRole() const
Expand All @@ -32,4 +33,15 @@ void ExternalDataIFaces::bmcRedundancy(const BMCRedundancy& bmcRedundancy)
_bmcRedundancy = bmcRedundancy;
}

SiblingBmcIP ExternalDataIFaces::siblingBmcIP() const
{
return _siblingBmcIP;
}

void ExternalDataIFaces::siblingBmcIP(const SiblingBmcIP& siblingBmcIP)
{
// lg2::info("siblingBmc IP: {SIBLING_IP}", "SIBLING_IP", siblingBmcIP);
_siblingBmcIP = siblingBmcIP;
}

} // namespace data_sync::ext_data
27 changes: 27 additions & 0 deletions src/external_data_ifaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace data_sync::ext_data
using RBMC = sdbusplus::common::xyz::openbmc_project::state::bmc::Redundancy;
using BMCRole = RBMC::Role;
using BMCRedundancy = bool;
using SiblingBmcIP = std::string;

/**
* @class ExternalDataIFaces
Expand Down Expand Up @@ -53,12 +54,24 @@ class ExternalDataIFaces
*/
BMCRedundancy bmcRedundancy() const;

/**
* @brief Used to obtain the Sibling BMC IP.
*
* @return The Sibling BMC IP
*/
SiblingBmcIP siblingBmcIP() const;

protected:
/**
* @brief Used to retrieve the BMC role.
*/
virtual sdbusplus::async::task<> fetchBMCRedundancyMgrProps() = 0;

/**
* @brief Used to retrieve the BMC Position.
*/
virtual sdbusplus::async::task<> fetchSiblingBmcIP() = 0;

/**
* @brief A utility API to assign the retrieved BMC role.
*
Expand All @@ -77,6 +90,15 @@ class ExternalDataIFaces
*/
void bmcRedundancy(const BMCRedundancy& bmcRedundancy);

/**
* @brief A utility API to assign the retrieved Sibling BMC IP.
*
* @param[in] siblingBmcIP - The retrieved Sibling BMC IP.
*
* @return None.
*/
void siblingBmcIP(const SiblingBmcIP& siblingBmcIP);

private:
/**
* @brief Holds the BMC role.
Expand All @@ -87,6 +109,11 @@ class ExternalDataIFaces
* @brief Indicates whether BMC redundancy is enabled in the system.
*/
BMCRedundancy _bmcRedundancy{false};

/**
* @brief hold the Sibling BMC IP
*/
SiblingBmcIP _siblingBmcIP;
};

} // namespace data_sync::ext_data
51 changes: 51 additions & 0 deletions src/external_data_ifaces_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "external_data_ifaces_impl.hpp"

#include <xyz/openbmc_project/State/BMC/Redundancy/Sibling/client.hpp>
#include <xyz/openbmc_project/State/BMC/Redundancy/client.hpp>

namespace data_sync::ext_data
Expand Down Expand Up @@ -41,4 +42,54 @@ sdbusplus::async::task<> ExternalDataIFacesImpl::fetchBMCRedundancyMgrProps()
co_return;
}

// NOLINTNEXTLINE
sdbusplus::async::task<> ExternalDataIFacesImpl::fetchSiblingBmcIP()
{
// TODO: Currently, the IP addresses for both BMCs are hardcoded.
// Once the network DBus exposes the IPs, update the logic to retrieve
// them dynamically from Dbus.
try
{
const data_sync::ext_data::SiblingBmcIP siblingIp0 = "10.0.2.100";
const data_sync::ext_data::SiblingBmcIP siblingIp1 = "10.2.2.100";

using siblingBmc = sdbusplus::client::xyz::openbmc_project::state::bmc::
redundancy::Sibling<>;

std::string object_path =
std::string(sdbusplus::common::xyz::openbmc_project::state::bmc::
redundancy::Sibling::namespace_path::value) +
"/" +
sdbusplus::common::xyz::openbmc_project::state::bmc::redundancy::
Sibling::namespace_path::bmc;

auto bmcPosition =
siblingBmc(_ctx)
.service(sdbusplus::common::xyz::openbmc_project::state::bmc::
redundancy::Sibling::interface)
.path(object_path);

auto propBmcPosition = co_await bmcPosition.bmc_position();

// lg2::info("Current bmcPosition: {BMC_POSITION}", "BMC_POSITION",
// propBmcPosition);

if (propBmcPosition == 0)
{
siblingBmcIP(siblingIp1);
}
else
{
siblingBmcIP(siblingIp0);
}

co_return;
}
catch (const std::exception& e)
{
// lg2::error("Error in fetchSiblingBmcIP: {ERROR}", "ERROR", e);
co_return;
}
}

} // namespace data_sync::ext_data
5 changes: 5 additions & 0 deletions src/external_data_ifaces_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class ExternalDataIFacesImpl : public ExternalDataIFaces
*/
sdbusplus::async::task<> fetchBMCRedundancyMgrProps() override;

/**
* @brief Used to retrieve the Sibling BMC IP from Dbus.
*/
sdbusplus::async::task<> fetchSiblingBmcIP() override;

/**
* @brief Used to get the async context
*/
Expand Down
4 changes: 4 additions & 0 deletions test/manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ TEST_F(ManagerTest, ParseDataSyncCfg)
// NOLINTNEXTLINE
.WillRepeatedly([]() -> sdbusplus::async::task<> { co_return; });

EXPECT_CALL(*mockExtDataIfaces, fetchSiblingBmcIP())
// NOLINTNEXTLINE
.WillRepeatedly([]() -> sdbusplus::async::task<> { co_return; });

sdbusplus::async::context ctx;

data_sync::Manager manager{ctx, std::move(extDataIface),
Expand Down
1 change: 1 addition & 0 deletions test/mock_ext_data_ifaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MockExternalDataIFaces : public ExternalDataIFaces

MOCK_METHOD(sdbusplus::async::task<>, fetchBMCRedundancyMgrProps, (),
(override));
MOCK_METHOD(sdbusplus::async::task<>, fetchSiblingBmcIP, (), (override));
};

} // namespace data_sync::ext_data

0 comments on commit 8ca9c30

Please sign in to comment.