From 75efe791eebf8325d5a4f0fd82a1c5ea786d5f87 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Oto=20=C5=A0=C5=A5=C3=A1va?= Date: Wed, 1 Jun 2022 13:34:12 +0200 Subject: [PATCH] tests/packaging: print build_log of failed commands --- tests/packaging/test_packaging.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/packaging/test_packaging.py b/tests/packaging/test_packaging.py index affa49406..1a9bc4139 100644 --- a/tests/packaging/test_packaging.py +++ b/tests/packaging/test_packaging.py @@ -150,15 +150,33 @@ class DockerImages(ABC): dockerf.close() + def build_printing_errors(self, path, dockerfile, network_mode, tag, rm): + try: + return client.images.build(path=path, dockerfile=dockerfile, + network_mode=network_mode, tag=tag, rm=rm) + except docker.errors.BuildError as e: + iterable = iter(e.build_log) + while True: + try: + item = next(iterable) + if item['stream']: + for l in item['stream'].splitlines(): + stripped = l.strip() + if stripped: + logging.error(stripped) + except StopIteration: + break + raise e + def build(self, tmpdir, tag="", from_image=None): self.__genDockerFile(tmpdir, from_image=from_image) logger.debug('tmpdir={}'.format(tmpdir)) logger.debug('datadir={}'.format(pytest.KR_ROOT_DIR)) logger.debug('tag={}'.format(tag)) - image = client.images.build(path=str(pytest.KR_ROOT_DIR), - dockerfile=os.path.join(tmpdir, 'Dockerfile-build'), - network_mode='host', tag=tag, rm=True) + image = self.build_printing_errors(path=str(pytest.KR_ROOT_DIR), + dockerfile=os.path.join(tmpdir, 'Dockerfile-build'), + network_mode='host', tag=tag, rm=True) logger.info('"Build image" ID={} created'.format(image[0].short_id)) self.build_id = image[0].short_id return self.build_id @@ -169,9 +187,9 @@ class DockerImages(ABC): logger.debug('tmpdir={}'.format(tmpdir)) logger.debug('datadir={}'.format(tmpdir)) logger.debug('tag={}'.format(tag)) - image = client.images.build(path=str(tmpdir), - dockerfile=os.path.join(tmpdir, 'Dockerfile-run'), - network_mode='host', tag=tag, rm=True) + image = self.build_printing_errors(path=str(tmpdir), + dockerfile=os.path.join(tmpdir, 'Dockerfile-run'), + network_mode='host', tag=tag, rm=True) logger.info('"Run image" ID={} created'.format(image[0].short_id)) self.run_id = image[0].short_id return self.run_id -- 2.47.3