Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/main/java/hudson/plugins/ec2/ssh/EC2SSHLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.util.OpenSSHPublicKeyUtil;
import org.bouncycastle.crypto.util.PublicKeyFactory;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.services.ec2.model.Instance;
import software.amazon.awssdk.services.ec2.model.InstanceStateName;

public abstract class EC2SSHLauncher extends EC2ComputerLauncher {

Expand Down Expand Up @@ -289,7 +289,7 @@

protected ClientSession connectToSsh(
SshClient client, EC2Computer computer, TaskListener listener, SlaveTemplate template)
throws SdkClientException, InterruptedException {
throws SdkException, InterruptedException {
final EC2AbstractSlave node = computer.getNode();
final long timeout = node == null ? 0L : node.getLaunchTimeoutInMillis();
final long startTime = System.currentTimeMillis();
Expand Down Expand Up @@ -415,8 +415,13 @@
}

protected static String getEC2HostAddress(EC2Computer computer, SlaveTemplate template)
throws InterruptedException {
throws SdkException, InterruptedException {
Instance instance = computer.updateInstanceDescription();
if (instance.state().name() == InstanceStateName.TERMINATED) {

Check warning on line 420 in src/main/java/hudson/plugins/ec2/ssh/EC2SSHLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 420 is only partially covered, one branch is missing
throw SdkException.builder()
.message("Instance " + instance.instanceId() + " is already terminated")
.build();

Check warning on line 423 in src/main/java/hudson/plugins/ec2/ssh/EC2SSHLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 421-423 are not covered by tests
}
ConnectionStrategy strategy = template.connectionStrategy;
return template.isMacAgent()
? EC2HostAddressProvider.mac(instance, strategy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.mockito.MockedStatic;
import software.amazon.awssdk.services.ec2.model.Instance;
import software.amazon.awssdk.services.ec2.model.InstanceState;
import software.amazon.awssdk.services.ec2.model.InstanceStateName;
import software.amazon.awssdk.services.ec2.model.KeyPairInfo;

@WithJenkins
Expand Down Expand Up @@ -248,6 +250,11 @@ private void defineBehaviourCommon() throws Exception {
mockTemplate.connectionStrategy = ConnectionStrategy.PUBLIC_DNS;
when(mockEC2Computer.updateInstanceDescription()).thenReturn(mockInstance);
when(mockInstance.publicDnsName()).thenReturn(mockHost);
when(mockInstance.state())
.thenReturn(InstanceState.builder()
.code(16)
.name(InstanceStateName.RUNNING)
.build());
mockStaticScpClientCreator.when(ScpClientCreator::instance).thenReturn(mockScpClientCreator);
when(mockScpClientCreator.createScpClient(mockClientSession)).thenReturn(mockScpClient);
mockStaticScpClientCreator
Expand Down