Skip to content

Commit 586f212

Browse files
committed
Swarm tests.
1 parent 5323605 commit 586f212

35 files changed

+334
-88
lines changed

.travis.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ install: true
1212

1313
env:
1414
global:
15+
- CODECOV=true
1516
- DOCKER_TLS_VERIFY=""
1617
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
1718
# via the "travis encrypt" command using the project repo's public key
@@ -21,12 +22,16 @@ env:
2122
- COVERITY_SCAN_NOTIFICATION_EMAIL="kanstantsin.sha@gmail.com"
2223

2324
matrix:
24-
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.12.1-0~trusty" CODECOV=true
25-
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.12.1-0~trusty" CODECOV=true
26-
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.11.2-0~trusty" DEPLOY=true COVERITY=true CODECOV=true
27-
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.11.2-0~trusty" CODECOV=true
28-
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.10.3-0~trusty" CODECOV=true
29-
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.10.3-0~trusty" CODECOV=true
25+
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2377" DOCKER_VERSION="1.13.1-0~ubuntu-trusty" SWARM_VERSION="1.2.5"
26+
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.13.1-0~ubuntu-trusty" DEPLOY=true COVERITY=true
27+
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.13.1-0~ubuntu-trusty"
28+
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2377" DOCKER_VERSION="1.12.6-0~ubuntu-trusty" SWARM_VERSION="1.2.5"
29+
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.12.6-0~ubuntu-trusty"
30+
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.12.6-0~ubuntu-trusty"
31+
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.11.2-0~trusty"
32+
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.11.2-0~trusty"
33+
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.10.3-0~trusty"
34+
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.10.3-0~trusty"
3035
# - repo="testing" DOCKER_HOST="tcp://127.0.0.1:2375"
3136
# - repo="testing" DOCKER_HOST="unix:///var/run/docker.sock"
3237
# - repo="experimental" DOCKER_HOST="tcp://127.0.0.1:2375"
@@ -48,5 +53,5 @@ script:
4853
after_success:
4954
- ./.travis/travis-after-success.sh
5055

51-
after_script:
52-
- sudo cat /var/log/upstart/docker.log
56+
#after_script:
57+
# - sudo cat /var/log/upstart/docker.log

.travis/travis-before-install.sh

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
#!/usr/bin/env bash
22

3+
SWARM_VERSION="${SWARM_VERSION:-}"
4+
FAST_BUILD="${FAST_BUILD:-}"
35

6+
## fix coverity issue
47
sudo apt-get install -y -q ca-certificates
5-
6-
export HOST_PORT=2375
78
echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt
9+
##
810

9-
10-
if [ "$FAST_BUILD" == true ]; then
11+
if [ "$FAST_BUILD" == "true" ]; then
1112
echo "Fast build, skipping docker installations."
1213
exit 0
1314
fi
1415

1516
set -exu
1617

18+
sudo ip a ls
19+
sudo ip r ls
20+
sudo ss -antpl
21+
22+
export HOST_PORT="2375"
23+
export SWARM_PORT="2377"
24+
export HOST_IP="$(ip a show dev eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)"
25+
# because of swarm use docker-engine directly
26+
export PRE_DOCKER_HOST="$DOCKER_HOST"
27+
export DOCKER_HOST="tcp://127.0.0.1:${HOST_PORT}"
28+
29+
1730
docker info
1831
docker version
1932

