pungi/0008-ostree-installer-Use-Python-function-to-copy.patch
2018-05-16 13:12:45 +02:00

247 lines
12 KiB
Diff

From 038dc1ff00cb566034b1a264a1af1b7d15cd37e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= <lsedlar@redhat.com>
Date: Tue, 15 May 2018 09:26:54 +0200
Subject: [PATCH 8/8] ostree-installer: Use Python function to copy
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This should give us better error reporting. The `copy_all` function
should preserve permissions on all files.
Relates: https://pagure.io/pungi/issue/932
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
---
pungi/phases/ostree_installer.py | 3 +-
tests/test_ostree_installer_phase.py | 57 ++++++++++++++++++------------------
2 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/pungi/phases/ostree_installer.py b/pungi/phases/ostree_installer.py
index 58eede96..0384a600 100644
--- a/pungi/phases/ostree_installer.py
+++ b/pungi/phases/ostree_installer.py
@@ -98,8 +98,7 @@ class OstreeInstallerThread(WorkerThread):
os_path = compose.paths.compose.os_tree(arch, variant)
boot_iso = os.path.join(output_dir, 'images', 'boot.iso')
- shortcuts.run('cp -rv %s/* %s/' %
- (shlex_quote(output_dir), shlex_quote(os_path)))
+ util.copy_all(output_dir, os_path)
try:
os.link(boot_iso, iso_path)
except OSError:
diff --git a/tests/test_ostree_installer_phase.py b/tests/test_ostree_installer_phase.py
index 62598315..51fac7d5 100644
--- a/tests/test_ostree_installer_phase.py
+++ b/tests/test_ostree_installer_phase.py
@@ -117,15 +117,16 @@ class OstreeThreadTest(helpers.PungiTestCase):
self.assertEqual(get_file_size.call_args_list, [mock.call(final_iso_path)])
self.assertEqual(get_mtime.call_args_list, [mock.call(final_iso_path)])
- def assertAllCopied(self, run):
+ def assertAllCopied(self, copy_all):
self.assertEqual(self.compose.get_image_name.call_args_list,
[mock.call('x86_64', self.compose.variants['Everything'], disc_type='ostree')])
self.assertTrue(os.path.isdir(self.topdir + '/work/x86_64/Everything/'))
self.assertFalse(os.path.isdir(self.topdir + '/work/x86_64/Everything/ostree_installer'))
- self.assertEqual(run.call_args_list,
- [mock.call('cp -rv {0}/work/x86_64/Everything/ostree_installer/* {0}/compose/Everything/x86_64/os/'.format(self.topdir))])
+ self.assertEqual(copy_all.call_args_list,
+ [mock.call('{0}/work/x86_64/Everything/ostree_installer'.format(self.topdir),
+ '{0}/compose/Everything/x86_64/os'.format(self.topdir))])
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -133,7 +134,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_run(self, KojiWrapper, link, iso,
- get_file_size, get_mtime, ImageCls, run):
+ get_file_size, get_mtime, ImageCls, copy_all):
self.compose.supported = False
pool = mock.Mock()
cfg = {
@@ -160,9 +161,9 @@ class OstreeThreadTest(helpers.PungiTestCase):
extra=['--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)])
self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)
self.assertImageAdded(self.compose, ImageCls, iso)
- self.assertAllCopied(run)
+ self.assertAllCopied(copy_all)
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -170,7 +171,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_run_external_source(self, KojiWrapper, link, iso,
- get_file_size, get_mtime, ImageCls, run):
+ get_file_size, get_mtime, ImageCls, copy_all):
pool = mock.Mock()
cfg = {
'repo': 'http://example.com/repo/$arch/',
@@ -194,9 +195,9 @@ class OstreeThreadTest(helpers.PungiTestCase):
extra=['--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)])
self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)
self.assertImageAdded(self.compose, ImageCls, iso)
- self.assertAllCopied(run)
+ self.assertAllCopied(copy_all)
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -204,7 +205,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_run_with_repo_key(self, KojiWrapper, link, iso,
- get_file_size, get_mtime, ImageCls, run):
+ get_file_size, get_mtime, ImageCls, copy_all):
pool = mock.Mock()
cfg = {
'release': '20160321.n.0',
@@ -234,7 +235,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
self.assertRunrootCall(koji, sources, cfg['release'], isfinal=True,
extra=['--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)])
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -242,7 +243,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_run_with_multiple_variant_repos(self, KojiWrapper, link, iso,
- get_file_size, get_mtime, ImageCls, run):
+ get_file_size, get_mtime, ImageCls, copy_all):
pool = mock.Mock()
cfg = {
'release': '20160321.n.0',
@@ -274,7 +275,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
self.assertRunrootCall(koji, sources, cfg['release'], isfinal=True,
extra=['--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)])
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -283,7 +284,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_fail_with_relative_template_path_but_no_repo(self, KojiWrapper, link,
iso, get_file_size,
- get_mtime, ImageCls, run):
+ get_mtime, ImageCls, copy_all):
pool = mock.Mock()
cfg = {
'repo': 'Everything',
@@ -307,7 +308,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
self.assertIn('template_repo', str(ctx.exception))
@mock.patch('pungi.wrappers.scm.get_dir_from_scm')
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -315,7 +316,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_run_clone_templates(self, KojiWrapper, link, iso,
- get_file_size, get_mtime, ImageCls, run,
+ get_file_size, get_mtime, ImageCls, copy_all,
get_dir_from_scm):
pool = mock.Mock()
cfg = {
@@ -354,9 +355,9 @@ class OstreeThreadTest(helpers.PungiTestCase):
'--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)])
self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)
self.assertImageAdded(self.compose, ImageCls, iso)
- self.assertAllCopied(run)
+ self.assertAllCopied(copy_all)
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -364,7 +365,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_run_with_explicitly_generated_release(self, KojiWrapper, link, iso,
- get_file_size, get_mtime, ImageCls, run):
+ get_file_size, get_mtime, ImageCls, copy_all):
pool = mock.Mock()
cfg = {
'repo': 'Everything',
@@ -415,9 +416,9 @@ class OstreeThreadTest(helpers.PungiTestCase):
)
self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)
self.assertImageAdded(self.compose, ImageCls, iso)
- self.assertAllCopied(run)
+ self.assertAllCopied(copy_all)
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -425,7 +426,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_run_with_implicit_release(self, KojiWrapper, link, iso,
- get_file_size, get_mtime, ImageCls, run):
+ get_file_size, get_mtime, ImageCls, copy_all):
pool = mock.Mock()
cfg = {
'repo': 'Everything',
@@ -476,9 +477,9 @@ class OstreeThreadTest(helpers.PungiTestCase):
)
self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)
self.assertImageAdded(self.compose, ImageCls, iso)
- self.assertAllCopied(run)
+ self.assertAllCopied(copy_all)
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -486,7 +487,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_fail_crash(self, KojiWrapper, link, iso, get_file_size,
- get_mtime, ImageCls, run):
+ get_mtime, ImageCls, copy_all):
pool = mock.Mock()
cfg = {
'repo': 'Everything',
@@ -504,7 +505,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
mock.call('BOOM')
])
- @mock.patch('kobo.shortcuts.run')
+ @mock.patch('pungi.util.copy_all')
@mock.patch('productmd.images.Image')
@mock.patch('pungi.util.get_mtime')
@mock.patch('pungi.util.get_file_size')
@@ -512,7 +513,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
@mock.patch('os.link')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
def test_fail_runroot_fail(self, KojiWrapper, link, iso,
- get_file_size, get_mtime, ImageCls, run):
+ get_file_size, get_mtime, ImageCls, copy_all):
pool = mock.Mock()
cfg = {
'repo': 'Everything',
--
2.14.3