mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 09:43:56 -06:00
docker.py: Improve subprocess exit code handling
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 <famz@redhat.com> Message-Id: <20170712075528.22770-3-famz@redhat.com> Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Fam Zheng <famz@redhat.com>
This commit is contained in:
parent
58bf7b6d8c
commit
0b95ff72cb
1 changed files with 12 additions and 7 deletions
|
@ -117,6 +117,11 @@ class Docker(object):
|
||||||
kwargs["stdout"] = DEVNULL
|
kwargs["stdout"] = DEVNULL
|
||||||
return subprocess.call(self._command + cmd, **kwargs)
|
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):
|
def _do_kill_instances(self, only_known, only_active=True):
|
||||||
cmd = ["ps", "-q"]
|
cmd = ["ps", "-q"]
|
||||||
if not only_active:
|
if not only_active:
|
||||||
|
@ -175,14 +180,14 @@ class Docker(object):
|
||||||
extra_files_cksum)))
|
extra_files_cksum)))
|
||||||
tmp_df.flush()
|
tmp_df.flush()
|
||||||
|
|
||||||
self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \
|
self._do_check(["build", "-t", tag, "-f", tmp_df.name] + argv + \
|
||||||
[docker_dir],
|
[docker_dir],
|
||||||
quiet=quiet)
|
quiet=quiet)
|
||||||
|
|
||||||
def update_image(self, tag, tarball, quiet=True):
|
def update_image(self, tag, tarball, quiet=True):
|
||||||
"Update a tagged image using "
|
"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):
|
def image_matches_dockerfile(self, tag, dockerfile):
|
||||||
try:
|
try:
|
||||||
|
@ -195,9 +200,9 @@ class Docker(object):
|
||||||
label = uuid.uuid1().hex
|
label = uuid.uuid1().hex
|
||||||
if not keep:
|
if not keep:
|
||||||
self._instances.append(label)
|
self._instances.append(label)
|
||||||
ret = self._do(["run", "--label",
|
ret = self._do_check(["run", "--label",
|
||||||
"com.qemu.instance.uuid=" + label] + cmd,
|
"com.qemu.instance.uuid=" + label] + cmd,
|
||||||
quiet=quiet)
|
quiet=quiet)
|
||||||
if not keep:
|
if not keep:
|
||||||
self._instances.remove(label)
|
self._instances.remove(label)
|
||||||
return ret
|
return ret
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue