Hypervisor: Fix redfish validator errors
Currently, Redfish validator fails for displaying empty mac address
when doing a GET on hypervisor ethernet interfaces.
This commit ensures that the redfish validator passes by making the
macaddress an optional property in EthernetInterfaceData structure and
removing the un-implemented "MACAddress" interface check in the
hypervisor GET handler method.
The following was the validator error:
[1] ERROR - MACAddress: String '' does not match pattern ''^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$''
Tested By:
Validator Passed.
Change-Id: Ib3f8085841093647ee97dee5602a0bb78fdd67c5
Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index ee1ad78..29b75fa 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -118,7 +118,7 @@
std::string defaultGateway;
std::string ipv6DefaultGateway;
std::string ipv6StaticDefaultGateway;
- std::string macAddress;
+ std::optional<std::string> macAddress;
std::optional<uint32_t> vlanId;
std::vector<std::string> nameServers;
std::vector<std::string> staticNameServers;
@@ -1863,7 +1863,10 @@
jsonResponse["SpeedMbps"] = ethData.speed;
jsonResponse["MTUSize"] = ethData.mtuSize;
- jsonResponse["MACAddress"] = ethData.macAddress;
+ if (ethData.macAddress)
+ {
+ jsonResponse["MACAddress"] = *ethData.macAddress;
+ }
jsonResponse["DHCPv4"]["DHCPEnabled"] =
translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpv4Enabled;
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index ebe9ea6..cc9d4c0 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -178,23 +178,8 @@
"/xyz/openbmc_project/network/hypervisor/" + ethIfaceId)
{
idFound = true;
- if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress")
- {
- for (const auto& propertyPair : ifacePair.second)
- {
- if (propertyPair.first == "MACAddress")
- {
- const std::string* mac =
- std::get_if<std::string>(&propertyPair.second);
- if (mac != nullptr)
- {
- ethData.macAddress = *mac;
- }
- }
- }
- }
- else if (ifacePair.first ==
- "xyz.openbmc_project.Network.EthernetInterface")
+ if (ifacePair.first ==
+ "xyz.openbmc_project.Network.EthernetInterface")
{
for (const auto& propertyPair : ifacePair.second)
{
@@ -472,8 +457,6 @@
jsonResponse["@odata.id"] = boost::urls::format(
"/redfish/v1/Systems/hypervisor/EthernetInterfaces/{}", ifaceId);
jsonResponse["InterfaceEnabled"] = true;
- jsonResponse["MACAddress"] = ethData.macAddress;
-
jsonResponse["HostName"] = ethData.hostName;
jsonResponse["DHCPv4"]["DHCPEnabled"] =
translateDhcpEnabledToBool(ethData.dhcpEnabled, true);