regulators: Support a string or vector for VPD
Add a 'byte_values' alternative to the 'value' entry in the compare VPD
action. This is to support VPD values that are not strings, such as
'HW', a new IBM keyword that describes the version of a piece of
hardware.
To support this, the VPD class now treats all VPD keyword values as
vectors of uint8_ts, including in its data cache. If a compare VPD
action in the JSON contains a string value, it will be converted to the
vector before the CompareVPDAction class is created.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I3fcabf896f4885feae1b07ee2c3da5929cf8bfa4
diff --git a/phosphor-regulators/src/actions/compare_vpd_action.cpp b/phosphor-regulators/src/actions/compare_vpd_action.cpp
index 1049cee..d7cccf0 100644
--- a/phosphor-regulators/src/actions/compare_vpd_action.cpp
+++ b/phosphor-regulators/src/actions/compare_vpd_action.cpp
@@ -30,7 +30,7 @@
try
{
// Get actual VPD keyword value
- std::string actualValue =
+ std::vector<uint8_t> actualValue =
environment.getServices().getVPD().getValue(fru, keyword);
// Check if actual value equals expected value
@@ -51,7 +51,13 @@
ss << "compare_vpd: { ";
ss << "fru: " << fru << ", ";
ss << "keyword: " << keyword << ", ";
- ss << "value: " << value << " }";
+ ss << "value: [ ";
+ ss << std::hex << std::uppercase;
+ for (unsigned int i = 0; i < value.size(); ++i)
+ {
+ ss << ((i > 0) ? ", " : "") << "0x" << static_cast<uint16_t>(value[i]);
+ }
+ ss << " ] }";
return ss.str();
}
diff --git a/phosphor-regulators/src/actions/compare_vpd_action.hpp b/phosphor-regulators/src/actions/compare_vpd_action.hpp
index af7e085..8825220 100644
--- a/phosphor-regulators/src/actions/compare_vpd_action.hpp
+++ b/phosphor-regulators/src/actions/compare_vpd_action.hpp
@@ -18,7 +18,9 @@
#include "action.hpp"
#include "action_environment.hpp"
+#include <cstdint>
#include <string>
+#include <vector>
namespace phosphor::power::regulators
{
@@ -52,7 +54,7 @@
*/
explicit CompareVPDAction(const std::string& fru,
const std::string& keyword,
- const std::string& value) :
+ const std::vector<uint8_t>& value) :
fru{fru},
keyword{keyword}, value{value}
{
@@ -96,7 +98,7 @@
*
* @return value
*/
- const std::string& getValue() const
+ const std::vector<uint8_t>& getValue() const
{
return value;
}
@@ -124,7 +126,7 @@
/**
* Expected value.
*/
- const std::string value{};
+ const std::vector<uint8_t> value{};
};
} // namespace phosphor::power::regulators