Skip to content

Commit 0003b96

Browse files
committed
add tests
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 8475604 commit 0003b96

File tree

3 files changed

+421
-13
lines changed

3 files changed

+421
-13
lines changed

api/src/main/java/com/cloud/cpu/CPU.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public enum CPUArch {
3232
this.bits = bits;
3333
}
3434

35+
public static CPUArch getDefault() {
36+
return amd64;
37+
}
38+
3539
public String getType() {
3640
return type;
3741
}
@@ -42,7 +46,7 @@ public int getBits() {
4246

4347
public static CPUArch fromType(String type) {
4448
if (StringUtils.isBlank(type)) {
45-
return amd64; // Default architecture
49+
return getDefault();
4650
}
4751
for (CPUArch arch : values()) {
4852
if (arch.type.equals(type)) {

engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class SystemVmTemplateRegistration {
9797
private static final String ABSOLUTE_TEMPLATE_PATH = "/usr/share/cloudstack-management/templates/systemvm/";
9898
private static final String TEMPLATES_PATH = fetchTemplatesPath();
9999
private static final String METADATA_FILE_NAME = "metadata.ini";
100-
private static final String METADATA_FILE = TEMPLATES_PATH + METADATA_FILE_NAME;
100+
protected static final String METADATA_FILE = TEMPLATES_PATH + METADATA_FILE_NAME;
101101
public static final String TEMPORARY_SECONDARY_STORE = "tmp";
102102
private static final String PARTIAL_TEMPLATE_FOLDER = String.format("/template/tmpl/%d/", Account.ACCOUNT_ID_SYSTEM);
103103
private static final String storageScriptsDir = "scripts/storage/secondary";
@@ -106,7 +106,7 @@ public class SystemVmTemplateRegistration {
106106
private static final Integer LINUX_7_ID = 183;
107107
private static final Integer SCRIPT_TIMEOUT = 1800000;
108108
private static final Integer LOCK_WAIT_TIMEOUT = 1200;
109-
private static final List<CPU.CPUArch> DOWNLOADABLE_TEMPLATE_ARCH_TYPES = Arrays.asList(
109+
protected static final List<CPU.CPUArch> DOWNLOADABLE_TEMPLATE_ARCH_TYPES = Arrays.asList(
110110
CPU.CPUArch.arm64
111111
);
112112

@@ -173,6 +173,10 @@ public String getSystemVmTemplateVersion() {
173173
return systemVmTemplateVersion;
174174
}
175175

176+
public File getTempDownloadDir() {
177+
return tempDownloadDir;
178+
}
179+
176180
private static class SystemVMTemplateDetails {
177181
Long id;
178182
String uuid;
@@ -391,15 +395,15 @@ private static String getHypervisorArchLog(Hypervisor.HypervisorType hypervisorT
391395
return sb.toString();
392396
}
393397

394-
private static String getHypervisorArchKey(Hypervisor.HypervisorType hypervisorType, CPU.CPUArch arch) {
398+
protected static String getHypervisorArchKey(Hypervisor.HypervisorType hypervisorType, CPU.CPUArch arch) {
395399
if (Hypervisor.HypervisorType.KVM.equals(hypervisorType)) {
396400
return String.format("%s-%s", hypervisorType.name().toLowerCase(),
397401
arch == null ? CPU.CPUArch.amd64.getType() : arch.getType());
398402
}
399403
return hypervisorType.name().toLowerCase();
400404
}
401405

402-
private static MetadataTemplateDetails getMetadataTemplateDetails(Hypervisor.HypervisorType hypervisorType,
406+
protected static MetadataTemplateDetails getMetadataTemplateDetails(Hypervisor.HypervisorType hypervisorType,
403407
CPU.CPUArch arch) {
404408
return NewTemplateMap.get(getHypervisorArchKey(hypervisorType, arch));
405409
}
@@ -441,7 +445,7 @@ private List<Long> getEligibleZoneIds() {
441445
return zoneIds;
442446
}
443447

444-
private Pair<String, Long> getNfsStoreInZone(Long zoneId) {
448+
protected Pair<String, Long> getNfsStoreInZone(Long zoneId) {
445449
ImageStoreVO storeVO = imageStoreDao.findOneByZoneAndProtocol(zoneId, "nfs");
446450
if (storeVO == null) {
447451
String errMsg = String.format("Failed to fetch NFS store in zone = %s for SystemVM template registration",
@@ -456,12 +460,13 @@ private Pair<String, Long> getNfsStoreInZone(Long zoneId) {
456460

457461
public static void mountStore(String storeUrl, String path, String nfsVersion) {
458462
try {
459-
if (storeUrl != null) {
460-
URI uri = new URI(UriUtils.encodeURIComponent(storeUrl));
461-
String host = uri.getHost();
462-
String mountPath = uri.getPath();
463-
Script.runSimpleBashScript(getMountCommand(nfsVersion, host + ":" + mountPath, path));
463+
if (storeUrl == null) {
464+
return;
464465
}
466+
URI uri = new URI(UriUtils.encodeURIComponent(storeUrl));
467+
String host = uri.getHost();
468+
String mountPath = uri.getPath();
469+
Script.runSimpleBashScript(getMountCommand(nfsVersion, host + ":" + mountPath, path));
465470
} catch (Exception e) {
466471
String msg = "NFS Store URL is not in the correct format";
467472
LOGGER.error(msg, e);
@@ -783,7 +788,7 @@ public static String parseMetadataFile() {
783788
hypervisorType.second()));
784789
}
785790
Ini.Section defaultSection = ini.get("default");
786-
return defaultSection.get("version");
791+
return defaultSection.get("version").trim();
787792
}
788793

789794

@@ -830,7 +835,7 @@ protected boolean isTemplateFileChecksumDifferent(MetadataTemplateDetails templa
830835
return false;
831836
}
832837

833-
private void validateTemplates(List<Pair<Hypervisor.HypervisorType, CPU.CPUArch>> hypervisorsArchInUse) {
838+
protected void validateTemplates(List<Pair<Hypervisor.HypervisorType, CPU.CPUArch>> hypervisorsArchInUse) {
834839
boolean templatesFound = true;
835840
for (Pair<Hypervisor.HypervisorType, CPU.CPUArch> hypervisorArch : hypervisorsArchInUse) {
836841
MetadataTemplateDetails matchedTemplate = getMetadataTemplateDetails(hypervisorArch.first(),

0 commit comments

Comments
 (0)