Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExternalData: Fetch required additional dependent data's #9

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/external_data_ifaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ 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(),
fetchRbmcCredentials());
}

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

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

void ExternalDataIFaces::siblingBmcIP(const SiblingBmcIP& siblingBmcIP)
{
_siblingBmcIP = siblingBmcIP;
}

void ExternalDataIFaces::rbmcCredentials(const RbmcCredentials& rbmcCredentials)
{
_rbmcCredentials = rbmcCredentials;
}

const RbmcCredentials& ExternalDataIFaces::rbmcCredentials() const
{
return _rbmcCredentials;
}
} // namespace data_sync::ext_data
57 changes: 57 additions & 0 deletions src/external_data_ifaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ 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;
using RbmcUserName = std::string;
using RbmcPassword = std::string;
using RbmcCredentials = std::pair<RbmcUserName, RbmcPassword>;

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

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

/**
* @brief Used to obtain the BMC username and password
*
* @return BMC Username and Password
*/
const RbmcCredentials& rbmcCredentials() const;

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

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

/**
* @brief Used to retrieve the BMC Username and Password.
*/
virtual sdbusplus::async::task<> fetchRbmcCredentials() = 0;

/**
* @brief A utility API to assign the retrieved BMC role.
*
Expand All @@ -77,6 +105,25 @@ 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);

/**
* @brief A utility API to assign the retrieved BMC Username and Password.
*
* @param[in] rbmcCredentials - The retrieved Sibling BMC Username and
* Password.
*
* @return None.
*/
void rbmcCredentials(const RbmcCredentials& rbmcCredentials);

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

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

/**
* @brief This is Pair, hold the BMCs Username and Password
*/
RbmcCredentials _rbmcCredentials;
};

} // namespace data_sync::ext_data
54 changes: 54 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,57 @@ 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.

// TODO: Handle the exception and exit gracefully, as the data sync relies
// heavily on these DBus properties and cannot function effectively
// without them.

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

using SiblingBMC = sdbusplus::common::xyz::openbmc_project::state::bmc::
redundancy::Sibling;

std::string siblingBMCInstancePath =
std::string(SiblingBMC::namespace_path::value) + "/" +
SiblingBMC::namespace_path::bmc;

auto siblingBMCMgr = SiblingBMCMgr(_ctx)
.service(SiblingBMC::interface)
.path(siblingBMCInstancePath);

auto siblingBMCPosition = co_await siblingBMCMgr.bmc_position();

if (siblingBMCPosition == 0)
{
// Using the simics bmc0 eth0 IP address
siblingBmcIP("10.0.2.100");
}
else
{
// Using the simics bmc1 eth0 IP address
siblingBmcIP("10.2.2.100");
}

co_return;
}

// NOLINTNEXTLINE
sdbusplus::async::task<> ExternalDataIFacesImpl::fetchRbmcCredentials()
{
// TODO: Currently, the username and password for BMCs are hardcoded.
// Once user management DBus exposes the username and the encrypted password
// available, update the logic to retrieve them dynamically.

// here, username hardcode as service and password as 0penBmc0
rbmcCredentials(std::make_pair("service", "0penBmc0"));
co_return;
}

} // namespace data_sync::ext_data
10 changes: 10 additions & 0 deletions src/external_data_ifaces_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ 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 retrieve the BMC Username and Password.
manish-t-in marked this conversation as resolved.
Show resolved Hide resolved
*/
sdbusplus::async::task<> fetchRbmcCredentials() override;

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

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

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

sdbusplus::async::context ctx;

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

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

} // namespace data_sync::ext_data