Redfish: Remove "state" response content from PATCH commands
A PATCH command should not return any JSON content for the NICs. PATCH
commands should only return success or failure responses.
Reporting state based upon the input to the command is, in most
instances, going to be incorrect in comparison to the actual state of
the HW. For example: moving from static addresses to a DHCP assigned
address cannot be predicted based upon the input. It also takes
several seconds for a DHCP transaction to complete, which creates a
significant temporal lag between what was sent and what will be.
Tested: Performed the following tests:
For IPv4:
"IPv4Addresses": [
{},
{
"Address": "192.168.20.12",
"SubnetMask": "255.255.255.0",
"Gateway": "192.168.20.1"
}
]
For IPv6:
"IPv6StaticAddresses": [
{
"Address": "2001::5:4:3:4",
"PrefixLength": 64
}
]
Both tests complete without emitting any JSON content.
Change-Id: Ic7eb824eb6d996d85d52a3b7c855e9825f4a0d87
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 7dd6f34..c4f60a9 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -588,18 +588,14 @@
const std::string &name, const std::string &newValue,
const std::shared_ptr<AsyncResp> asyncResp)
{
- auto callback = [asyncResp, ipIdx, name{std::string(name)},
- newValue{std::move(newValue)}](
- const boost::system::error_code ec) {
- if (ec)
- {
- messages::internalError(asyncResp->res);
- }
- else
- {
- asyncResp->res.jsonValue["IPv4Addresses"][ipIdx][name] = newValue;
- }
- };
+ auto callback =
+ [asyncResp, ipIdx, name{std::string(name)},
+ newValue{std::move(newValue)}](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ }
+ };
crow::connections::systemBus->async_method_call(
std::move(callback), "xyz.openbmc_project.Network",
@@ -616,7 +612,6 @@
* @param[in] ipIdx Index of IP in input array that should be
* modified
* @param[in] ipHash DBus Hash id of modified IP
- * @param[in] newValueStr Mask in dot notation as string
* @param[in] newValue Mask as PrefixLength in bitcount
* @param[io] asyncResp Response object that will be returned to client
*
@@ -624,21 +619,14 @@
*/
inline void changeIPv4SubnetMaskProperty(const std::string &ifaceId, int ipIdx,
const std::string &ipHash,
- const std::string &newValueStr,
uint8_t &newValue,
std::shared_ptr<AsyncResp> asyncResp)
{
- auto callback = [asyncResp, ipIdx, newValueStr{std::move(newValueStr)}](
- const boost::system::error_code ec) {
+ auto callback = [asyncResp, ipIdx](const boost::system::error_code ec) {
if (ec)
{
messages::internalError(asyncResp->res);
}
- else
- {
- asyncResp->res.jsonValue["IPv4Addresses"][ipIdx]["SubnetMask"] =
- newValueStr;
- }
};
crow::connections::systemBus->async_method_call(
@@ -653,26 +641,20 @@
* @brief Deletes given IPv4
*
* @param[in] ifaceId Id of interface whose IP should be deleted
- * @param[in] ipIdx Index of IP in input array that should be deleted
* @param[in] ipHash DBus Hash id of IP that should be deleted
* @param[io] asyncResp Response object that will be returned to client
*
* @return None
*/
inline void deleteIPv4(const std::string &ifaceId, const std::string &ipHash,
- unsigned int ipIdx,
const std::shared_ptr<AsyncResp> asyncResp)
{
crow::connections::systemBus->async_method_call(
- [ipIdx, asyncResp](const boost::system::error_code ec) {
+ [asyncResp](const boost::system::error_code ec) {
if (ec)
{
messages::internalError(asyncResp->res);
}
- else
- {
- asyncResp->res.jsonValue["IPv4Addresses"][ipIdx] = nullptr;
- }
},
"xyz.openbmc_project.Network",
"/xyz/openbmc_project/network/" + ifaceId + "/ipv4/" + ipHash,
@@ -714,26 +696,19 @@
*
* @param[in] ifaceId Id of interface whose IP should be deleted
* @param[in] ipHash DBus Hash id of IP that should be deleted
- * @param[in] ipIdx Index of IP in input array that should be deleted
* @param[io] asyncResp Response object that will be returned to client
*
* @return None
*/
inline void deleteIPv6(const std::string &ifaceId, const std::string &ipHash,
- unsigned int ipIdx,
const std::shared_ptr<AsyncResp> asyncResp)
{
crow::connections::systemBus->async_method_call(
- [ipIdx, asyncResp](const boost::system::error_code ec) {
+ [asyncResp](const boost::system::error_code ec) {
if (ec)
{
messages::internalError(asyncResp->res);
}
- else
- {
- asyncResp->res.jsonValue["IPv6StaticAddresses"][ipIdx] =
- nullptr;
- }
},
"xyz.openbmc_project.Network",
"/xyz/openbmc_project/network/" + ifaceId + "/ipv6/" + ipHash,
@@ -1048,7 +1023,6 @@
messages::internalError(asyncResp->res);
return;
}
- asyncResp->res.jsonValue["MACAddress"] = std::move(macAddress);
},
"xyz.openbmc_project.Network",
"/xyz/openbmc_project/network/" + ifaceId,
@@ -1056,6 +1030,7 @@
"xyz.openbmc_project.Network.MACAddress", "MACAddress",
std::variant<std::string>(macAddress));
}
+
void setDHCPEnabled(const std::string &ifaceId,
const std::string &propertyName, const bool &value,
const std::shared_ptr<AsyncResp> asyncResp)
@@ -1159,7 +1134,7 @@
{
if (thisData != ipv4Data.end())
{
- deleteIPv4(ifaceId, thisData->id, entryIdx, asyncResp);
+ deleteIPv4(ifaceId, thisData->id, asyncResp);
thisData++;
}
else
@@ -1247,18 +1222,14 @@
// Apply changes
if (address)
{
- auto callback = [asyncResp, entryIdx,
- address{std::string(*address)}](
- const boost::system::error_code ec) {
- if (ec)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res
- .jsonValue["IPv4Addresses"][entryIdx]["Address"] =
- std::move(address);
- };
+ auto callback =
+ [asyncResp](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ };
crow::connections::systemBus->async_method_call(
std::move(callback), "xyz.openbmc_project.Network",
@@ -1272,24 +1243,20 @@
if (subnetMask)
{
changeIPv4SubnetMaskProperty(ifaceId, entryIdx,
- thisData->id, *subnetMask,
- prefixLength, asyncResp);
+ thisData->id, prefixLength,
+ asyncResp);
}
if (gateway)
{
- auto callback = [asyncResp, entryIdx,
- gateway{std::string(*gateway)}](
- const boost::system::error_code ec) {
- if (ec)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res
- .jsonValue["IPv4Addresses"][entryIdx]["Gateway"] =
- std::move(gateway);
- };
+ auto callback =
+ [asyncResp](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ };
crow::connections::systemBus->async_method_call(
std::move(callback), "xyz.openbmc_project.Network",
@@ -1345,17 +1312,12 @@
const std::shared_ptr<AsyncResp> &asyncResp)
{
crow::connections::systemBus->async_method_call(
- [asyncResp,
- updatedStaticNameServers](const boost::system::error_code ec) {
+ [asyncResp](const boost::system::error_code ec) {
if (ec)
{
messages::internalError(asyncResp->res);
return;
}
- asyncResp->res.jsonValue["NameServers"] =
- updatedStaticNameServers;
- asyncResp->res.jsonValue["StaticNameServers"] =
- updatedStaticNameServers;
},
"xyz.openbmc_project.Network",
"/xyz/openbmc_project/network/" + ifaceId,
@@ -1388,7 +1350,7 @@
{
if (thisData != ipv6StaticData.end())
{
- deleteIPv6(ifaceId, thisData->id, entryIdx, asyncResp);
+ deleteIPv6(ifaceId, thisData->id, asyncResp);
thisData++;
}
else
@@ -1432,18 +1394,14 @@
// Apply changes
if (address)
{
- auto callback = [asyncResp, entryIdx,
- address{std::string(*address)}](
- const boost::system::error_code ec) {
- if (ec)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["IPv6StaticAddresses"]
- [entryIdx]["Address"] =
- std::move(address);
- };
+ auto callback =
+ [asyncResp](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ };
crow::connections::systemBus->async_method_call(
std::move(callback), "xyz.openbmc_project.Network",
@@ -1456,18 +1414,14 @@
if (prefixLength)
{
- auto callback = [asyncResp, entryIdx,
- prefixLength{uint8_t(*prefixLength)}](
- const boost::system::error_code ec) {
- if (ec)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["IPv6StaticAddresses"]
- [entryIdx]["PrefixLength"] =
- std::move(prefixLength);
- };
+ auto callback =
+ [asyncResp](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ };
crow::connections::systemBus->async_method_call(
std::move(callback), "xyz.openbmc_project.Network",
@@ -1705,9 +1659,6 @@
return;
}
- parseInterfaceData(asyncResp->res.jsonValue, iface_id, ethData,
- ipv4Data, ipv6Data, ipv6StaticData);
-
if (hostname)
{
handleHostnamePatch(*hostname, asyncResp);
@@ -1754,32 +1705,6 @@
nlohmann::json ipv6Static = std::move(*ipv6StaticAddresses);
handleIPv6StaticAddressesPatch(iface_id, ipv6Static,
ipv6StaticData, asyncResp);
-
- // call getEthernetIfaceData to populate updated static
- // addresses data to "IPv6Addresses" json collection
- getEthernetIfaceData(
- iface_id,
- [this, asyncResp, iface_id](
- const bool &success,
- const EthernetInterfaceData ðData,
- const boost::container::flat_set<IPv4AddressData>
- &ipv4Data,
- const boost::container::flat_set<IPv6AddressData>
- &ipv6Data,
- const boost::container::flat_set<IPv6AddressData>
- &ipv6StaticData) {
- if (!success)
- {
- messages::resourceNotFound(asyncResp->res,
- "Ethernet Interface",
- iface_id);
- return;
- }
-
- parseInterfaceData(asyncResp->res.jsonValue,
- iface_id, ethData, ipv4Data,
- ipv6Data, ipv6StaticData);
- });
}
});
}
@@ -1944,9 +1869,6 @@
&ipv6StaticData) {
if (success && !ethData.vlan_id.empty())
{
- parseInterfaceData(asyncResp->res.jsonValue, parentIfaceId,
- ifaceId, ethData, ipv4Data, ipv6Data,
- ipv6StaticData);
auto callback =
[asyncResp](const boost::system::error_code ec) {
if (ec)
@@ -2019,10 +1941,6 @@
&ipv6StaticData) {
if (success && !ethData.vlan_id.empty())
{
- parseInterfaceData(asyncResp->res.jsonValue, parentIfaceId,
- ifaceId, ethData, ipv4Data, ipv6Data,
- ipv6StaticData);
-
auto callback =
[asyncResp](const boost::system::error_code ec) {
if (ec)