Skip to content
Merged
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 @@ -431,7 +431,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv

protected static final String LOCAL_STORAGE_PATH = "local.storage.path";
protected static final String LOCAL_STORAGE_UUID = "local.storage.uuid";
protected static final String DEFAULT_LOCAL_STORAGE_PATH = "/var/lib/libvirt/images/";
public static final String DEFAULT_LOCAL_STORAGE_PATH = "/var/lib/libvirt/images";

protected List<String> localStoragePaths = new ArrayList<>();
protected List<String> localStorageUUIDs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,78 @@
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.DeleteStoragePoolCommand;
import com.cloud.agent.api.to.StorageFilerTO;
import com.cloud.agent.dao.impl.PropertiesStorage;
import com.cloud.agent.properties.AgentProperties;
import com.cloud.agent.properties.AgentPropertiesFileHandler;
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
import com.cloud.resource.CommandWrapper;
import com.cloud.resource.ResourceWrapper;
import com.cloud.storage.Storage;
import com.cloud.utils.exception.CloudRuntimeException;

import java.util.Arrays;
import java.util.HashMap;
import java.util.stream.Collectors;

@ResourceWrapper(handles = DeleteStoragePoolCommand.class)
public final class LibvirtDeleteStoragePoolCommandWrapper extends CommandWrapper<DeleteStoragePoolCommand, Answer, LibvirtComputingResource> {
@Override
public Answer execute(final DeleteStoragePoolCommand command, final LibvirtComputingResource libvirtComputingResource) {
try {
// if getRemoveDatastore() is true, then we are dealing with managed storage and can skip the delete logic here
if (!command.getRemoveDatastore()) {
final StorageFilerTO pool = command.getPool();
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();

storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid());
handleStoragePoolDeletion(command, libvirtComputingResource);
}

return new Answer(command);
} catch (final CloudRuntimeException e) {
return new Answer(command, false, e.toString());
}
}

private void handleStoragePoolDeletion(final DeleteStoragePoolCommand command, final LibvirtComputingResource libvirtComputingResource) {
final StorageFilerTO pool = command.getPool();
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid());

if (isLocalStorageAndNotHavingDefaultPath(pool, libvirtComputingResource)) {
updateLocalStorageProperties(pool);

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L60

Added line #L60 was not covered by tests
}
}

private boolean isLocalStorageAndNotHavingDefaultPath(final StorageFilerTO pool, final LibvirtComputingResource libvirtComputingResource) {
return Storage.StoragePoolType.Filesystem.equals(pool.getType())
&& !libvirtComputingResource.DEFAULT_LOCAL_STORAGE_PATH.equals(pool.getPath());
}

private void updateLocalStorageProperties(final StorageFilerTO pool) {
String localStoragePath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_PATH);
String localStorageUuid = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_UUID);

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L69-L71

Added lines #L69 - L71 were not covered by tests

String uuidToRemove = pool.getUuid();
String pathToRemove = pool.getPath();

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L73-L74

Added lines #L73 - L74 were not covered by tests

if (localStorageUuid != null && uuidToRemove != null) {
localStorageUuid = Arrays.stream(localStorageUuid.split(","))

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L77

Added line #L77 was not covered by tests
.filter(uuid -> !uuid.equals(uuidToRemove))
.collect(Collectors.joining(","));

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L79

Added line #L79 was not covered by tests
}

if (localStoragePath != null && pathToRemove != null) {
localStoragePath = Arrays.stream(localStoragePath.split(","))

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L83

Added line #L83 was not covered by tests
.filter(path -> !path.equals(pathToRemove))
.collect(Collectors.joining(","));

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L85

Added line #L85 was not covered by tests
}

PropertiesStorage agentProperties = new PropertiesStorage();
agentProperties.configure("AgentProperties", new HashMap<String, Object>());

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L88-L89

Added lines #L88 - L89 were not covered by tests

if (localStorageUuid != null) {
agentProperties.persist(AgentProperties.LOCAL_STORAGE_UUID.getName(), localStorageUuid);

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L92

Added line #L92 was not covered by tests
}

if (localStoragePath != null) {
agentProperties.persist(AgentProperties.LOCAL_STORAGE_PATH.getName(), localStoragePath);

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L96

Added line #L96 was not covered by tests
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java#L98

Added line #L98 was not covered by tests
}
14 changes: 11 additions & 3 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,9 @@
if (!(dc.isLocalStorageEnabled() || useLocalStorageForSystemVM)) {
return null;
}
DataStore store;
DataStore store = null;
DataStoreProvider provider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();

Check warning on line 808 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L806-L808

Added lines #L806 - L808 were not covered by tests
try {
String hostAddress = pInfo.getHost();
if (host.getHypervisorType() == Hypervisor.HypervisorType.VMware) {
Expand All @@ -829,8 +831,6 @@
}
}

DataStoreProvider provider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
if (pool == null) {
Map<String, Object> params = new HashMap<String, Object>();
String name = pInfo.getName() != null ? pInfo.getName() : createLocalStoragePoolName(host, pInfo);
Expand Down Expand Up @@ -860,6 +860,14 @@

} catch (Exception e) {
s_logger.warn("Unable to setup the local storage pool for " + host, e);
try {

Check warning on line 863 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L863

Added line #L863 was not covered by tests
if (store != null) {
s_logger.debug(String.format("Trying to delete storage pool entry if exists %s", store));
lifeCycle.deleteDataStore(store);

Check warning on line 866 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L865-L866

Added lines #L865 - L866 were not covered by tests
}
} catch (Exception ex) {
s_logger.debug(String.format("Failed to clean up local storage pool: %s", ex.getMessage()));
}

Check warning on line 870 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L868-L870

Added lines #L868 - L870 were not covered by tests
throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e);
}

Expand Down
Loading