mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Changed the implementation of isVolumeOnManagedStorage(VolumeInfo) to check if the data store in question is for primary storage (and added a unit test from Daan Hoogland)
This commit is contained in:
parent
461c4ad027
commit
ab83c198a5
@ -196,12 +196,18 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy {
|
||||
}
|
||||
|
||||
private boolean isVolumeOnManagedStorage(VolumeInfo volumeInfo) {
|
||||
long storagePooldId = volumeInfo.getDataStore().getId();
|
||||
DataStore dataStore = volumeInfo.getDataStore();
|
||||
|
||||
if (dataStore.getRole() == DataStoreRole.Primary) {
|
||||
long storagePooldId = dataStore.getId();
|
||||
StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePooldId);
|
||||
|
||||
return storagePoolVO.isManaged();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// canHandle returns true if the storage driver for the DataObject that's passed in can support certain features (what features we
|
||||
// care about during a particular invocation of this method depend on what type of DataObject was passed in (ex. VolumeInfo versus SnapshotInfo)).
|
||||
private boolean canHandle(DataObject dataObject) {
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.motion;
|
||||
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.storage.ImageStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionStrategy;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority;
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreImpl;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
|
||||
import org.apache.cloudstack.storage.volume.VolumeObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class StorageSystemDataMotionStrategyTest {
|
||||
|
||||
@Mock
|
||||
VolumeObject source;
|
||||
@Mock
|
||||
DataObject destination;
|
||||
@Mock
|
||||
PrimaryDataStore sourceStore;
|
||||
@Mock
|
||||
ImageStore destinationStore;
|
||||
|
||||
@InjectMocks
|
||||
DataMotionStrategy strategy = new StorageSystemDataMotionStrategy();
|
||||
@Mock
|
||||
PrimaryDataStoreDao _storagePoolDao;
|
||||
|
||||
@Before public void setUp() throws Exception {
|
||||
sourceStore = mock(PrimaryDataStoreImpl.class);
|
||||
destinationStore = mock(ImageStoreImpl.class);
|
||||
source = mock(VolumeObject.class);
|
||||
destination = mock(VolumeObject.class);
|
||||
|
||||
initMocks(strategy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cantHandleSecondary() {
|
||||
doReturn(sourceStore).when(source).getDataStore();
|
||||
doReturn(DataStoreRole.Primary).when(sourceStore).getRole();
|
||||
doReturn(destinationStore).when(destination).getDataStore();
|
||||
doReturn(DataStoreRole.Image).when((DataStore)destinationStore).getRole();
|
||||
doReturn(sourceStore).when(source).getDataStore();
|
||||
doReturn(destinationStore).when(destination).getDataStore();
|
||||
StoragePoolVO storeVO = new StoragePoolVO();
|
||||
doReturn(storeVO).when(_storagePoolDao).findById(0l);
|
||||
|
||||
assertTrue(strategy.canHandle(source,destination) == StrategyPriority.CANT_HANDLE);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user