* [Qemu-devel] [PATCH] docker: Handle exceptions when looking for docker command
@ 2016-09-20 11:05 Eduardo Habkost
2016-09-20 11:16 ` Fam Zheng
0 siblings, 1 reply; 2+ messages in thread
From: Eduardo Habkost @ 2016-09-20 11:05 UTC (permalink / raw)
To: Fam Zheng; +Cc: qemu-devel
When trying to run docker tests on a host without the docker
command, we get the following Python backtrace:
$ make docker-test-quick@centos6 V=1
.../qemu/tests/docker/docker.py build qemu:centos6 .../qemu/tests/docker/dockerfiles/centos6.docker
Traceback (most recent call last):
File ".../qemu/tests/docker/docker.py", line 339, in <module>
sys.exit(main())
File ".../qemu/tests/docker/docker.py", line 336, in main
return args.cmdobj.run(args, argv)
File ".../qemu/tests/docker/docker.py", line 231, in run
dkr = Docker()
File ".../qemu/tests/docker/docker.py", line 98, in __init__
self._command = _guess_docker_command()
File ".../qemu/tests/docker/docker.py", line 41, in _guess_docker_command
stdout=DEVNULL, stderr=DEVNULL) == 0:
File "/usr/lib64/python2.7/subprocess.py", line 523, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
.../qemu/tests/docker/Makefile.include:47: recipe for target 'docker-image-centos6' failed
make: *** [docker-image-centos6] Error 1
Change _guess_docker_command() to handle OSError exceptions
raised by subprocess.call(), so we will keep looking for other
commands and print a better error message.
New output will be:
$ make docker-test-quick@centos6 V=1
.../qemu/tests/docker/docker.py build qemu:centos6 .../qemu/tests/docker/dockerfiles/centos6.docker
Traceback (most recent call last):
File ".../qemu/tests/docker/docker.py", line 343, in <module>
sys.exit(main())
File ".../qemu/tests/docker/docker.py", line 340, in main
return args.cmdobj.run(args, argv)
File ".../qemu/tests/docker/docker.py", line 235, in run
dkr = Docker()
File ".../qemu/tests/docker/docker.py", line 102, in __init__
self._command = _guess_docker_command()
File ".../qemu/tests/docker/docker.py", line 49, in _guess_docker_command
commands_txt)
Exception: Cannot find working docker command. Tried:
docker
sudo -n docker
.../qemu/tests/docker/Makefile.include:47: recipe for target 'docker-image-centos6' failed
make: *** [docker-image-centos6] Error 1
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
tests/docker/docker.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index b85c165..daff340 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -13,6 +13,7 @@
import os
import sys
+import exceptions
import subprocess
import json
import hashlib
@@ -37,9 +38,12 @@ def _guess_docker_command():
""" Guess a working docker command or raise exception if not found"""
commands = [["docker"], ["sudo", "-n", "docker"]]
for cmd in commands:
- if subprocess.call(cmd + ["images"],
- stdout=DEVNULL, stderr=DEVNULL) == 0:
- return cmd
+ try:
+ if subprocess.call(cmd + ["images"],
+ stdout=DEVNULL, stderr=DEVNULL) == 0:
+ return cmd
+ except exceptions.OSError:
+ pass
commands_txt = "\n".join([" " + " ".join(x) for x in commands])
raise Exception("Cannot find working docker command. Tried:\n%s" % \
commands_txt)
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] docker: Handle exceptions when looking for docker command
2016-09-20 11:05 [Qemu-devel] [PATCH] docker: Handle exceptions when looking for docker command Eduardo Habkost
@ 2016-09-20 11:16 ` Fam Zheng
0 siblings, 0 replies; 2+ messages in thread
From: Fam Zheng @ 2016-09-20 11:16 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: qemu-devel
On Tue, 09/20 08:05, Eduardo Habkost wrote:
> When trying to run docker tests on a host without the docker
> command, we get the following Python backtrace:
>
> $ make docker-test-quick@centos6 V=1
> .../qemu/tests/docker/docker.py build qemu:centos6 .../qemu/tests/docker/dockerfiles/centos6.docker
> Traceback (most recent call last):
> File ".../qemu/tests/docker/docker.py", line 339, in <module>
> sys.exit(main())
> File ".../qemu/tests/docker/docker.py", line 336, in main
> return args.cmdobj.run(args, argv)
> File ".../qemu/tests/docker/docker.py", line 231, in run
> dkr = Docker()
> File ".../qemu/tests/docker/docker.py", line 98, in __init__
> self._command = _guess_docker_command()
> File ".../qemu/tests/docker/docker.py", line 41, in _guess_docker_command
> stdout=DEVNULL, stderr=DEVNULL) == 0:
> File "/usr/lib64/python2.7/subprocess.py", line 523, in call
> return Popen(*popenargs, **kwargs).wait()
> File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
> errread, errwrite)
> File "/usr/lib64/python2.7/subprocess.py", line 1343, in _execute_child
> raise child_exception
> OSError: [Errno 2] No such file or directory
> .../qemu/tests/docker/Makefile.include:47: recipe for target 'docker-image-centos6' failed
> make: *** [docker-image-centos6] Error 1
>
> Change _guess_docker_command() to handle OSError exceptions
> raised by subprocess.call(), so we will keep looking for other
> commands and print a better error message.
>
> New output will be:
>
> $ make docker-test-quick@centos6 V=1
> .../qemu/tests/docker/docker.py build qemu:centos6 .../qemu/tests/docker/dockerfiles/centos6.docker
> Traceback (most recent call last):
> File ".../qemu/tests/docker/docker.py", line 343, in <module>
> sys.exit(main())
> File ".../qemu/tests/docker/docker.py", line 340, in main
> return args.cmdobj.run(args, argv)
> File ".../qemu/tests/docker/docker.py", line 235, in run
> dkr = Docker()
> File ".../qemu/tests/docker/docker.py", line 102, in __init__
> self._command = _guess_docker_command()
> File ".../qemu/tests/docker/docker.py", line 49, in _guess_docker_command
> commands_txt)
> Exception: Cannot find working docker command. Tried:
> docker
> sudo -n docker
> .../qemu/tests/docker/Makefile.include:47: recipe for target 'docker-image-centos6' failed
> make: *** [docker-image-centos6] Error 1
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> tests/docker/docker.py | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/tests/docker/docker.py b/tests/docker/docker.py
> index b85c165..daff340 100755
> --- a/tests/docker/docker.py
> +++ b/tests/docker/docker.py
> @@ -13,6 +13,7 @@
>
> import os
> import sys
> +import exceptions
> import subprocess
> import json
> import hashlib
> @@ -37,9 +38,12 @@ def _guess_docker_command():
> """ Guess a working docker command or raise exception if not found"""
> commands = [["docker"], ["sudo", "-n", "docker"]]
> for cmd in commands:
> - if subprocess.call(cmd + ["images"],
> - stdout=DEVNULL, stderr=DEVNULL) == 0:
> - return cmd
> + try:
> + if subprocess.call(cmd + ["images"],
> + stdout=DEVNULL, stderr=DEVNULL) == 0:
> + return cmd
> + except exceptions.OSError:
> + pass
> commands_txt = "\n".join([" " + " ".join(x) for x in commands])
> raise Exception("Cannot find working docker command. Tried:\n%s" % \
> commands_txt)
> --
> 2.7.4
>
Looks good, except that like exceptions.Exception, OSError is also magically
addressable as "OSError", saving us one import. _copy_with_mkdir below already
does that. Fixing that for consistency and queued for next PULL, thanks!
Fam
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-20 11:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-20 11:05 [Qemu-devel] [PATCH] docker: Handle exceptions when looking for docker command Eduardo Habkost
2016-09-20 11:16 ` Fam Zheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).