Skip to content
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 @@ -52,7 +52,7 @@ public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperat
}
long volumeId = snapshot.getVolumeId();
VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId);
boolean baseVolumeExists = volumeVO.getRemoved() == null;
boolean baseVolumeExists = volumeVO != null && volumeVO.getRemoved() == null;
if (!baseVolumeExists) {
return StrategyPriority.CANT_HANDLE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperat
}
long volumeId = snapshot.getVolumeId();
VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId);
boolean baseVolumeExists = volumeVO.getRemoved() == null;
boolean baseVolumeExists = volumeVO != null && volumeVO.getRemoved() == null;
if (!baseVolumeExists) {
return StrategyPriority.CANT_HANDLE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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.isManaged()) {
return StrategyPriority.HIGHEST;
}
}
}
}
Expand All @@ -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());

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
Expand Up @@ -65,12 +65,24 @@ public void canHandleTestNotReomvedAndSnapshotNotStoredOnRbd() {

@Test
public void canHandleTestReomvedAndSnapshotNotStoredOnRbd() {
configureAndVerifyCanHandle(null, false);
configureAndVerifyCanHandle(new Date(), false);
}

@Test
public void canHandleTestReomvedAndSnapshotStoredOnRbd() {
configureAndVerifyCanHandle(null, true);
configureAndVerifyCanHandle(new Date(), true);
}

@Test
public void canHandleTestVolumeRowMissing() {
Snapshot snapshot = Mockito.mock(Snapshot.class);
Mockito.when(snapshot.getVolumeId()).thenReturn(1L);
Mockito.when(volumeDao.findByIdIncludingRemoved(1L)).thenReturn(null);

for (SnapshotOperation op : SnapshotOperation.values()) {
Assert.assertEquals(StrategyPriority.CANT_HANDLE, cephSnapshotStrategy.canHandle(snapshot, null, op));
}
Mockito.verify(cephSnapshotStrategy, Mockito.never()).isSnapshotStoredOnRbdStoragePoolAndOperationForSameZone(Mockito.any(), Mockito.any());
}

private void configureAndVerifyCanHandle(Date removed, boolean isSnapshotStoredOnRbdStoragePool) {
Expand All @@ -85,7 +97,7 @@ private void configureAndVerifyCanHandle(Date removed, boolean isSnapshotStoredO

for (int i = 0; i < snapshotOps.length - 1; i++) {
StrategyPriority strategyPriority = cephSnapshotStrategy.canHandle(snapshot, null, snapshotOps[i]);
if (snapshotOps[i] == SnapshotOperation.REVERT && isSnapshotStoredOnRbdStoragePool) {
if (snapshotOps[i] == SnapshotOperation.REVERT && isSnapshotStoredOnRbdStoragePool && removed == null) {
Assert.assertEquals(StrategyPriority.HIGHEST, strategyPriority);
} else {
Assert.assertEquals(StrategyPriority.CANT_HANDLE, strategyPriority);
Expand Down
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);
}
}
Loading
Loading