utils: Add function to check if PSU is associated
Add a helper function to check if a PSU is in an association list, which
will be used in future commits to check if a PSU is running a software
image.
Tested: added unit test case and verify it passes.
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I99b5d3d8d09f8e09a1eb42ba104a4804b7214cf1
diff --git a/src/utils.hpp b/src/utils.hpp
index bb5f13f..ae08156 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "types.hpp"
+
#include <experimental/any>
#include <sdbusplus/bus.hpp>
#include <set>
@@ -11,6 +13,7 @@
class UtilsInterface;
+using AssociationList = phosphor::software::updater::AssociationList;
// Due to a libstdc++ bug, we got compile error using std::any with gmock.
// A temporary workaround is to use std::experimental::any.
// See details in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90415
@@ -91,6 +94,16 @@
*/
std::string getLatestVersion(const std::set<std::string>& versions);
+/** @brief Check if the PSU is associated
+ *
+ * @param[in] psuInventoryPath - The PSU inventory path
+ * @param[in] assocs - The list of associations
+ *
+ * @return true if the psu is in the association list
+ */
+bool isAssociated(const std::string& psuInventoryPath,
+ const AssociationList& assocs);
+
/**
* @brief The interface for utils
*/
@@ -119,6 +132,9 @@
virtual std::string
getLatestVersion(const std::set<std::string>& versions) const = 0;
+ virtual bool isAssociated(const std::string& psuInventoryPath,
+ const AssociationList& assocs) const = 0;
+
virtual any getPropertyImpl(sdbusplus::bus::bus& bus, const char* service,
const char* path, const char* interface,
const char* propertyName) const = 0;
@@ -155,6 +171,9 @@
std::string
getLatestVersion(const std::set<std::string>& versions) const override;
+ bool isAssociated(const std::string& psuInventoryPath,
+ const AssociationList& assocs) const override;
+
any getPropertyImpl(sdbusplus::bus::bus& bus, const char* service,
const char* path, const char* interface,
const char* propertyName) const override;
@@ -193,6 +212,12 @@
return getUtils().getLatestVersion(versions);
}
+inline bool isAssociated(const std::string& psuInventoryPath,
+ const AssociationList& assocs)
+{
+ return getUtils().isAssociated(psuInventoryPath, assocs);
+}
+
template <typename T>
T getProperty(sdbusplus::bus::bus& bus, const char* service, const char* path,
const char* interface, const char* propertyName)