Browse code

Merge pull request #9741 from tianon/test-docker-py

Add docker-py integration tests aginst the docker daemon

Alexander Morozov authored on 2014/12/20 04:57:35
Showing 7 changed files
... ...
@@ -42,6 +42,9 @@ RUN	apt-get update && apt-get install -y \
42 42
 	lxc=1.0* \
43 43
 	mercurial \
44 44
 	parallel \
45
+	python-mock \
46
+	python-pip \
47
+	python-websocket \
45 48
 	reprepro \
46 49
 	ruby1.9.1 \
47 50
 	ruby1.9.1-dev \
... ...
@@ -93,6 +96,9 @@ RUN	git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.gi
93 93
 # Get the "cirros" image source so we can import it instead of fetching it during tests
94 94
 RUN	curl -sSL -o /cirros.tar.gz https://github.com/ewindisch/docker-cirros/raw/1cded459668e8b9dbf4ef976c94c05add9bbd8e9/cirros-0.3.0-x86_64-lxc.tar.gz
95 95
 
96
+# Get the "docker-py" source so we can run their integration tests
97
+RUN	git clone -b 0.7.0 https://github.com/docker/docker-py.git /docker-py
98
+
96 99
 # Setup s3cmd config
97 100
 RUN	/bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEY' > $HOME/.s3cfg
98 101
 
... ...
@@ -1,4 +1,4 @@
1
-.PHONY: all binary build cross default docs docs-build docs-shell shell test test-unit test-integration test-integration-cli validate
1
+.PHONY: all binary build cross default docs docs-build docs-shell shell test test-unit test-integration test-integration-cli test-docker-py validate
2 2
 
3 3
 # env vars passed through directly to Docker's build scripts
4 4
 # to allow things like `make DOCKER_CLIENTONLY=1 binary` easily
... ...
@@ -59,7 +59,7 @@ docs-test: docs-build
59 59
 	$(DOCKER_RUN_DOCS) "$(DOCKER_DOCS_IMAGE)" ./test.sh
60 60
 
61 61
 test: build
62
-	$(DOCKER_RUN_DOCKER) hack/make.sh binary cross test-unit test-integration test-integration-cli
62
+	$(DOCKER_RUN_DOCKER) hack/make.sh binary cross test-unit test-integration test-integration-cli test-docker-py
63 63
 
64 64
 test-unit: build
65 65
 	$(DOCKER_RUN_DOCKER) hack/make.sh test-unit
... ...
@@ -70,6 +70,9 @@ test-integration: build
70 70
 test-integration-cli: build
71 71
 	$(DOCKER_RUN_DOCKER) hack/make.sh binary test-integration-cli
72 72
 
73
+test-docker-py: build
74
+	$(DOCKER_RUN_DOCKER) hack/make.sh binary test-docker-py
75
+
73 76
 validate: build
74 77
 	$(DOCKER_RUN_DOCKER) hack/make.sh validate-gofmt validate-dco
75 78
 
... ...
@@ -50,6 +50,7 @@ DEFAULT_BUNDLES=(
50 50
 	test-unit
51 51
 	test-integration
52 52
 	test-integration-cli
53
+	test-docker-py
53 54
 
54 55
 	dynbinary
55 56
 	dyntest-unit
56 57
new file mode 100644
... ...
@@ -0,0 +1,24 @@
0
+#!/bin/bash
1
+
2
+# see test-integration-cli for example usage of this script
3
+
4
+export PATH="$DEST/../binary:$DEST/../dynbinary:$PATH"
5
+
6
+if ! command -v docker &> /dev/null; then
7
+	echo >&2 'error: binary or dynbinary must be run before .integration-daemon-start'
8
+	false
9
+fi
10
+
11
+# intentionally open a couple bogus file descriptors to help test that they get scrubbed in containers
12
+exec 41>&1 42>&2
13
+
14
+DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs}
15
+DOCKER_EXECDRIVER=${DOCKER_EXECDRIVER:-native}
16
+
17
+( set -x; exec \
18
+	docker --daemon --debug \
19
+	--storage-driver "$DOCKER_GRAPHDRIVER" \
20
+	--exec-driver "$DOCKER_EXECDRIVER" \
21
+	--pidfile "$DEST/docker.pid" \
22
+		&> "$DEST/docker.log"
23
+) &
0 24
new file mode 100644
... ...
@@ -0,0 +1,7 @@
0
+#!/bin/bash
1
+
2
+for pid in $(find "$DEST" -name docker.pid); do
3
+	DOCKER_PID=$(set -x; cat "$pid")
4
+	( set -x; kill $DOCKER_PID )
5
+	wait $DOCKERD_PID || true
6
+done
0 7
new file mode 100644
... ...
@@ -0,0 +1,22 @@
0
+#!/bin/bash
1
+set -e
2
+
3
+DEST=$1
4
+
5
+# subshell so that we can export PATH without breaking other things
6
+exec > >(tee -a $DEST/test.log) 2>&1
7
+(
8
+	source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
9
+
10
+	dockerPy='/docker-py'
11
+	[ -d "$dockerPy" ] || {
12
+		dockerPy="$DEST/docker-py"
13
+		git clone https://github.com/docker/docker-py.git "$dockerPy"
14
+	}
15
+
16
+	cd "$dockerPy"
17
+	export PYTHONPATH=. # import "docker" from "."
18
+	python tests/integration_test.py
19
+
20
+	source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
21
+)
... ...
@@ -3,9 +3,6 @@ set -e
3 3
 
4 4
 DEST=$1
5 5
 
6
-DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs}
7
-DOCKER_EXECDRIVER=${DOCKER_EXECDRIVER:-native}
8
-
9 6
 bundle_test_integration_cli() {
10 7
 	go_test_dir ./integration-cli
11 8
 }
... ...
@@ -13,23 +10,7 @@ bundle_test_integration_cli() {
13 13
 # subshell so that we can export PATH without breaking other things
14 14
 exec > >(tee -a $DEST/test.log) 2>&1
15 15
 (
16
-	export PATH="$DEST/../binary:$DEST/../dynbinary:$PATH"
17
-
18
-	if ! command -v docker &> /dev/null; then
19
-		echo >&2 'error: binary or dynbinary must be run before test-integration-cli'
20
-		false
21
-	fi
22
-
23
-	# intentionally open a couple bogus file descriptors to help test that they get scrubbed in containers
24
-	exec 41>&1 42>&2
25
-
26
-	( set -x; exec \
27
-		docker --daemon --debug \
28
-		--storage-driver "$DOCKER_GRAPHDRIVER" \
29
-		--exec-driver "$DOCKER_EXECDRIVER" \
30
-		--pidfile "$DEST/docker.pid" \
31
-			&> "$DEST/docker.log"
32
-	) &
16
+	source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
33 17
 
34 18
 	# pull the busybox image before running the tests
35 19
 	sleep 2
... ...
@@ -38,9 +19,5 @@ exec > >(tee -a $DEST/test.log) 2>&1
38 38
 
39 39
 	bundle_test_integration_cli
40 40
 
41
-	for pid in $(find "$DEST" -name docker.pid); do
42
-		DOCKER_PID=$(set -x; cat "$pid")
43
-		( set -x; kill $DOCKER_PID )
44
-		wait $DOCKERD_PID || true
45
-	done
41
+	source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
46 42
 )