@@ -89,3 +102,69 @@ registry.email=${registry_email}
89102
registry.url=https://index.docker.io/v1/
90103
91104
EOF
105+
106+
if [[ -n $SWARM_VERSION ]]; then
107+
# export SWARM_PORT="${PRE_DOCKER_HOST##*:}"
108+
109+
docker pull swarm
110+
111+
# # kv store https://docs.docker.com/v1.11/engine/userguide/networking/get-started-overlay/
112+
# docker run -d \
113+
# -p "8500:8500" \
114+
# -h "consul" \
115+
# --name=consul \
116+
# progrium/consul -server -bootstrap
117+
#
118+
# sleep 5
119+
120+
# SWARM_TOKEN=$(docker run swarm c)
121+
122+
# docker run \
123+
# -d \
124+
# --name=swarm_manager \
125+
# -p ${SWARM_PORT}:2375 \
126+
# "swarm:${SWARM_VERSION}" \
127+
# manage token://${SWARM_TOKEN}
128+
129+
docker run \
130+
-d \
131+
-p ${SWARM_PORT}:2375 \
132+
--name=swarm_manager \
133+
swarm manage --engine-refresh-min-interval "3s" --engine-refresh-max-interval "6s" "nodes://${HOST_IP}:${HOST_PORT}"
134+
# swarm manage --engine-refresh-min-interval "3s" --engine-refresh-max-interval "6s" "consul://${HOST_IP}:8500"
135+
136+
# join engine to swarm
137+
docker run \
138+
-d \
139+
"--name=swarm_join" \
140+
"swarm:${SWARM_VERSION}" \
141+
join --advertise="${HOST_IP}:${HOST_PORT}" --delay="0s" --heartbeat "5s" "nodes://${HOST_IP}:${HOST_PORT}"
142+
# join --advertise="${HOST_IP}:${HOST_PORT}" --delay="0s" --heartbeat "5s" "token://${SWARM_TOKEN}"
143+
144+
docker run --rm \
145+
"swarm:${SWARM_VERSION}" list "nodes://${HOST_IP}:${HOST_PORT}"
146+
147+
docker ps -a
148+
sudo ss -antpl
149+
150+
sleep 30
151+
152+
docker logs swarm_join
153+
docker logs swarm_manager
154+
# docker logs consul
155+
156+
# switch to swarm connection
157+
DOCKER_HOST="$PRE_DOCKER_HOST"
158+
159+
docker version
160+
docker info
161+
162+
NODES=$(docker info | grep "Nodes:" | awk '{ print $2 }')
163+
if [[ $NODES -eq "0" ]]; then
164+
echo "Swarm didn't connect"
165+
exit 1
166+
fi
167+
168+
# test via swarm
169+
docker pull busybox
170+
fi

