From 8a2390a4f4743f700da1d07c3bc04d6661ce1487 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Thu, 13 Jul 2017 15:43:52 +0100 Subject: docker: Don't enable networking as a side-effect of DEBUG=1 When trying to debug problems with tests it is natural to set DEBUG=1 when starting the docker environment. Unfortunately this has a side-effect of enabling an eth0 network interface in the container, which changes the operating environment of the test suite. IOW tests with fail may suddenly start working again if DEBUG=1 is set, due to changed network setup. Add a separate NETWORK variable to allow enablement of networking separately from DEBUG=1. This can be used in two ways. To enable the default docker network backend make docker-test-build@fedora NETWORK=1 while to enable a specific network backend, eg join the network associated with the container 'wibble': make docker-test-build@fedora NETWORK=container:wibble Signed-off-by: Daniel P. Berrange Message-Id: <20170713144352.2212-1-berrange@redhat.com> [Drop the superfluous second $(subst ...). - Fam] Signed-off-by: Fam Zheng --- tests/docker/Makefile.include | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include index 037cb9e..012a2fc 100644 --- a/tests/docker/Makefile.include +++ b/tests/docker/Makefile.include @@ -106,6 +106,8 @@ docker: @echo ' (default is 1)' @echo ' DEBUG=1 Stop and drop to shell in the created container' @echo ' before running the command.' + @echo ' NETWORK=1 Enable virtual network interface with default backend.' + @echo ' NETWORK=$BACKEND Enable virtual network interface with $BACKEND.' @echo ' NOUSER Define to disable adding current user to containers passwd.' @echo ' NOCACHE=1 Ignore cache when build images.' @echo ' EXECUTABLE= Include executable in image.' @@ -132,7 +134,8 @@ docker-run: docker-qemu-src $(SRC_PATH)/tests/docker/docker.py run \ $(if $(NOUSER),,-u $(shell id -u)) -t \ $(if $V,,--rm) \ - $(if $(DEBUG),-i,--net=none) \ + $(if $(DEBUG),-i,) \ + $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \ -e TARGET_LIST=$(TARGET_LIST) \ -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \ -e V=$V -e J=$J -e DEBUG=$(DEBUG) \ -- cgit v1.1 From 58bf7b6d8ccc469d8c001b8cf2b632d3f9e7fa38 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Wed, 12 Jul 2017 15:55:27 +0800 Subject: docker.py: Drop infile parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The **kwargs can do this just well. Signed-off-by: Fam Zheng Message-Id: <20170712075528.22770-2-famz@redhat.com> Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Fam Zheng --- tests/docker/docker.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/docker/docker.py b/tests/docker/docker.py index e707e5b..f5ac86b 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -112,11 +112,9 @@ class Docker(object): signal.signal(signal.SIGTERM, self._kill_instances) signal.signal(signal.SIGHUP, self._kill_instances) - def _do(self, cmd, quiet=True, infile=None, **kwargs): + def _do(self, cmd, quiet=True, **kwargs): if quiet: kwargs["stdout"] = DEVNULL - if infile: - kwargs["stdin"] = infile return subprocess.call(self._command + cmd, **kwargs) def _do_kill_instances(self, only_known, only_active=True): @@ -184,7 +182,7 @@ class Docker(object): def update_image(self, tag, tarball, quiet=True): "Update a tagged image using " - self._do(["build", "-t", tag, "-"], quiet=quiet, infile=tarball) + self._do(["build", "-t", tag, "-"], quiet=quiet, stdin=tarball) def image_matches_dockerfile(self, tag, dockerfile): try: -- cgit v1.1 From 0b95ff72cb42567dd71685bfdafbcdcd9784ea83 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Wed, 12 Jul 2017 15:55:28 +0800 Subject: docker.py: Improve subprocess exit code handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A few error handlings are missing because we ignore the subprocess exit code, for example "docker build" errors are currently ignored. Introduce _do_check() aside the existing _do() method and use it in a few places. Signed-off-by: Fam Zheng Message-Id: <20170712075528.22770-3-famz@redhat.com> Tested-by: Philippe Mathieu-Daudé Signed-off-by: Fam Zheng --- tests/docker/docker.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/docker/docker.py b/tests/docker/docker.py index f5ac86b..ee40ca0 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -117,6 +117,11 @@ class Docker(object): kwargs["stdout"] = DEVNULL return subprocess.call(self._command + cmd, **kwargs) + def _do_check(self, cmd, quiet=True, **kwargs): + if quiet: + kwargs["stdout"] = DEVNULL + return subprocess.check_call(self._command + cmd, **kwargs) + def _do_kill_instances(self, only_known, only_active=True): cmd = ["ps", "-q"] if not only_active: @@ -175,14 +180,14 @@ class Docker(object): extra_files_cksum))) tmp_df.flush() - self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \ - [docker_dir], - quiet=quiet) + self._do_check(["build", "-t", tag, "-f", tmp_df.name] + argv + \ + [docker_dir], + quiet=quiet) def update_image(self, tag, tarball, quiet=True): "Update a tagged image using " - self._do(["build", "-t", tag, "-"], quiet=quiet, stdin=tarball) + self._do_check(["build", "-t", tag, "-"], quiet=quiet, stdin=tarball) def image_matches_dockerfile(self, tag, dockerfile): try: @@ -195,9 +200,9 @@ class Docker(object): label = uuid.uuid1().hex if not keep: self._instances.append(label) - ret = self._do(["run", "--label", - "com.qemu.instance.uuid=" + label] + cmd, - quiet=quiet) + ret = self._do_check(["run", "--label", + "com.qemu.instance.uuid=" + label] + cmd, + quiet=quiet) if not keep: self._instances.remove(label) return ret -- cgit v1.1