Skip to content

Commit

Permalink
[PLAT-12804] UT fixes due to bad merge
Browse files Browse the repository at this point in the history
Summary:
There was a bad merge during merge for https://phorge.dev.yugabyte.com/D32562, that caused the UTs to started
failing. This diff fixes the same.

Test Plan: UT pipeline

Reviewers: anijhawan, muthu

Reviewed By: anijhawan

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D32743
  • Loading branch information
Vars-07 committed Feb 29, 2024
1 parent 3b5b4f6 commit 9bec1a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,10 @@ public void validateEditProvider(
if (!confGetter.getGlobalConf(GlobalConfKeys.allowUsedProviderEdit) && universeCount > 0) {
validateProviderEditPayload(provider, editProviderReq);
}
boolean enableVMOSPatching = confGetter.getGlobalConf(GlobalConfKeys.enableVMOSPatching);
if (enableVMOSPatching) {
validateDefaultImageBundleExistence(editProviderReq.getImageBundles());
}
Set<Region> regionsToAdd = checkIfRegionsToAdd(editProviderReq, provider);
// Validate regions to add. We only support providing custom VPCs for now.
// So the user must have entered the VPC Info for the regions, as well as
Expand All @@ -992,7 +996,6 @@ public void validateEditProvider(
editProviderReq.getImageBundles().stream()
.filter(iB -> iB.getMetadata().getType() != ImageBundleType.YBA_ACTIVE)
.collect(Collectors.toList());
boolean enableVMOSPatching = confGetter.getGlobalConf(GlobalConfKeys.enableVMOSPatching);
for (Region region : regionsToAdd) {
if (region.getZones() != null || !region.getZones().isEmpty()) {
region
Expand All @@ -1015,7 +1018,6 @@ public void validateEditProvider(
}
}
}
validateDefaultImageBundleExistence(editProviderReq.getImageBundles());
// TODO: Remove this code once the validators are added for all cloud provider.
CloudAPI cloudAPI = cloudAPIFactory.get(provider.getCode());
if (cloudAPI != null
Expand Down Expand Up @@ -1081,16 +1083,26 @@ public void validateImageBundles(Region region, List<ImageBundle> bundles) {

public void validateDefaultImageBundleExistence(List<ImageBundle> bundles) {
// Check if there is at least one active default bundle for a architecture
for (Architecture arch : Architecture.values()) {
if (bundles.stream()
.noneMatch(
bundle ->
bundle.getDetails().getArch().equals(arch)
&& bundle.getActive()
&& bundle.getUseAsDefault())) {
throw new PlatformServiceException(
BAD_REQUEST,
"One of the image bundles should be default for the " + arch.name() + " architecture");
if (bundles.size() > 0) {
for (Architecture arch : Architecture.values()) {
boolean hasBundleForArch =
bundles.stream().anyMatch(bundle -> bundle.getDetails().getArch().equals(arch));
boolean hasOneDefaultBundle =
bundles.stream()
.filter(
bundle ->
bundle.getDetails().getArch().equals(arch)
&& bundle.getActive()
&& bundle.getUseAsDefault())
.count()
== 1;
if (hasBundleForArch && !hasOneDefaultBundle) {
throw new PlatformServiceException(
BAD_REQUEST,
"There should be exactly one default image bundle for the "
+ arch.name()
+ " architecture");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,11 @@ public void testImageBundleEditProvider() throws InterruptedException {
ImageBundle ib = new ImageBundle();
ib.setName("ib-2");
ib.setProvider(p);
ib.setUseAsDefault(true);
ib.setDetails(details);

List<ImageBundle> ibs = p.getImageBundles();
ibs.get(0).setUseAsDefault(false);
ibs.add(ib);
p.setImageBundles(ibs);
UUID taskUUID = doEditProvider(p, false);
Expand All @@ -816,6 +818,15 @@ public void testImageBundleEditProvider() throws InterruptedException {

p = Provider.getOrBadRequest(p.getUuid());
assertEquals(2, p.getImageBundles().size());
p.getImageBundles()
.forEach(
bundle -> {
if (bundle.getName().equals("ib-1")) {
assertEquals(false, bundle.getUseAsDefault());
} else {
assertEquals(true, bundle.getUseAsDefault());
}
});
}

@Test
Expand Down

0 comments on commit 9bec1a0

Please sign in to comment.