Repository navigation
Don't fail snapshot strategy selection when a snapshot's volume row is gone #14600
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
base: 4.22
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -951,10 +951,8 @@ public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperat | |
|
|
||
| VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId); | ||
|
|
||
| long volumeStoragePoolId = (volumeVO.getPoolId() != null ? volumeVO.getPoolId() : volumeVO.getLastPoolId()); | ||
|
|
||
| if (SnapshotOperation.REVERT.equals(op)) { | ||
| boolean baseVolumeExists = volumeVO.getRemoved() == null; | ||
| boolean baseVolumeExists = volumeVO != null && volumeVO.getRemoved() == null; | ||
|
|
||
| if (baseVolumeExists) { | ||
| boolean acceptableFormat = isAcceptableRevertFormat(volumeVO); | ||
|
|
@@ -964,6 +962,8 @@ public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperat | |
|
|
||
| boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshot.getId()); | ||
|
|
||
| Long volumeStoragePoolId = getVolumeStoragePoolId(volumeVO); | ||
|
|
||
| if (usingBackendSnapshot) { | ||
| if (snapshotStore != null) { | ||
| long snapshotStoragePoolId = snapshotStore.getDataStoreId(); | ||
|
|
@@ -975,7 +975,7 @@ public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperat | |
| return StrategyPriority.HIGHEST; | ||
| } | ||
|
|
||
| storageSystemSupportsCapability = storageSystemSupportsCapability(volumeStoragePoolId, | ||
| storageSystemSupportsCapability = volumeStoragePoolId != null && storageSystemSupportsCapability(volumeStoragePoolId, | ||
| DataStoreCapabilities.CAN_REVERT_VOLUME_TO_SNAPSHOT.toString()); | ||
|
|
||
| if (storageSystemSupportsCapability) { | ||
|
|
@@ -994,10 +994,12 @@ public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperat | |
| } | ||
| } | ||
|
|
||
| StoragePoolVO storagePoolVO = storagePoolDao.findById(volumeStoragePoolId); | ||
| if (volumeStoragePoolId != null) { | ||
| StoragePoolVO storagePoolVO = storagePoolDao.findById(volumeStoragePoolId); | ||
|
|
||
| if (storagePoolVO.isManaged()) { | ||
| return StrategyPriority.HIGHEST; | ||
| if (storagePoolVO != null && storagePoolVO.isManaged()) { | ||
| return StrategyPriority.HIGHEST; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1006,9 +1008,15 @@ public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperat | |
| return StrategyPriority.CANT_HANDLE; | ||
| } | ||
|
|
||
| long volumeStoragePoolId = getVolumeStoragePoolId(volumeVO); | ||
|
|
||
| boolean storageSystemSupportsCapability = storageSystemSupportsCapability(volumeStoragePoolId, DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as line 978 this also could be changed to : storageSystemSupportsCapability = volumeStoragePoolId != null && storageSystemSupportsCapability(volumeStoragePoolId,DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd keep this one as it is. COPY and DELETE return before this point, so only TAKE and BACKUP get here, and they need the volume's pool. Returning |
||
|
|
||
| return storageSystemSupportsCapability ? StrategyPriority.HIGHEST : StrategyPriority.CANT_HANDLE; | ||
| } | ||
|
|
||
| private Long getVolumeStoragePoolId(VolumeVO volumeVO) { | ||
| return volumeVO.getPoolId() != null ? volumeVO.getPoolId() : volumeVO.getLastPoolId(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * 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.snapshot; | ||
|
|
||
| import java.util.Date; | ||
|
|
||
| import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy.SnapshotOperation; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority; | ||
| import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; | ||
| import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; | ||
| 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 com.cloud.storage.Snapshot; | ||
| import com.cloud.storage.VolumeVO; | ||
| import com.cloud.storage.dao.VolumeDao; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class ScaleIOSnapshotStrategyTest { | ||
|
|
||
| @Spy | ||
| @InjectMocks | ||
| private ScaleIOSnapshotStrategy scaleIOSnapshotStrategy; | ||
| @Mock | ||
| private SnapshotDataStoreDao snapshotStoreDao; | ||
| @Mock | ||
| private PrimaryDataStoreDao primaryDataStoreDao; | ||
| @Mock | ||
| private VolumeDao volumeDao; | ||
|
|
||
| private void verifyCantHandleAnyOperation(VolumeVO volumeVO) { | ||
| Snapshot snapshot = Mockito.mock(Snapshot.class); | ||
| Mockito.when(snapshot.getVolumeId()).thenReturn(1L); | ||
| Mockito.when(volumeDao.findByIdIncludingRemoved(1L)).thenReturn(volumeVO); | ||
|
|
||
| for (SnapshotOperation op : SnapshotOperation.values()) { | ||
| Assert.assertEquals(StrategyPriority.CANT_HANDLE, scaleIOSnapshotStrategy.canHandle(snapshot, null, op)); | ||
| } | ||
| Mockito.verifyNoInteractions(snapshotStoreDao, primaryDataStoreDao); | ||
| } | ||
|
|
||
| @Test | ||
| public void canHandleTestVolumeExistsAndSnapshotStoredOnScaleIO() { | ||
| Snapshot snapshot = Mockito.mock(Snapshot.class); | ||
| Mockito.when(snapshot.getVolumeId()).thenReturn(1L); | ||
| VolumeVO volumeVO = Mockito.mock(VolumeVO.class); | ||
| Mockito.when(volumeVO.getRemoved()).thenReturn(null); | ||
| Mockito.when(volumeDao.findByIdIncludingRemoved(1L)).thenReturn(volumeVO); | ||
| Mockito.doReturn(true).when(scaleIOSnapshotStrategy).isSnapshotStoredOnScaleIOStoragePoolAndOperationForSameZone(Mockito.any(), Mockito.any()); | ||
|
|
||
| for (SnapshotOperation op : SnapshotOperation.values()) { | ||
| StrategyPriority expected = (op == SnapshotOperation.REVERT || op == SnapshotOperation.DELETE) ? StrategyPriority.HIGHEST : StrategyPriority.CANT_HANDLE; | ||
| Assert.assertEquals(expected, scaleIOSnapshotStrategy.canHandle(snapshot, null, op)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void canHandleTestVolumeRowMissing() { | ||
| verifyCantHandleAnyOperation(null); | ||
| } | ||
|
|
||
| @Test | ||
| public void canHandleTestVolumeRemoved() { | ||
| VolumeVO volumeVO = Mockito.mock(VolumeVO.class); | ||
| Mockito.when(volumeVO.getRemoved()).thenReturn(new Date()); | ||
| verifyCantHandleAnyOperation(volumeVO); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.