From 9bec1a0671fcb33e78accfc670a81f81bb55562e Mon Sep 17 00:00:00 2001 From: Shubham Varshney Date: Thu, 29 Feb 2024 14:52:57 +0530 Subject: [PATCH] [PLAT-12804] UT fixes due to bad merge 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 --- .../yw/common/CloudProviderHelper.java | 36 ++++++++++++------- .../tasks/CloudProviderEditTest.java | 11 ++++++ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/managed/src/main/java/com/yugabyte/yw/common/CloudProviderHelper.java b/managed/src/main/java/com/yugabyte/yw/common/CloudProviderHelper.java index ceb40001b3d5..ca708de095df 100644 --- a/managed/src/main/java/com/yugabyte/yw/common/CloudProviderHelper.java +++ b/managed/src/main/java/com/yugabyte/yw/common/CloudProviderHelper.java @@ -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 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 @@ -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 @@ -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 @@ -1081,16 +1083,26 @@ public void validateImageBundles(Region region, List bundles) { public void validateDefaultImageBundleExistence(List 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"); + } } } } diff --git a/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/CloudProviderEditTest.java b/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/CloudProviderEditTest.java index 730e29eef6cc..368ec873c1dd 100644 --- a/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/CloudProviderEditTest.java +++ b/managed/src/test/java/com/yugabyte/yw/commissioner/tasks/CloudProviderEditTest.java @@ -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 ibs = p.getImageBundles(); + ibs.get(0).setUseAsDefault(false); ibs.add(ib); p.setImageBundles(ibs); UUID taskUUID = doEditProvider(p, false); @@ -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