Skip to content

Commit

Permalink
JENKINS-75098:Log EC2 errors while calling RunInstances for reserved …
Browse files Browse the repository at this point in the history
…capacity (#1032)

* Log EC2 errors while calling RunInstances for reserved capacity

* Address format violations
  • Loading branch information
sfc-gh-mmansour authored Jan 8, 2025
1 parent 630462d commit 3bc68a3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,12 @@ private List<EC2AbstractSlave> provisionOndemand(
}
}
} else {
newInstances = ec2.runInstances(riRequest).getReservation().getInstances();
try {
newInstances = ec2.runInstances(riRequest).getReservation().getInstances();
} catch (AmazonEC2Exception e) {
logProvisionInfo("Error while trying to run instances for reserved capacity: " + e.getMessage());
throw e;
}
}
// Have to create a new instance

Expand Down
55 changes: 55 additions & 0 deletions src/test/java/hudson/plugins/ec2/SlaveTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,61 @@ public void provisionOnDemandSetsMetadataDefaultOptions() throws Exception {
assertEquals(metadataOptionsRequest.getHttpPutResponseHopLimit(), Integer.valueOf(1));
}

@Test(expected = AmazonEC2Exception.class)
public void provisionOnDemandSetsMetadataDefaultOptionsWithEC2Exception() throws Exception {
SlaveTemplate template = new SlaveTemplate(
TEST_AMI,
TEST_ZONE,
TEST_SPOT_CFG,
TEST_SEC_GROUPS,
TEST_REMOTE_FS,
TEST_INSTANCE_TYPE,
TEST_EBSO,
TEST_LABEL,
Node.Mode.NORMAL,
"",
"bar",
"bbb",
"aaa",
"10",
"fff",
null,
"java",
"-Xmx1g",
false,
"subnet 456",
null,
null,
0,
0,
null,
"",
true,
false,
"",
false,
"",
true,
false,
false,
ConnectionStrategy.PUBLIC_IP,
-1,
Collections.emptyList(),
null,
Tenancy.Default,
EbsEncryptRootVolume.DEFAULT,
null,
true,
null,
true);

AmazonEC2 mockedEC2 = setupTestForProvisioning(template);
when(mockedEC2.runInstances(any(RunInstancesRequest.class)))
.thenThrow(new AmazonEC2Exception("InsufficientInstanceCapacity"));

template.provision(2, EnumSet.noneOf(ProvisionOptions.class));
}

private HtmlForm getConfigForm(EC2Cloud ac) throws IOException, SAXException {
return r.createWebClient().goTo(ac.getUrl() + "configure").getFormByName("config");
}
Expand Down

0 comments on commit 3bc68a3

Please sign in to comment.