Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Launch RESIZE event on volume snapshot revert #10482

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -390,15 +390,27 @@

boolean result = snapshotStrategy.revertSnapshot(snapshotInfo);
if (result) {
// update volume size and primary storage count
_resourceLimitMgr.decrementResourceCount(snapshot.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize() - snapshot.getSize()));
volume.setSize(snapshot.getSize());
_volsDao.update(volume.getId(), volume);
updateVolumeSizeAndPrimaryStorageCount(volume, snapshot);
return snapshotInfo;
}
return null;
}

public void updateVolumeSizeAndPrimaryStorageCount(VolumeVO volume, SnapshotVO snapshot) {
Long differenceBetweenVolumeAndSnapshotSize = new Long(volume.getSize() - snapshot.getSize());
if (differenceBetweenVolumeAndSnapshotSize != 0) {
if (differenceBetweenVolumeAndSnapshotSize > 0) {
_resourceLimitMgr.decrementResourceCount(snapshot.getAccountId(), ResourceType.primary_storage, differenceBetweenVolumeAndSnapshotSize);

Check warning on line 403 in server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java#L403

Added line #L403 was not covered by tests
} else if (differenceBetweenVolumeAndSnapshotSize < 0) {
_resourceLimitMgr.incrementResourceCount(snapshot.getAccountId(), ResourceType.primary_storage, differenceBetweenVolumeAndSnapshotSize * -1L);

Check warning on line 405 in server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java#L405

Added line #L405 was not covered by tests
}
volume.setSize(snapshot.getSize());
_volsDao.update(volume.getId(), volume);
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
volume.getDiskOfferingId(), volume.getTemplateId(), volume.getSize(), Volume.class.getName(), volume.getUuid());

Check warning on line 410 in server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java#L407-L410

Added lines #L407 - L410 were not covered by tests
}
}

@Override
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_POLICY_UPDATE, eventDescription = "updating snapshot policy", async = true)
public SnapshotPolicy updateSnapshotPolicy(UpdateSnapshotPolicyCmd cmd) {
Expand Down Expand Up @@ -805,7 +817,7 @@

return result;
} catch (Exception e) {
logger.debug("Failed to delete snapshot {}:{}", snapshotCheck, e.toString());
logger.debug("Failed to delete snapshot {}:{}", snapshotCheck.getId(), e.toString());

Check warning on line 820 in server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java#L820

Added line #L820 was not covered by tests

throw new CloudRuntimeException("Failed to delete snapshot:" + e.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ public void setup() throws ResourceAllocationException {

doNothing().when(_resourceLimitMgr).checkResourceLimit(any(Account.class), any(ResourceType.class));
doNothing().when(_resourceLimitMgr).checkResourceLimit(any(Account.class), any(ResourceType.class), anyLong());
doNothing().when(_resourceLimitMgr).decrementResourceCount(anyLong(), any(ResourceType.class), anyLong());
doNothing().when(_resourceLimitMgr).incrementResourceCount(anyLong(), any(ResourceType.class));
doNothing().when(_resourceLimitMgr).incrementResourceCount(anyLong(), any(ResourceType.class), anyLong());

Expand Down Expand Up @@ -352,7 +351,6 @@ public void testRevertSnapshotF3() {
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
when(vmMock.getState()).thenReturn(State.Stopped);
when (snapshotStrategy.revertSnapshot(any(SnapshotInfo.class))).thenReturn(true);
when(_volumeDao.update(anyLong(), any(VolumeVO.class))).thenReturn(true);
doReturn(DataStoreRole.Image).when(snapshotHelperMock).getDataStoreRole(any());
Snapshot snapshot = _snapshotMgr.revertSnapshot(TEST_SNAPSHOT_ID);
Assert.assertNotNull(snapshot);
Expand Down
4 changes: 2 additions & 2 deletions utils/src/test/java/com/cloud/utils/UriUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ public void testIsUrlForCompressedFile() {

@Test
public void validateUrl() {
Pair<String, Integer> url1 = UriUtils.validateUrl("https://www.cloudstack.org");
Assert.assertEquals(url1.first(), "www.cloudstack.org");
Pair<String, Integer> url1 = UriUtils.validateUrl("https://cloudstack.apache.org/");
Assert.assertEquals(url1.first(), "cloudstack.apache.org");

Pair<String, Integer> url2 = UriUtils.validateUrl("https://www.apache.org");
Assert.assertEquals(url2.first(), "www.apache.org");
Expand Down
Loading