From 2132574d2fbda7ae08a05071efcf9ef5f7868525 Mon Sep 17 00:00:00 2001 From: ManishTiwari Date: Fri, 10 Jan 2025 03:12:31 -0600 Subject: [PATCH 1/2] ExternalData: Add API for Retrieving Sibling BMC IP - Adds an interface to fetch the Sibling BMC IP, which will be used to obtain the sibling BMC IP. - The API fetches the sibling BMC IP in parallel with other tasks, ensuring that the IP is retrieved alongside other necessary data. - Currently, the IP addresses for both BMCs are hardcoded. These will be updated to retrieve dynamically from Network DBus once the IPs are exposed. Tested: - Verified that the Sibling BMC IP is correctly fetched (currently hardcoded until Network DBus is hosting it). - bmc0 output: SiblingBmcPosition: 1 siblingBmcIP: 10.2.2.100 - bmc1 output: SiblingBmcPosition: 0 siblingBmcIP: 10.0.2.100 Change-Id: Icad7a826b7577e8e85e68cd2ee812961a372cebb Signed-off-by: Manish Tiwari --- src/external_data_ifaces.cpp | 13 ++++++++- src/external_data_ifaces.hpp | 27 +++++++++++++++++++ src/external_data_ifaces_impl.cpp | 45 +++++++++++++++++++++++++++++++ src/external_data_ifaces_impl.hpp | 5 ++++ test/manager_test.cpp | 4 +++ test/mock_ext_data_ifaces.hpp | 1 + 6 files changed, 94 insertions(+), 1 deletion(-) diff --git a/src/external_data_ifaces.cpp b/src/external_data_ifaces.cpp index 619fce0..d9ebcdf 100644 --- a/src/external_data_ifaces.cpp +++ b/src/external_data_ifaces.cpp @@ -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 @@ -32,4 +33,14 @@ void ExternalDataIFaces::bmcRedundancy(const BMCRedundancy& bmcRedundancy) _bmcRedundancy = bmcRedundancy; } +SiblingBmcIP ExternalDataIFaces::siblingBmcIP() const +{ + return _siblingBmcIP; +} + +void ExternalDataIFaces::siblingBmcIP(const SiblingBmcIP& siblingBmcIP) +{ + _siblingBmcIP = siblingBmcIP; +} + } // namespace data_sync::ext_data diff --git a/src/external_data_ifaces.hpp b/src/external_data_ifaces.hpp index 02e0d4b..dbbaa5a 100644 --- a/src/external_data_ifaces.hpp +++ b/src/external_data_ifaces.hpp @@ -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 @@ -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 Sibling BMC IP. + */ + virtual sdbusplus::async::task<> fetchSiblingBmcIP() = 0; + /** * @brief A utility API to assign the retrieved BMC role. * @@ -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. @@ -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 diff --git a/src/external_data_ifaces_impl.cpp b/src/external_data_ifaces_impl.cpp index 95d94cf..31d5831 100644 --- a/src/external_data_ifaces_impl.cpp +++ b/src/external_data_ifaces_impl.cpp @@ -2,6 +2,7 @@ #include "external_data_ifaces_impl.hpp" +#include #include namespace data_sync::ext_data @@ -41,4 +42,48 @@ 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(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 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 bmc0 eth0 IP address + siblingBmcIP("10.2.2.100"); + } + + co_return; +} + } // namespace data_sync::ext_data diff --git a/src/external_data_ifaces_impl.hpp b/src/external_data_ifaces_impl.hpp index 11ba457..c6ea0ae 100644 --- a/src/external_data_ifaces_impl.hpp +++ b/src/external_data_ifaces_impl.hpp @@ -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 */ diff --git a/test/manager_test.cpp b/test/manager_test.cpp index 7be80c0..4cc7e3c 100644 --- a/test/manager_test.cpp +++ b/test/manager_test.cpp @@ -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), diff --git a/test/mock_ext_data_ifaces.hpp b/test/mock_ext_data_ifaces.hpp index 82a7927..0e01e8d 100644 --- a/test/mock_ext_data_ifaces.hpp +++ b/test/mock_ext_data_ifaces.hpp @@ -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 From bfc9b8b022ad57eabdcf5077470e338b84a3cf73 Mon Sep 17 00:00:00 2001 From: ManishTiwari Date: Mon, 13 Jan 2025 08:44:36 -0600 Subject: [PATCH 2/2] ExternalData: Add API for Retrieving BMC Username and Password - Implements an interface to fetch the BMC username and password. - The API retrieves both username and password in parallel. - Currently, the username and password are hardcoded since they are not yet available - These credentials are not required when mTLS is enabled. Tested: - Verified the API returns the hardcoded username and password as expected. - output: rbmc_username: service rbmc_password: 0penBmc0 Change-Id: Ife2d1ca07cf450e420550760350d763ac7e4fb1e Signed-off-by: Manish Tiwari --- src/external_data_ifaces.cpp | 14 ++++++++++++-- src/external_data_ifaces.hpp | 32 ++++++++++++++++++++++++++++++- src/external_data_ifaces_impl.cpp | 21 ++++++++++++++------ src/external_data_ifaces_impl.hpp | 5 +++++ test/manager_test.cpp | 4 ++++ test/mock_ext_data_ifaces.hpp | 1 + 6 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/external_data_ifaces.cpp b/src/external_data_ifaces.cpp index d9ebcdf..40518b8 100644 --- a/src/external_data_ifaces.cpp +++ b/src/external_data_ifaces.cpp @@ -10,7 +10,8 @@ sdbusplus::async::task<> ExternalDataIFaces::startExtDataFetches() { // NOLINTNEXTLINE co_return co_await sdbusplus::async::execution::when_all( - fetchBMCRedundancyMgrProps(), fetchSiblingBmcIP()); + fetchBMCRedundancyMgrProps(), fetchSiblingBmcIP(), + fetchRbmcCredentials()); } BMCRole ExternalDataIFaces::bmcRole() const @@ -33,7 +34,7 @@ void ExternalDataIFaces::bmcRedundancy(const BMCRedundancy& bmcRedundancy) _bmcRedundancy = bmcRedundancy; } -SiblingBmcIP ExternalDataIFaces::siblingBmcIP() const +const SiblingBmcIP& ExternalDataIFaces::siblingBmcIP() const { return _siblingBmcIP; } @@ -43,4 +44,13 @@ 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 diff --git a/src/external_data_ifaces.hpp b/src/external_data_ifaces.hpp index dbbaa5a..b0ebc59 100644 --- a/src/external_data_ifaces.hpp +++ b/src/external_data_ifaces.hpp @@ -12,6 +12,9 @@ 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; /** * @class ExternalDataIFaces @@ -59,7 +62,14 @@ class ExternalDataIFaces * * @return The Sibling BMC IP */ - SiblingBmcIP siblingBmcIP() const; + const SiblingBmcIP& siblingBmcIP() const; + + /** + * @brief Used to obtain the BMC username and password + * + * @return BMC Username and Password + */ + const RbmcCredentials& rbmcCredentials() const; protected: /** @@ -72,6 +82,11 @@ class ExternalDataIFaces */ 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. * @@ -99,6 +114,16 @@ class ExternalDataIFaces */ 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. @@ -114,6 +139,11 @@ class ExternalDataIFaces * @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 diff --git a/src/external_data_ifaces_impl.cpp b/src/external_data_ifaces_impl.cpp index 31d5831..3144e02 100644 --- a/src/external_data_ifaces_impl.cpp +++ b/src/external_data_ifaces_impl.cpp @@ -60,11 +60,8 @@ sdbusplus::async::task<> ExternalDataIFacesImpl::fetchSiblingBmcIP() redundancy::Sibling; std::string siblingBMCInstancePath = - 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; + std::string(SiblingBMC::namespace_path::value) + "/" + + SiblingBMC::namespace_path::bmc; auto siblingBMCMgr = SiblingBMCMgr(_ctx) .service(SiblingBMC::interface) @@ -79,11 +76,23 @@ sdbusplus::async::task<> ExternalDataIFacesImpl::fetchSiblingBmcIP() } else { - // Using the simics bmc0 eth0 IP address + // 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 diff --git a/src/external_data_ifaces_impl.hpp b/src/external_data_ifaces_impl.hpp index c6ea0ae..8471850 100644 --- a/src/external_data_ifaces_impl.hpp +++ b/src/external_data_ifaces_impl.hpp @@ -43,6 +43,11 @@ class ExternalDataIFacesImpl : public ExternalDataIFaces */ sdbusplus::async::task<> fetchSiblingBmcIP() override; + /** + * @brief Used to retrieve the BMC Username and Password. + */ + sdbusplus::async::task<> fetchRbmcCredentials() override; + /** * @brief Used to get the async context */ diff --git a/test/manager_test.cpp b/test/manager_test.cpp index 4cc7e3c..13e64cd 100644 --- a/test/manager_test.cpp +++ b/test/manager_test.cpp @@ -81,6 +81,10 @@ TEST_F(ManagerTest, ParseDataSyncCfg) // 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), diff --git a/test/mock_ext_data_ifaces.hpp b/test/mock_ext_data_ifaces.hpp index 0e01e8d..bb5d451 100644 --- a/test/mock_ext_data_ifaces.hpp +++ b/test/mock_ext_data_ifaces.hpp @@ -15,6 +15,7 @@ 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