Verify PSU is present before code update
When an Activation is set to the Activating state, it checks all the
PSUs in the system to see which ones are compatible. Compatibility is
determined based on the Model and Manufacturer properties. It performs a
code update only on compatible PSUs.
Update the Activation class to also check whether a PSU is present. A
code update should not be attempted on a missing PSU. The attempt will
fail, and that will cause the remaining PSUs to be skipped.
Tested:
* Activation::startActivation()
* Test where PSU is not present
* Verify it is skipped
* Test where PSU is present
* Verify the compatibility is checked
* Test where PSU is not compatible
* Verify it is skipped
* Test where PSU is compatible
* Verify it is code updated
* Activation::isPresent()
* Test where PSU is present
* Test where PSU is not present
* Test where a D-Bus error occurs
* Verify error is written to the journal
* Verify false is returned
Change-Id: I5647e51177d84d22f6ae5a38afa970243fe9ecdd
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/src/activation.cpp b/src/activation.cpp
index 400f03c..65db23b 100644
--- a/src/activation.cpp
+++ b/src/activation.cpp
@@ -176,6 +176,10 @@
for (const auto& p : psuPaths)
{
+ if (!isPresent(p))
+ {
+ continue;
+ }
if (isCompatible(p))
{
if (utils::isAssociated(p, associations()))
@@ -293,6 +297,27 @@
}
}
+bool Activation::isPresent(const std::string& psuInventoryPath)
+{
+ bool isPres{false};
+ try
+ {
+ auto service =
+ utils::getService(bus, psuInventoryPath.c_str(), ITEM_IFACE);
+ isPres = utils::getProperty<bool>(bus, service.c_str(),
+ psuInventoryPath.c_str(), ITEM_IFACE,
+ PRESENT);
+ }
+ catch (const std::exception& e)
+ {
+ // Treat as a warning condition and assume the PSU is missing. The
+ // D-Bus information might not be available if the PSU is missing.
+ lg2::warning("Unable to determine if PSU {PSU} is present: {ERROR}",
+ "PSU", psuInventoryPath, "ERROR", e);
+ }
+ return isPres;
+}
+
bool Activation::isCompatible(const std::string& psuInventoryPath)
{
bool isCompat{false};