Fix generating last client Id
When the user sets an invalid Address or sets an existing Address and
Port, the correct logic is to return an error but cannot update the
lastClientId.
Tested:
Before:
busctl call xyz.openbmc_project.Network.SNMP /xyz/openbmc_project/network/snmp/manager xyz.openbmc_project.Network.Client.Create Client sq 192.168.0.1 100
s "/xyz/openbmc_project/network/snmp/manager/1"
busctl call xyz.openbmc_project.Network.SNMP /xyz/openbmc_project/network/snmp/manager xyz.openbmc_project.Network.Client.Create Client sq 192.168.0.1 100
Call failed: Invalid argument was given.
busctl call xyz.openbmc_project.Network.SNMP /xyz/openbmc_project/network/snmp/manager xyz.openbmc_project.Network.Client.Create Client sq 192.168.0.2 100
s "/xyz/openbmc_project/network/snmp/manager/3"
With this patch:
busctl call xyz.openbmc_project.Network.SNMP /xyz/openbmc_project/network/snmp/manager xyz.openbmc_project.Network.Client.Create Client sq 192.168.0.1 100
s "/xyz/openbmc_project/network/snmp/manager/1"
busctl call xyz.openbmc_project.Network.SNMP /xyz/openbmc_project/network/snmp/manager xyz.openbmc_project.Network.Client.Create Client sq 192.168.0.1 100
Call failed: Invalid argument was given.
busctl call xyz.openbmc_project.Network.SNMP /xyz/openbmc_project/network/snmp/manager xyz.openbmc_project.Network.Client.Create Client sq 192.168.0.2 100
s "/xyz/openbmc_project/network/snmp/manager/2"
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Icf595e3f0d44a0b807526f084819015dc42cf57c
diff --git a/snmp_conf_manager.cpp b/snmp_conf_manager.cpp
index a606370..dab7317 100644
--- a/snmp_conf_manager.cpp
+++ b/snmp_conf_manager.cpp
@@ -36,7 +36,6 @@
// will throw exception if it is already configured.
checkClientConfigured(address, port);
- lastClientId++;
try
{
// just to check whether given address is valid or not.
@@ -49,6 +48,7 @@
Argument::ARGUMENT_VALUE(address.c_str()));
}
+ lastClientId++;
// create the D-Bus object
std::filesystem::path objPath;
objPath /= objectPath;