Skip to content
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

[PowerFlex] Add & Remove PowerFlex/ScaleIO MDMs for the storage SDC connections #9903

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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 @@ -46,6 +46,10 @@
templateInfo = tInfo;
}

public ModifyStoragePoolAnswer(ModifyStoragePoolCommand cmd, boolean success, String details) {
super(cmd, success, details);
}

Check warning on line 51 in core/src/main/java/com/cloud/agent/api/ModifyStoragePoolAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ModifyStoragePoolAnswer.java#L50-L51

Added lines #L50 - L51 were not covered by tests

public void setPoolInfo(StoragePoolInfo poolInfo) {
this.poolInfo = poolInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@

package com.cloud.agent.api;

import java.util.Map;

import com.cloud.storage.Storage.StoragePoolType;

public class UnprepareStorageClientCommand extends Command {
private StoragePoolType poolType;
private String poolUuid;
private Map<String, String> details;

public UnprepareStorageClientCommand() {
}

public UnprepareStorageClientCommand(StoragePoolType poolType, String poolUuid) {
public UnprepareStorageClientCommand(StoragePoolType poolType, String poolUuid, Map<String, String> details) {

Check warning on line 34 in core/src/main/java/com/cloud/agent/api/UnprepareStorageClientCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/UnprepareStorageClientCommand.java#L34

Added line #L34 was not covered by tests
this.poolType = poolType;
this.poolUuid = poolUuid;
this.details = details;

Check warning on line 37 in core/src/main/java/com/cloud/agent/api/UnprepareStorageClientCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/UnprepareStorageClientCommand.java#L37

Added line #L37 was not covered by tests
}

@Override
Expand All @@ -45,4 +49,8 @@
public String getPoolUuid() {
return poolUuid;
}

public Map<String, String> getDetails() {
return details;
}

Check warning on line 55 in core/src/main/java/com/cloud/agent/api/UnprepareStorageClientCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/UnprepareStorageClientCommand.java#L53-L55

Added lines #L53 - L55 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
boolean canCopy(DataObject srcData, DataObject destData);

void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback);

default boolean canDisplayDetails() {
return true;
}

Check warning on line 51 in engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreDriver.java

View check run for this annotation

Codecov / codecov/patch

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreDriver.java#L49-L51

Added lines #L49 - L51 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@
return false;
}

/**
* intended for managed storage
* returns true if the host can be disconnected from storage pool
*/
default boolean canDisconnectHostFromStoragePool(Host host, StoragePool pool) {
return true;
}

Check warning on line 146 in engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java

View check run for this annotation

Codecov / codecov/patch

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java#L144-L146

Added lines #L144 - L146 were not covered by tests

/**
* Used by storage pools which want to keep VMs' information
* @return true if additional VM info is needed (intended for storage pools).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ static Boolean getFullCloneConfiguration(Long storeId) {

boolean canHostPrepareStoragePoolAccess(Host host, StoragePool pool);

boolean canDisconnectHostFromStoragePool(Host host, StoragePool pool);

Host getHost(long hostId);

Host updateSecondaryStorage(long secStorageId, String newUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {

StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details, List<String> tags, Boolean isTagARule);

StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details, List<String> tags, Boolean isTagARule, boolean displayDetails);

/**
* Find pool by name.
*
Expand Down Expand Up @@ -103,6 +105,8 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {

void updateDetails(long poolId, Map<String, String> details);

void removeDetails(long poolId);

Map<String, String> getDetails(long poolId);

List<String> searchForStoragePoolTags(long poolId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,19 @@
}

@Override
@DB
public StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details, List<String> tags, Boolean isTagARule) {
return persist(pool, details, tags, isTagARule, true);
}

Check warning on line 301 in engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java#L300-L301

Added lines #L300 - L301 were not covered by tests

@Override
@DB
public StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details, List<String> tags, Boolean isTagARule, boolean displayDetails) {

Check warning on line 305 in engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java#L305

Added line #L305 was not covered by tests
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
pool = super.persist(pool);
if (details != null) {
for (Map.Entry<String, String> detail : details.entrySet()) {
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue(), true);
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue(), displayDetails);

Check warning on line 311 in engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java#L311

Added line #L311 was not covered by tests
_detailsDao.persist(vo);
}
}
Expand Down Expand Up @@ -570,6 +575,11 @@
}
}

@Override
public void removeDetails(long poolId) {
_detailsDao.removeDetails(poolId);
}

Check warning on line 581 in engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java#L579-L581

Added lines #L579 - L581 were not covered by tests

@Override
public Map<String, String> getDetails(long poolId) {
return _detailsDao.listDetailsKeyPairs(poolId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient;
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientConnectionPool;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil;
Expand Down Expand Up @@ -300,7 +301,11 @@
srcSnapshotDestVolumeMap.put(srcSnapshotVolumeId, destVolumeId);
}

String systemId = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue();
String systemId = null;
StoragePoolDetailVO systemIdDetail = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID);

Check warning on line 305 in engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java#L304-L305

Added lines #L304 - L305 were not covered by tests
if (systemIdDetail != null) {
systemId = systemIdDetail.getValue();

Check warning on line 307 in engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java#L307

Added line #L307 was not covered by tests
}
if (systemId == null) {
throw new CloudRuntimeException("Failed to get the system id for PowerFlex storage pool for reverting VM snapshot: " + vmSnapshot.getName());
}
Expand Down Expand Up @@ -379,7 +384,11 @@
try {
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(vmSnapshot.getVmId());
Long storagePoolId = vmSnapshotHelper.getStoragePoolForVM(userVm.getId());
String systemId = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue();
String systemId = null;
StoragePoolDetailVO systemIdDetail = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID);

Check warning on line 388 in engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java#L387-L388

Added lines #L387 - L388 were not covered by tests
if (systemIdDetail != null) {
systemId = systemIdDetail.getValue();

Check warning on line 390 in engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java#L390

Added line #L390 was not covered by tests
}
if (systemId == null) {
throw new CloudRuntimeException("Failed to get the system id for PowerFlex storage pool for deleting VM snapshot: " + vmSnapshot.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@

import org.apache.cloudstack.annotation.AnnotationService;
import org.apache.cloudstack.annotation.dao.AnnotationDao;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreParameters;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
Expand Down Expand Up @@ -75,6 +78,8 @@
protected StoragePoolHostDao storagePoolHostDao;
@Inject
private AnnotationDao annotationDao;
@Inject
DataStoreProviderManager dataStoreProviderMgr;

public DataStore createPrimaryDataStore(PrimaryDataStoreParameters params) {
if(params == null)
Expand Down Expand Up @@ -141,7 +146,17 @@
storageTags.add(tag);
}
}
dataStoreVO = dataStoreDao.persist(dataStoreVO, details, storageTags, params.isTagARule());

boolean displayDetails = true;
DataStoreProvider storeProvider = dataStoreProviderMgr.getDataStoreProvider(params.getProviderName());

Check warning on line 151 in engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java#L150-L151

Added lines #L150 - L151 were not covered by tests
if (storeProvider != null) {
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();

Check warning on line 153 in engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java#L153

Added line #L153 was not covered by tests
if (storeDriver != null) {
displayDetails = storeDriver.canDisplayDetails();

Check warning on line 155 in engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java#L155

Added line #L155 was not covered by tests
}
}

dataStoreVO = dataStoreDao.persist(dataStoreVO, details, storageTags, params.isTagARule(), displayDetails);

Check warning on line 159 in engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java#L159

Added line #L159 was not covered by tests
return dataStoreMgr.getDataStore(dataStoreVO.getId(), DataStoreRole.Primary);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
@Override
public Answer execute(final ModifyStoragePoolCommand command, final LibvirtComputingResource libvirtComputingResource) {
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
if (!command.getAdd()) {
boolean status = storagePoolMgr.deleteStoragePool(command.getPool().getType(), command.getPool().getUuid(), command.getDetails());

Check warning on line 42 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyStoragePoolCommandWrapper.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyStoragePoolCommandWrapper.java#L42

Added line #L42 was not covered by tests
if (status) {
final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, true, null);
return answer;

Check warning on line 45 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyStoragePoolCommandWrapper.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyStoragePoolCommandWrapper.java#L44-L45

Added lines #L44 - L45 were not covered by tests
}

final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, false, "Failed to delete storage pool");
return answer;

Check warning on line 49 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyStoragePoolCommandWrapper.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyStoragePoolCommandWrapper.java#L48-L49

Added lines #L48 - L49 were not covered by tests
}

final KVMStoragePool storagepool =
storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType(), command.getDetails());
Expand All @@ -47,7 +58,6 @@

final Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, storagepool.getCapacity(), storagepool.getAvailable(), tInfo, storagepool.getDetails());

return answer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class LibvirtUnprepareStorageClientCommandWrapper extends CommandWrapper<
@Override
public Answer execute(UnprepareStorageClientCommand cmd, LibvirtComputingResource libvirtComputingResource) {
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
Pair<Boolean, String> unprepareStorageClientResult = storagePoolMgr.unprepareStorageClient(cmd.getPoolType(), cmd.getPoolUuid());
Pair<Boolean, String> unprepareStorageClientResult = storagePoolMgr.unprepareStorageClient(cmd.getPoolType(), cmd.getPoolUuid(), cmd.getDetails());
if (!unprepareStorageClientResult.first()) {
String msg = unprepareStorageClientResult.second();
logger.debug("Couldn't unprepare storage client, due to: " + msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,26 @@

public boolean deleteStoragePool(StoragePoolType type, String uuid) {
StorageAdaptor adaptor = getStorageAdaptor(type);
_haMonitor.removeStoragePool(uuid);
adaptor.deleteStoragePool(uuid);
if (type == StoragePoolType.NetworkFilesystem) {

Check warning on line 413 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java#L413

Added line #L413 was not covered by tests
_haMonitor.removeStoragePool(uuid);
}

Check warning on line 415 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java#L415

Added line #L415 was not covered by tests
boolean deleteStatus = adaptor.deleteStoragePool(uuid);;
synchronized (_storagePools) {
_storagePools.remove(uuid);
}
return deleteStatus;
}

Check warning on line 422 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java#L417-L422

Added lines #L417 - L422 were not covered by tests
public boolean deleteStoragePool(StoragePoolType type, String uuid, Map<String, String> details) {
StorageAdaptor adaptor = getStorageAdaptor(type);
if (type == StoragePoolType.NetworkFilesystem) {

Check warning on line 425 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java#L424-L425

Added lines #L424 - L425 were not covered by tests
_haMonitor.removeStoragePool(uuid);
}

Check warning on line 427 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java#L427

Added line #L427 was not covered by tests
boolean deleteStatus = adaptor.deleteStoragePool(uuid, details);
synchronized (_storagePools) {
_storagePools.remove(uuid);
}
return true;
return deleteStatus;

Check warning on line 432 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java#L432

Added line #L432 was not covered by tests
}

public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, String name, Storage.ProvisioningType provisioningType,
Expand Down Expand Up @@ -479,11 +493,11 @@

public Ternary<Boolean, Map<String, String>, String> prepareStorageClient(StoragePoolType type, String uuid, Map<String, String> details) {
StorageAdaptor adaptor = getStorageAdaptor(type);
return adaptor.prepareStorageClient(type, uuid, details);
return adaptor.prepareStorageClient(uuid, details);

Check warning on line 496 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java#L496

Added line #L496 was not covered by tests
}

public Pair<Boolean, String> unprepareStorageClient(StoragePoolType type, String uuid) {
public Pair<Boolean, String> unprepareStorageClient(StoragePoolType type, String uuid, Map<String, String> details) {
StorageAdaptor adaptor = getStorageAdaptor(type);
return adaptor.unprepareStorageClient(type, uuid);
return adaptor.unprepareStorageClient(uuid, details);

Check warning on line 501 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java#L501

Added line #L501 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.UUID;

import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient;
import org.apache.cloudstack.storage.datastore.manager.ScaleIOSDCManager;
import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil;
import org.apache.cloudstack.utils.cryptsetup.CryptSetup;
import org.apache.cloudstack.utils.cryptsetup.CryptSetupException;
Expand Down Expand Up @@ -148,12 +149,37 @@
@Override
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, Storage.StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage) {
ScaleIOStoragePool storagePool = new ScaleIOStoragePool(uuid, host, port, path, type, details, this);
if (details != null && details.containsKey(ScaleIOSDCManager.ConnectOnDemand.key())) {
String connectOnDemand = details.get(ScaleIOSDCManager.ConnectOnDemand.key());

Check warning on line 153 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L153

Added line #L153 was not covered by tests
if (connectOnDemand != null && !Boolean.parseBoolean(connectOnDemand)) {
Ternary<Boolean, Map<String, String>, String> prepareStorageClientStatus = prepareStorageClient(uuid, details);

Check warning on line 155 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L155

Added line #L155 was not covered by tests
if (prepareStorageClientStatus.first()) {
details.putAll(prepareStorageClientStatus.second());

Check warning on line 157 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L157

Added line #L157 was not covered by tests
}
}
}
MapStorageUuidToStoragePool.put(uuid, storagePool);
return storagePool;
}

@Override
public boolean deleteStoragePool(String uuid) {
ScaleIOStoragePool storagePool = (ScaleIOStoragePool) MapStorageUuidToStoragePool.get(uuid);

Check warning on line 167 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L167

Added line #L167 was not covered by tests
if (storagePool != null) {
unprepareStorageClient(uuid, storagePool.getDetails());

Check warning on line 169 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L169

Added line #L169 was not covered by tests
}
return MapStorageUuidToStoragePool.remove(uuid) != null;
}

Check warning on line 172 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L172

Added line #L172 was not covered by tests

@Override
public boolean deleteStoragePool(String uuid, Map<String, String> details) {

Check warning on line 175 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L175

Added line #L175 was not covered by tests
if (details != null && details.containsKey(ScaleIOSDCManager.ConnectOnDemand.key())) {
String connectOnDemand = details.get(ScaleIOSDCManager.ConnectOnDemand.key());

Check warning on line 177 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L177

Added line #L177 was not covered by tests
if (connectOnDemand != null && !Boolean.parseBoolean(connectOnDemand)) {
Pair<Boolean, String> unprepareStorageClientStatus = unprepareStorageClient(uuid, details);

Check warning on line 179 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L179

Added line #L179 was not covered by tests
return MapStorageUuidToStoragePool.remove(uuid) != null && unprepareStorageClientStatus.first();
}
}
return MapStorageUuidToStoragePool.remove(uuid) != null;
}

Expand Down Expand Up @@ -567,7 +593,7 @@
qemu.resize(options, objects, usableSizeBytes);
}

public Ternary<Boolean, Map<String, String>, String> prepareStorageClient(Storage.StoragePoolType type, String uuid, Map<String, String> details) {
public Ternary<Boolean, Map<String, String>, String> prepareStorageClient(String uuid, Map<String, String> details) {
if (!ScaleIOUtil.isSDCServiceInstalled()) {
logger.debug("SDC service not installed on host, preparing the SDC client not possible");
return new Ternary<>(false, null, "SDC service not installed on host");
Expand All @@ -584,14 +610,28 @@
if (!ScaleIOUtil.startSDCService()) {
return new Ternary<>(false, null, "Couldn't start SDC service on host");
}
} else if (!ScaleIOUtil.restartSDCService()) {
return new Ternary<>(false, null, "Couldn't restart SDC service on host");
}

if (details != null && details.containsKey(ScaleIOGatewayClient.STORAGE_POOL_MDMS)) {
// Assuming SDC service is started, add mdms
String mdms = details.get(ScaleIOGatewayClient.STORAGE_POOL_MDMS);
String[] mdmAddresses = mdms.split(",");

Check warning on line 618 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L617-L618

Added lines #L617 - L618 were not covered by tests
if (mdmAddresses.length > 0) {
if (ScaleIOUtil.mdmAdded(mdmAddresses[0])) {
return new Ternary<>(true, getSDCDetails(details), "MDM added, no need to prepare the SDC client");

Check warning on line 621 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L621

Added line #L621 was not covered by tests
}

ScaleIOUtil.addMdms(Arrays.asList(mdmAddresses));

Check warning on line 624 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L624

Added line #L624 was not covered by tests
if (!ScaleIOUtil.mdmAdded(mdmAddresses[0])) {
return new Ternary<>(false, null, "Failed to add MDMs");

Check warning on line 626 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L626

Added line #L626 was not covered by tests
}
}
}

return new Ternary<>( true, getSDCDetails(details), "Prepared client successfully");
}

public Pair<Boolean, String> unprepareStorageClient(Storage.StoragePoolType type, String uuid) {
public Pair<Boolean, String> unprepareStorageClient(String uuid, Map<String, String> details) {
if (!ScaleIOUtil.isSDCServiceInstalled()) {
logger.debug("SDC service not installed on host, no need to unprepare the SDC client");
return new Pair<>(true, "SDC service not installed on host, no need to unprepare the SDC client");
Expand All @@ -602,8 +642,19 @@
return new Pair<>(true, "SDC service not enabled on host, no need to unprepare the SDC client");
}

if (!ScaleIOUtil.stopSDCService()) {
return new Pair<>(false, "Couldn't stop SDC service on host");
if (details != null && details.containsKey(ScaleIOGatewayClient.STORAGE_POOL_MDMS)) {
String mdms = details.get(ScaleIOGatewayClient.STORAGE_POOL_MDMS);
String[] mdmAddresses = mdms.split(",");
if (mdmAddresses.length > 0) {
if (!ScaleIOUtil.mdmAdded(mdmAddresses[0])) {
return new Pair<>(true, "MDM not added, no need to unprepare the SDC client");
}

ScaleIOUtil.removeMdms(Arrays.asList(mdmAddresses));
if (ScaleIOUtil.mdmAdded(mdmAddresses[0])) {
return new Pair<>(false, "Failed to remove MDMs, unable to unprepare the SDC client");
}
}
}

return new Pair<>(true, "Unprepared SDC client successfully");
Expand Down
Loading
Loading