Browse code

Tweak test-docker-py feature

- move docker/docker-py clone to the Dockerfile
- put "integration test daemon startup" code in a separate file for both scripts to source
- add new test-docker-py Makefile target
- include "python-websocket" package in Dockerfile for running the tests

Signed-off-by: Andrew "Tianon" Page <admwiggin@gmail.com>

Tianon Gravi authored on 2014/12/19 16:20:59
Showing 7 changed files
... ...
@@ -44,6 +44,7 @@ RUN	apt-get update && apt-get install -y \
44 44
 	parallel \
45 45
 	python-mock \
46 46
 	python-pip \
47
+	python-websocket \
47 48
 	reprepro \
48 49
 	ruby1.9.1 \
49 50
 	ruby1.9.1-dev \
... ...
@@ -95,6 +96,9 @@ RUN	git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.gi
95 95
 # Get the "cirros" image source so we can import it instead of fetching it during tests
96 96
 RUN	curl -sSL -o /cirros.tar.gz https://github.com/ewindisch/docker-cirros/raw/1cded459668e8b9dbf4ef976c94c05add9bbd8e9/cirros-0.3.0-x86_64-lxc.tar.gz
97 97
 
98
+# Get the "docker-py" source so we can run their integration tests
99
+RUN	git clone -b 0.7.0 https://github.com/docker/docker-py.git /docker-py
100
+
98 101
 # Setup s3cmd config
99 102
 RUN	/bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEY' > $HOME/.s3cfg
100 103
 
... ...
@@ -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
... ...
@@ -67,6 +67,9 @@ test-integration: build
67 67
 test-integration-cli: build
68 68
 	$(DOCKER_RUN_DOCKER) hack/make.sh binary test-integration-cli
69 69
 
70
+test-docker-py: build
71
+	$(DOCKER_RUN_DOCKER) hack/make.sh binary test-docker-py
72
+
70 73
 validate: build
71 74
 	$(DOCKER_RUN_DOCKER) hack/make.sh validate-gofmt validate-dco
72 75
 
... ...
@@ -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
... ...
@@ -3,41 +3,20 @@ 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
 # subshell so that we can export PATH without breaking other things
10 7
 exec > >(tee -a $DEST/test.log) 2>&1
11 8
 (
12
-	export PATH="$DEST/../binary:$DEST/../dynbinary:$PATH"
13
-
14
-	if ! command -v docker &> /dev/null; then
15
-		echo >&2 'error: binary or dynbinary must be run before test-docker-py'
16
-		false
17
-	fi
9
+	source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
18 10
 
19
-	# intentionally open a couple bogus file descriptors to help test that they get scrubbed in containers
20
-	exec 41>&1 42>&2
11
+	dockerPy='/docker-py'
12
+	[ -d "$dockerPy" ] || {
13
+		dockerPy="$DEST/docker-py"
14
+		git clone https://github.com/docker/docker-py.git "$dockerPy"
15
+	}
21 16
 
22
-	( set -x; exec \
23
-		docker --daemon --debug \
24
-		--storage-driver "$DOCKER_GRAPHDRIVER" \
25
-		--exec-driver "$DOCKER_EXECDRIVER" \
26
-		--pidfile "$DEST/docker.pid" \
27
-			&> "$DEST/docker.log"
28
-	) &
29
-
30
-	mkdir -p /tmp/dockerpy-tests && cd /tmp/dockerpy-tests
31
-	git clone https://github.com/docker/docker-py.git
32
-	cd docker-py
33
-	git checkout 0.6.0-integration
34
-	python setup.py install
17
+	cd "$dockerPy"
18
+	export PYTHONPATH=. # import "docker" from "."
35 19
 	python tests/integration_test.py
36 20
 
37
-	for pid in $(find "$DEST" -name docker.pid); do
38
-		DOCKER_PID=$(set -x; cat "$pid")
39
-		( set -x; kill $DOCKER_PID )
40
-		wait $DOCKERD_PID || true
41
-	done
21
+	source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
42 22
 )
43
-
... ...
@@ -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
 )