From 286b9118a35ba8c212972b9c30a257ee41c5d7d2 Mon Sep 17 00:00:00 2001 From: Johnathan Mantey Date: Mon, 10 Jun 2019 13:38:04 -0700 Subject: 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 --- redfish-core/lib/ethernet.hpp | 180 ++++++++++++------------------------------ 1 file changed, 49 insertions(+), 131 deletions(-) (limited to 'redfish-core/lib/ethernet.hpp') diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index 7dd6f34095..c4f60a9c96 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -588,18 +588,14 @@ inline void changeIPv4AddressProperty( const std::string &name, const std::string &newValue, const std::shared_ptr 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 @@ inline void changeIPv4AddressProperty( * @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 changeIPv4AddressProperty( */ inline void changeIPv4SubnetMaskProperty(const std::string &ifaceId, int ipIdx, const std::string &ipHash, - const std::string &newValueStr, uint8_t &newValue, std::shared_ptr 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 @@ inline void changeIPv4SubnetMaskProperty(const std::string &ifaceId, int ipIdx, * @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) { 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 @@ inline void createIPv4(const std::string &ifaceId, unsigned int ipIdx, * * @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) { 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 @@ class EthernetInterface : public Node 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 @@ class EthernetInterface : public Node "xyz.openbmc_project.Network.MACAddress", "MACAddress", std::variant(macAddress)); } + void setDHCPEnabled(const std::string &ifaceId, const std::string &propertyName, const bool &value, const std::shared_ptr asyncResp) @@ -1159,7 +1134,7 @@ class EthernetInterface : public Node { if (thisData != ipv4Data.end()) { - deleteIPv4(ifaceId, thisData->id, entryIdx, asyncResp); + deleteIPv4(ifaceId, thisData->id, asyncResp); thisData++; } else @@ -1247,18 +1222,14 @@ class EthernetInterface : public Node // 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 @@ class EthernetInterface : public Node 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 @@ class EthernetInterface : public Node const std::shared_ptr &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 @@ class EthernetInterface : public Node { if (thisData != ipv6StaticData.end()) { - deleteIPv6(ifaceId, thisData->id, entryIdx, asyncResp); + deleteIPv6(ifaceId, thisData->id, asyncResp); thisData++; } else @@ -1432,18 +1394,14 @@ class EthernetInterface : public Node // 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 @@ class EthernetInterface : public Node 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 @@ class EthernetInterface : public Node return; } - parseInterfaceData(asyncResp->res.jsonValue, iface_id, ethData, - ipv4Data, ipv6Data, ipv6StaticData); - if (hostname) { handleHostnamePatch(*hostname, asyncResp); @@ -1754,32 +1705,6 @@ class EthernetInterface : public Node 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 - &ipv4Data, - const boost::container::flat_set - &ipv6Data, - const boost::container::flat_set - &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 @@ class VlanNetworkInterface : public Node &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 @@ class VlanNetworkInterface : public Node &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) -- cgit v1.2.3