Skip to content
Permalink
Browse files

Issue #140: Report meaningful issue in case instance boot times out

  • Loading branch information...
olivergondza committed Feb 7, 2017
1 parent efcbecc commit 610e0c32933f9b560723feee756b3694a4cd8b0e
@@ -250,6 +250,9 @@ private boolean isOurs(@Nonnull Server server) {
debug("Booting machine");
try {
Server server = _bootAndWaitActive(request, timeout);
if (server == null) {
throw new ActionFailed("Failed to provision the server in time (" + timeout + "ms)");
}
debug("Machine started: " + server.getName());
throwIfFailed(server);
return server;
@@ -32,12 +32,14 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.iterableWithSize;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
@@ -47,6 +49,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.times;
@@ -396,4 +399,25 @@ public void correctMetadataSet() throws Exception {
assertEquals(template.name, m.get(JCloudsSlaveTemplate.OPENSTACK_TEMPLATE_NAME_KEY));
assertEquals(new ServerScope.Node(server.getName()).getValue(), m.get(ServerScope.METADATA_KEY));
}

@Test
public void timeoutProvisioning() throws Exception {
JCloudsCloud c = j.dummyCloud(j.dummySlaveTemplate("label"));
Openstack os = c.getOpenstack();
when(os._bootAndWaitActive(any(ServerCreateBuilder.class), anyInt())).thenReturn(null); // Timeout
when(os.bootAndWaitActive(any(ServerCreateBuilder.class), anyInt())).thenCallRealMethod();

for (NodeProvisioner.PlannedNode pn : c.provision(Label.get("label"), 1)) {
try {
pn.future.get();
fail();
} catch (ExecutionException ex) {
assertThat(ex.getCause(), instanceOf(Openstack.ActionFailed.class));
assertThat(ex.getMessage(), containsString("Failed to provision the server in time"));
}
}

verify(os).bootAndWaitActive(any(ServerCreateBuilder.class), anyInt());
verify(os)._bootAndWaitActive(any(ServerCreateBuilder.class), anyInt());
}
}

0 comments on commit 610e0c3

Please sign in to comment.
You can’t perform that action at this time.