From 6d014fa21903c005398c4feb690debcf9340b5b6 Mon Sep 17 00:00:00 2001 From: Rakesh Date: Fri, 31 Jan 2020 11:57:20 +0100 Subject: [PATCH] network: de-associate IP address if enabling static nat fails (#3836) Associating static NAT on IP to VM fails even though the IP is not allocated. When we try enable static NAT on second IP address to the same VM, the operation fails but the IP address is still allocated in the db and it can't be used to enable static NAT on different VM. Steps to reproduce the issue: (1) create a vpc (vpc-001) and a vpc tier (vpc-001-001) (2) create a vm (vm-001-001) in vpc-001-001 (3) acquire a public ip (ip-1) and enable static nat to vm-001-001, operation succeeds. (4) acquire a public ip (ip-2) and enable static nat to vm-001-001, operation fails but the ip is still assigned to vpc tier vpc-001-001. Note down the ip address and the id of it. (5) create another vpc tier vpc-001-002, and vm (vm-001-002) in the tier (6) enabled ip-2 static nat to vm-001-002, operation should succeed --- .../src/main/java/com/cloud/network/rules/RulesManagerImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/com/cloud/network/rules/RulesManagerImpl.java b/server/src/main/java/com/cloud/network/rules/RulesManagerImpl.java index 9dc7a3d3fba..aea24a49ee5 100644 --- a/server/src/main/java/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/main/java/com/cloud/network/rules/RulesManagerImpl.java @@ -500,6 +500,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules s_logger.debug("The ip is not associated with the VPC network id=" + networkId + ", so assigning"); try { ipAddress = _ipAddrMgr.associateIPToGuestNetwork(ipId, networkId, false); + performedIpAssoc = true; } catch (Exception ex) { s_logger.warn("Failed to associate ip id=" + ipId + " to VPC network id=" + networkId + " as " + "a part of enable static nat"); return false;