Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public interface DataCenterVnetDao extends GenericDao<DataCenterVnetVO, Long> {

public void release(String vnet, long physicalNetworkId, long accountId, String reservationId);

public void releaseForAccount(long accountId);

public void releaseDedicatedGuestVlans(Long dedicatedGuestVlanRangeId);

public int countVnetsAllocatedToAccount(long dcId, long accountId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ public void release(String vnet, long physicalNetworkId, long accountId, String
update(vo.getId(), vo);
}

@Override
public void releaseForAccount(long accountId) {
SearchCriteria<DataCenterVnetVO> sc = VnetDcSearchAllocated.create();
sc.setParameters("account", accountId);

DataCenterVnetVO vo = findOneIncludingRemovedBy(sc);
vo.setTakenAt(null);
vo.setAccountId(null);
vo.setReservationId(null);
update(vo.getId(), vo);
}

@Override
public void releaseDedicatedGuestVlans(Long dedicatedGuestVlanRangeId) {
SearchCriteria<DataCenterVnetVO> sc = DedicatedGuestVlanRangeSearch.create();
Expand Down
5 changes: 5 additions & 0 deletions server/src/main/java/com/cloud/user/AccountManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,11 @@ public int compare(NetworkVO network1, NetworkVO network2) {
for (AccountGuestVlanMapVO map : maps) {
_dataCenterVnetDao.releaseDedicatedGuestVlans(map.getId());
}
// this is clearing the operational reservations or vlans for the account
// this should have happened before and covers up the release issues for the vlans
// but as it is purely operational and no business logic is involved we clean now
// as a last resort, to prevent allocation issue on the long run.
_dataCenterVnetDao.releaseForAccount(accountId);
int vlansReleased = _accountGuestVlanMapDao.removeByAccountId(accountId);
logger.info("deleteAccount: Released {} dedicated guest vlan ranges from account {}", vlansReleased, account);

Expand Down
2 changes: 1 addition & 1 deletion test/integration/smoke/test_events_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def test_01_events_resource(self):
self.apiclient,
self.services["network_offering"],
)
self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
self.services["network"]["networkoffering"] = self.network_offering.id
self.cleanup.append(self.network_offering)
self.services["zoneid"] = self.zone.id
self.services["template"] = template.id
self.services["network"]["zoneid"] = self.zone.id
Expand Down
64 changes: 31 additions & 33 deletions test/integration/smoke/test_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ def setUpClass(cls):
cls.api_client,
cls.test_data["service_offerings"]["tiny"]
)
cls._cleanup.append(cls.service_offering)

# Create Network offering without userdata
cls.network_offering_nouserdata = NetworkOffering.create(
cls.api_client,
cls.test_data["network_offering"]
)
cls._cleanup.append(cls.network_offering_nouserdata)
# Enable Network offering
cls.network_offering_nouserdata.update(cls.api_client,
state='Enabled')
Expand All @@ -124,54 +126,39 @@ def setUpClass(cls):
cls.api_client,
cls.test_data["isolated_network_offering"]
)
cls._cleanup.append(cls.network_offering_all)
# Enable Network offering
cls.network_offering_all.update(cls.api_client, state='Enabled')

cls.native_vpc_network_offering = NetworkOffering.create(
cls.api_client,
cls.test_data["nw_offering_isolated_vpc"],
conservemode=False)
cls._cleanup.append(cls.native_vpc_network_offering)
cls.native_vpc_network_offering.update(cls.api_client,
state='Enabled')

cls._cleanup = [
cls.service_offering,
cls.network_offering_nouserdata,
cls.network_offering_all,
cls.native_vpc_network_offering
]

def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
if not self.hypervisorNotSupported:
self.account = Account.create(
self.apiclient,
self.test_data["account"],
admin=True,
domainid=self.domain.id
)
self.cleanup = []
self.cleanup.append(self.account)
return

def tearDown(self):
try:
if not self.hypervisorNotSupported:
self.account.delete(self.apiclient)
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestNetworkMigration, self).tearDown()

