Skip to content

Commit 1111531

Browse files
authored
Merge pull request #83 from TomasTomecek/fix-78
sanity check container backend before using it
2 parents b680e43 + 66e40ed commit 1111531

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

ansible_bender/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ def build(self, build):
6565
self.db.record_build(build)
6666

6767
builder = self.get_builder(build)
68+
builder.sanity_check()
6869

6970
# before we start messing with the base image, we need to check for its presence first
7071
if not builder.is_base_image_present():
7172
builder.pull()
7273
build.pulled = True
7374

75+
builder.check_container_creation()
76+
7477
# let's record base image as a first layer
7578
base_image_id = builder.get_image_id(build.base_image)
7679
build.record_layer(None, base_image_id, None, cached=True)

ansible_bender/builders/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,13 @@ def get_logs(self):
104104
105105
:return: list of str
106106
"""
107+
108+
def sanity_check(self):
109+
"""
110+
invoke container tooling and thus verify they work well
111+
"""
112+
113+
def check_container_creation(self):
114+
"""
115+
check that containers can be created
116+
"""

ansible_bender/builders/buildah_builder.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,20 @@ def get_logs(self):
273273
274274
:return: list of str
275275
"""
276+
277+
def sanity_check(self):
278+
"""
279+
invoke container tooling and thus verify they work well
280+
"""
281+
# doing podman info would be super-handy, but it will immensely clutter the output
282+
logger.debug("checking that podman command works")
283+
run_cmd(["podman", "version"], log_stderr=True, log_output=True)
284+
logger.debug("checking that buildah command works")
285+
run_cmd(["buildah", "version"], log_stderr=True, log_output=True)
286+
287+
def check_container_creation(self):
288+
"""
289+
check that containers can be created
290+
"""
291+
logger.debug("trying to create a dummy container using podman")
292+
podman_run_cmd(self.build.base_image, ["true"], log_stderr=True)

tests/unit/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_build_pulls_base_img_if_not_present(application, build, is_base_present
1616
flexmock(BuildahBuilder)
1717
BuildahBuilder.should_receive("is_base_image_present").and_return(is_base_present).once()
1818
BuildahBuilder.should_receive("pull").times(times_called)
19+
BuildahBuilder.should_receive("check_container_creation").and_return(None).once()
1920
BuildahBuilder.should_receive("get_image_id").and_return("1").once()
2021
BuildahBuilder.should_receive("find_python_interpreter").and_return("").once()
2122
BuildahBuilder.should_receive("create").once()

0 commit comments

Comments
 (0)