-
Notifications
You must be signed in to change notification settings - Fork 1.3k
vmware: fix vm snapshot with datastore cluster, drs #6643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shwstppr
merged 10 commits into
apache:4.17
from
shapeblue:fix-vmw-datastorecluster-vmsnap
Aug 31, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
630484f
[WIP] vmware: fix vm snapshot with datastore cluster, drs
shwstppr 859b4f3
fix
shwstppr 795984b
refactor
shwstppr 62adc89
sync only volumes from datastorecluster
shwstppr 4e2f0b0
fix test
shwstppr 72f42f9
fix fo ds uuid npe
shwstppr b8154ca
add test
shwstppr 379a4af
new line
shwstppr 1794197
remove unnecessary mock
shwstppr 39f3ecc
fix datastorecluster type check
shwstppr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...src/test/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategyTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.cloudstack.storage.vmsnapshot; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; | ||
| import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; | ||
| import org.apache.cloudstack.storage.to.VolumeObjectTO; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.Spy; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
| import org.mockito.stubbing.Answer; | ||
|
|
||
| import com.cloud.storage.Storage; | ||
| import com.cloud.storage.Volume; | ||
| import com.cloud.storage.VolumeVO; | ||
| import com.cloud.storage.dao.VolumeDao; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class DefaultVMSnapshotStrategyTest { | ||
| @Mock | ||
| VolumeDao volumeDao; | ||
| @Mock | ||
| PrimaryDataStoreDao primaryDataStoreDao; | ||
|
|
||
| @Spy | ||
| @InjectMocks | ||
| private final DefaultVMSnapshotStrategy defaultVMSnapshotStrategy = new DefaultVMSnapshotStrategy(); | ||
|
|
||
| protected List<VolumeVO> persistedVolumes = new ArrayList<>(); | ||
|
|
||
|
|
||
| private void setupVolumeDaoPersistMock() { | ||
| persistedVolumes.clear(); | ||
| Mockito.when(volumeDao.persist(Mockito.any())).thenAnswer((Answer<VolumeVO>) invocation -> { | ||
| VolumeVO volume = (VolumeVO)invocation.getArguments()[0]; | ||
| persistedVolumes.add(volume); | ||
| return volume; | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUpdateVolumePath() { | ||
| setupVolumeDaoPersistMock(); | ||
| VolumeObjectTO vol1 = Mockito.mock(VolumeObjectTO.class); | ||
| Mockito.when(vol1.getDataStoreUuid()).thenReturn(null); | ||
| Mockito.when(vol1.getPath()).thenReturn(null); | ||
| Mockito.when(vol1.getChainInfo()).thenReturn(null); | ||
| VolumeObjectTO vol2 = Mockito.mock(VolumeObjectTO.class); | ||
| Long volumeId = 1L; | ||
| String newDSUuid = UUID.randomUUID().toString(); | ||
| String oldVolPath = "old"; | ||
| String newVolPath = "new"; | ||
| String oldVolChain = "old-chain"; | ||
| String newVolChain = "new-chain"; | ||
| Long vmSnapshotChainSize = 1000L; | ||
| Long oldPoolId = 1L; | ||
| Long newPoolId = 2L; | ||
| Mockito.when(vol2.getDataStoreUuid()).thenReturn(newDSUuid); | ||
| Mockito.when(vol2.getPath()).thenReturn(newVolPath); | ||
| Mockito.when(vol2.getChainInfo()).thenReturn(newVolChain); | ||
| Mockito.when(vol2.getSize()).thenReturn(vmSnapshotChainSize); | ||
| Mockito.when(vol2.getId()).thenReturn(volumeId); | ||
| VolumeVO volumeVO = new VolumeVO("name", 0l, 0l, 0l, 0l, 0l, "folder", "path", Storage.ProvisioningType.THIN, 0l, Volume.Type.ROOT); | ||
| volumeVO.setPoolId(oldPoolId); | ||
| volumeVO.setChainInfo(oldVolChain); | ||
| volumeVO.setPath(oldVolPath); | ||
| Mockito.when(volumeDao.findById(volumeId)).thenReturn(volumeVO); | ||
| StoragePoolVO storagePoolVO = Mockito.mock(StoragePoolVO.class); | ||
| Mockito.when(storagePoolVO.getId()).thenReturn(newPoolId); | ||
| Mockito.when(primaryDataStoreDao.findPoolByUUID(newDSUuid)).thenReturn(storagePoolVO); | ||
| Mockito.when(volumeDao.findById(volumeId)).thenReturn(volumeVO); | ||
| defaultVMSnapshotStrategy.updateVolumePath(List.of(vol1, vol2)); | ||
| Assert.assertEquals(1, persistedVolumes.size()); | ||
| VolumeVO persistedVolume = persistedVolumes.get(0); | ||
| Assert.assertNotNull(persistedVolume); | ||
| Assert.assertEquals(newPoolId, persistedVolume.getPoolId()); | ||
| Assert.assertEquals(newVolPath, persistedVolume.getPath()); | ||
| Assert.assertEquals(vmSnapshotChainSize, persistedVolume.getVmSnapshotChainSize()); | ||
| Assert.assertEquals(newVolChain, persistedVolume.getChainInfo()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More of a general remark than about this piece of code; can these lines be extracted and tested in unit tests. (extracted is maybe not needed in this case, but unit tests would be nice)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DaanHoogland added unit test