mirror of https://github.com/apache/jclouds.git
[JCLOUDS-1157] fix networks in DockerComputeServiceAdapterLiveTest
This commit is contained in:
parent
58e11d42d1
commit
c4605a32d4
|
@ -46,6 +46,7 @@ import org.jclouds.docker.compute.strategy.DockerComputeServiceAdapter;
|
||||||
import org.jclouds.docker.domain.Container;
|
import org.jclouds.docker.domain.Container;
|
||||||
import org.jclouds.docker.domain.Image;
|
import org.jclouds.docker.domain.Image;
|
||||||
import org.jclouds.docker.domain.Network;
|
import org.jclouds.docker.domain.Network;
|
||||||
|
import org.jclouds.docker.features.NetworkApi;
|
||||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||||
|
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "DockerComputeServiceAdapterLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "DockerComputeServiceAdapterLiveTest")
|
||||||
|
@ -67,8 +68,8 @@ public class DockerComputeServiceAdapterLiveTest extends BaseDockerApiLiveTest {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
String imageName = SSHABLE_IMAGE + ":" + SSHABLE_IMAGE_TAG;
|
String imageName = SSHABLE_IMAGE + ":" + SSHABLE_IMAGE_TAG;
|
||||||
defaultImage = adapter.getImage(imageName);
|
defaultImage = adapter.getImage(imageName);
|
||||||
network1 = api.getNetworkApi().createNetwork(Network.builder().name("network1").driver("overlay").build());
|
network1 = createAndInspectNetwork("network1");
|
||||||
network2 = api.getNetworkApi().createNetwork(Network.builder().name("network2").driver("overlay").build());
|
network2 = createAndInspectNetwork("network2");
|
||||||
assertNotNull(defaultImage);
|
assertNotNull(defaultImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,47 +117,60 @@ public class DockerComputeServiceAdapterLiveTest extends BaseDockerApiLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetImageNotHiddenByCache() {
|
public void testGetImageNotHiddenByCache() {
|
||||||
//Ensure image to be tested is unknown to jclouds and docker and that cache is warm
|
// Ensure image to be tested is unknown to jclouds and docker and that
|
||||||
|
// cache is warm
|
||||||
assertNull(findImageFromListImages(CHUANWEN_COWSAY));
|
assertNull(findImageFromListImages(CHUANWEN_COWSAY));
|
||||||
assertNull(api.getImageApi().inspectImage(CHUANWEN_COWSAY));
|
assertNull(api.getImageApi().inspectImage(CHUANWEN_COWSAY));
|
||||||
|
|
||||||
// Get new image
|
// Get new image
|
||||||
adapter.getImage(CHUANWEN_COWSAY);
|
adapter.getImage(CHUANWEN_COWSAY);
|
||||||
|
|
||||||
assertNotNull(findImageFromListImages(CHUANWEN_COWSAY), "New image is not available from listImages presumably due to caching");
|
assertNotNull(findImageFromListImages(CHUANWEN_COWSAY),
|
||||||
|
"New image is not available from listImages presumably due to caching");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateNodeWithMultipleNetworks() {
|
public void testCreateNodeWithMultipleNetworks() {
|
||||||
String name = "container" + new Random().nextInt();
|
String name = "container" + new Random().nextInt();
|
||||||
Template template = templateBuilder.imageId(defaultImage.id()).build();
|
Template template = templateBuilder.imageId(defaultImage.id()).build();
|
||||||
DockerTemplateOptions options = template.getOptions().as(DockerTemplateOptions.class);
|
DockerTemplateOptions options = template.getOptions().as(DockerTemplateOptions.class);
|
||||||
options.env(ImmutableList.of("ROOT_PASSWORD=password"));
|
options.env(ImmutableList.of("ROOT_PASSWORD=password"));
|
||||||
options.networkMode("bridge");
|
options.networkMode("bridge");
|
||||||
options.networks(network1.name(), network2.name());
|
options.networks(network1.name(), network2.name());
|
||||||
guest = adapter.createNodeWithGroupEncodedIntoName("test", name, template);
|
guest = adapter.createNodeWithGroupEncodedIntoName("test", name, template);
|
||||||
|
|
||||||
assertTrue(guest.getNode().networkSettings().networks().containsKey("network1"));
|
assertTrue(guest.getNode().networkSettings().networks().containsKey("network1"));
|
||||||
assertTrue(guest.getNode().networkSettings().networks().containsKey("network2"));
|
assertTrue(guest.getNode().networkSettings().networks().containsKey("network2"));
|
||||||
assertEquals(guest.getNode().networkSettings().secondaryIPAddresses().size(), 2);
|
assertEquals(guest.getNode().networkSettings().networks().size(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Image findImageFromListImages(final String image) {
|
private Image findImageFromListImages(final String image) {
|
||||||
return Iterables.find(adapter.listImages(), new Predicate<Image>() {
|
return Iterables.find(adapter.listImages(), new Predicate<Image>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
for (String tag : input.repoTags()) {
|
for (String tag : input.repoTags()) {
|
||||||
if (tag.equals(image) || tag.equals(CHUANWEN_COWSAY + ":latest")) {
|
if (tag.equals(image) || tag.equals(CHUANWEN_COWSAY + ":latest")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Iterable<Module> setupModules() {
|
protected Iterable<Module> setupModules() {
|
||||||
return ImmutableSet.<Module>of(getLoggingModule(), new SshjSshClientModule());
|
return ImmutableSet.<Module> of(getLoggingModule(), new SshjSshClientModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates network (driver="bridge") with given name and then inspects it to
|
||||||
|
* fully populate the returned {@link Network} object.
|
||||||
|
*
|
||||||
|
* @param networkName
|
||||||
|
*/
|
||||||
|
private Network createAndInspectNetwork(final String networkName) {
|
||||||
|
final NetworkApi networkApi = api.getNetworkApi();
|
||||||
|
Network network = networkApi.createNetwork(Network.builder().name(networkName).driver("bridge").build());
|
||||||
|
return networkApi.inspectNetwork(network.id());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue