From 943a4eb96dd1d39e21ffc8073c69604b5c3ff523 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Wed, 28 Aug 2024 10:40:56 +0200 Subject: [PATCH] Static: remove allocated IPv4 subnet when delete a network or vpc --- .../cloudstack/network/RoutedIpv4ManagerImpl.java | 12 +----------- test/integration/smoke/test_ipv4_routing.py | 10 ++++------ 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/server/src/main/java/org/apache/cloudstack/network/RoutedIpv4ManagerImpl.java b/server/src/main/java/org/apache/cloudstack/network/RoutedIpv4ManagerImpl.java index 055c23c441e1..593fc449fe7f 100644 --- a/server/src/main/java/org/apache/cloudstack/network/RoutedIpv4ManagerImpl.java +++ b/server/src/main/java/org/apache/cloudstack/network/RoutedIpv4ManagerImpl.java @@ -480,17 +480,7 @@ public void releaseIpv4SubnetForVpc(long vpcId) { } private void releaseIpv4SubnetForGuestNetworkOrVpcInternal(Ipv4GuestSubnetNetworkMapVO mapVO) { - if (mapVO.getParentId() == null) { - // if parent_id is NULL, remove it - ipv4GuestSubnetNetworkMapDao.remove(mapVO.getId()); - } else { - // otherwise, release it - mapVO.setAllocated(null); - mapVO.setVpcId(null); - mapVO.setNetworkId(null); - mapVO.setState(State.Free); - ipv4GuestSubnetNetworkMapDao.update(mapVO.getId(), mapVO); - } + ipv4GuestSubnetNetworkMapDao.remove(mapVO.getId()); } @Override diff --git a/test/integration/smoke/test_ipv4_routing.py b/test/integration/smoke/test_ipv4_routing.py index b975543b38ae..124be678965c 100644 --- a/test/integration/smoke/test_ipv4_routing.py +++ b/test/integration/smoke/test_ipv4_routing.py @@ -684,10 +684,9 @@ def test_04_create_isolated_network_routed_mode_with_cidrsize(self): subnet=network_cidr ) self.assertEqual( - isinstance(subnets, list) and len(subnets) == 1 - and not subnets[0].networkid and subnets[0].state == "Free", + not isinstance(subnets, list) or len(subnets) == 0, True, - "The subnet should be created for isolated_network %s" % isolated_network.name + "The subnet should be removed for isolated_network %s" % isolated_network.name ) @attr(tags=['advanced'], required_hardware=False) @@ -735,10 +734,9 @@ def test_05_create_vpc_routed_mode_with_cidrsize(self): subnet=vpc_cidr ) self.assertEqual( - isinstance(subnets, list) and len(subnets) == 1 - and not subnets[0].vpcid and subnets[0].state == "Free", + not isinstance(subnets, list) or len(subnets) == 0, True, - "The subnet should be created for vpc %s" % vpc.name + "The subnet should be removed for vpc %s" % vpc.name ) @attr(tags=['advanced'], required_hardware=False)