Skip to content
Merged
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 @@ -17,6 +17,29 @@
package com.cloud.hypervisor.kvm.storage;


import com.cloud.agent.api.to.DiskTO;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.ProvisioningType;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import org.apache.cloudstack.storage.datastore.util.StorPoolUtil;
import org.apache.cloudstack.utils.qemu.QemuImg;
import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
import org.apache.cloudstack.utils.qemu.QemuImgException;
import org.apache.cloudstack.utils.qemu.QemuImgFile;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.libvirt.LibvirtException;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
Expand All @@ -26,19 +49,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import com.cloud.agent.api.to.DiskTO;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.ProvisioningType;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script;
import java.util.UUID;

public class StorPoolStorageAdaptor implements StorageAdaptor {
public static void SP_LOG(String fmt, Object... args) {
Expand Down Expand Up @@ -149,6 +160,10 @@
}

public static boolean attachOrDetachVolume(String command, String type, String volumeUuid) {
if (volumeUuid == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command can be attach and detach only, right? can use bool instead of string, or for define any enum for operation and use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sureshanaparti, yes, there is an option for boolean/enum, but this method is used almost everywhere in the StorPool plug-in (agent's part). I don't think this PR is the place for refactoring

LOGGER.debug("Could not attach volume. The volume ID is null");
return false;

Check warning on line 165 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L164-L165

Added lines #L164 - L165 were not covered by tests
}
final String name = getVolumeNameFromPath(volumeUuid, true);
if (name == null) {
return false;
Expand Down Expand Up @@ -345,11 +360,85 @@
throw new UnsupportedOperationException("A folder cannot be created in this configuration.");
}

public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFilePath, String destTemplatePath,
KVMStoragePool destPool, ImageFormat format, int timeout) {
@Override
public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, String name,
PhysicalDiskFormat format, long size, KVMStoragePool destPool, int timeout, byte[] passphrase) {

Check warning on line 365 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L365

Added line #L365 was not covered by tests
return null;
}

@Override
public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFilePath, String destTemplatePath,
KVMStoragePool destPool, ImageFormat format, int timeout) {

Check warning on line 371 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L371

Added line #L371 was not covered by tests
if (StringUtils.isEmpty(templateFilePath) || destPool == null) {
throw new CloudRuntimeException(

Check warning on line 373 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L373

Added line #L373 was not covered by tests
"Unable to create template from direct download template file due to insufficient data");
}

File sourceFile = new File(templateFilePath);

Check warning on line 377 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L377

Added line #L377 was not covered by tests
if (!sourceFile.exists()) {
throw new CloudRuntimeException(

Check warning on line 379 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L379

Added line #L379 was not covered by tests
"Direct download template file " + templateFilePath + " does not exist on this host");
}

if (!StoragePoolType.StorPool.equals(destPool.getType())) {
throw new CloudRuntimeException("Unsupported storage pool type: " + destPool.getType().toString());

Check warning on line 384 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L384

Added line #L384 was not covered by tests
}

if (!Storage.ImageFormat.QCOW2.equals(format)) {
throw new CloudRuntimeException("Unsupported template format: " + format.toString());

Check warning on line 388 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L388

Added line #L388 was not covered by tests
}

String srcTemplateFilePath = templateFilePath;
KVMPhysicalDisk destDisk = null;
QemuImgFile srcFile = null;
QemuImgFile destFile = null;
String templateName = UUID.randomUUID().toString();
String volume = null;
try {

Check warning on line 397 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L391-L397

Added lines #L391 - L397 were not covered by tests

srcTemplateFilePath = extractTemplate(templateFilePath, sourceFile, srcTemplateFilePath, templateName);

Check warning on line 399 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L399

Added line #L399 was not covered by tests

QemuImg.PhysicalDiskFormat srcFileFormat = QemuImg.PhysicalDiskFormat.QCOW2;

Check warning on line 401 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L401

Added line #L401 was not covered by tests

srcFile = new QemuImgFile(srcTemplateFilePath, srcFileFormat);

Check warning on line 403 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L403

Added line #L403 was not covered by tests

String spTemplate = destPool.getUuid().split(";")[0];

Check warning on line 405 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L405

Added line #L405 was not covered by tests

QemuImg qemu = new QemuImg(timeout);
OutputInterpreter.AllLinesParser parser = createStorPoolVolume(destPool, srcFile, qemu, spTemplate);

Check warning on line 408 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L407-L408

Added lines #L407 - L408 were not covered by tests

String response = parser.getLines();

Check warning on line 410 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L410

Added line #L410 was not covered by tests

LOGGER.debug(response);
volume = StorPoolUtil.devPath(getNameFromResponse(response, false, false));
attachOrDetachVolume("attach", "volume", volume);
destDisk = destPool.getPhysicalDisk(volume);

Check warning on line 415 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L412-L415

Added lines #L412 - L415 were not covered by tests
if (destDisk == null) {
throw new CloudRuntimeException(
"Failed to find the disk: " + volume + " of the storage pool: " + destPool.getUuid());

Check warning on line 418 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L417-L418

Added lines #L417 - L418 were not covered by tests
}

destFile = new QemuImgFile(destDisk.getPath(), QemuImg.PhysicalDiskFormat.RAW);

Check warning on line 421 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L421

Added line #L421 was not covered by tests

qemu.convert(srcFile, destFile);
parser = volumeSnapshot(StorPoolStorageAdaptor.getVolumeNameFromPath(volume, true), spTemplate);
response = parser.getLines();
LOGGER.debug(response);
String newPath = StorPoolUtil.devPath(getNameFromResponse(response, false, true));
destDisk = destPool.getPhysicalDisk(newPath);
} catch (QemuImgException | LibvirtException e) {
destDisk = null;

Check warning on line 430 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L423-L430

Added lines #L423 - L430 were not covered by tests
} finally {
if (volume != null) {
attachOrDetachVolume("detach", "volume", volume);
volumeDelete(StorPoolStorageAdaptor.getVolumeNameFromPath(volume, true));

Check warning on line 434 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L433-L434

Added lines #L433 - L434 were not covered by tests
}
Script.runSimpleBashScript("rm -f " + srcTemplateFilePath);

Check warning on line 436 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L436

Added line #L436 was not covered by tests
}

return destDisk;
}

Check warning on line 440 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L439-L440

Added lines #L439 - L440 were not covered by tests

@Override
public boolean createFolder(String uuid, String path, String localPath) {
return false;
Expand All @@ -367,9 +456,104 @@
return null;
}

@Override
public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, String name,
PhysicalDiskFormat format, long size, KVMStoragePool destPool, int timeout, byte[] passphrase) {
return null;
private OutputInterpreter.AllLinesParser createStorPoolVolume(KVMStoragePool destPool, QemuImgFile srcFile,
QemuImg qemu, String templateUuid) throws QemuImgException, LibvirtException {
Map<String, String> info = qemu.info(srcFile);
Map<String, Object> reqParams = new HashMap<>();
reqParams.put("template", templateUuid);
reqParams.put("size", info.get("virtual_size"));
Map<String, String> tags = new HashMap<>();
tags.put("cs", "template");
reqParams.put("tags", tags);
Gson gson = new Gson();
String js = gson.toJson(reqParams);

Check warning on line 469 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L460-L469

Added lines #L460 - L469 were not covered by tests

Script sc = createStorPoolRequest(js, "VolumeCreate", null,true);
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();

Check warning on line 472 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L471-L472

Added lines #L471 - L472 were not covered by tests

String res = sc.execute(parser);

Check warning on line 474 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L474

Added line #L474 was not covered by tests
if (res != null) {
throw new CloudRuntimeException("Could not create volume due to: " + res);

Check warning on line 476 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L476

Added line #L476 was not covered by tests
}
return parser;
}

Check warning on line 479 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L478-L479

Added lines #L478 - L479 were not covered by tests

private OutputInterpreter.AllLinesParser volumeSnapshot(String volumeName, String templateUuid) {
Map<String, String> reqParams = new HashMap<>();
reqParams.put("template", templateUuid);
Gson gson = new Gson();
String js = gson.toJson(reqParams);

Check warning on line 485 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L481-L485

Added lines #L481 - L485 were not covered by tests

Script sc = createStorPoolRequest(js, "VolumeSnapshot", volumeName,true);
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();

Check warning on line 488 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L487-L488

Added lines #L487 - L488 were not covered by tests

String res = sc.execute(parser);

Check warning on line 490 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L490

Added line #L490 was not covered by tests
if (res != null) {
throw new CloudRuntimeException("Could not snapshot volume due to: " + res);

Check warning on line 492 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L492

Added line #L492 was not covered by tests
}
return parser;
}

Check warning on line 495 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L494-L495

Added lines #L494 - L495 were not covered by tests

private OutputInterpreter.AllLinesParser volumeDelete(String volumeName) {
Script sc = createStorPoolRequest(null, "VolumeDelete", volumeName, false);
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();

Check warning on line 499 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L497-L499

Added lines #L497 - L499 were not covered by tests

String res = sc.execute(parser);

Check warning on line 501 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L501

Added line #L501 was not covered by tests
if (res != null) {
throw new CloudRuntimeException("Could not delete volume due to: " + res);

Check warning on line 503 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L503

Added line #L503 was not covered by tests
}
return parser;
}

Check warning on line 506 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L505-L506

Added lines #L505 - L506 were not covered by tests
@NotNull
private static Script createStorPoolRequest(String js, String apiCall, String param, boolean jsonRequired) {
Script sc = new Script("storpool_req", 0, LOGGER);
sc.add("-P");
sc.add("-M");

Check warning on line 511 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L508-L511

Added lines #L508 - L511 were not covered by tests
if (jsonRequired) {
sc.add("--json");
sc.add(js);

Check warning on line 514 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L513-L514

Added lines #L513 - L514 were not covered by tests
}
sc.add(apiCall);

Check warning on line 516 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L516

Added line #L516 was not covered by tests
if (param != null) {
sc.add(param);

Check warning on line 518 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L518

Added line #L518 was not covered by tests
}
return sc;
}

Check warning on line 521 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L520-L521

Added lines #L520 - L521 were not covered by tests

private String extractTemplate(String templateFilePath, File sourceFile, String srcTemplateFilePath,
String templateName) {

Check warning on line 524 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L524

Added line #L524 was not covered by tests
if (isTemplateExtractable(templateFilePath)) {
srcTemplateFilePath = sourceFile.getParent() + "/" + templateName;
String extractCommand = getExtractCommandForDownloadedFile(templateFilePath, srcTemplateFilePath);
Script.runSimpleBashScript(extractCommand);
Script.runSimpleBashScript("rm -f " + templateFilePath);

Check warning on line 529 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L526-L529

Added lines #L526 - L529 were not covered by tests
}
return srcTemplateFilePath;
}

Check warning on line 532 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L531-L532

Added lines #L531 - L532 were not covered by tests

private boolean isTemplateExtractable(String templatePath) {
String type = Script.runSimpleBashScript("file " + templatePath + " | awk -F' ' '{print $2}'");

Check warning on line 535 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L534-L535

Added lines #L534 - L535 were not covered by tests
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
}

Check warning on line 537 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L537

Added line #L537 was not covered by tests

private String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String templateFile) {

Check warning on line 539 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L539

Added line #L539 was not covered by tests
if (downloadedTemplateFile.endsWith(".zip")) {
return "unzip -p " + downloadedTemplateFile + " | cat > " + templateFile;

Check warning on line 541 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L541

Added line #L541 was not covered by tests
} else if (downloadedTemplateFile.endsWith(".bz2")) {
return "bunzip2 -c " + downloadedTemplateFile + " > " + templateFile;

Check warning on line 543 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L543

Added line #L543 was not covered by tests
} else if (downloadedTemplateFile.endsWith(".gz")) {
return "gunzip -c " + downloadedTemplateFile + " > " + templateFile;

Check warning on line 545 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L545

Added line #L545 was not covered by tests
} else {
throw new CloudRuntimeException("Unable to extract template " + downloadedTemplateFile);

Check warning on line 547 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L547

Added line #L547 was not covered by tests
}
}

Check warning on line 549 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L549

Added line #L549 was not covered by tests

private String getNameFromResponse(String resp, boolean tildeNeeded, boolean isSnapshot) {
JsonParser jsonParser = new JsonParser();
JsonObject respObj = (JsonObject) jsonParser.parse(resp);

Check warning on line 553 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L551-L553

Added lines #L551 - L553 were not covered by tests
JsonPrimitive data = isSnapshot ? respObj.getAsJsonPrimitive("snapshotGlobalId") : respObj.getAsJsonPrimitive("globalId");
String name = data !=null ? data.getAsString() : null;
name = name != null ? name.startsWith("~") && !tildeNeeded ? name.split("~")[1] : name : name;
return name;

Check warning on line 557 in plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java#L557

Added line #L557 was not covered by tests
}
}
Loading