Make current user owner of build log files

We run buildah as root, hence the logfiles are created with root
as owner. This is a hack to get around that. When we move to
rootless buildah we can remove it.

Change-Id: I11f02b9d01c569b344a8df7be62dfadf8d119c57
This commit is contained in:
Rabi Mishra
2020-09-02 14:42:12 +05:30
parent fc14b60ab4
commit 5c7b224998
2 changed files with 20 additions and 5 deletions

View File

@@ -16,6 +16,7 @@
from concurrent import futures
import os
import pathlib
import six
import tenacity
@@ -138,6 +139,12 @@ class BuildahBuilder(base.BaseBuilder):
# TODO(emilien): Stop ignoring TLS. The deployer should either secure
# the registry or add it to insecure_registries.
logfile = container_build_path + '/' + container_name + '-build.log'
# TODO(ramishra) Hack to make the logfile readable by current user,
# as we're running buildah as root. This would be removed once we
# move to rootless buildah.
pathlib.Path(logfile).touch()
bud_args = ['bud']
for v in self.volumes:
bud_args.extend(['--volume', v])

View File

@@ -17,6 +17,7 @@
import copy
from concurrent import futures
from concurrent.futures import ThreadPoolExecutor as tpe
import pathlib
from unittest import mock
from tripleo_common.image.builder.buildah import BuildahBuilder as bb
@@ -70,7 +71,8 @@ R_BROKEN = (set(R_BROKEN_LISTS[0]), set(R_BROKEN_LISTS[1]))
class TestBuildahBuilder(base.TestCase):
@mock.patch.object(process, 'execute', autospec=True)
def test_build(self, mock_process):
@mock.patch.object(pathlib.Path, 'touch', autospec=True)
def test_build(self, mock_touch, mock_process):
args = copy.copy(BUILDAH_CMD_BASE)
dest = '127.0.0.1:8787/master/fedora-binary-fedora-base:latest'
container_build_path = WORK_DIR + '/' + 'fedora-base'
@@ -88,7 +90,8 @@ class TestBuildahBuilder(base.TestCase):
)
@mock.patch.object(process, 'execute', autospec=True)
def test_build_without_img_type(self, mock_process):
@mock.patch.object(pathlib.Path, 'touch', autospec=True)
def test_build_without_img_type(self, mock_touch, mock_process):
args = copy.copy(BUILDAH_CMD_BASE)
dest = '127.0.0.1:8787/master/fedora-fedora-base:latest'
container_build_path = WORK_DIR + '/' + 'fedora-base'
@@ -107,7 +110,8 @@ class TestBuildahBuilder(base.TestCase):
)
@mock.patch.object(process, 'execute', autospec=True)
def test_build_with_volumes(self, mock_process):
@mock.patch.object(pathlib.Path, 'touch', autospec=True)
def test_build_with_volumes(self, mock_touch, mock_process):
args = copy.copy(BUILDAH_CMD_BASE)
dest = '127.0.0.1:8787/master/fedora-binary-fedora-base:latest'
container_build_path = WORK_DIR + '/' + 'fedora-base'
@@ -204,11 +208,15 @@ class TestBuildahBuilder(base.TestCase):
@mock.patch.object(tpe, 'submit', autospec=True)
@mock.patch.object(futures, 'wait', autospec=True, return_value=R_OK)
@mock.patch.object(process, 'execute', autospec=True)
def test_build_all_dict_ok(self, mock_build, mock_wait, mock_submit):
@mock.patch.object(pathlib.Path, 'touch', autospec=True)
def test_build_all_dict_ok(self, mock_touch,
mock_build, mock_wait, mock_submit):
bb(WORK_DIR, DEPS).build_all(deps=BUILD_ALL_DICT_CONTAINERS)
@mock.patch.object(tpe, 'submit', autospec=True)
@mock.patch.object(futures, 'wait', autospec=True, return_value=R_OK)
@mock.patch.object(process, 'execute', autospec=True)
def test_build_all_str_ok(self, mock_build, mock_wait, mock_submit):
@mock.patch.object(pathlib.Path, 'touch', autospec=True)
def test_build_all_str_ok(self, mock_touch,
mock_build, mock_wait, mock_submit):
bb(WORK_DIR, DEPS).build_all(deps=BUILD_ALL_STR_CONTAINER)