@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)

except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
super(TestNetworkMigration, cls).tearDownClass()

def migrate_network(self, nw_off, network, resume=False):
return network.migrate(self.api_client, nw_off.id, resume)
Expand Down Expand Up @@ -204,14 +191,17 @@ def test_01_native_to_native_network_migration(self):
networkofferingid=self.network_offering_all.id,
zoneid=self.zone.id
)
self.cleanup.append(isolated_network)

self.migrate_network(
self.network_offering_nouserdata,
isolated_network, resume=False)
self.network_offering_nouserdata,
isolated_network,
resume=False)

self.migrate_network(
self.network_offering_all,
isolated_network, resume=False)
self.network_offering_all,
isolated_network,
resume=False)

deployVmResponse = VirtualMachine.create(
self.apiclient,
Expand All @@ -221,14 +211,14 @@ def test_01_native_to_native_network_migration(self):
serviceofferingid=self.service_offering.id,
networkids=[str(isolated_network.id)],
templateid=self.template.id,
zoneid=self.zone.id
)
zoneid=self.zone.id)
self.cleanup.append(deployVmResponse)

Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] There's an extra blank line added after appending deployVmResponse to the cleanup list (line 215), but no blank line after other similar append operations (e.g., lines 194, 255, 271). For consistency, either remove this blank line or add blank lines after all similar operations throughout the file.

Suggested change

Copilot uses AI. Check for mistakes.
vms = list_virtual_machines(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
id=deployVmResponse.id
)
id=deployVmResponse.id)
self.assertTrue(len(vms) > 0, "There are no Vms deployed in the account"
" %s" % self.account.name)
vm = vms[0]
Expand All @@ -237,12 +227,14 @@ def test_01_native_to_native_network_migration(self):
self.assertTrue(vm.state == "Running", "VM is not in Running state")

self.migrate_network(
self.network_offering_nouserdata,
isolated_network, resume=False)
self.network_offering_nouserdata,
isolated_network,
resume=False)

self.migrate_network(
self.network_offering_all,
isolated_network, resume=False)
self.network_offering_all,
isolated_network,
resume=False)

@skipTestIf("hypervisorNotSupported")
@attr(tags=["advanced", "smoke", "nativevpconly"],
Expand All @@ -262,6 +254,7 @@ def test_02_native_to_native_vpc_migration(self):
native_vpc_off = VpcOffering.create(
self.apiclient,
self.test_data["vpc_offering_reduced"])
self.cleanup.append(native_vpc_off)

self.debug("Enabling the VPC offering created")
native_vpc_off.update(self.apiclient, state='Enabled')
Expand All @@ -277,13 +270,16 @@ def test_02_native_to_native_vpc_migration(self):
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(vpc)

Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Similar to the previous comment, there's an extra blank line after appending vpc to the cleanup list. This inconsistency in spacing should be addressed to maintain uniform code style throughout the file.

Suggested change

Copilot uses AI. Check for mistakes.
self.debug("Creating native VPC Network Tier offering "
"with Static NAT service provider as VPCVR")
native_tiernet_off = \
NetworkOffering.create(self.apiclient,
self.test_data
["nw_offering_reduced_vpc"],
conservemode=False)
self.cleanup.append(native_tiernet_off)
native_tiernet_off.update(self.apiclient, state='Enabled')

self.debug("Creating a VPC tier network with Static NAT service")
Expand All @@ -296,6 +292,7 @@ def test_02_native_to_native_vpc_migration(self):
gateway='10.1.1.1',
vpcid=vpc.id if vpc else self.vpc.id
)
self.cleanup.append(vpc_tier)
self.debug("Created network with ID: %s" % vpc_tier.id)

network_offering_map = \
Expand Down Expand Up @@ -323,6 +320,7 @@ def test_02_native_to_native_vpc_migration(self):
templateid=self.template.id,
zoneid=self.zone.id
)
self.cleanup.append(vm)
self.debug('Created VM=%s in network=%s' %
(vm.id, native_tiernet_off.name))

Expand Down
Loading