psutils: Add --get-model option
Add a --get-model command line option to the psutils tool. This option
obtains the PSU model using information in sysfs.
Supports both methods of obtaining information about a PSU:
* psu.json file
* D-Bus
Tested:
* Verified --get-version still works
* With psu.json file
* Without psu.json file
* Verified new --get-model property works
* With psu.json file
* Without psu.json file
* Tested all error paths
* See the following gist for the complete test plan:
https://gist.github.com/smccarney/859ffaaa94ce12992af1b24e6c899962
Change-Id: If1be01f4b70ad9d80ce01402c57730990fd2c2ea
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/tools/power-utils/main.cpp b/tools/power-utils/main.cpp
index 8fae3a1..8ca7c04 100644
--- a/tools/power-utils/main.cpp
+++ b/tools/power-utils/main.cpp
@@ -15,6 +15,7 @@
*/
#include "config.h"
+#include "model.hpp"
#include "updater.hpp"
#include "utils.hpp"
#include "version.hpp"
@@ -30,15 +31,17 @@
int main(int argc, char** argv)
{
- std::string psuPath;
+ std::string psuPathVersion, psuPathModel;
std::vector<std::string> versions;
bool rawOutput = false;
std::vector<std::string> updateArguments;
CLI::App app{"PSU utils app for OpenBMC"};
auto action = app.add_option_group("Action");
- action->add_option("-g,--get-version", psuPath,
+ action->add_option("-g,--get-version", psuPathVersion,
"Get PSU version from inventory path");
+ action->add_option("-m,--get-model", psuPathModel,
+ "Get PSU model from inventory path");
action->add_option("-c,--compare", versions,
"Compare and get the latest version");
action
@@ -54,17 +57,21 @@
bool useJsonFile = utils::checkFileExists(PSU_JSON_PATH);
auto bus = sdbusplus::bus::new_default();
- if (!psuPath.empty())
+ if (!psuPathVersion.empty())
{
if (!useJsonFile)
{
- ret = version::getVersion(bus, psuPath);
+ ret = version::getVersion(bus, psuPathVersion);
}
else
{
- ret = version::getVersion(psuPath);
+ ret = version::getVersion(psuPathVersion);
}
}
+ if (!psuPathModel.empty())
+ {
+ ret = model::getModel(bus, psuPathModel);
+ }
if (!versions.empty())
{
ret = version::getLatest(versions);