Skip to content

Commit

Permalink
#6919: Fix crashing onprem provider page due to missing instance type…
Browse files Browse the repository at this point in the history
… details

Summary:
Fixed regression where the `InstanceTypesController.get` method will not return the
`instance_type_details_json` for onprem providers, which will cause the UI to crash.

Test Plan:
Create onprem provider and check if page loads.
Create AWS provider and check if page loads.

sbt "test-only com.yugabyte.yw.models.InstanceTypeTest"

Reviewers: sb-yb, arnav, daniel, spotachev

Reviewed By: spotachev

Subscribers: jenkins-bot, yugaware

Differential Revision: https://phabricator.dev.yugabyte.com/D10391
  • Loading branch information
WesleyW committed Jan 19, 2021
1 parent 47122ef commit 11d08f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ public static List<InstanceType> findByProvider(Provider provider, Config config
.eq("active", true)
.findList();
if (provider.code.equals("aws")) {
entries = populateDefaultsIfEmpty(entries, config);
return populateDefaultsIfEmpty(entries, config);
} else {
return entries.stream().map(entry -> InstanceType.get(entry.getProviderCode(),
entry.getInstanceTypeCode())).collect(Collectors.toList());
}

return entries;
}

public static InstanceType createWithMetadata(Provider provider, String instanceTypeCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@RunWith(MockitoJUnitRunner.class)
public class InstanceTypeTest extends FakeDBApplication {
private Provider defaultProvider;
private Provider onpremProvider;
private Customer defaultCustomer;
private InstanceType.InstanceTypeDetails defaultDetails;

Expand All @@ -42,6 +43,7 @@ public class InstanceTypeTest extends FakeDBApplication {
public void setUp() {
defaultCustomer = ModelFactory.testCustomer();
defaultProvider = ModelFactory.awsProvider(defaultCustomer);
onpremProvider = ModelFactory.onpremProvider(defaultCustomer);
InstanceType.VolumeDetails volumeDetails = new InstanceType.VolumeDetails();
volumeDetails.volumeSizeGB = 100;
volumeDetails.volumeType = InstanceType.VolumeType.EBS;
Expand Down Expand Up @@ -107,9 +109,23 @@ public void testFindByProvider() {
possibleTypes.add("c3.large");
for (InstanceType it : instanceTypeList) {
assertTrue(possibleTypes.contains(it.getInstanceTypeCode()));
assertNotNull(it.instanceTypeDetails);
}
}

@Test
public void testFindByProviderOnprem() {
Provider newProvider = ModelFactory.onpremProvider(defaultCustomer);
InstanceType.upsert(newProvider.code, "bar", 2, 10.0, defaultDetails);
List<InstanceType> instanceTypeList = InstanceType.findByProvider(newProvider, mockConfig);
assertEquals(1, instanceTypeList.size());

InstanceType it = instanceTypeList.get(0);
assertTrue(it.getInstanceTypeCode().equals("bar"));
assertNotNull(it.instanceTypeDetails);
}


@Test
public void testFindByProviderWithUnSupportedInstances() {
InstanceType.upsert(defaultProvider.code, "t2.medium", 3, 10.0, defaultDetails);
Expand Down Expand Up @@ -139,7 +155,7 @@ public void testFindByProviderWithEmptyInstanceTypeDetails() {
assertEquals(250, volumeDetails.volumeSizeGB.intValue());
assertEquals(InstanceType.VolumeType.EBS, volumeDetails.volumeType);
assertEquals(String.format("/mnt/d%d", 0), volumeDetails.mountPath);
assertThat(instanceTypeList.get(0).getInstanceTypeDetails().getVolumeDetailsList().size(),
assertThat(instanceTypeList.get(0).instanceTypeDetails.volumeDetailsList.size(),
allOf(notNullValue(), equalTo(1)));
}

Expand Down

0 comments on commit 11d08f6

Please sign in to comment.