src/main/java/com/github/dockerjava/api/model/PullResponseItem.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class PullResponseItem extends ResponseItem {
1919

2020
private static final String DOWNLOAD_COMPLETE = "Download complete";
2121

22+
private static final String DOWNLOADED_SWARM = ": downloaded";
23+
2224
/**
2325
* Returns whether the status indicates a successful pull operation
2426
*
@@ -30,7 +32,11 @@ public boolean isPullSuccessIndicated() {
3032
return false;
3133
}
3234

33-
return (getStatus().contains(DOWNLOAD_COMPLETE) || getStatus().contains(IMAGE_UP_TO_DATE)
34-
|| getStatus().contains(DOWNLOADED_NEWER_IMAGE) || getStatus().contains(LEGACY_REGISTRY));
35+
return (getStatus().contains(DOWNLOAD_COMPLETE) ||
36+
getStatus().contains(IMAGE_UP_TO_DATE) ||
37+
getStatus().contains(DOWNLOADED_NEWER_IMAGE) ||
38+
getStatus().contains(LEGACY_REGISTRY) ||
39+
getStatus().contains(DOWNLOADED_SWARM)
40+
);
3541
}
3642
}

src/test/java/com/github/dockerjava/core/command/CommitCmdImplTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.core.command;
22

3+
import static com.github.dockerjava.utils.TestUtils.isSwarm;
34
import static org.hamcrest.MatcherAssert.assertThat;
45
import static org.hamcrest.Matchers.equalTo;
56
import static org.hamcrest.Matchers.isEmptyString;
@@ -10,6 +11,7 @@
1011
import java.lang.reflect.Method;
1112

1213
import org.testng.ITestResult;
14+
import org.testng.SkipException;
1315
import org.testng.annotations.AfterMethod;
1416
import org.testng.annotations.AfterTest;
1517
import org.testng.annotations.BeforeMethod;
@@ -47,6 +49,8 @@ public void afterMethod(ITestResult result) {
4749

4850
@Test
4951
public void commit() throws DockerException {
52+
//FIXME swarm
53+
if (isSwarm(dockerClient)) throw new SkipException("FIXME Swarm");
5054

5155
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("touch", "/test").exec();
5256

src/test/java/com/github/dockerjava/core/command/ConnectToNetworkCmdImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.github.dockerjava.api.model.Network;
99
import com.github.dockerjava.client.AbstractDockerClientTest;
1010
import org.testng.ITestResult;
11+
import org.testng.SkipException;
1112
import org.testng.annotations.AfterMethod;
1213
import org.testng.annotations.AfterTest;
1314
import org.testng.annotations.BeforeMethod;
@@ -17,6 +18,7 @@
1718
import java.lang.reflect.Method;
1819
import java.util.Collections;
1920

21+
import static com.github.dockerjava.utils.TestUtils.isSwarm;
2022
import static org.hamcrest.Matchers.hasItem;
2123
import static org.hamcrest.core.Is.is;
2224
import static org.junit.Assert.assertThat;
@@ -46,6 +48,7 @@ public void afterMethod(ITestResult result) {
4648

4749
@Test
4850
public void connectToNetwork() throws InterruptedException {
51+
if (isSwarm(dockerClient)) throw new SkipException("Swarm has no network");
4952

5053
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec();
5154
dockerClient.startContainerCmd(container.getId()).exec();
@@ -65,6 +68,8 @@ public void connectToNetwork() throws InterruptedException {
6568

6669
@Test
6770
public void connectToNetworkWithContainerNetwork() throws InterruptedException {
71+
if (isSwarm(dockerClient)) throw new SkipException("Swarm has no network");
72+
6873
final String NETWORK_SUBNET = "10.100.102.0/24";
6974
final String NETWORK_NAME = "jerseyTestNetwork";
7075
final String CONTAINER_IP = "10.100.102.100";

src/test/java/com/github/dockerjava/core/command/CopyFileFromContainerCmdImplTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.dockerjava.core.command;
22

33
import static com.github.dockerjava.utils.TestUtils.getVersion;
4+
import static com.github.dockerjava.utils.TestUtils.isSwarm;
45
import static org.hamcrest.MatcherAssert.assertThat;
56
import static org.hamcrest.Matchers.isEmptyOrNullString;
67
import static org.hamcrest.Matchers.not;
@@ -50,6 +51,8 @@ public void copyFromContainer() throws Exception {
5051
if (getVersion(dockerClient).isGreaterOrEqual(RemoteApiVersion.VERSION_1_24)) {
5152
throw new SkipException("Doesn't work since 1.24");
5253
}
54+
//FIXME swarm
55+
if (isSwarm(dockerClient)) throw new SkipException("FIXME Swarm");
5356

5457
// TODO extract this into a shared method
5558
CreateContainerResponse container = dockerClient.createContainerCmd("busybox")

src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@
4343

4444
import static com.github.dockerjava.api.model.Capability.MKNOD;
4545
import static com.github.dockerjava.api.model.Capability.NET_ADMIN;
46+
import static com.github.dockerjava.utils.TestUtils.isSwarm;
4647
import static com.github.dockerjava.utils.TestUtils.getVersion;
4748
import static org.hamcrest.MatcherAssert.assertThat;
49+
import static org.hamcrest.Matchers.allOf;
4850
import static org.hamcrest.Matchers.contains;
4951
import static org.hamcrest.Matchers.containsInAnyOrder;
5052
import static org.hamcrest.Matchers.containsString;
5153
import static org.hamcrest.Matchers.equalTo;
54+
import static org.hamcrest.Matchers.hasEntry;
5255
import static org.hamcrest.Matchers.hasItem;
5356
import static org.hamcrest.Matchers.hasItemInArray;
57+
import static org.hamcrest.Matchers.hasItems;
5458
import static org.hamcrest.Matchers.is;
5559
import static org.hamcrest.Matchers.isEmptyString;
5660
import static org.hamcrest.Matchers.not;
@@ -281,6 +285,7 @@ public void createContainerWithLink() throws DockerException {
281285

282286
@Test
283287
public void createContainerWithLinkInCustomNetwork() throws DockerException {
288+
if (isSwarm(dockerClient)) throw new SkipException("Swarm has no network");
284289

285290
CreateNetworkResponse createNetworkResponse = dockerClient.createNetworkCmd()
286291
.withName("linkNet")
@@ -318,11 +323,12 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException {
318323

319324
ContainerNetwork linkNet = inspectContainerResponse2.getNetworkSettings().getNetworks().get("linkNet");
320325
assertNotNull(linkNet);
321-
ArrayAsserts.assertArrayEquals(new Link[]{ new Link("container1", "container1Link")}, linkNet.getLinks());
326+
ArrayAsserts.assertArrayEquals(new Link[]{new Link("container1", "container1Link")}, linkNet.getLinks());
322327
}
323328

324329
@Test
325330
public void createContainerWithCustomIp() throws DockerException {
331+
if (isSwarm(dockerClient)) throw new SkipException("Swarm has no network");
326332

327333
CreateNetworkResponse createNetworkResponse = dockerClient.createNetworkCmd()
328334
.withIpam(new Network.Ipam()
@@ -355,6 +361,7 @@ public void createContainerWithCustomIp() throws DockerException {
355361

356362
@Test
357363
public void createContainerWithAlias() throws DockerException {
364+
if (isSwarm(dockerClient)) throw new SkipException("Swarm has no network");
358365

359366
CreateNetworkResponse createNetworkResponse = dockerClient.createNetworkCmd()
360367
.withName("aliasNet")
@@ -653,7 +660,12 @@ public void createContainerWithLabels() throws DockerException {
653660

654661
// null becomes empty string
655662
labels.put("com.github.dockerjava.null", "");
656-
assertThat(inspectContainerResponse.getConfig().getLabels(), is(equalTo(labels)));
663+
664+
// swarm adds 3d label
665+
assertThat(inspectContainerResponse.getConfig().getLabels(), allOf(
666+
hasEntry("com.github.dockerjava.null", ""),
667+
hasEntry("com.github.dockerjava.Boolean", "true")
668+
));
657669
}
658670

659671
@Test(groups = "ignoreInCircleCi")
@@ -745,7 +757,7 @@ public void createContainerWithCgroupParent() throws DockerException {
745757
public void createContainerWithShmSize() throws DockerException {
746758
HostConfig hostConfig = new HostConfig().withShmSize(96 * FileUtils.ONE_MB);
747759
CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE)
748-
.withHostConfig(hostConfig).withCmd("true").exec();
760+
.withHostConfig(hostConfig).withCmd("true").exec();
749761

750762
LOG.info("Created container {}", container.toString());
751763

src/test/java/com/github/dockerjava/core/command/CreateNetworkCmdImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.github.dockerjava.api.model.Network;
66
import com.github.dockerjava.client.AbstractDockerClientTest;
77
import org.testng.ITestResult;
8+
import org.testng.SkipException;
89
import org.testng.annotations.AfterMethod;
910
import org.testng.annotations.AfterTest;
1011
import org.testng.annotations.BeforeMethod;
@@ -13,6 +14,8 @@
1314

1415
import java.lang.reflect.Method;
1516

17+
import static com.github.dockerjava.utils.TestUtils.isSwarm;
18+
1619
@Test(groups = "integration")
1720
public class CreateNetworkCmdImplTest extends AbstractDockerClientTest {
1821

@@ -38,6 +41,7 @@ public void afterMethod(ITestResult result) {
3841

3942
@Test
4043
public void createNetwork() throws DockerException {
44+
if (isSwarm(dockerClient)) throw new SkipException("Swarm has no network");
4145

4246
String networkName = "testNetwork";
4347

@@ -52,6 +56,7 @@ public void createNetwork() throws DockerException {
5256

5357
@Test
5458
public void createNetworkWithIpamConfig() throws DockerException {
59+
if (isSwarm(dockerClient)) throw new SkipException("Swarm has no network");
5560

5661
String networkName = "testNetwork";
5762
Network.Ipam ipam = new Network.Ipam().withConfig(new Network.Ipam.Config().withSubnet("10.67.79.0/24"));

src/test/java/com/github/dockerjava/core/command/DisconnectFromNetworkCmdImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.github.dockerjava.api.model.Network;
66
import com.github.dockerjava.client.AbstractDockerClientTest;
77
import org.testng.ITestResult;
8+
import org.testng.SkipException;
89
import org.testng.annotations.AfterMethod;
910
import org.testng.annotations.AfterTest;
1011
import org.testng.annotations.BeforeMethod;
@@ -13,6 +14,8 @@
1314

1415
import java.lang.reflect.Method;
1516

17+
import static com.github.dockerjava.utils.TestUtils.isSwarm;
18+
1619
@Test(groups = "integration")
1720
public class DisconnectFromNetworkCmdImplTest extends AbstractDockerClientTest {
1821

@@ -38,6 +41,7 @@ public void afterMethod(ITestResult result) {
3841

3942
@Test
4043
public void disconnectFromNetwork() throws InterruptedException {
44+
if (isSwarm(dockerClient)) throw new SkipException("Swarm has no network");
4145

4246
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec();
4347
dockerClient.startContainerCmd(container.getId()).exec();
@@ -59,6 +63,7 @@ public void disconnectFromNetwork() throws InterruptedException {
5963

6064
@Test
6165
public void forceDisconnectFromNetwork() throws InterruptedException {
66+
if (isSwarm(dockerClient)) throw new SkipException("Swarm has no network");
6267

6368
CreateNetworkResponse network = dockerClient.createNetworkCmd().withName("testNetwork").exec();
6469

0 commit comments

Comments
 (0)