Move buildinstall results to final directories if using pungi-buildinstall Koji plugin.
If Koji pungi-buildinstall is used, then the buildinstall results are stored in the `output_dir` dir, but in "results" and "logs" subdirectories. We need to move them to final_output_dir. Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
This commit is contained in:
parent
3cd94a4aa5
commit
145c3adbef
@ -28,7 +28,7 @@ from six.moves import shlex_quote
|
||||
from pungi.arch import get_valid_arches
|
||||
from pungi.util import get_volid, get_arch_variant_data
|
||||
from pungi.util import get_file_size, get_mtime, failable, makedirs
|
||||
from pungi.util import copy_all, translate_path
|
||||
from pungi.util import copy_all, translate_path, move_all
|
||||
from pungi.wrappers.lorax import LoraxWrapper
|
||||
from pungi.wrappers import iso
|
||||
from pungi.wrappers.scm import get_file_from_scm
|
||||
@ -577,6 +577,20 @@ class BuildinstallThread(WorkerThread):
|
||||
makedirs(final_log_dir)
|
||||
log_dir = os.path.join(output_dir, "logs")
|
||||
copy_all(log_dir, final_log_dir)
|
||||
elif lorax_use_koji_plugin:
|
||||
# If Koji pungi-buildinstall is used, then the buildinstall results are
|
||||
# not stored directly in `output_dir` dir, but in "results" and "logs"
|
||||
# subdirectories. We need to move them to final_output_dir.
|
||||
results_dir = os.path.join(output_dir, "results")
|
||||
move_all(results_dir, final_output_dir, rm_src_dir=True)
|
||||
|
||||
# Get the log_dir into which we should copy the resulting log files.
|
||||
log_fname = "buildinstall-%s-logs/dummy" % variant.uid
|
||||
final_log_dir = os.path.dirname(compose.paths.log.log_file(arch, log_fname))
|
||||
if not os.path.exists(final_log_dir):
|
||||
makedirs(final_log_dir)
|
||||
log_dir = os.path.join(output_dir, "logs")
|
||||
move_all(log_dir, final_log_dir, rm_src_dir=True)
|
||||
|
||||
log_file = compose.paths.log.log_file(arch, log_filename + "-RPMs")
|
||||
rpms = runroot.get_buildroot_rpms()
|
||||
|
@ -662,6 +662,34 @@ def copy_all(src, dest):
|
||||
return recursive_file_list(src)
|
||||
|
||||
|
||||
def move_all(src, dest, rm_src_dir=False):
|
||||
"""
|
||||
Copy all files and directories within ``src`` to the ``dest`` directory.
|
||||
|
||||
This is equivalent to running ``mv src/* dest``.
|
||||
|
||||
:param src:
|
||||
Source directory to move from.
|
||||
|
||||
:param dest:
|
||||
Destination directory to move to.
|
||||
|
||||
:param rm_src_dir:
|
||||
If True, the `src` directory is removed once its content is moved.
|
||||
"""
|
||||
contents = os.listdir(src)
|
||||
if not contents:
|
||||
raise RuntimeError("Source directory %s is empty." % src)
|
||||
makedirs(dest)
|
||||
for item in contents:
|
||||
source = os.path.join(src, item)
|
||||
destination = os.path.join(dest, item)
|
||||
shutil.move(source, destination)
|
||||
|
||||
if rm_src_dir:
|
||||
os.rmdir(src)
|
||||
|
||||
|
||||
def recursive_file_list(directory):
|
||||
"""Return a list of files contained in ``directory``.
|
||||
|
||||
|
@ -1200,8 +1200,9 @@ class BuildinstallThreadTestCase(PungiTestCase):
|
||||
@mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper")
|
||||
@mock.patch("pungi.wrappers.kojiwrapper.get_buildroot_rpms")
|
||||
@mock.patch("pungi.phases.buildinstall.run")
|
||||
@mock.patch("pungi.phases.buildinstall.move_all")
|
||||
def test_buildinstall_thread_with_lorax_using_koji_plugin(
|
||||
self, run, get_buildroot_rpms, KojiWrapperMock, mock_tweak, mock_link
|
||||
self, move_all, run, get_buildroot_rpms, KojiWrapperMock, mock_tweak, mock_link
|
||||
):
|
||||
compose = BuildInstallCompose(
|
||||
self.topdir,
|
||||
@ -1284,6 +1285,17 @@ class BuildinstallThreadTestCase(PungiTestCase):
|
||||
mock_link.call_args_list,
|
||||
[mock.call(compose, "x86_64", compose.variants["Server"], False)],
|
||||
)
|
||||
self.assertEqual(
|
||||
move_all.call_args_list,
|
||||
[
|
||||
mock.call(os.path.join(destdir, "results"), destdir, rm_src_dir=True),
|
||||
mock.call(
|
||||
os.path.join(destdir, "logs"),
|
||||
os.path.join(self.topdir, "logs/x86_64/buildinstall-Server-logs"),
|
||||
rm_src_dir=True,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@mock.patch("pungi.phases.buildinstall.link_boot_iso")
|
||||
@mock.patch("pungi.phases.buildinstall.tweak_buildinstall")
|
||||
|
@ -1008,6 +1008,30 @@ class TestCopyAll(PungiTestCase):
|
||||
self.assertEqual(os.readlink(os.path.join(self.dst, "symlink")), "broken")
|
||||
|
||||
|
||||
class TestMoveAll(PungiTestCase):
|
||||
def setUp(self):
|
||||
super(TestMoveAll, self).setUp()
|
||||
self.src = os.path.join(self.topdir, "src")
|
||||
self.dst = os.path.join(self.topdir, "dst")
|
||||
util.makedirs(self.src)
|
||||
|
||||
def test_move_all(self):
|
||||
touch(os.path.join(self.src, "target"))
|
||||
util.move_all(self.src, self.dst)
|
||||
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.dst, "target")))
|
||||
self.assertTrue(os.path.exists(os.path.join(self.src)))
|
||||
self.assertFalse(os.path.isfile(os.path.join(self.src, "target")))
|
||||
|
||||
def test_move_all_rm_src_dir(self):
|
||||
touch(os.path.join(self.src, "target"))
|
||||
util.move_all(self.src, self.dst, rm_src_dir=True)
|
||||
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.dst, "target")))
|
||||
self.assertFalse(os.path.exists(os.path.join(self.src)))
|
||||
self.assertFalse(os.path.isfile(os.path.join(self.src, "target")))
|
||||
|
||||
|
||||
@mock.patch("six.moves.urllib.request.urlretrieve")
|
||||
class TestAsLocalFile(PungiTestCase):
|
||||
def test_local_file(self, urlretrieve):
|
||||
|
Loading…
Reference in New Issue
Block a user