unified-iso: Only link to non-empty variants

Instead of adding images to metadata and then creating hardlinks in a
separate step, do it immediately while we still have accurate
information about what variants it should be linked to.

Fixes: https://pagure.io/pungi/issue/670
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-07-31 14:25:08 +02:00
parent 471e369d23
commit c66f2228b5
2 changed files with 36 additions and 74 deletions

View File

@ -76,7 +76,6 @@ class UnifiedISO(object):
self.repos = {} # {arch/src: {variant: new_path}
self.comps = {} # {arch/src: {variant: old_path}
self.productid = {} # {arch/stc: {variant: old_path}
self.images = {} # {arch/src: [*.iso, *.iso.{md5,sha1,sha256}sum]}
self.conf = self.read_config()
def create(self, delete_temp=True):
@ -86,7 +85,6 @@ class UnifiedISO(object):
self.createrepo()
self.discinfo()
self.createiso()
self.link_to_compose()
self.update_checksums()
self.dump_manifest()
finally:
@ -330,9 +328,6 @@ class UnifiedISO(object):
img.bootable = False
img.unified = True
self.images.setdefault(typed_arch, set()).add(iso_path)
self.images.setdefault(typed_arch, set()).add(iso_path + ".manifest")
img.implant_md5 = iso.get_implanted_md5(iso_path)
try:
img.volume_id = iso.get_volume_id(iso_path)
@ -367,23 +362,11 @@ class UnifiedISO(object):
)
im.add(variant.uid, tree_arch, variant_img)
def link_to_compose(self):
for variant in self.ci.get_variants(recursive=False):
for arch in variant.arches | set(['debug-' + a for a in variant.arches]) | set(['src']):
bare_arch = arch.split('-', 1)[-1]
if arch == 'src':
dir = 'source'
elif arch.startswith('debug-'):
dir = bare_arch + '/debug'
else:
dir = bare_arch
default_path = os.path.join(variant.uid, dir, "iso")
isos = os.path.join(self.compose_path, default_path)
makedirs(isos)
for image in self.images.get(arch, []):
dst = os.path.join(isos, os.path.basename(image))
print("Linking {0} -> {1}".format(image, dst))
self.linker.link(image, dst)
dst = os.path.join(self.compose_path, variant_img.path)
print("Linking {0} -> {1}".format(iso_path, dst))
makedirs(os.path.dirname(dst))
self.linker.link(iso_path, dst)
self.linker.link(iso_path + '.manifest', dst + '.manifest')
def _get_base_filename(self, variant, arch):
substs = {

View File

@ -54,7 +54,7 @@ class TestCreate(PungiTestCase):
def test_create_method(self):
methods = ('link_to_temp', 'createrepo', 'discinfo', 'createiso',
'link_to_compose', 'update_checksums', 'dump_manifest')
'update_checksums', 'dump_manifest')
for attr in methods:
setattr(self.isos, attr, mock.Mock())
@ -390,28 +390,25 @@ class TestCreateiso(PungiTestCase):
self.isos.linker = mock.Mock()
# TODO mock treeinfo and use mappings for other data
self.isos.link_to_temp()
# Reset linker to only mock calls from createiso method.
self.isos.linker = mock.Mock()
self.maxDiff = None
self.mkisofs_cmd = None
self.binary_fn = 'DP-1.0-20161013.t.4-x86_64-dvd.iso'
self.binary = os.path.join(self.isos.temp_dir, 'iso', 'x86_64', self.binary_fn)
self.source_fn = 'DP-1.0-20161013.t.4-source-dvd.iso'
self.source = os.path.join(self.isos.temp_dir, 'iso', 'source', self.source_fn)
self.debug_fn = 'DP-1.0-20161013.t.4-x86_64-debuginfo-dvd.iso'
self.debug = os.path.join(self.isos.temp_dir, 'iso', 'x86_64-debuginfo', self.debug_fn)
def mock_gmc(self, path, *args, **kwargs):
touch(path, 'ISO FILE\n')
self.mkisofs_cmd = self.mkisofs_cmd or mock.Mock(name='mkisofs cmd')
return self.mkisofs_cmd
def _img(self, arch):
base_path = os.path.join(self.isos.temp_dir, 'iso', arch,
u'DP-1.0-20161013.t.4-%s-dvd.iso' % arch)
yield base_path
yield base_path + '.manifest'
def _imgs(self, arches):
images = {}
for arch in arches:
file_arch = arch
if arch.startswith('debug-'):
file_arch = arch.split('-', 1)[-1] + '-debuginfo'
images[arch] = set(self._img(file_arch if arch != 'src' else 'source'))
return images
def _iso(self, variant, arch, name):
return os.path.join(self.compose_path, variant, arch, 'iso', name)
def assertResults(self, iso, run, arches):
self.assertEqual(
@ -421,8 +418,6 @@ class TestCreateiso(PungiTestCase):
mock.call(iso.get_manifest_cmd.return_value)] * len(arches)
)
self.assertEqual(self.isos.images, self._imgs(arches))
images = self.isos.compose.images
for v in ('Client', 'Server'):
@ -438,6 +433,25 @@ class TestCreateiso(PungiTestCase):
else:
self.fail('Image for %s.%s missing' % (v, a))
expected = [
mock.call(self.binary, self._iso('Client', 'x86_64', self.binary_fn)),
mock.call(self.binary + '.manifest', self._iso('Client', 'x86_64', self.binary_fn + '.manifest')),
mock.call(self.binary, self._iso('Server', 'x86_64', self.binary_fn)),
mock.call(self.binary + '.manifest', self._iso('Server', 'x86_64', self.binary_fn + '.manifest')),
mock.call(self.source, self._iso('Client', 'source', self.source_fn)),
mock.call(self.source + '.manifest', self._iso('Client', 'source', self.source_fn + '.manifest')),
mock.call(self.source, self._iso('Server', 'source', self.source_fn)),
mock.call(self.source + '.manifest', self._iso('Server', 'source', self.source_fn + '.manifest')),
]
if 'debug-x86_64' in arches:
expected.extend([
mock.call(self.debug, self._iso('Client', 'x86_64/debug', self.debug_fn)),
mock.call(self.debug + '.manifest', self._iso('Client', 'x86_64/debug', self.debug_fn + '.manifest')),
mock.call(self.debug, self._iso('Server', 'x86_64/debug', self.debug_fn)),
mock.call(self.debug + '.manifest', self._iso('Server', 'x86_64/debug', self.debug_fn + '.manifest')),
])
self.assertItemsEqual(self.isos.linker.link.call_args_list, expected)
@mock.patch('pungi_utils.unified_isos.iso')
@mock.patch('pungi_utils.unified_isos.run')
def test_createiso(self, run, iso):
@ -468,41 +482,6 @@ class TestCreateiso(PungiTestCase):
self.assertResults(iso, run, ['src', 'x86_64', 'debug-x86_64'])
class TestLinkToCompose(PungiTestCase):
def setUp(self):
super(TestLinkToCompose, self).setUp()
shutil.copytree(os.path.join(FIXTURE_DIR, COMPOSE_ID),
os.path.join(self.topdir, COMPOSE_ID))
self.compose_path = os.path.join(self.topdir, COMPOSE_ID, 'compose')
self.isos = unified_isos.UnifiedISO(self.compose_path)
self.isos.linker = mock.Mock()
self.binary = os.path.join(self.isos.temp_dir, 'isos', 'x86_64', 'binary.iso')
self.debug = os.path.join(self.isos.temp_dir, 'isos', 'x86_64', 'debug.iso')
self.source = os.path.join(self.isos.temp_dir, 'isos', 'src', 'source.iso')
self.isos.images = {
'x86_64': set([self.binary]),
'debug-x86_64': set([self.debug]),
'src': set([self.source]),
}
self.maxDiff = None
def _iso(self, variant, arch, name):
return os.path.join(self.compose_path, variant, arch, 'iso', name)
def test_link_to_compose(self):
self.isos.link_to_compose()
self.assertItemsEqual(
self.isos.linker.link.call_args_list,
[mock.call(self.binary, self._iso('Client', 'x86_64', 'binary.iso')),
mock.call(self.debug, self._iso('Client', 'x86_64/debug', 'debug.iso')),
mock.call(self.binary, self._iso('Server', 'x86_64', 'binary.iso')),
mock.call(self.debug, self._iso('Server', 'x86_64/debug', 'debug.iso')),
mock.call(self.source, self._iso('Client', 'source', 'source.iso')),
mock.call(self.source, self._iso('Server', 'source', 'source.iso'))]
)
class MockImage(mock.Mock):
def __eq__(self, another):
return self.path == another.path