psutils: Do not pad PSU version with blanks
When `psutils --get-version <inventory_path>` is run, it returns the
firmware version for the specified PSU inventory path.
If no psu.json file is found, the PSU I2C bus and address are obtained
from D-Bus. The PSU version is then obtained from a file in sysfs.
The contents of the sysfs file are currently treated as VPD. Invalid
characters are replaced with spaces, and the value is padded with spaces
if needed to reach an expected VPD length.
If an error occurs trying to read the sysfs file, the version is
initially set to "". However, since it is being treated as VPD it is
later padded with blanks. Since the version is not an empty string, it
is treated as valid by psutils and the PSU code update application.
This causes subsequent code update issues.
Modify psutils so that the contents of the sysfs file are treated as a
simple string. If an error occurs, set the version to "". This will
cause psutils and the PSU code update application to correctly conclude
that an error occurred and the version is not valid.
Tested:
* psutils --get-version
* psu.json file exists
* Test where getting the version works
* Verify file contents are obtained
* Verify psutils prints out the version
* Verify psutils exits with a return code of 0
* Test where getting the version fails
* Verify exception is written to the journal
* Verify psutils prints out an empty string
* Verify psutils exits with a return code of 1
* psu.json file does not exist; PSU information is obtained from D-Bus
* Test where getting the version works
* Verify file contents are obtained
* Verify psutils prints out the version
* Verify psutils exits with a return code of 0
* Test where getting the version fails
* Verify exception is written to the journal
* Verify psutils prints out an empty string
* Verify psutils exits with a return code of 1
Change-Id: I131ba1b73f5ee96606bcfe86943da258196eca62
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/tools/power-utils/version.cpp b/tools/power-utils/version.cpp
index 1987342..fab0705 100644
--- a/tools/power-utils/version.cpp
+++ b/tools/power-utils/version.cpp
@@ -254,31 +254,20 @@
std::string getVersion(sdbusplus::bus_t& bus,
const std::string& psuInventoryPath)
{
+ std::string version;
try
{
- constexpr auto FW_VERSION = "fw_version";
- using namespace phosphor::pmbus;
- const auto IBMCFFPS_FW_VERSION_SIZE = 12;
const auto& [i2cbus, i2caddr] = utils::getPsuI2c(bus, psuInventoryPath);
-
- auto pmbusIntf = utils::getPmbusIntf(i2cbus, i2caddr);
-
- if (!pmbusIntf)
- {
- log<level::WARNING>("Unable to get pointer PMBus Interface");
- return "";
- }
-
- std::string fwVersion =
- utils::readVPDValue(*pmbusIntf, FW_VERSION, Type::HwmonDeviceDebug,
- IBMCFFPS_FW_VERSION_SIZE);
- return fwVersion;
+ auto pmbus = utils::getPmbusIntf(i2cbus, i2caddr);
+ std::string name = "fw_version";
+ auto type = phosphor::pmbus::Type::HwmonDeviceDebug;
+ version = pmbus->readString(name, type);
}
catch (const std::exception& e)
{
log<level::ERR>(std::format("Error: {}", e.what()).c_str());
- return "";
}
+ return version;
}
std::string getLatest(const std::vector<std::string>& versions)