From 38142d30bab12156af163c64ca7941410e8c7cde Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Wed, 22 Jan 2020 18:02:22 +0800 Subject: [PATCH] Format tests with black JIRA: COMPOSE-4086 Signed-off-by: Haibo Lin --- setup.py | 1 + tests/helpers.py | 150 +- tests/test_arch.py | 80 +- tests/test_arguments.py | 14 +- tests/test_buildinstall.py | 1880 +++++++++++++++++--------- tests/test_checks.py | 324 +++-- tests/test_compose.py | 594 ++++---- tests/test_comps_wrapper.py | 135 +- tests/test_config.py | 427 +++--- tests/test_createiso_phase.py | 1469 ++++++++++++-------- tests/test_createiso_script.py | 498 ++++--- tests/test_createrepo_wrapper.py | 142 +- tests/test_createrepophase.py | 1220 +++++++++++------ tests/test_extra_files_phase.py | 175 ++- tests/test_extra_isos_phase.py | 857 +++++++----- tests/test_fus_wrapper.py | 6 +- tests/test_gather.py | 419 +++--- tests/test_gather_method_deps.py | 176 ++- tests/test_gather_method_hybrid.py | 34 +- tests/test_gather_method_nodeps.py | 6 +- tests/test_gather_phase.py | 1303 ++++++++++++------ tests/test_graph.py | 47 +- tests/test_imagebuildphase.py | 1516 +++++++++++---------- tests/test_imagechecksumphase.py | 309 +++-- tests/test_initphase.py | 373 +++-- tests/test_iso_wrapper.py | 116 +- tests/test_koji_wrapper.py | 1226 ++++++++++------- tests/test_linker.py | 44 +- tests/test_liveimagesphase.py | 1388 +++++++++++-------- tests/test_livemediaphase.py | 1130 +++++++++------- tests/test_lorax_wrapper.py | 97 +- tests/test_media_split.py | 87 +- tests/test_metadata.py | 186 +-- tests/test_notifier.py | 148 +- tests/test_orchestrator.py | 6 +- tests/test_osbs_phase.py | 501 +++---- tests/test_ostree_installer_phase.py | 812 ++++++----- tests/test_ostree_phase.py | 748 ++++++---- tests/test_ostree_script.py | 432 +++--- tests/test_patch_iso.py | 364 ++--- tests/test_pathmatch.py | 5 +- tests/test_phase_base.py | 9 +- tests/test_pkgset_pkgsets.py | 509 ++++--- tests/test_pkgset_source_koji.py | 332 ++--- tests/test_repoclosure_wrapper.py | 108 +- tests/test_runroot.py | 181 ++- tests/test_scm.py | 331 +++-- tests/test_test_phase.py | 337 +++-- tests/test_unified_isos.py | 780 +++++++---- tests/test_util.py | 912 +++++++------ tox.ini | 3 +- 51 files changed, 13767 insertions(+), 9180 deletions(-) diff --git a/setup.py b/setup.py index 5eca8b32..9f1c3fdd 100755 --- a/setup.py +++ b/setup.py @@ -76,6 +76,7 @@ setup( ] }, tests_require = [ + "black", "mock", "nose", "nose-cov", diff --git a/tests/helpers.py b/tests/helpers.py index bdf51c11..662bbd14 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -23,23 +23,25 @@ from pungi.module_util import Modulemd class BaseTestCase(unittest.TestCase): - def assertFilesEqual(self, fn1, fn2): - with open(fn1, 'rb') as f1: - lines1 = f1.read().decode('utf-8').splitlines() - with open(fn2, 'rb') as f2: - lines2 = f2.read().decode('utf-8').splitlines() - diff = '\n'.join(difflib.unified_diff(lines1, lines2, - fromfile='EXPECTED', tofile='ACTUAL')) - self.assertEqual(diff, '', 'Files differ:\n' + diff) + with open(fn1, "rb") as f1: + lines1 = f1.read().decode("utf-8").splitlines() + with open(fn2, "rb") as f2: + lines2 = f2.read().decode("utf-8").splitlines() + diff = "\n".join( + difflib.unified_diff(lines1, lines2, fromfile="EXPECTED", tofile="ACTUAL") + ) + self.assertEqual(diff, "", "Files differ:\n" + diff) def assertFileContent(self, fn, expected): - with open(fn, 'rb') as f: - lines = f.read().decode('utf-8').splitlines() - diff = '\n'.join(difflib.unified_diff( - lines, expected.splitlines(), fromfile='EXPECTED', tofile='ACTUAL') + with open(fn, "rb") as f: + lines = f.read().decode("utf-8").splitlines() + diff = "\n".join( + difflib.unified_diff( + lines, expected.splitlines(), fromfile="EXPECTED", tofile="ACTUAL" + ) ) - self.assertEqual(diff, '', 'Files differ:\n' + diff) + self.assertEqual(diff, "", "Files differ:\n" + diff) class PungiTestCase(BaseTestCase): @@ -72,7 +74,7 @@ class PungiTestCase(BaseTestCase): class MockVariant(mock.Mock): def __init__(self, is_empty=False, name=None, *args, **kwargs): super(MockVariant, self).__init__(*args, is_empty=is_empty, **kwargs) - self.parent = kwargs.get('parent', None) + self.parent = kwargs.get("parent", None) self.arch_mmds = {} self.module_uid_to_koji_tag = {} self.variants = {} @@ -85,8 +87,11 @@ class MockVariant(mock.Mock): return self.uid def get_variants(self, arch=None, types=None): - return [v for v in list(self.variants.values()) - if (not arch or arch in v.arches) and (not types or v.type in types)] + return [ + v + for v in list(self.variants.values()) + if (not arch or arch in v.arches) and (not types or v.type in types) + ] def get_modules(self, arch=None, types=None): return [] @@ -133,22 +138,19 @@ class IterableMock(mock.Mock): class DummyCompose(object): def __init__(self, topdir, config): self.supported = True - self.compose_date = '20151203' - self.compose_type_suffix = '.t' - self.compose_type = 'test' + self.compose_date = "20151203" + self.compose_type_suffix = ".t" + self.compose_type = "test" self.compose_respin = 0 - self.compose_id = 'Test-20151203.0.t' + self.compose_id = "Test-20151203.0.t" self.compose_label = None self.compose_label_major_version = None - self.image_release = '20151203.t.0' - self.image_version = '25' + self.image_release = "20151203.t.0" + self.image_version = "25" self.ci_base = mock.Mock( - release_id='Test-1.0', + release_id="Test-1.0", release=mock.Mock( - short='test', - version='1.0', - is_layered=False, - type_suffix='' + short="test", version="1.0", is_layered=False, type_suffix="" ), ) self.topdir = topdir @@ -157,12 +159,27 @@ class DummyCompose(object): self.paths = paths.Paths(self) self.has_comps = True self.variants = { - 'Server': MockVariant(uid='Server', arches=['x86_64', 'amd64'], - type='variant', id='Server', name='Server'), - 'Client': MockVariant(uid='Client', arches=['amd64'], - type='variant', id='Client', name='Client'), - 'Everything': MockVariant(uid='Everything', arches=['x86_64', 'amd64'], - type='variant', id='Everything', name='Everything'), + "Server": MockVariant( + uid="Server", + arches=["x86_64", "amd64"], + type="variant", + id="Server", + name="Server", + ), + "Client": MockVariant( + uid="Client", + arches=["amd64"], + type="variant", + id="Client", + name="Client", + ), + "Everything": MockVariant( + uid="Everything", + arches=["x86_64", "amd64"], + type="variant", + id="Everything", + name="Everything", + ), } self.all_variants = self.variants.copy() @@ -174,13 +191,13 @@ class DummyCompose(object): self.log_error = mock.Mock() self.log_debug = mock.Mock() self.log_warning = mock.Mock() - self.get_image_name = mock.Mock(return_value='image-name') + self.get_image_name = mock.Mock(return_value="image-name") self.image = mock.Mock( - path='Client/i386/iso/image.iso', can_fail=False, size=123, _max_size=None, + path="Client/i386/iso/image.iso", can_fail=False, size=123, _max_size=None, ) - self.im = mock.Mock(images={'Client': {'amd64': [self.image]}}) + self.im = mock.Mock(images={"Client": {"amd64": [self.image]}}) self.old_composes = [] - self.config_dir = '/home/releng/config' + self.config_dir = "/home/releng/config" self.notifier = None self.attempt_deliverable = mock.Mock() self.fail_deliverable = mock.Mock() @@ -189,23 +206,32 @@ class DummyCompose(object): self.cache_region = None def setup_optional(self): - self.all_variants['Server-optional'] = MockVariant( - uid='Server-optional', arches=['x86_64'], type='optional') - self.all_variants['Server-optional'].parent = self.variants['Server'] - self.variants['Server'].variants['optional'] = self.all_variants['Server-optional'] + self.all_variants["Server-optional"] = MockVariant( + uid="Server-optional", arches=["x86_64"], type="optional" + ) + self.all_variants["Server-optional"].parent = self.variants["Server"] + self.variants["Server"].variants["optional"] = self.all_variants[ + "Server-optional" + ] def setup_addon(self): - self.all_variants['Server-HA'] = MockVariant( - uid='Server-HA', arches=['x86_64'], type='addon', is_empty=False) - self.all_variants['Server-HA'].parent = self.variants['Server'] - self.variants['Server'].variants['HA'] = self.all_variants['Server-HA'] + self.all_variants["Server-HA"] = MockVariant( + uid="Server-HA", arches=["x86_64"], type="addon", is_empty=False + ) + self.all_variants["Server-HA"].parent = self.variants["Server"] + self.variants["Server"].variants["HA"] = self.all_variants["Server-HA"] def get_variants(self, arch=None, types=None): - return [v for v in list(self.all_variants.values()) - if (not arch or arch in v.arches) and (not types or v.type in types)] + return [ + v + for v in list(self.all_variants.values()) + if (not arch or arch in v.arches) and (not types or v.type in types) + ] def can_fail(self, variant, arch, deliverable): - failable = get_arch_variant_data(self.conf, 'failable_deliverables', arch, variant) + failable = get_arch_variant_data( + self.conf, "failable_deliverables", arch, variant + ) return deliverable in failable def get_arches(self): @@ -221,19 +247,19 @@ class DummyCompose(object): def touch(path, content=None): """Helper utility that creates an dummy file in given location. Directories will be created.""" - content = content or (path + '\n') + content = content or (path + "\n") try: os.makedirs(os.path.dirname(path)) except OSError: pass if not isinstance(content, six.binary_type): content = content.encode() - with open(path, 'wb') as f: + with open(path, "wb") as f: f.write(content) return path -FIXTURE_DIR = os.path.join(os.path.dirname(__file__), 'fixtures') +FIXTURE_DIR = os.path.join(os.path.dirname(__file__), "fixtures") def copy_fixture(fixture_name, dest): @@ -243,27 +269,25 @@ def copy_fixture(fixture_name, dest): def boom(*args, **kwargs): - raise Exception('BOOM') + raise Exception("BOOM") -def mk_boom(cls=Exception, msg='BOOM'): +def mk_boom(cls=Exception, msg="BOOM"): def b(*args, **kwargs): raise cls(msg) + return b -PKGSET_REPOS = dict( - pkgset_source='repos', - pkgset_repos={}, -) +PKGSET_REPOS = dict(pkgset_source="repos", pkgset_repos={},) BASE_CONFIG = dict( - release_short='test', - release_name='Test', - release_version='1.0', - variants_file='variants.xml', - createrepo_checksum='sha256', - gather_method='deps', + release_short="test", + release_name="Test", + release_version="1.0", + variants_file="variants.xml", + createrepo_checksum="sha256", + gather_method="deps", ) diff --git a/tests/test_arch.py b/tests/test_arch.py index 5dbb50fd..9be23050 100644 --- a/tests/test_arch.py +++ b/tests/test_arch.py @@ -6,49 +6,66 @@ import unittest import os import sys -from pungi.arch import (get_compatible_arches, get_valid_arches, get_valid_multilib_arches, - is_excluded, is_valid_arch, split_name_arch) +from pungi.arch import ( + get_compatible_arches, + get_valid_arches, + get_valid_multilib_arches, + is_excluded, + is_valid_arch, + split_name_arch, +) class TestArch(unittest.TestCase): - def test_i386(self): arches = get_valid_arches("i386") - self.assertEqual(arches, ['i686', 'i586', 'i486', 'i386', 'noarch']) + self.assertEqual(arches, ["i686", "i586", "i486", "i386", "noarch"]) arches = get_valid_arches("i386", multilib=False) - self.assertEqual(arches, ['i686', 'i586', 'i486', 'i386', 'noarch']) + self.assertEqual(arches, ["i686", "i586", "i486", "i386", "noarch"]) arches = get_valid_arches("i386", add_src=True) - self.assertEqual(arches, ['i686', 'i586', 'i486', 'i386', 'noarch', 'src']) + self.assertEqual(arches, ["i686", "i586", "i486", "i386", "noarch", "src"]) def test_x86_64(self): arches = get_valid_arches("x86_64") - self.assertEqual(arches, ['x86_64', 'athlon', 'i686', 'i586', 'i486', 'i386', 'noarch']) + self.assertEqual( + arches, ["x86_64", "athlon", "i686", "i586", "i486", "i386", "noarch"] + ) arches = get_valid_arches("x86_64", multilib=False) - self.assertEqual(arches, ['x86_64', 'noarch']) + self.assertEqual(arches, ["x86_64", "noarch"]) arches = get_valid_arches("x86_64", add_src=True) - self.assertEqual(arches, ['x86_64', 'athlon', 'i686', 'i586', 'i486', 'i386', 'noarch', 'src']) + self.assertEqual( + arches, + ["x86_64", "athlon", "i686", "i586", "i486", "i386", "noarch", "src"], + ) def test_armhfp(self): arches = get_valid_arches("armhfp") - self.assertEqual(arches, ['armv7hnl', 'armv7hl', 'armv6hl', 'noarch']) + self.assertEqual(arches, ["armv7hnl", "armv7hl", "armv6hl", "noarch"]) arches = get_valid_arches("armhfp", multilib=False) - self.assertEqual(arches, ['armv7hnl', 'armv7hl', 'armv6hl', 'noarch']) + self.assertEqual(arches, ["armv7hnl", "armv7hl", "armv6hl", "noarch"]) arches = get_valid_arches("armhfp", add_src=True) - self.assertEqual(arches, ['armv7hnl', 'armv7hl', 'armv6hl', 'noarch', 'src']) + self.assertEqual(arches, ["armv7hnl", "armv7hl", "armv6hl", "noarch", "src"]) def test_get_compatible_arches(self): self.assertEqual(get_compatible_arches("noarch"), ["noarch"]) self.assertEqual(get_compatible_arches("i386"), get_valid_arches("i386")) self.assertEqual(get_compatible_arches("i586"), get_valid_arches("i386")) - self.assertEqual(get_compatible_arches("x86_64"), get_valid_arches("x86_64", multilib=False)) - self.assertEqual(get_compatible_arches("ppc64p7"), get_valid_arches("ppc64", multilib=False)) - self.assertEqual(get_compatible_arches("armhfp"), get_valid_arches("armv7hnl", multilib=False)) + self.assertEqual( + get_compatible_arches("x86_64"), get_valid_arches("x86_64", multilib=False) + ) + self.assertEqual( + get_compatible_arches("ppc64p7"), get_valid_arches("ppc64", multilib=False) + ) + self.assertEqual( + get_compatible_arches("armhfp"), + get_valid_arches("armv7hnl", multilib=False), + ) def test_is_valid_arch(self): self.assertEqual(is_valid_arch("i386"), True) @@ -63,29 +80,38 @@ class TestArch(unittest.TestCase): self.assertEqual(split_name_arch("package"), ("package", None)) self.assertEqual(split_name_arch("package.x86_64"), ("package", "x86_64")) self.assertEqual(split_name_arch("package.foo"), ("package.foo", None)) - self.assertEqual(split_name_arch("i386"), ("i386", None)) # we suppose that $name is never empty + self.assertEqual( + split_name_arch("i386"), ("i386", None) + ) # we suppose that $name is never empty def test_get_valid_multilib_arches(self): self.assertEqual(get_valid_multilib_arches("noarch"), []) self.assertEqual(get_valid_multilib_arches("athlon"), []) - self.assertEqual(get_valid_multilib_arches("x86_64"), ['athlon', 'i686', 'i586', 'i486', 'i386']) + self.assertEqual( + get_valid_multilib_arches("x86_64"), + ["athlon", "i686", "i586", "i486", "i386"], + ) class TestExclusiveExcludeArch(unittest.TestCase): def test_no_exclude(self): - pkg = mock.Mock(excludearch=[], exclusivearch=[], file_name='pkg.rpm') - self.assertFalse(is_excluded(pkg, ['x86_64'])) + pkg = mock.Mock(excludearch=[], exclusivearch=[], file_name="pkg.rpm") + self.assertFalse(is_excluded(pkg, ["x86_64"])) def test_exclude_arch(self): log = mock.Mock() - pkg = mock.Mock(excludearch=['x86_64'], exclusivearch=[], file_name='pkg.rpm') - self.assertTrue(is_excluded(pkg, ['x86_64'], logger=log)) - self.assertEqual(log.mock_calls, - [mock.call.debug("Excluding (EXCLUDEARCH: ['x86_64']): pkg.rpm")]) + pkg = mock.Mock(excludearch=["x86_64"], exclusivearch=[], file_name="pkg.rpm") + self.assertTrue(is_excluded(pkg, ["x86_64"], logger=log)) + self.assertEqual( + log.mock_calls, + [mock.call.debug("Excluding (EXCLUDEARCH: ['x86_64']): pkg.rpm")], + ) def test_exclusive_arch(self): log = mock.Mock() - pkg = mock.Mock(excludearch=[], exclusivearch=['aarch64'], file_name='pkg.rpm') - self.assertTrue(is_excluded(pkg, ['x86_64'], logger=log)) - self.assertEqual(log.mock_calls, - [mock.call.debug("Excluding (EXCLUSIVEARCH: ['aarch64']): pkg.rpm")]) + pkg = mock.Mock(excludearch=[], exclusivearch=["aarch64"], file_name="pkg.rpm") + self.assertTrue(is_excluded(pkg, ["x86_64"], logger=log)) + self.assertEqual( + log.mock_calls, + [mock.call.debug("Excluding (EXCLUSIVEARCH: ['aarch64']): pkg.rpm")], + ) diff --git a/tests/test_arguments.py b/tests/test_arguments.py index 8817859b..20bf17ed 100644 --- a/tests/test_arguments.py +++ b/tests/test_arguments.py @@ -1,4 +1,5 @@ import mock + try: import unittest2 as unittest except ImportError: @@ -9,17 +10,16 @@ from pungi.scripts.pungi_koji import cli_main class PungiKojiTestCase(unittest.TestCase): - - @mock.patch('sys.argv', new=['prog', '--version']) - @mock.patch('sys.stderr', new_callable=six.StringIO) - @mock.patch('sys.stdout', new_callable=six.StringIO) - @mock.patch('pungi.scripts.pungi_koji.get_full_version', return_value='a-b-c.111') + @mock.patch("sys.argv", new=["prog", "--version"]) + @mock.patch("sys.stderr", new_callable=six.StringIO) + @mock.patch("sys.stdout", new_callable=six.StringIO) + @mock.patch("pungi.scripts.pungi_koji.get_full_version", return_value="a-b-c.111") def test_version(self, get_full_version, stdout, stderr): with self.assertRaises(SystemExit) as cm: cli_main() self.assertEqual(cm.exception.code, 0) # Python 2.7 prints the version to stderr, 3.4+ to stdout. if six.PY3: - self.assertMultiLineEqual(stdout.getvalue(), 'a-b-c.111\n') + self.assertMultiLineEqual(stdout.getvalue(), "a-b-c.111\n") else: - self.assertMultiLineEqual(stderr.getvalue(), 'a-b-c.111\n') + self.assertMultiLineEqual(stderr.getvalue(), "a-b-c.111\n") diff --git a/tests/test_buildinstall.py b/tests/test_buildinstall.py index 8174670b..9a6df8b9 100644 --- a/tests/test_buildinstall.py +++ b/tests/test_buildinstall.py @@ -7,8 +7,13 @@ import six import os import sys -from pungi.phases.buildinstall import (BuildinstallPhase, BuildinstallThread, link_boot_iso, - BOOT_CONFIGS, tweak_configs) +from pungi.phases.buildinstall import ( + BuildinstallPhase, + BuildinstallThread, + link_boot_iso, + BOOT_CONFIGS, + tweak_configs, +) from tests.helpers import DummyCompose, PungiTestCase, touch @@ -16,12 +21,20 @@ class BuildInstallCompose(DummyCompose): def __init__(self, *args, **kwargs): super(BuildInstallCompose, self).__init__(*args, **kwargs) self.variants = { - 'Server': mock.Mock(uid='Server', arches=['x86_64', 'amd64'], - type='variant', buildinstallpackages=['bash', 'vim'], - is_empty=False), - 'Client': mock.Mock(uid='Client', arches=['amd64'], - type='variant', buildinstallpackages=[], - is_empty=False), + "Server": mock.Mock( + uid="Server", + arches=["x86_64", "amd64"], + type="variant", + buildinstallpackages=["bash", "vim"], + is_empty=False, + ), + "Client": mock.Mock( + uid="Client", + arches=["amd64"], + type="variant", + buildinstallpackages=[], + is_empty=False, + ), } self.all_variants = self.variants.copy() self.has_comps = True @@ -30,7 +43,6 @@ class BuildInstallCompose(DummyCompose): class TestBuildinstallPhase(PungiTestCase): - def test_config_skip_unless_bootable(self): compose = BuildInstallCompose(self.topdir, {}) compose.just_phases = None @@ -40,25 +52,24 @@ class TestBuildinstallPhase(PungiTestCase): self.assertTrue(phase.skip()) - @mock.patch('pungi.phases.buildinstall.ThreadPool') - @mock.patch('pungi.phases.buildinstall.LoraxWrapper') - @mock.patch('pungi.phases.buildinstall.get_volid') + @mock.patch("pungi.phases.buildinstall.ThreadPool") + @mock.patch("pungi.phases.buildinstall.LoraxWrapper") + @mock.patch("pungi.phases.buildinstall.get_volid") def test_skip_option(self, get_volid, loraxCls, poolCls): - compose = BuildInstallCompose(self.topdir, { - 'bootable': True, - 'buildinstall_method': 'lorax', - 'buildinstall_skip': [ - ('^Server$', { - 'amd64': True - }), - ('^Client$', { - '*': True, - }), - ] - }) + compose = BuildInstallCompose( + self.topdir, + { + "bootable": True, + "buildinstall_method": "lorax", + "buildinstall_skip": [ + ("^Server$", {"amd64": True}), + ("^Client$", {"*": True}), + ], + }, + ) - get_volid.return_value = 'vol_id' - loraxCls.return_value.get_lorax_cmd.return_value = ['lorax', '...'] + get_volid.return_value = "vol_id" + loraxCls.return_value.get_lorax_cmd.return_value = ["lorax", "..."] phase = BuildinstallPhase(compose, self._make_pkgset_phase(["p1"])) @@ -68,7 +79,7 @@ class TestBuildinstallPhase(PungiTestCase): self.assertEqual(1, len(pool.queue_put.mock_calls)) def test_does_not_skip_on_bootable(self): - compose = BuildInstallCompose(self.topdir, {'buildinstall_method': 'lorax'}) + compose = BuildInstallCompose(self.topdir, {"buildinstall_method": "lorax"}) compose.just_phases = None compose.skip_phases = [] @@ -76,21 +87,24 @@ class TestBuildinstallPhase(PungiTestCase): self.assertFalse(phase.skip()) - @mock.patch('pungi.phases.buildinstall.ThreadPool') - @mock.patch('pungi.phases.buildinstall.LoraxWrapper') - @mock.patch('pungi.phases.buildinstall.get_volid') + @mock.patch("pungi.phases.buildinstall.ThreadPool") + @mock.patch("pungi.phases.buildinstall.LoraxWrapper") + @mock.patch("pungi.phases.buildinstall.get_volid") def test_starts_threads_for_each_cmd_with_lorax(self, get_volid, loraxCls, poolCls): - compose = BuildInstallCompose(self.topdir, { - 'bootable': True, - 'release_name': 'Test', - 'release_short': 't', - 'release_version': '1', - 'buildinstall_method': 'lorax', - 'disc_types': {'dvd': 'DVD'}, - }) + compose = BuildInstallCompose( + self.topdir, + { + "bootable": True, + "release_name": "Test", + "release_short": "t", + "release_version": "1", + "buildinstall_method": "lorax", + "disc_types": {"dvd": "DVD"}, + }, + ) - get_volid.return_value = 'vol_id' - loraxCls.return_value.get_lorax_cmd.return_value = ['lorax', '...'] + get_volid.return_value = "vol_id" + loraxCls.return_value.get_lorax_cmd.return_value = ["lorax", "..."] phase = BuildinstallPhase(compose, self._make_pkgset_phase(["p1", "p2"])) @@ -103,75 +117,142 @@ class TestBuildinstallPhase(PungiTestCase): six.assertCountEqual( self, [call[0][0][3] for call in pool.queue_put.call_args_list], - ['rm -rf %s/work/amd64/buildinstall/Client && lorax ...' % self.topdir, - 'rm -rf %s/work/amd64/buildinstall/Server && lorax ...' % self.topdir, - 'rm -rf %s/work/x86_64/buildinstall/Server && lorax ...' % self.topdir]) + [ + "rm -rf %s/work/amd64/buildinstall/Client && lorax ..." % self.topdir, + "rm -rf %s/work/amd64/buildinstall/Server && lorax ..." % self.topdir, + "rm -rf %s/work/x86_64/buildinstall/Server && lorax ..." % self.topdir, + ], + ) # Obtained correct lorax commands. six.assertCountEqual( self, loraxCls.return_value.get_lorax_cmd.mock_calls, - [mock.call('Test', '1', '1', - [self.topdir + "/work/x86_64/repo/p1", + [ + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/x86_64/repo/p1", self.topdir + "/work/x86_64/repo/p2", - self.topdir + '/work/x86_64/comps_repo_Server'], - self.topdir + '/work/x86_64/buildinstall/Server', - buildarch='x86_64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/x86_64/buildinstall-Server-logs", - dracut_args=[]), - mock.call('Test', '1', '1', - [self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/x86_64/comps_repo_Server", + ], + self.topdir + "/work/x86_64/buildinstall/Server", + buildarch="x86_64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/x86_64/buildinstall-Server-logs", + dracut_args=[], + ), + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/amd64/repo/p1", self.topdir + "/work/amd64/repo/p2", - self.topdir + '/work/amd64/comps_repo_Server'], - self.topdir + '/work/amd64/buildinstall/Server', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/amd64/buildinstall-Server-logs", - dracut_args=[]), - mock.call('Test', '1', '1', - [self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/amd64/comps_repo_Server", + ], + self.topdir + "/work/amd64/buildinstall/Server", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/amd64/buildinstall-Server-logs", + dracut_args=[], + ), + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/amd64/repo/p1", self.topdir + "/work/amd64/repo/p2", - self.topdir + '/work/amd64/comps_repo_Client'], - self.topdir + '/work/amd64/buildinstall/Client', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Client', buildinstallpackages=[], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", - dracut_args=[])]) + self.topdir + "/work/amd64/comps_repo_Client", + ], + self.topdir + "/work/amd64/buildinstall/Client", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Client", + buildinstallpackages=[], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", + dracut_args=[], + ), + ], + ) six.assertCountEqual( self, get_volid.mock_calls, - [mock.call(compose, 'x86_64', variant=compose.variants['Server'], disc_type='DVD'), - mock.call(compose, 'amd64', variant=compose.variants['Client'], disc_type='DVD'), - mock.call(compose, 'amd64', variant=compose.variants['Server'], disc_type='DVD')]) + [ + mock.call( + compose, + "x86_64", + variant=compose.variants["Server"], + disc_type="DVD", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Client"], + disc_type="DVD", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Server"], + disc_type="DVD", + ), + ], + ) - @mock.patch('pungi.phases.buildinstall.ThreadPool') - @mock.patch('pungi.phases.buildinstall.get_volid') + @mock.patch("pungi.phases.buildinstall.ThreadPool") + @mock.patch("pungi.phases.buildinstall.get_volid") def test_starts_threads_for_each_cmd_with_lorax_koji_plugin( - self, get_volid, poolCls): - compose = BuildInstallCompose(self.topdir, { - 'bootable': True, - 'release_name': 'Test', - 'release_short': 't', - 'release_version': '1', - 'buildinstall_method': 'lorax', - 'lorax_use_koji_plugin': True, - 'disc_types': {'dvd': 'DVD'}, - }) + self, get_volid, poolCls + ): + compose = BuildInstallCompose( + self.topdir, + { + "bootable": True, + "release_name": "Test", + "release_short": "t", + "release_version": "1", + "buildinstall_method": "lorax", + "lorax_use_koji_plugin": True, + "disc_types": {"dvd": "DVD"}, + }, + ) - get_volid.return_value = 'vol_id' + get_volid.return_value = "vol_id" phase = BuildinstallPhase(compose, self._make_pkgset_phase(["p1", "p2"])) @@ -180,43 +261,79 @@ class TestBuildinstallPhase(PungiTestCase): expected_args = [ { - 'product': 'Test', 'version': '1', 'release': '1', - 'sources': [self.topdir + "/work/amd64/repo/p1", - self.topdir + "/work/amd64/repo/p2", - self.topdir + '/work/amd64/comps_repo_Server'], - 'variant': 'Server', 'installpkgs': ['bash', 'vim'], - 'isfinal': True, 'buildarch': 'amd64', 'volid': 'vol_id', - 'nomacboot': True, 'bugurl': None, 'add-template': [], - 'add-arch-template': [], 'add-template-var': [], - 'add-arch-template-var': [], 'noupgrade': True, - 'rootfs-size': None, 'dracut-args': [], - 'outputdir': self.topdir + '/work/amd64/buildinstall/Server' + "product": "Test", + "version": "1", + "release": "1", + "sources": [ + self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/amd64/repo/p2", + self.topdir + "/work/amd64/comps_repo_Server", + ], + "variant": "Server", + "installpkgs": ["bash", "vim"], + "isfinal": True, + "buildarch": "amd64", + "volid": "vol_id", + "nomacboot": True, + "bugurl": None, + "add-template": [], + "add-arch-template": [], + "add-template-var": [], + "add-arch-template-var": [], + "noupgrade": True, + "rootfs-size": None, + "dracut-args": [], + "outputdir": self.topdir + "/work/amd64/buildinstall/Server", }, { - 'product': 'Test', 'version': '1', 'release': '1', - 'sources': [self.topdir + "/work/amd64/repo/p1", - self.topdir + "/work/amd64/repo/p2", - self.topdir + '/work/amd64/comps_repo_Client'], - 'variant': 'Client', 'installpkgs': [], - 'isfinal': True, 'buildarch': 'amd64', 'volid': 'vol_id', - 'nomacboot': True, 'bugurl': None, 'add-template': [], - 'add-arch-template': [], 'add-template-var': [], - 'add-arch-template-var': [], 'noupgrade': True, - 'rootfs-size': None, 'dracut-args': [], - 'outputdir': self.topdir + '/work/amd64/buildinstall/Client' + "product": "Test", + "version": "1", + "release": "1", + "sources": [ + self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/amd64/repo/p2", + self.topdir + "/work/amd64/comps_repo_Client", + ], + "variant": "Client", + "installpkgs": [], + "isfinal": True, + "buildarch": "amd64", + "volid": "vol_id", + "nomacboot": True, + "bugurl": None, + "add-template": [], + "add-arch-template": [], + "add-template-var": [], + "add-arch-template-var": [], + "noupgrade": True, + "rootfs-size": None, + "dracut-args": [], + "outputdir": self.topdir + "/work/amd64/buildinstall/Client", }, { - 'product': 'Test', 'version': '1', 'release': '1', - 'sources': [self.topdir + "/work/x86_64/repo/p1", - self.topdir + "/work/x86_64/repo/p2", - self.topdir + '/work/x86_64/comps_repo_Server'], - 'variant': 'Server', 'installpkgs': ['bash', 'vim'], - 'isfinal': True, 'buildarch': 'x86_64', 'volid': 'vol_id', - 'nomacboot': True, 'bugurl': None, 'add-template': [], - 'add-arch-template': [], 'add-template-var': [], - 'add-arch-template-var': [], 'noupgrade': True, - 'rootfs-size': None, 'dracut-args': [], - 'outputdir': self.topdir + '/work/x86_64/buildinstall/Server' + "product": "Test", + "version": "1", + "release": "1", + "sources": [ + self.topdir + "/work/x86_64/repo/p1", + self.topdir + "/work/x86_64/repo/p2", + self.topdir + "/work/x86_64/comps_repo_Server", + ], + "variant": "Server", + "installpkgs": ["bash", "vim"], + "isfinal": True, + "buildarch": "x86_64", + "volid": "vol_id", + "nomacboot": True, + "bugurl": None, + "add-template": [], + "add-arch-template": [], + "add-template-var": [], + "add-arch-template-var": [], + "noupgrade": True, + "rootfs-size": None, + "dracut-args": [], + "outputdir": self.topdir + "/work/x86_64/buildinstall/Server", }, ] @@ -227,30 +344,52 @@ class TestBuildinstallPhase(PungiTestCase): six.assertCountEqual( self, [call[0][0][3] for call in pool.queue_put.call_args_list], - expected_args) + expected_args, + ) six.assertCountEqual( self, get_volid.mock_calls, - [mock.call(compose, 'x86_64', variant=compose.variants['Server'], disc_type='DVD'), - mock.call(compose, 'amd64', variant=compose.variants['Client'], disc_type='DVD'), - mock.call(compose, 'amd64', variant=compose.variants['Server'], disc_type='DVD')]) + [ + mock.call( + compose, + "x86_64", + variant=compose.variants["Server"], + disc_type="DVD", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Client"], + disc_type="DVD", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Server"], + disc_type="DVD", + ), + ], + ) - @mock.patch('pungi.phases.buildinstall.ThreadPool') - @mock.patch('pungi.phases.buildinstall.LoraxWrapper') - @mock.patch('pungi.phases.buildinstall.get_volid') + @mock.patch("pungi.phases.buildinstall.ThreadPool") + @mock.patch("pungi.phases.buildinstall.LoraxWrapper") + @mock.patch("pungi.phases.buildinstall.get_volid") def test_lorax_skips_empty_variants(self, get_volid, loraxCls, poolCls): - compose = BuildInstallCompose(self.topdir, { - 'bootable': True, - 'release_name': 'Test', - 'release_short': 't', - 'release_version': '1', - 'buildinstall_method': 'lorax' - }) + compose = BuildInstallCompose( + self.topdir, + { + "bootable": True, + "release_name": "Test", + "release_short": "t", + "release_version": "1", + "buildinstall_method": "lorax", + }, + ) - get_volid.return_value = 'vol_id' - compose.variants['Server'].is_empty = True - loraxCls.return_value.get_lorax_cmd.return_value = ['lorax', '...'] + get_volid.return_value = "vol_id" + compose.variants["Server"].is_empty = True + loraxCls.return_value.get_lorax_cmd.return_value = ["lorax", "..."] phase = BuildinstallPhase(compose, self._make_pkgset_phase(["p1"])) @@ -260,42 +399,72 @@ class TestBuildinstallPhase(PungiTestCase): self.assertEqual(1, len(pool.queue_put.mock_calls)) self.assertEqual( [call[0][0][3] for call in pool.queue_put.call_args_list], - ['rm -rf %s/work/amd64/buildinstall/Client && lorax ...' % self.topdir]) + ["rm -rf %s/work/amd64/buildinstall/Client && lorax ..." % self.topdir], + ) # Obtained correct lorax command. lorax = loraxCls.return_value lorax.get_lorax_cmd.assert_has_calls( - [mock.call('Test', '1', '1', - [self.topdir + "/work/amd64/repo/p1", - self.topdir + '/work/amd64/comps_repo_Client'], - self.topdir + '/work/amd64/buildinstall/Client', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Client', buildinstallpackages=[], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", - dracut_args=[])], - any_order=True) + [ + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/amd64/comps_repo_Client", + ], + self.topdir + "/work/amd64/buildinstall/Client", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Client", + buildinstallpackages=[], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", + dracut_args=[], + ) + ], + any_order=True, + ) self.assertEqual( get_volid.mock_calls, - [mock.call(compose, 'amd64', variant=compose.variants['Client'], disc_type='dvd')]) + [ + mock.call( + compose, + "amd64", + variant=compose.variants["Client"], + disc_type="dvd", + ) + ], + ) - @mock.patch('pungi.phases.buildinstall.ThreadPool') - @mock.patch('pungi.phases.buildinstall.LoraxWrapper') - @mock.patch('pungi.phases.buildinstall.get_volid') - def test_starts_threads_for_each_cmd_with_buildinstall(self, get_volid, loraxCls, poolCls): - compose = BuildInstallCompose(self.topdir, { - 'bootable': True, - 'release_name': 'Test', - 'release_short': 't', - 'release_version': '1', - 'buildinstall_method': 'buildinstall', - 'disc_types': {'dvd': 'DVD'}, - }) + @mock.patch("pungi.phases.buildinstall.ThreadPool") + @mock.patch("pungi.phases.buildinstall.LoraxWrapper") + @mock.patch("pungi.phases.buildinstall.get_volid") + def test_starts_threads_for_each_cmd_with_buildinstall( + self, get_volid, loraxCls, poolCls + ): + compose = BuildInstallCompose( + self.topdir, + { + "bootable": True, + "release_name": "Test", + "release_short": "t", + "release_version": "1", + "buildinstall_method": "buildinstall", + "disc_types": {"dvd": "DVD"}, + }, + ) - get_volid.return_value = 'vol_id' + get_volid.return_value = "vol_id" phase = BuildinstallPhase(compose, self._make_pkgset_phase(["p1"])) @@ -309,52 +478,76 @@ class TestBuildinstallPhase(PungiTestCase): six.assertCountEqual( self, loraxCls.return_value.get_buildinstall_cmd.mock_calls, - [mock.call('Test', '1', '1', [self.topdir + "/work/x86_64/repo/p1"], - self.topdir + '/work/x86_64/buildinstall', - buildarch='x86_64', is_final=True, volid='vol_id'), - mock.call('Test', '1', '1', [self.topdir + "/work/amd64/repo/p1"], - self.topdir + '/work/amd64/buildinstall', - buildarch='amd64', is_final=True, volid='vol_id')]) + [ + mock.call( + "Test", + "1", + "1", + [self.topdir + "/work/x86_64/repo/p1"], + self.topdir + "/work/x86_64/buildinstall", + buildarch="x86_64", + is_final=True, + volid="vol_id", + ), + mock.call( + "Test", + "1", + "1", + [self.topdir + "/work/amd64/repo/p1"], + self.topdir + "/work/amd64/buildinstall", + buildarch="amd64", + is_final=True, + volid="vol_id", + ), + ], + ) six.assertCountEqual( self, get_volid.mock_calls, - [mock.call(compose, 'x86_64', disc_type='DVD'), - mock.call(compose, 'amd64', disc_type='DVD')]) + [ + mock.call(compose, "x86_64", disc_type="DVD"), + mock.call(compose, "amd64", disc_type="DVD"), + ], + ) - @mock.patch('pungi.phases.buildinstall.ThreadPool') - @mock.patch('pungi.phases.buildinstall.LoraxWrapper') - @mock.patch('pungi.phases.buildinstall.get_volid') + @mock.patch("pungi.phases.buildinstall.ThreadPool") + @mock.patch("pungi.phases.buildinstall.LoraxWrapper") + @mock.patch("pungi.phases.buildinstall.get_volid") def test_uses_lorax_options(self, get_volid, loraxCls, poolCls): - compose = BuildInstallCompose(self.topdir, { - 'bootable': True, - 'release_name': 'Test', - 'release_short': 't', - 'release_version': '1', - 'buildinstall_method': 'lorax', - 'lorax_options': [ - ('^.*$', {'*': {}}), - ('^Server$', { - 'x86_64': { - 'bugurl': 'http://example.com', - 'add_template': ['foo', 'FOO'], - 'add_arch_template': ['bar'], - 'add_template_var': ['baz=1'], - 'add_arch_template_var': ['quux=2'], - "rootfs_size": 3, - "version": "1.2.3", - "dracut_args": ["--xz", "--install", "/.buildstamp"], - }, - 'amd64': {'noupgrade': False} - }), - ('^Client$', { - '*': {'nomacboot': False} - }), - ('^.*$', {'*': {}}), - ] - }) + compose = BuildInstallCompose( + self.topdir, + { + "bootable": True, + "release_name": "Test", + "release_short": "t", + "release_version": "1", + "buildinstall_method": "lorax", + "lorax_options": [ + ("^.*$", {"*": {}}), + ( + "^Server$", + { + "x86_64": { + "bugurl": "http://example.com", + "add_template": ["foo", "FOO"], + "add_arch_template": ["bar"], + "add_template_var": ["baz=1"], + "add_arch_template_var": ["quux=2"], + "rootfs_size": 3, + "version": "1.2.3", + "dracut_args": ["--xz", "--install", "/.buildstamp"], + }, + "amd64": {"noupgrade": False}, + }, + ), + ("^Client$", {"*": {"nomacboot": False}}), + ("^.*$", {"*": {}}), + ], + }, + ) - get_volid.return_value = 'vol_id' - loraxCls.return_value.get_lorax_cmd.return_value = ['lorax', '...'] + get_volid.return_value = "vol_id" + loraxCls.return_value.get_lorax_cmd.return_value = ["lorax", "..."] phase = BuildinstallPhase(compose, self._make_pkgset_phase(["p1"])) @@ -367,77 +560,143 @@ class TestBuildinstallPhase(PungiTestCase): six.assertCountEqual( self, [call[0][0][3] for call in pool.queue_put.call_args_list], - ['rm -rf %s/work/amd64/buildinstall/Client && lorax ...' % self.topdir, - 'rm -rf %s/work/amd64/buildinstall/Server && lorax ...' % self.topdir, - 'rm -rf %s/work/x86_64/buildinstall/Server && lorax ...' % self.topdir]) + [ + "rm -rf %s/work/amd64/buildinstall/Client && lorax ..." % self.topdir, + "rm -rf %s/work/amd64/buildinstall/Server && lorax ..." % self.topdir, + "rm -rf %s/work/x86_64/buildinstall/Server && lorax ..." % self.topdir, + ], + ) # Obtained correct lorax commands. six.assertCountEqual( self, loraxCls.return_value.get_lorax_cmd.mock_calls, - [mock.call('Test', '1.2.3', '1.2.3', - [self.topdir + "/work/x86_64/repo/p1", - self.topdir + '/work/x86_64/comps_repo_Server'], - self.topdir + '/work/x86_64/buildinstall/Server', - buildarch='x86_64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - add_template=['foo', 'FOO'], add_arch_template=['bar'], - add_template_var=['baz=1'], add_arch_template_var=['quux=2'], - bugurl='http://example.com', - rootfs_size=3, - log_dir=self.topdir + "/logs/x86_64/buildinstall-Server-logs", - dracut_args=["--xz", "--install", "/.buildstamp"]), - mock.call('Test', '1', '1', - [self.topdir + "/work/amd64/repo/p1", - self.topdir + '/work/amd64/comps_repo_Server'], - self.topdir + '/work/amd64/buildinstall/Server', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=False, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/amd64/buildinstall-Server-logs", - dracut_args=[]), - mock.call('Test', '1', '1', - [self.topdir + "/work/amd64/repo/p1", - self.topdir + '/work/amd64/comps_repo_Client'], - self.topdir + '/work/amd64/buildinstall/Client', - buildarch='amd64', is_final=True, nomacboot=False, noupgrade=True, - volid='vol_id', variant='Client', buildinstallpackages=[], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", - dracut_args=[])]) + [ + mock.call( + "Test", + "1.2.3", + "1.2.3", + [ + self.topdir + "/work/x86_64/repo/p1", + self.topdir + "/work/x86_64/comps_repo_Server", + ], + self.topdir + "/work/x86_64/buildinstall/Server", + buildarch="x86_64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + add_template=["foo", "FOO"], + add_arch_template=["bar"], + add_template_var=["baz=1"], + add_arch_template_var=["quux=2"], + bugurl="http://example.com", + rootfs_size=3, + log_dir=self.topdir + "/logs/x86_64/buildinstall-Server-logs", + dracut_args=["--xz", "--install", "/.buildstamp"], + ), + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/amd64/comps_repo_Server", + ], + self.topdir + "/work/amd64/buildinstall/Server", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=False, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/amd64/buildinstall-Server-logs", + dracut_args=[], + ), + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/amd64/comps_repo_Client", + ], + self.topdir + "/work/amd64/buildinstall/Client", + buildarch="amd64", + is_final=True, + nomacboot=False, + noupgrade=True, + volid="vol_id", + variant="Client", + buildinstallpackages=[], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", + dracut_args=[], + ), + ], + ) six.assertCountEqual( self, get_volid.mock_calls, - [mock.call(compose, 'x86_64', variant=compose.variants['Server'], disc_type='dvd'), - mock.call(compose, 'amd64', variant=compose.variants['Client'], disc_type='dvd'), - mock.call(compose, 'amd64', variant=compose.variants['Server'], disc_type='dvd')]) + [ + mock.call( + compose, + "x86_64", + variant=compose.variants["Server"], + disc_type="dvd", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Client"], + disc_type="dvd", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Server"], + disc_type="dvd", + ), + ], + ) - @mock.patch('pungi.phases.buildinstall.ThreadPool') - @mock.patch('pungi.phases.buildinstall.LoraxWrapper') - @mock.patch('pungi.phases.buildinstall.get_volid') + @mock.patch("pungi.phases.buildinstall.ThreadPool") + @mock.patch("pungi.phases.buildinstall.LoraxWrapper") + @mock.patch("pungi.phases.buildinstall.get_volid") def test_multiple_lorax_options(self, get_volid, loraxCls, poolCls): - compose = BuildInstallCompose(self.topdir, { - 'bootable': True, - 'release_name': 'Test', - 'release_short': 't', - 'release_version': '1', - 'buildinstall_method': 'lorax', - 'lorax_options': [ - ('^.*$', { - 'x86_64': {'nomacboot': False}, - '*': {'noupgrade': False} - }), - ] - }) + compose = BuildInstallCompose( + self.topdir, + { + "bootable": True, + "release_name": "Test", + "release_short": "t", + "release_version": "1", + "buildinstall_method": "lorax", + "lorax_options": [ + ( + "^.*$", + {"x86_64": {"nomacboot": False}, "*": {"noupgrade": False}}, + ), + ], + }, + ) - get_volid.return_value = 'vol_id' - loraxCls.return_value.get_lorax_cmd.return_value = ['lorax', '...'] + get_volid.return_value = "vol_id" + loraxCls.return_value.get_lorax_cmd.return_value = ["lorax", "..."] phase = BuildinstallPhase(compose, self._make_pkgset_phase(["p1"])) @@ -450,77 +709,144 @@ class TestBuildinstallPhase(PungiTestCase): six.assertCountEqual( self, [call[0][0][3] for call in pool.queue_put.call_args_list], - ['rm -rf %s/work/amd64/buildinstall/Client && lorax ...' % self.topdir, - 'rm -rf %s/work/amd64/buildinstall/Server && lorax ...' % self.topdir, - 'rm -rf %s/work/x86_64/buildinstall/Server && lorax ...' % self.topdir]) + [ + "rm -rf %s/work/amd64/buildinstall/Client && lorax ..." % self.topdir, + "rm -rf %s/work/amd64/buildinstall/Server && lorax ..." % self.topdir, + "rm -rf %s/work/x86_64/buildinstall/Server && lorax ..." % self.topdir, + ], + ) # Obtained correct lorax commands. six.assertCountEqual( self, loraxCls.return_value.get_lorax_cmd.mock_calls, - [mock.call('Test', '1', '1', - [self.topdir + "/work/x86_64/repo/p1", - self.topdir + '/work/x86_64/comps_repo_Server'], - self.topdir + '/work/x86_64/buildinstall/Server', - buildarch='x86_64', is_final=True, nomacboot=False, noupgrade=False, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/x86_64/buildinstall-Server-logs", - dracut_args=[]), - mock.call('Test', '1', '1', - [self.topdir + "/work/amd64/repo/p1", - self.topdir + '/work/amd64/comps_repo_Server'], - self.topdir + '/work/amd64/buildinstall/Server', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=False, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/amd64/buildinstall-Server-logs", - dracut_args=[]), - mock.call('Test', '1', '1', - [self.topdir + "/work/amd64/repo/p1", - self.topdir + '/work/amd64/comps_repo_Client'], - self.topdir + '/work/amd64/buildinstall/Client', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=False, - volid='vol_id', variant='Client', buildinstallpackages=[], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", - dracut_args=[])]) + [ + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/x86_64/repo/p1", + self.topdir + "/work/x86_64/comps_repo_Server", + ], + self.topdir + "/work/x86_64/buildinstall/Server", + buildarch="x86_64", + is_final=True, + nomacboot=False, + noupgrade=False, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/x86_64/buildinstall-Server-logs", + dracut_args=[], + ), + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/amd64/comps_repo_Server", + ], + self.topdir + "/work/amd64/buildinstall/Server", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=False, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/amd64/buildinstall-Server-logs", + dracut_args=[], + ), + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/amd64/comps_repo_Client", + ], + self.topdir + "/work/amd64/buildinstall/Client", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=False, + volid="vol_id", + variant="Client", + buildinstallpackages=[], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", + dracut_args=[], + ), + ], + ) six.assertCountEqual( self, get_volid.mock_calls, - [mock.call(compose, 'x86_64', variant=compose.variants['Server'], disc_type='dvd'), - mock.call(compose, 'amd64', variant=compose.variants['Client'], disc_type='dvd'), - mock.call(compose, 'amd64', variant=compose.variants['Server'], disc_type='dvd')]) + [ + mock.call( + compose, + "x86_64", + variant=compose.variants["Server"], + disc_type="dvd", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Client"], + disc_type="dvd", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Server"], + disc_type="dvd", + ), + ], + ) - @mock.patch('pungi.phases.buildinstall.ThreadPool') - @mock.patch('pungi.phases.buildinstall.LoraxWrapper') - @mock.patch('pungi.phases.buildinstall.get_volid') + @mock.patch("pungi.phases.buildinstall.ThreadPool") + @mock.patch("pungi.phases.buildinstall.LoraxWrapper") + @mock.patch("pungi.phases.buildinstall.get_volid") def test_uses_lorax_options_buildinstall_topdir(self, get_volid, loraxCls, poolCls): - compose = BuildInstallCompose(self.topdir, { - 'bootable': True, - 'release_name': 'Test', - 'release_short': 't', - 'release_version': '1', - 'buildinstall_method': 'lorax', - 'buildinstall_topdir': '/buildinstall_topdir', - 'translate_paths': [(self.topdir, "http://localhost/")], - }) + compose = BuildInstallCompose( + self.topdir, + { + "bootable": True, + "release_name": "Test", + "release_short": "t", + "release_version": "1", + "buildinstall_method": "lorax", + "buildinstall_topdir": "/buildinstall_topdir", + "translate_paths": [(self.topdir, "http://localhost/")], + }, + ) buildinstall_topdir = os.path.join( - "/buildinstall_topdir", "buildinstall-" + os.path.basename(self.topdir)) + "/buildinstall_topdir", "buildinstall-" + os.path.basename(self.topdir) + ) self.maxDiff = None - get_volid.return_value = 'vol_id' - loraxCls.return_value.get_lorax_cmd.return_value = ['lorax', '...'] + get_volid.return_value = "vol_id" + loraxCls.return_value.get_lorax_cmd.return_value = ["lorax", "..."] phase = BuildinstallPhase(compose, self._make_pkgset_phase(["p1"])) @@ -533,79 +859,149 @@ class TestBuildinstallPhase(PungiTestCase): six.assertCountEqual( self, [call[0][0][3] for call in pool.queue_put.call_args_list], - ['rm -rf %s/amd64/Client && lorax ...' % buildinstall_topdir, - 'rm -rf %s/amd64/Server && lorax ...' % buildinstall_topdir, - 'rm -rf %s/x86_64/Server && lorax ...' % buildinstall_topdir]) + [ + "rm -rf %s/amd64/Client && lorax ..." % buildinstall_topdir, + "rm -rf %s/amd64/Server && lorax ..." % buildinstall_topdir, + "rm -rf %s/x86_64/Server && lorax ..." % buildinstall_topdir, + ], + ) # Obtained correct lorax commands. six.assertCountEqual( self, loraxCls.return_value.get_lorax_cmd.mock_calls, - [mock.call('Test', '1', '1', - ["http://localhost/work/x86_64/repo/p1", - 'http://localhost/work/x86_64/comps_repo_Server'], - buildinstall_topdir + '/x86_64/Server/results', - buildarch='x86_64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - bugurl=None, - rootfs_size=None, - log_dir=buildinstall_topdir + "/x86_64/Server/logs", - dracut_args=[]), - mock.call('Test', '1', '1', - ["http://localhost/work/amd64/repo/p1", - 'http://localhost/work/amd64/comps_repo_Server'], - buildinstall_topdir + '/amd64/Server/results', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=buildinstall_topdir + "/amd64/Server/logs", - dracut_args=[]), - mock.call('Test', '1', '1', - ["http://localhost/work/amd64/repo/p1", - 'http://localhost/work/amd64/comps_repo_Client'], - buildinstall_topdir + '/amd64/Client/results', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Client', buildinstallpackages=[], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=buildinstall_topdir + "/amd64/Client/logs", - dracut_args=[])]) + [ + mock.call( + "Test", + "1", + "1", + [ + "http://localhost/work/x86_64/repo/p1", + "http://localhost/work/x86_64/comps_repo_Server", + ], + buildinstall_topdir + "/x86_64/Server/results", + buildarch="x86_64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + bugurl=None, + rootfs_size=None, + log_dir=buildinstall_topdir + "/x86_64/Server/logs", + dracut_args=[], + ), + mock.call( + "Test", + "1", + "1", + [ + "http://localhost/work/amd64/repo/p1", + "http://localhost/work/amd64/comps_repo_Server", + ], + buildinstall_topdir + "/amd64/Server/results", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=buildinstall_topdir + "/amd64/Server/logs", + dracut_args=[], + ), + mock.call( + "Test", + "1", + "1", + [ + "http://localhost/work/amd64/repo/p1", + "http://localhost/work/amd64/comps_repo_Client", + ], + buildinstall_topdir + "/amd64/Client/results", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Client", + buildinstallpackages=[], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=buildinstall_topdir + "/amd64/Client/logs", + dracut_args=[], + ), + ], + ) six.assertCountEqual( self, get_volid.mock_calls, - [mock.call(compose, 'x86_64', variant=compose.variants['Server'], disc_type='dvd'), - mock.call(compose, 'amd64', variant=compose.variants['Client'], disc_type='dvd'), - mock.call(compose, 'amd64', variant=compose.variants['Server'], disc_type='dvd')]) + [ + mock.call( + compose, + "x86_64", + variant=compose.variants["Server"], + disc_type="dvd", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Client"], + disc_type="dvd", + ), + mock.call( + compose, + "amd64", + variant=compose.variants["Server"], + disc_type="dvd", + ), + ], + ) - @mock.patch('pungi.phases.buildinstall.ThreadPool') - @mock.patch('pungi.phases.buildinstall.LoraxWrapper') - @mock.patch('pungi.phases.buildinstall.get_volid') + @mock.patch("pungi.phases.buildinstall.ThreadPool") + @mock.patch("pungi.phases.buildinstall.LoraxWrapper") + @mock.patch("pungi.phases.buildinstall.get_volid") def test_uses_lorax_extra_repos(self, get_volid, loraxCls, poolCls): - compose = BuildInstallCompose(self.topdir, { - 'bootable': True, - 'release_name': 'Test', - 'release_short': 't', - 'release_version': '1', - 'buildinstall_method': 'lorax', - 'lorax_extra_sources': [ - ('^Server$', { - 'x86_64': "http://example.com/repo1", - }), - ('^Client$', { - '*': ["http://example.com/repo2", "http://example.com/repo3"], - }), - ] - }) + compose = BuildInstallCompose( + self.topdir, + { + "bootable": True, + "release_name": "Test", + "release_short": "t", + "release_version": "1", + "buildinstall_method": "lorax", + "lorax_extra_sources": [ + ("^Server$", {"x86_64": "http://example.com/repo1"}), + ( + "^Client$", + { + "*": [ + "http://example.com/repo2", + "http://example.com/repo3", + ], + }, + ), + ], + }, + ) - get_volid.return_value = 'vol_id' - loraxCls.return_value.get_lorax_cmd.return_value = ['lorax', '...'] + get_volid.return_value = "vol_id" + loraxCls.return_value.get_lorax_cmd.return_value = ["lorax", "..."] phase = BuildinstallPhase(compose, self._make_pkgset_phase(["p1"])) @@ -615,106 +1011,168 @@ class TestBuildinstallPhase(PungiTestCase): six.assertCountEqual( self, loraxCls.return_value.get_lorax_cmd.mock_calls, - [mock.call('Test', '1', '1', - [self.topdir + "/work/x86_64/repo/p1", + [ + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/x86_64/repo/p1", "http://example.com/repo1", - self.topdir + '/work/x86_64/comps_repo_Server'], - self.topdir + '/work/x86_64/buildinstall/Server', - buildarch='x86_64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - bugurl=None, - rootfs_size=None, - log_dir=self.topdir + "/logs/x86_64/buildinstall-Server-logs", - dracut_args=[]), - mock.call('Test', '1', '1', - [self.topdir + "/work/amd64/repo/p1", - self.topdir + '/work/amd64/comps_repo_Server'], - self.topdir + '/work/amd64/buildinstall/Server', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim'], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/amd64/buildinstall-Server-logs", - dracut_args=[]), - mock.call('Test', '1', '1', - [self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/x86_64/comps_repo_Server", + ], + self.topdir + "/work/x86_64/buildinstall/Server", + buildarch="x86_64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + bugurl=None, + rootfs_size=None, + log_dir=self.topdir + "/logs/x86_64/buildinstall-Server-logs", + dracut_args=[], + ), + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/amd64/repo/p1", + self.topdir + "/work/amd64/comps_repo_Server", + ], + self.topdir + "/work/amd64/buildinstall/Server", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Server", + buildinstallpackages=["bash", "vim"], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/amd64/buildinstall-Server-logs", + dracut_args=[], + ), + mock.call( + "Test", + "1", + "1", + [ + self.topdir + "/work/amd64/repo/p1", "http://example.com/repo2", "http://example.com/repo3", - self.topdir + '/work/amd64/comps_repo_Client'], - self.topdir + '/work/amd64/buildinstall/Client', - buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True, - volid='vol_id', variant='Client', buildinstallpackages=[], - bugurl=None, - add_template=[], add_arch_template=[], - add_template_var=[], add_arch_template_var=[], - rootfs_size=None, - log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", - dracut_args=[])]) + self.topdir + "/work/amd64/comps_repo_Client", + ], + self.topdir + "/work/amd64/buildinstall/Client", + buildarch="amd64", + is_final=True, + nomacboot=True, + noupgrade=True, + volid="vol_id", + variant="Client", + buildinstallpackages=[], + bugurl=None, + add_template=[], + add_arch_template=[], + add_template_var=[], + add_arch_template_var=[], + rootfs_size=None, + log_dir=self.topdir + "/logs/amd64/buildinstall-Client-logs", + dracut_args=[], + ), + ], + ) @mock.patch( - 'pungi.phases.buildinstall.get_volid', new=lambda *args, **kwargs: "dummy-volid" + "pungi.phases.buildinstall.get_volid", new=lambda *args, **kwargs: "dummy-volid" ) class BuildinstallThreadTestCase(PungiTestCase): - def setUp(self): super(BuildinstallThreadTestCase, self).setUp() self.pool = mock.Mock(finished_tasks=set()) self.cmd = mock.Mock() - @mock.patch('pungi.phases.buildinstall.link_boot_iso') - @mock.patch('pungi.phases.buildinstall.tweak_buildinstall') - @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.link_boot_iso") + @mock.patch("pungi.phases.buildinstall.tweak_buildinstall") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + @mock.patch("pungi.wrappers.kojiwrapper.get_buildroot_rpms") + @mock.patch("pungi.phases.buildinstall.run") def test_buildinstall_thread_with_lorax_in_runroot( self, run, get_buildroot_rpms, KojiWrapperMock, mock_tweak, mock_link ): - compose = BuildInstallCompose(self.topdir, { - 'buildinstall_method': 'lorax', - 'runroot_tag': 'rrt', - 'koji_profile': 'koji', - 'runroot_weights': {'buildinstall': 123}, - }) + compose = BuildInstallCompose( + self.topdir, + { + "buildinstall_method": "lorax", + "runroot_tag": "rrt", + "koji_profile": "koji", + "runroot_weights": {"buildinstall": 123}, + }, + ) - get_buildroot_rpms.return_value = ['bash', 'zsh'] + get_buildroot_rpms.return_value = ["bash", "zsh"] get_runroot_cmd = KojiWrapperMock.return_value.get_runroot_cmd run_runroot_cmd = KojiWrapperMock.return_value.run_runroot_cmd run_runroot_cmd.return_value = { - 'output': 'Foo bar baz', - 'retcode': 0, - 'task_id': 1234, + "output": "Foo bar baz", + "retcode": 0, + "task_id": 1234, } t = BuildinstallThread(self.pool) - with mock.patch('time.sleep'): - t.process((compose, 'x86_64', compose.variants['Server'], self.cmd), 0) + with mock.patch("time.sleep"): + t.process((compose, "x86_64", compose.variants["Server"], self.cmd), 0) destdir = os.path.join(self.topdir, "work/x86_64/buildinstall/Server") self.assertEqual( get_runroot_cmd.mock_calls, - [mock.call( - 'rrt', 'x86_64', self.cmd, channel=None, - use_shell=True, - packages=['lorax'], mounts=[self.topdir], weight=123, - chown_paths=[ - destdir, - os.path.join(self.topdir, "logs/x86_64/buildinstall-Server-logs"), - ], - )]) + [ + mock.call( + "rrt", + "x86_64", + self.cmd, + channel=None, + use_shell=True, + packages=["lorax"], + mounts=[self.topdir], + weight=123, + chown_paths=[ + destdir, + os.path.join( + self.topdir, "logs/x86_64/buildinstall-Server-logs" + ), + ], + ) + ], + ) self.assertEqual( run_runroot_cmd.mock_calls, - [mock.call(get_runroot_cmd.return_value, - log_file=self.topdir + '/logs/x86_64/buildinstall-Server.x86_64.log')]) - with open(self.topdir + '/logs/x86_64/buildinstall-Server-RPMs.x86_64.log') as f: - rpms = f.read().strip().split('\n') + [ + mock.call( + get_runroot_cmd.return_value, + log_file=self.topdir + + "/logs/x86_64/buildinstall-Server.x86_64.log", + ) + ], + ) + with open( + self.topdir + "/logs/x86_64/buildinstall-Server-RPMs.x86_64.log" + ) as f: + rpms = f.read().strip().split("\n") six.assertCountEqual(self, rpms, ["bash", "zsh"]) six.assertCountEqual(self, self.pool.finished_tasks, [("Server", "x86_64")]) @@ -738,52 +1196,73 @@ class BuildinstallThreadTestCase(PungiTestCase): [mock.call(compose, "x86_64", compose.variants["Server"], False)], ) - @mock.patch('pungi.phases.buildinstall.link_boot_iso') - @mock.patch('pungi.phases.buildinstall.tweak_buildinstall') - @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.link_boot_iso") + @mock.patch("pungi.phases.buildinstall.tweak_buildinstall") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + @mock.patch("pungi.wrappers.kojiwrapper.get_buildroot_rpms") + @mock.patch("pungi.phases.buildinstall.run") def test_buildinstall_thread_with_lorax_using_koji_plugin( self, run, get_buildroot_rpms, KojiWrapperMock, mock_tweak, mock_link ): - compose = BuildInstallCompose(self.topdir, { - 'buildinstall_method': 'lorax', - 'lorax_use_koji_plugin': True, - 'runroot_tag': 'rrt', - 'koji_profile': 'koji', - 'runroot_weights': {'buildinstall': 123}, - }) + compose = BuildInstallCompose( + self.topdir, + { + "buildinstall_method": "lorax", + "lorax_use_koji_plugin": True, + "runroot_tag": "rrt", + "koji_profile": "koji", + "runroot_weights": {"buildinstall": 123}, + }, + ) - get_buildroot_rpms.return_value = ['bash', 'zsh'] + get_buildroot_rpms.return_value = ["bash", "zsh"] - get_pungi_buildinstall_cmd = KojiWrapperMock.return_value.get_pungi_buildinstall_cmd + get_pungi_buildinstall_cmd = ( + KojiWrapperMock.return_value.get_pungi_buildinstall_cmd + ) run_runroot_cmd = KojiWrapperMock.return_value.run_runroot_cmd run_runroot_cmd.return_value = { - 'output': 'Foo bar baz', - 'retcode': 0, - 'task_id': 1234, + "output": "Foo bar baz", + "retcode": 0, + "task_id": 1234, } t = BuildinstallThread(self.pool) - with mock.patch('time.sleep'): - t.process((compose, 'x86_64', compose.variants['Server'], self.cmd), 0) + with mock.patch("time.sleep"): + t.process((compose, "x86_64", compose.variants["Server"], self.cmd), 0) destdir = os.path.join(self.topdir, "work/x86_64/buildinstall/Server") self.assertEqual( get_pungi_buildinstall_cmd.mock_calls, - [mock.call( - 'rrt', 'x86_64', self.cmd, channel=None, - packages=['lorax'], mounts=[self.topdir], - weight=123, chown_uid=os.getuid() - )]) + [ + mock.call( + "rrt", + "x86_64", + self.cmd, + channel=None, + packages=["lorax"], + mounts=[self.topdir], + weight=123, + chown_uid=os.getuid(), + ) + ], + ) self.assertEqual( run_runroot_cmd.mock_calls, - [mock.call(get_pungi_buildinstall_cmd.return_value, - log_file=self.topdir + '/logs/x86_64/buildinstall-Server.x86_64.log')]) - with open(self.topdir + '/logs/x86_64/buildinstall-Server-RPMs.x86_64.log') as f: - rpms = f.read().strip().split('\n') + [ + mock.call( + get_pungi_buildinstall_cmd.return_value, + log_file=self.topdir + + "/logs/x86_64/buildinstall-Server.x86_64.log", + ) + ], + ) + with open( + self.topdir + "/logs/x86_64/buildinstall-Server-RPMs.x86_64.log" + ) as f: + rpms = f.read().strip().split("\n") six.assertCountEqual(self, rpms, ["bash", "zsh"]) six.assertCountEqual(self, self.pool.finished_tasks, [("Server", "x86_64")]) @@ -807,51 +1286,67 @@ class BuildinstallThreadTestCase(PungiTestCase): [mock.call(compose, "x86_64", compose.variants["Server"], False)], ) - @mock.patch('pungi.phases.buildinstall.link_boot_iso') - @mock.patch('pungi.phases.buildinstall.tweak_buildinstall') - @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.link_boot_iso") + @mock.patch("pungi.phases.buildinstall.tweak_buildinstall") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + @mock.patch("pungi.wrappers.kojiwrapper.get_buildroot_rpms") + @mock.patch("pungi.phases.buildinstall.run") def test_buildinstall_thread_with_buildinstall_in_runroot( self, run, get_buildroot_rpms, KojiWrapperMock, mock_tweak, mock_link ): - compose = BuildInstallCompose(self.topdir, { - 'buildinstall_method': 'buildinstall', - 'runroot_tag': 'rrt', - 'koji_profile': 'koji', - }) + compose = BuildInstallCompose( + self.topdir, + { + "buildinstall_method": "buildinstall", + "runroot_tag": "rrt", + "koji_profile": "koji", + }, + ) - get_buildroot_rpms.return_value = ['bash', 'zsh'] + get_buildroot_rpms.return_value = ["bash", "zsh"] get_runroot_cmd = KojiWrapperMock.return_value.get_runroot_cmd run_runroot_cmd = KojiWrapperMock.return_value.run_runroot_cmd run_runroot_cmd.return_value = { - 'output': 'Foo bar baz', - 'retcode': 0, - 'task_id': 1234, + "output": "Foo bar baz", + "retcode": 0, + "task_id": 1234, } t = BuildinstallThread(self.pool) - with mock.patch('time.sleep'): + with mock.patch("time.sleep"): t.process((compose, "amd64", None, self.cmd), 0) destdir = os.path.join(self.topdir, "work/amd64/buildinstall") self.assertEqual( get_runroot_cmd.mock_calls, - [mock.call( - "rrt", "amd64", self.cmd, channel=None, - use_shell=True, - packages=['anaconda'], mounts=[self.topdir], weight=None, - chown_paths=[destdir], - )]) + [ + mock.call( + "rrt", + "amd64", + self.cmd, + channel=None, + use_shell=True, + packages=["anaconda"], + mounts=[self.topdir], + weight=None, + chown_paths=[destdir], + ) + ], + ) self.assertEqual( run_runroot_cmd.mock_calls, - [mock.call(get_runroot_cmd.return_value, - log_file=self.topdir + "/logs/amd64/buildinstall.amd64.log")]) + [ + mock.call( + get_runroot_cmd.return_value, + log_file=self.topdir + "/logs/amd64/buildinstall.amd64.log", + ) + ], + ) with open(self.topdir + "/logs/amd64/buildinstall-RPMs.amd64.log") as f: - rpms = f.read().strip().split('\n') + rpms = f.read().strip().split("\n") six.assertCountEqual(self, rpms, ["bash", "zsh"]) six.assertCountEqual(self, self.pool.finished_tasks, [(None, "amd64")]) six.assertCountEqual( @@ -880,163 +1375,211 @@ class BuildinstallThreadTestCase(PungiTestCase): ], ) - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - @mock.patch('pungi.wrappers.kojiwrapper.get_buildroot_rpms') - @mock.patch('pungi.phases.buildinstall.run') - def test_buildinstall_fail_exit_code(self, run, get_buildroot_rpms, KojiWrapperMock): - compose = BuildInstallCompose(self.topdir, { - 'buildinstall_method': 'buildinstall', - 'runroot_tag': 'rrt', - 'koji_profile': 'koji', - 'failable_deliverables': [ - ('^.+$', {'*': ['buildinstall']}) - ], - }) + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + @mock.patch("pungi.wrappers.kojiwrapper.get_buildroot_rpms") + @mock.patch("pungi.phases.buildinstall.run") + def test_buildinstall_fail_exit_code( + self, run, get_buildroot_rpms, KojiWrapperMock + ): + compose = BuildInstallCompose( + self.topdir, + { + "buildinstall_method": "buildinstall", + "runroot_tag": "rrt", + "koji_profile": "koji", + "failable_deliverables": [("^.+$", {"*": ["buildinstall"]})], + }, + ) - get_buildroot_rpms.return_value = ['bash', 'zsh'] + get_buildroot_rpms.return_value = ["bash", "zsh"] run_runroot_cmd = KojiWrapperMock.return_value.run_runroot_cmd run_runroot_cmd.return_value = { - 'output': 'Foo bar baz', - 'retcode': 1, - 'task_id': 1234, + "output": "Foo bar baz", + "retcode": 1, + "task_id": 1234, } t = BuildinstallThread(self.pool) - with mock.patch('time.sleep'): - t.process((compose, 'x86_64', None, self.cmd), 0) + with mock.patch("time.sleep"): + t.process((compose, "x86_64", None, self.cmd), 0) - compose._logger.error.assert_has_calls([ - mock.call('[FAIL] Buildinstall (variant None, arch x86_64) failed, but going on anyway.'), - mock.call('Runroot task failed: 1234. See %s/logs/x86_64/buildinstall.x86_64.log for more details.' - % self.topdir) - ]) + compose._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Buildinstall (variant None, arch x86_64) failed, but going on anyway." + ), + mock.call( + "Runroot task failed: 1234. See %s/logs/x86_64/buildinstall.x86_64.log for more details." + % self.topdir + ), + ] + ) self.assertEqual(self.pool.finished_tasks, set()) - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - @mock.patch('pungi.wrappers.kojiwrapper.get_buildroot_rpms') - @mock.patch('pungi.phases.buildinstall.run') + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + @mock.patch("pungi.wrappers.kojiwrapper.get_buildroot_rpms") + @mock.patch("pungi.phases.buildinstall.run") def test_lorax_fail_exit_code(self, run, get_buildroot_rpms, KojiWrapperMock): - compose = BuildInstallCompose(self.topdir, { - 'buildinstall_method': 'lorax', - 'runroot_tag': 'rrt', - 'koji_profile': 'koji', - 'failable_deliverables': [ - ('^.+$', {'*': ['buildinstall']}) - ], - }) + compose = BuildInstallCompose( + self.topdir, + { + "buildinstall_method": "lorax", + "runroot_tag": "rrt", + "koji_profile": "koji", + "failable_deliverables": [("^.+$", {"*": ["buildinstall"]})], + }, + ) - get_buildroot_rpms.return_value = ['bash', 'zsh'] + get_buildroot_rpms.return_value = ["bash", "zsh"] run_runroot_cmd = KojiWrapperMock.return_value.run_runroot_cmd run_runroot_cmd.return_value = { - 'output': 'Foo bar baz', - 'retcode': 1, - 'task_id': 1234, + "output": "Foo bar baz", + "retcode": 1, + "task_id": 1234, } t = BuildinstallThread(self.pool) - with mock.patch('time.sleep'): - t.process((compose, 'x86_64', compose.variants['Server'], self.cmd), 0) + with mock.patch("time.sleep"): + t.process((compose, "x86_64", compose.variants["Server"], self.cmd), 0) - compose._logger.error.assert_has_calls([ - mock.call('[FAIL] Buildinstall (variant Server, arch x86_64) failed, but going on anyway.'), - mock.call('Runroot task failed: 1234. See %s/logs/x86_64/buildinstall-Server.x86_64.log for more details.' % self.topdir) - ]) + compose._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Buildinstall (variant Server, arch x86_64) failed, but going on anyway." + ), + mock.call( + "Runroot task failed: 1234. See %s/logs/x86_64/buildinstall-Server.x86_64.log for more details." + % self.topdir + ), + ] + ) self.assertEqual(self.pool.finished_tasks, set()) - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - @mock.patch('pungi.wrappers.kojiwrapper.get_buildroot_rpms') - @mock.patch('pungi.phases.buildinstall.run') - def test_skips_on_existing_output_dir(self, run, get_buildroot_rpms, KojiWrapperMock): - compose = BuildInstallCompose(self.topdir, { - 'buildinstall_method': 'lorax', - 'runroot_tag': 'rrt', - 'koji_profile': 'koji', - 'failable_deliverables': [ - ('^.+$', {'*': ['buildinstall']}) - ], - }) + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + @mock.patch("pungi.wrappers.kojiwrapper.get_buildroot_rpms") + @mock.patch("pungi.phases.buildinstall.run") + def test_skips_on_existing_output_dir( + self, run, get_buildroot_rpms, KojiWrapperMock + ): + compose = BuildInstallCompose( + self.topdir, + { + "buildinstall_method": "lorax", + "runroot_tag": "rrt", + "koji_profile": "koji", + "failable_deliverables": [("^.+$", {"*": ["buildinstall"]})], + }, + ) - get_buildroot_rpms.return_value = ['bash', 'zsh'] + get_buildroot_rpms.return_value = ["bash", "zsh"] - dummy_file = os.path.join(self.topdir, 'work/x86_64/buildinstall/Server/dummy') + dummy_file = os.path.join(self.topdir, "work/x86_64/buildinstall/Server/dummy") touch(os.path.join(dummy_file)) t = BuildinstallThread(self.pool) - with mock.patch('time.sleep'): - t.process((compose, 'x86_64', compose.variants['Server'], self.cmd), 0) + with mock.patch("time.sleep"): + t.process((compose, "x86_64", compose.variants["Server"], self.cmd), 0) self.assertEqual(0, len(run.mock_calls)) self.assertTrue(os.path.exists(dummy_file)) self.assertEqual(self.pool.finished_tasks, set()) - @mock.patch('pungi.phases.buildinstall.link_boot_iso') - @mock.patch('pungi.phases.buildinstall.tweak_buildinstall') - @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.copy_all') + @mock.patch("pungi.phases.buildinstall.link_boot_iso") + @mock.patch("pungi.phases.buildinstall.tweak_buildinstall") + @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.copy_all") def test_buildinstall_thread_with_lorax_custom_buildinstall_topdir( - self, copy_all, run, get_buildroot_rpms, KojiWrapperMock, mock_tweak, mock_link + self, copy_all, run, get_buildroot_rpms, KojiWrapperMock, mock_tweak, mock_link ): - compose = BuildInstallCompose(self.topdir, { - 'buildinstall_method': 'lorax', - 'runroot_tag': 'rrt', - 'koji_profile': 'koji', - 'runroot_weights': {'buildinstall': 123}, - 'buildinstall_topdir': '/buildinstall_topdir', - }) + compose = BuildInstallCompose( + self.topdir, + { + "buildinstall_method": "lorax", + "runroot_tag": "rrt", + "koji_profile": "koji", + "runroot_weights": {"buildinstall": 123}, + "buildinstall_topdir": "/buildinstall_topdir", + }, + ) - get_buildroot_rpms.return_value = ['bash', 'zsh'] + get_buildroot_rpms.return_value = ["bash", "zsh"] get_runroot_cmd = KojiWrapperMock.return_value.get_runroot_cmd run_runroot_cmd = KojiWrapperMock.return_value.run_runroot_cmd run_runroot_cmd.return_value = { - 'output': 'Foo bar baz', - 'retcode': 0, - 'task_id': 1234, + "output": "Foo bar baz", + "retcode": 0, + "task_id": 1234, } t = BuildinstallThread(self.pool) - with mock.patch('time.sleep'): - t.process((compose, 'x86_64', compose.variants['Server'], self.cmd), 0) + with mock.patch("time.sleep"): + t.process((compose, "x86_64", compose.variants["Server"], self.cmd), 0) self.assertEqual( get_runroot_cmd.mock_calls, - [mock.call( - 'rrt', 'x86_64', self.cmd, channel=None, - use_shell=True, - packages=['lorax'], mounts=[self.topdir], weight=123, - chown_paths=[ - "/buildinstall_topdir/buildinstall-%s/x86_64/Server" % os.path.basename(self.topdir), - "/buildinstall_topdir/buildinstall-%s/x86_64/Server/logs" % os.path.basename(self.topdir), - ], - )]) + [ + mock.call( + "rrt", + "x86_64", + self.cmd, + channel=None, + use_shell=True, + packages=["lorax"], + mounts=[self.topdir], + weight=123, + chown_paths=[ + "/buildinstall_topdir/buildinstall-%s/x86_64/Server" + % os.path.basename(self.topdir), + "/buildinstall_topdir/buildinstall-%s/x86_64/Server/logs" + % os.path.basename(self.topdir), + ], + ) + ], + ) self.assertEqual( run_runroot_cmd.mock_calls, - [mock.call(get_runroot_cmd.return_value, - log_file=self.topdir + '/logs/x86_64/buildinstall-Server.x86_64.log')]) - with open(self.topdir + '/logs/x86_64/buildinstall-Server-RPMs.x86_64.log') as f: - rpms = f.read().strip().split('\n') + [ + mock.call( + get_runroot_cmd.return_value, + log_file=self.topdir + + "/logs/x86_64/buildinstall-Server.x86_64.log", + ) + ], + ) + with open( + self.topdir + "/logs/x86_64/buildinstall-Server-RPMs.x86_64.log" + ) as f: + rpms = f.read().strip().split("\n") six.assertCountEqual(self, rpms, ["bash", "zsh"]) six.assertCountEqual(self, self.pool.finished_tasks, [("Server", "x86_64")]) buildinstall_topdir = os.path.join( - "/buildinstall_topdir", "buildinstall-" + os.path.basename(self.topdir)) + "/buildinstall_topdir", "buildinstall-" + os.path.basename(self.topdir) + ) six.assertCountEqual( self, copy_all.mock_calls, - [mock.call(os.path.join(buildinstall_topdir, 'x86_64/Server/results'), - os.path.join(self.topdir, 'work/x86_64/buildinstall/Server')), - mock.call(os.path.join(buildinstall_topdir, 'x86_64/Server/logs'), - os.path.join(self.topdir, 'logs/x86_64/buildinstall-Server-logs'))] + [ + mock.call( + os.path.join(buildinstall_topdir, "x86_64/Server/results"), + os.path.join(self.topdir, "work/x86_64/buildinstall/Server"), + ), + mock.call( + os.path.join(buildinstall_topdir, "x86_64/Server/logs"), + os.path.join(self.topdir, "logs/x86_64/buildinstall-Server-logs"), + ), + ], ) self.assertEqual( @@ -1061,35 +1604,46 @@ class BuildinstallThreadTestCase(PungiTestCase): class TestSymlinkIso(PungiTestCase): - def setUp(self): super(TestSymlinkIso, self).setUp() self.compose = BuildInstallCompose(self.topdir, {}) - os_tree = self.compose.paths.compose.os_tree('x86_64', self.compose.variants['Server']) + os_tree = self.compose.paths.compose.os_tree( + "x86_64", self.compose.variants["Server"] + ) self.boot_iso_path = os.path.join(os_tree, "images", "boot.iso") touch(self.boot_iso_path) - @mock.patch('pungi.phases.buildinstall.Image') - @mock.patch('pungi.phases.buildinstall.get_mtime') - @mock.patch('pungi.phases.buildinstall.get_file_size') - @mock.patch('pungi.phases.buildinstall.iso') - @mock.patch('pungi.phases.buildinstall.run') + @mock.patch("pungi.phases.buildinstall.Image") + @mock.patch("pungi.phases.buildinstall.get_mtime") + @mock.patch("pungi.phases.buildinstall.get_file_size") + @mock.patch("pungi.phases.buildinstall.iso") + @mock.patch("pungi.phases.buildinstall.run") def test_hardlink(self, run, iso, get_file_size, get_mtime, ImageCls): - self.compose.conf = {'buildinstall_symlink': False, 'disc_types': {}} + self.compose.conf = {"buildinstall_symlink": False, "disc_types": {}} get_file_size.return_value = 1024 get_mtime.return_value = 13579 - link_boot_iso(self.compose, 'x86_64', self.compose.variants['Server'], False) + link_boot_iso(self.compose, "x86_64", self.compose.variants["Server"], False) - tgt = self.topdir + '/compose/Server/x86_64/iso/image-name' + tgt = self.topdir + "/compose/Server/x86_64/iso/image-name" self.assertTrue(os.path.isfile(tgt)) - self.assertEqual(os.stat(tgt).st_ino, - os.stat(self.topdir + '/compose/Server/x86_64/os/images/boot.iso').st_ino) + self.assertEqual( + os.stat(tgt).st_ino, + os.stat(self.topdir + "/compose/Server/x86_64/os/images/boot.iso").st_ino, + ) self.assertEqual( self.compose.get_image_name.mock_calls, - [mock.call('x86_64', self.compose.variants['Server'], - disc_type='boot', disc_num=None, suffix='.iso')]) + [ + mock.call( + "x86_64", + self.compose.variants["Server"], + disc_type="boot", + disc_num=None, + suffix=".iso", + ) + ], + ) self.assertEqual(iso.get_implanted_md5.mock_calls, [mock.call(tgt)]) self.assertEqual(iso.get_manifest_cmd.mock_calls, [mock.call("image-name")]) self.assertEqual(iso.get_volume_id.mock_calls, [mock.call(tgt)]) @@ -1104,10 +1658,10 @@ class TestSymlinkIso(PungiTestCase): ) image = ImageCls.return_value - self.assertEqual(image.path, 'Server/x86_64/iso/image-name') + self.assertEqual(image.path, "Server/x86_64/iso/image-name") self.assertEqual(image.mtime, 13579) self.assertEqual(image.size, 1024) - self.assertEqual(image.arch, 'x86_64') + self.assertEqual(image.arch, "x86_64") self.assertEqual(image.type, "boot") self.assertEqual(image.format, "iso") self.assertEqual(image.disc_number, 1) @@ -1115,33 +1669,46 @@ class TestSymlinkIso(PungiTestCase): self.assertEqual(image.bootable, True) self.assertEqual(image.implant_md5, iso.get_implanted_md5.return_value) self.assertEqual(image.can_fail, False) - self.assertEqual(self.compose.im.add.mock_calls, - [mock.call('Server', 'x86_64', image)]) + self.assertEqual( + self.compose.im.add.mock_calls, [mock.call("Server", "x86_64", image)] + ) - @mock.patch('pungi.phases.buildinstall.Image') - @mock.patch('pungi.phases.buildinstall.get_mtime') - @mock.patch('pungi.phases.buildinstall.get_file_size') - @mock.patch('pungi.phases.buildinstall.iso') - @mock.patch('pungi.phases.buildinstall.run') - def test_hardlink_with_custom_type(self, run, iso, get_file_size, get_mtime, ImageCls): + @mock.patch("pungi.phases.buildinstall.Image") + @mock.patch("pungi.phases.buildinstall.get_mtime") + @mock.patch("pungi.phases.buildinstall.get_file_size") + @mock.patch("pungi.phases.buildinstall.iso") + @mock.patch("pungi.phases.buildinstall.run") + def test_hardlink_with_custom_type( + self, run, iso, get_file_size, get_mtime, ImageCls + ): self.compose.conf = { - 'buildinstall_symlink': False, - 'disc_types': {'boot': 'netinst'}, + "buildinstall_symlink": False, + "disc_types": {"boot": "netinst"}, } get_file_size.return_value = 1024 get_mtime.return_value = 13579 - link_boot_iso(self.compose, 'x86_64', self.compose.variants['Server'], True) + link_boot_iso(self.compose, "x86_64", self.compose.variants["Server"], True) - tgt = self.topdir + '/compose/Server/x86_64/iso/image-name' + tgt = self.topdir + "/compose/Server/x86_64/iso/image-name" self.assertTrue(os.path.isfile(tgt)) - self.assertEqual(os.stat(tgt).st_ino, - os.stat(self.topdir + '/compose/Server/x86_64/os/images/boot.iso').st_ino) + self.assertEqual( + os.stat(tgt).st_ino, + os.stat(self.topdir + "/compose/Server/x86_64/os/images/boot.iso").st_ino, + ) self.assertEqual( self.compose.get_image_name.mock_calls, - [mock.call('x86_64', self.compose.variants['Server'], - disc_type='netinst', disc_num=None, suffix='.iso')]) + [ + mock.call( + "x86_64", + self.compose.variants["Server"], + disc_type="netinst", + disc_num=None, + suffix=".iso", + ) + ], + ) self.assertEqual(iso.get_implanted_md5.mock_calls, [mock.call(tgt)]) self.assertEqual(iso.get_manifest_cmd.mock_calls, [mock.call("image-name")]) self.assertEqual(iso.get_volume_id.mock_calls, [mock.call(tgt)]) @@ -1156,10 +1723,10 @@ class TestSymlinkIso(PungiTestCase): ) image = ImageCls.return_value - self.assertEqual(image.path, 'Server/x86_64/iso/image-name') + self.assertEqual(image.path, "Server/x86_64/iso/image-name") self.assertEqual(image.mtime, 13579) self.assertEqual(image.size, 1024) - self.assertEqual(image.arch, 'x86_64') + self.assertEqual(image.arch, "x86_64") self.assertEqual(image.type, "boot") self.assertEqual(image.format, "iso") self.assertEqual(image.disc_number, 1) @@ -1167,23 +1734,28 @@ class TestSymlinkIso(PungiTestCase): self.assertEqual(image.bootable, True) self.assertEqual(image.implant_md5, iso.get_implanted_md5.return_value) self.assertEqual(image.can_fail, True) - self.assertEqual(self.compose.im.add.mock_calls, - [mock.call('Server', 'x86_64', image)]) + self.assertEqual( + self.compose.im.add.mock_calls, [mock.call("Server", "x86_64", image)] + ) class TestTweakConfigs(PungiTestCase): - def test_tweak_configs(self): logger = mock.Mock() configs = [] for cfg in BOOT_CONFIGS: - if 'yaboot' not in cfg: + if "yaboot" not in cfg: configs.append(os.path.join(self.topdir, cfg)) - touch(configs[-1], ':LABEL=baz') - found_configs = tweak_configs(self.topdir, 'new volid', os.path.join(self.topdir, 'ks.cfg'), logger=logger) + touch(configs[-1], ":LABEL=baz") + found_configs = tweak_configs( + self.topdir, "new volid", os.path.join(self.topdir, "ks.cfg"), logger=logger + ) self.assertEqual( logger.info.call_args_list, - [mock.call('Boot config %s changed' % os.path.join(self.topdir, cfg)) for cfg in found_configs] + [ + mock.call("Boot config %s changed" % os.path.join(self.topdir, cfg)) + for cfg in found_configs + ], ) for cfg in configs: self.assertFileContent( @@ -1193,10 +1765,10 @@ class TestTweakConfigs(PungiTestCase): def test_tweak_configs_yaboot(self): configs = [] for cfg in BOOT_CONFIGS: - if 'yaboot' in cfg: + if "yaboot" in cfg: configs.append(os.path.join(self.topdir, cfg)) - touch(configs[-1], ':LABEL=baz') - tweak_configs(self.topdir, 'new volid', os.path.join(self.topdir, 'ks.cfg')) + touch(configs[-1], ":LABEL=baz") + tweak_configs(self.topdir, "new volid", os.path.join(self.topdir, "ks.cfg")) for cfg in configs: self.assertFileContent( cfg, ":LABEL=new\\\\x20volid ks=hd:LABEL=new\\\\x20volid:/ks.cfg\n" diff --git a/tests/test_checks.py b/tests/test_checks.py index 4b945a0d..ccac53ae 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import mock + try: import unittest2 as unittest except ImportError: @@ -15,7 +16,6 @@ from pungi import checks class CheckDependenciesTestCase(unittest.TestCase): - def dont_find(self, paths): return lambda path: path not in paths @@ -23,149 +23,147 @@ class CheckDependenciesTestCase(unittest.TestCase): def custom_exists(path): return False - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('os.path.exists') as exists: + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("os.path.exists") as exists: exists.side_effect = custom_exists result = checks.check({}) - self.assertGreater(len(out.getvalue().strip().split('\n')), 1) + self.assertGreater(len(out.getvalue().strip().split("\n")), 1) self.assertFalse(result) def test_all_deps_ok(self): - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('platform.machine') as machine: - machine.return_value = 'x86_64' - with mock.patch('os.path.exists') as exists: + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("platform.machine") as machine: + machine.return_value = "x86_64" + with mock.patch("os.path.exists") as exists: exists.side_effect = self.dont_find([]) result = checks.check({}) - self.assertEqual('', out.getvalue()) + self.assertEqual("", out.getvalue()) self.assertTrue(result) def test_does_not_require_jigdo_if_not_configured(self): - conf = { - 'create_jigdo': False - } + conf = {"create_jigdo": False} - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('platform.machine') as machine: - machine.return_value = 'x86_64' - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/jigdo-lite']) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("platform.machine") as machine: + machine.return_value = "x86_64" + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/jigdo-lite"]) result = checks.check(conf) - self.assertEqual('', out.getvalue()) + self.assertEqual("", out.getvalue()) self.assertTrue(result) def test_isohybrid_not_required_without_productimg_phase(self): conf = { - 'bootable': True, - 'productimg': False, - 'runroot_tag': 'dummy_tag', + "bootable": True, + "productimg": False, + "runroot_tag": "dummy_tag", } - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/isohybrid']) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/isohybrid"]) result = checks.check(conf) - self.assertEqual('', out.getvalue()) + self.assertEqual("", out.getvalue()) self.assertTrue(result) def test_isohybrid_not_required_on_not_bootable(self): conf = { - 'bootable': False, - 'runroot_tag': 'dummy_tag', + "bootable": False, + "runroot_tag": "dummy_tag", } - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/isohybrid']) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/isohybrid"]) result = checks.check(conf) - self.assertEqual('', out.getvalue()) + self.assertEqual("", out.getvalue()) self.assertTrue(result) def test_isohybrid_not_required_on_arm(self): conf = { - 'buildinstall_method': 'lorax', - 'runroot_tag': '', + "buildinstall_method": "lorax", + "runroot_tag": "", } - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('platform.machine') as machine: - machine.return_value = 'armhfp' - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/isohybrid']) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("platform.machine") as machine: + machine.return_value = "armhfp" + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/isohybrid"]) result = checks.check(conf) - self.assertRegexpMatches(out.getvalue(), r'^Not checking.*Expect failures.*$') + self.assertRegexpMatches(out.getvalue(), r"^Not checking.*Expect failures.*$") self.assertTrue(result) def test_isohybrid_not_needed_in_runroot(self): conf = { - 'runroot_tag': 'dummy_tag', + "runroot_tag": "dummy_tag", } - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/isohybrid']) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/isohybrid"]) result = checks.check(conf) - self.assertEqual('', out.getvalue()) + self.assertEqual("", out.getvalue()) self.assertTrue(result) def test_genisoimg_not_needed_in_runroot(self): conf = { - 'runroot_tag': 'dummy_tag', + "runroot_tag": "dummy_tag", } - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/genisoimage']) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/genisoimage"]) result = checks.check(conf) - self.assertEqual('', out.getvalue()) + self.assertEqual("", out.getvalue()) self.assertTrue(result) def test_requires_modifyrepo(self): - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/modifyrepo']) - result = checks.check({'createrepo_c': False}) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/modifyrepo"]) + result = checks.check({"createrepo_c": False}) - self.assertIn('createrepo', out.getvalue()) + self.assertIn("createrepo", out.getvalue()) self.assertFalse(result) def test_requires_modifyrepo_c(self): - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/modifyrepo_c']) - result = checks.check({'createrepo_c': True}) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/modifyrepo_c"]) + result = checks.check({"createrepo_c": True}) - self.assertIn('createrepo_c', out.getvalue()) + self.assertIn("createrepo_c", out.getvalue()) self.assertFalse(result) def test_requires_createrepo_c(self): - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/createrepo_c']) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/createrepo_c"]) result = checks.check({}) - self.assertIn('createrepo_c', out.getvalue()) + self.assertIn("createrepo_c", out.getvalue()) self.assertFalse(result) def test_doesnt_require_createrepo_c_if_configured(self): conf = { - 'createrepo_c': False, + "createrepo_c": False, } - with mock.patch('sys.stdout', new_callable=StringIO) as out: - with mock.patch('os.path.exists') as exists: - exists.side_effect = self.dont_find(['/usr/bin/createrepo_c']) + with mock.patch("sys.stdout", new_callable=StringIO) as out: + with mock.patch("os.path.exists") as exists: + exists.side_effect = self.dont_find(["/usr/bin/createrepo_c"]) result = checks.check(conf) - self.assertNotIn('createrepo_c', out.getvalue()) + self.assertNotIn("createrepo_c", out.getvalue()) self.assertTrue(result) @@ -175,7 +173,7 @@ class TestSchemaValidator(unittest.TestCase): conf.load_from_string(string) return conf - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_property(self, make_schema): schema = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -198,7 +196,7 @@ class TestSchemaValidator(unittest.TestCase): self.assertEqual(len(warnings), 0) self.assertEqual(config.get("release_name", None), "dummy product") - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_alias_property(self, make_schema): schema = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -218,10 +216,13 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 1) - self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*") + self.assertRegexpMatches( + warnings[0], + r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*", + ) self.assertEqual(config.get("release_name", None), "dummy product") - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_required_is_missing(self, make_schema): schema = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -241,11 +242,13 @@ class TestSchemaValidator(unittest.TestCase): config = self._load_conf_from_string(string) errors, warnings = checks.validate(config) self.assertEqual(len(errors), 1) - self.assertIn("Failed validation in : 'release_name' is a required property", errors) + self.assertIn( + "Failed validation in : 'release_name' is a required property", errors + ) self.assertEqual(len(warnings), 1) self.assertIn("WARNING: Unrecognized config option: name.", warnings) - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_required_is_in_alias(self, make_schema): schema = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -266,10 +269,13 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 1) - self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*") + self.assertRegexpMatches( + warnings[0], + r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*", + ) self.assertEqual(config.get("release_name", None), "dummy product") - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_redundant_alias(self, make_schema): schema = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -290,12 +296,18 @@ class TestSchemaValidator(unittest.TestCase): config = self._load_conf_from_string(string) errors, warnings = checks.validate(config) self.assertEqual(len(errors), 1) - self.assertRegexpMatches(errors[0], r"^ERROR: Config option 'product_name' is an alias of 'release_name', only one can be used.*") + self.assertRegexpMatches( + errors[0], + r"^ERROR: Config option 'product_name' is an alias of 'release_name', only one can be used.*", + ) self.assertEqual(len(warnings), 1) - self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*") + self.assertRegexpMatches( + warnings[0], + r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*", + ) self.assertEqual(config.get("release_name", None), "dummy product") - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_properties_in_deep(self, make_schema): schema = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -303,15 +315,10 @@ class TestSchemaValidator(unittest.TestCase): "type": "object", "properties": { "release_name": {"type": "string", "alias": "product_name"}, - "keys": { - "type": "array", - "items": {"type": "string"}, - }, + "keys": {"type": "array", "items": {"type": "string"}}, "foophase": { "type": "object", - "properties": { - "repo": {"type": "string", "alias": "tree"}, - }, + "properties": {"repo": {"type": "string", "alias": "tree"}}, "additionalProperties": False, "required": ["repo"], }, @@ -331,22 +338,27 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 2) - self.assertRegexpMatches(warnings[0], r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*") - self.assertRegexpMatches(warnings[1], r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*") + self.assertRegexpMatches( + warnings[0], + r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*", + ) + self.assertRegexpMatches( + warnings[1], + r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*", + ) self.assertEqual(config.get("release_name", None), "dummy product") - self.assertEqual(config.get("foophase", {}).get("repo", None), "http://www.exampe.com/os") + self.assertEqual( + config.get("foophase", {}).get("repo", None), "http://www.exampe.com/os" + ) - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_append_option(self, make_schema): schema = { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Pungi Configuration", "type": "object", "definitions": { - "list_of_strings": { - "type": "array", - "items": {"type": "string"}, - }, + "list_of_strings": {"type": "array", "items": {"type": "string"}}, "strings": { "anyOf": [ {"type": "string"}, @@ -356,7 +368,7 @@ class TestSchemaValidator(unittest.TestCase): }, "properties": { "release_name": {"type": "string"}, - "repo": {"$ref": "#/definitions/strings", "append": "repo_from"} + "repo": {"$ref": "#/definitions/strings", "append": "repo_from"}, }, "additionalProperties": False, } @@ -371,22 +383,25 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 2) - self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") - self.assertRegexpMatches(warnings[1], r"^WARNING: Value from config option 'repo_from' is now appended to option 'repo'") + self.assertRegexpMatches( + warnings[0], + r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", + ) + self.assertRegexpMatches( + warnings[1], + r"^WARNING: Value from config option 'repo_from' is now appended to option 'repo'", + ) self.assertEqual(config.get("release_name", None), "dummy product") self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server"]) - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_append_to_nonexist_option(self, make_schema): schema = { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Pungi Configuration", "type": "object", "definitions": { - "list_of_strings": { - "type": "array", - "items": {"type": "string"}, - }, + "list_of_strings": {"type": "array", "items": {"type": "string"}}, "strings": { "anyOf": [ {"type": "string"}, @@ -396,7 +411,7 @@ class TestSchemaValidator(unittest.TestCase): }, "properties": { "release_name": {"type": "string"}, - "repo": {"$ref": "#/definitions/strings", "append": "repo_from"} + "repo": {"$ref": "#/definitions/strings", "append": "repo_from"}, }, "additionalProperties": False, } @@ -410,22 +425,25 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 2) - self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") - self.assertRegexpMatches(warnings[1], r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,") + self.assertRegexpMatches( + warnings[0], + r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", + ) + self.assertRegexpMatches( + warnings[1], + r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,", + ) self.assertEqual(config.get("release_name", None), "dummy product") self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server"]) - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_multiple_appends(self, make_schema): schema = { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Pungi Configuration", "type": "object", "definitions": { - "list_of_strings": { - "type": "array", - "items": {"type": "string"}, - }, + "list_of_strings": {"type": "array", "items": {"type": "string"}}, "strings": { "anyOf": [ {"type": "string"}, @@ -437,8 +455,8 @@ class TestSchemaValidator(unittest.TestCase): "release_name": {"type": "string"}, "repo": { "$ref": "#/definitions/strings", - "append": ["repo_from", "source_repo_from"] - } + "append": ["repo_from", "source_repo_from"], + }, }, "additionalProperties": False, } @@ -453,14 +471,28 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 4) - self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") - self.assertRegexpMatches(warnings[1], r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,") - self.assertRegexpMatches(warnings[2], r"^WARNING: Config option 'source_repo_from' is deprecated, its value will be appended to option 'repo'") - self.assertRegexpMatches(warnings[3], r"^WARNING: Value from config option 'source_repo_from' is now appended to option 'repo'.") + self.assertRegexpMatches( + warnings[0], + r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", + ) + self.assertRegexpMatches( + warnings[1], + r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,", + ) + self.assertRegexpMatches( + warnings[2], + r"^WARNING: Config option 'source_repo_from' is deprecated, its value will be appended to option 'repo'", + ) + self.assertRegexpMatches( + warnings[3], + r"^WARNING: Value from config option 'source_repo_from' is now appended to option 'repo'.", + ) self.assertEqual(config.get("release_name", None), "dummy product") - self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server", "Client"]) + self.assertEqual( + config.get("repo", None), ["http://url/to/repo", "Server", "Client"] + ) - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_anyof_validator_not_raise_our_warnings_as_error(self, make_schema): # https://pagure.io/pungi/issue/598 schema = { @@ -470,26 +502,21 @@ class TestSchemaValidator(unittest.TestCase): "definitions": { "live_image_config": { "type": "object", - "properties": { - "repo": { - "type": "string", - "append": "repo_from", - }, - }, + "properties": {"repo": {"type": "string", "append": "repo_from"}}, }, }, "properties": { - "live_images": checks._variant_arch_mapping({ - "anyOf": [ - {"$ref": "#/definitions/live_image_config"}, - { - "type": "array", - "items": { - "$ref": "#/definitions/live_image_config" - } - } - ] - }), + "live_images": checks._variant_arch_mapping( + { + "anyOf": [ + {"$ref": "#/definitions/live_image_config"}, + { + "type": "array", + "items": {"$ref": "#/definitions/live_image_config"}, + }, + ] + } + ), }, } make_schema.return_value = schema @@ -506,12 +533,20 @@ class TestSchemaValidator(unittest.TestCase): errors, warnings = checks.validate(config) self.assertEqual(len(errors), 0) self.assertEqual(len(warnings), 2) - self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*") - self.assertRegexpMatches(warnings[1], r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified, value from 'repo_from' is now added as 'repo'.*") - self.assertEqual(config.get("live_images")[0][1]['armhfp']['repo'], 'Everything') + self.assertRegexpMatches( + warnings[0], + r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", + ) + self.assertRegexpMatches( + warnings[1], + r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified, value from 'repo_from' is now added as 'repo'.*", + ) + self.assertEqual( + config.get("live_images")[0][1]["armhfp"]["repo"], "Everything" + ) @mock.patch("pungi.util.resolve_git_url") - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_resolve_url(self, make_schema, resolve_git_url): resolve_git_url.return_value = "git://example.com/repo.git#CAFE" make_schema.return_value = { @@ -527,7 +562,7 @@ class TestSchemaValidator(unittest.TestCase): self.assertEqual(config["foo"], resolve_git_url.return_value) @mock.patch("pungi.util.resolve_git_url") - @mock.patch('pungi.checks.make_schema') + @mock.patch("pungi.checks.make_schema") def test_resolve_url_when_offline(self, make_schema, resolve_git_url): make_schema.return_value = { "$schema": "http://json-schema.org/draft-04/schema#", @@ -594,8 +629,13 @@ class TestUmask(unittest.TestCase): checks.check_umask(logger) self.assertEqual( logger.mock_calls, - [mock.call.warning('Unusually strict umask detected (0%03o), ' - 'expect files with broken permissions.', 0o044)] + [ + mock.call.warning( + "Unusually strict umask detected (0%03o), " + "expect files with broken permissions.", + 0o044, + ) + ], ) diff --git a/tests/test_compose.py b/tests/test_compose.py index 18be7c6b..4419f6a0 100644 --- a/tests/test_compose.py +++ b/tests/test_compose.py @@ -2,6 +2,7 @@ import logging import mock + try: import unittest2 as unittest except ImportError: @@ -18,7 +19,9 @@ from pungi.compose import Compose class ConfigWrapper(dict): def __init__(self, *args, **kwargs): super(ConfigWrapper, self).__init__(*args, **kwargs) - self._open_file = '%s/fixtures/config.conf' % os.path.abspath(os.path.dirname(__file__)) + self._open_file = "%s/fixtures/config.conf" % os.path.abspath( + os.path.dirname(__file__) + ) class ComposeTestCase(unittest.TestCase): @@ -28,17 +31,19 @@ class ComposeTestCase(unittest.TestCase): def tearDown(self): shutil.rmtree(self.tmp_dir) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_setup_logger(self, ci): conf = {} - logger = logging.getLogger('test_setup_logger') + logger = logging.getLogger("test_setup_logger") compose = Compose(conf, self.tmp_dir, logger=logger) self.assertEqual(len(logger.handlers), 2) pungi_log = logger.handlers[0].stream.name exclude_arch_log = logger.handlers[1].stream.name - self.assertEqual(os.path.basename(pungi_log), 'pungi.global.log') - self.assertEqual(os.path.basename(exclude_arch_log), 'excluding-arch.global.log') + self.assertEqual(os.path.basename(pungi_log), "pungi.global.log") + self.assertEqual( + os.path.basename(exclude_arch_log), "excluding-arch.global.log" + ) msg = "test log" compose.log_info(msg) @@ -52,240 +57,322 @@ class ComposeTestCase(unittest.TestCase): with open(exclude_arch_log) as f: self.assertTrue(msg in f.read()) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_can_fail(self, ci): conf = { - 'failable_deliverables': [ - ('^.*$', { - '*': ['buildinstall'], - 'i386': ['buildinstall', 'live', 'iso'], - }), + "failable_deliverables": [ + ( + "^.*$", + {"*": ["buildinstall"], "i386": ["buildinstall", "live", "iso"]}, + ), ] } compose = Compose(conf, self.tmp_dir) - variant = mock.Mock(uid='Server') + variant = mock.Mock(uid="Server") - self.assertTrue(compose.can_fail(variant, 'x86_64', 'buildinstall')) - self.assertFalse(compose.can_fail(variant, 'x86_64', 'live')) - self.assertTrue(compose.can_fail(variant, 'i386', 'live')) + self.assertTrue(compose.can_fail(variant, "x86_64", "buildinstall")) + self.assertFalse(compose.can_fail(variant, "x86_64", "live")) + self.assertTrue(compose.can_fail(variant, "i386", "live")) - self.assertFalse(compose.can_fail(None, 'x86_64', 'live')) - self.assertTrue(compose.can_fail(None, 'i386', 'live')) + self.assertFalse(compose.can_fail(None, "x86_64", "live")) + self.assertTrue(compose.can_fail(None, "i386", "live")) - self.assertTrue(compose.can_fail(variant, '*', 'buildinstall')) - self.assertFalse(compose.can_fail(variant, '*', 'live')) + self.assertTrue(compose.can_fail(variant, "*", "buildinstall")) + self.assertFalse(compose.can_fail(variant, "*", "live")) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_image_name(self, ci): conf = {} - variant = mock.Mock(uid='Server', type='variant') + variant = mock.Mock(uid="Server", type="variant") ci.return_value.compose.respin = 2 - ci.return_value.compose.id = 'compose_id' - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' - ci.return_value.compose.label = 'RC-1.0' - ci.return_value.compose.label_major_version = '1' + ci.return_value.compose.id = "compose_id" + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" + ci.return_value.compose.label = "RC-1.0" + ci.return_value.compose.label_major_version = "1" - ci.return_value.release.version = '3.0' - ci.return_value.release.short = 'rel_short' + ci.return_value.release.version = "3.0" + ci.return_value.release.short = "rel_short" compose = Compose(conf, self.tmp_dir) - keys = ['arch', 'compose_id', 'date', 'disc_num', 'disc_type', - 'label', 'label_major_version', 'release_short', 'respin', - 'suffix', 'type', 'type_suffix', 'variant', 'version'] - format = '-'.join(['%(' + k + ')s' for k in keys]) - name = compose.get_image_name('x86_64', variant, format=format, - disc_num=7, disc_type='live', suffix='.iso') + keys = [ + "arch", + "compose_id", + "date", + "disc_num", + "disc_type", + "label", + "label_major_version", + "release_short", + "respin", + "suffix", + "type", + "type_suffix", + "variant", + "version", + ] + format = "-".join(["%(" + k + ")s" for k in keys]) + name = compose.get_image_name( + "x86_64", + variant, + format=format, + disc_num=7, + disc_type="live", + suffix=".iso", + ) - self.assertEqual(name, '-'.join(['x86_64', 'compose_id', '20160107', '7', 'live', - 'RC-1.0', '1', 'rel_short', '2', '.iso', 'nightly', - '.n', 'Server', '3.0'])) + self.assertEqual( + name, + "-".join( + [ + "x86_64", + "compose_id", + "20160107", + "7", + "live", + "RC-1.0", + "1", + "rel_short", + "2", + ".iso", + "nightly", + ".n", + "Server", + "3.0", + ] + ), + ) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_image_name_variant_mapping(self, ci): conf = {"image_name_format": {"^Server$": "whatever"}} - variant = mock.Mock(uid='Server', type='variant') + variant = mock.Mock(uid="Server", type="variant") compose = Compose(conf, self.tmp_dir) name = compose.get_image_name( - 'x86_64', variant, disc_num=7, disc_type='live', suffix='.iso' + "x86_64", variant, disc_num=7, disc_type="live", suffix=".iso" ) self.assertEqual(name, "whatever") - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_image_name_variant_mapping_no_match(self, ci): conf = {"image_name_format": {"^Client$": "whatever"}} - variant = mock.Mock(uid='Server', type='variant') - ci.return_value.compose.id = 'compose_id' + variant = mock.Mock(uid="Server", type="variant") + ci.return_value.compose.id = "compose_id" compose = Compose(conf, self.tmp_dir) name = compose.get_image_name( - 'x86_64', variant, disc_num=7, disc_type='live', suffix='.iso' + "x86_64", variant, disc_num=7, disc_type="live", suffix=".iso" ) self.assertEqual(name, "compose_id-Server-x86_64-live7.iso") - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_image_name_layered_product(self, ci): conf = {} - variant = mock.Mock(uid='Server-LP', type='layered-product') - variant.parent = mock.Mock(uid='Server') + variant = mock.Mock(uid="Server-LP", type="layered-product") + variant.parent = mock.Mock(uid="Server") ci.return_value.compose.respin = 2 - ci.return_value.compose.id = 'compose_id' - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' - ci.return_value.compose.label = 'RC-1.0' - ci.return_value.compose.label_major_version = '1' + ci.return_value.compose.id = "compose_id" + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" + ci.return_value.compose.label = "RC-1.0" + ci.return_value.compose.label_major_version = "1" - ci.return_value.release.version = '3.0' - ci.return_value.release.short = 'rel_short' + ci.return_value.release.version = "3.0" + ci.return_value.release.short = "rel_short" - ci.return_value['Server-LP'].compose_id = 'Gluster 1.0' + ci.return_value["Server-LP"].compose_id = "Gluster 1.0" compose = Compose(conf, self.tmp_dir) - format = '{compose_id} {variant}' - name = compose.get_image_name('x86_64', variant, format=format, - disc_num=7, disc_type='live', suffix='.iso') + format = "{compose_id} {variant}" + name = compose.get_image_name( + "x86_64", + variant, + format=format, + disc_num=7, + disc_type="live", + suffix=".iso", + ) - self.assertEqual(name, 'Gluster 1.0 Server') + self.assertEqual(name, "Gluster 1.0 Server") - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_image_name_type_netinst(self, ci): conf = {} - variant = mock.Mock(uid='Server', type='variant') + variant = mock.Mock(uid="Server", type="variant") ci.return_value.compose.respin = 2 - ci.return_value.compose.id = 'compose_id' - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' - ci.return_value.compose.label = 'RC-1.0' - ci.return_value.compose.label_major_version = '1' + ci.return_value.compose.id = "compose_id" + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" + ci.return_value.compose.label = "RC-1.0" + ci.return_value.compose.label_major_version = "1" - ci.return_value.release.version = '3.0' - ci.return_value.release.short = 'rel_short' + ci.return_value.release.version = "3.0" + ci.return_value.release.short = "rel_short" compose = Compose(conf, self.tmp_dir) - keys = ['arch', 'compose_id', 'date', 'disc_num', 'disc_type', - 'label', 'label_major_version', 'release_short', 'respin', - 'suffix', 'type', 'type_suffix', 'variant', 'version'] - format = '-'.join(['%(' + k + ')s' for k in keys]) - name = compose.get_image_name('x86_64', variant, format=format, - disc_num=7, disc_type='netinst', suffix='.iso') + keys = [ + "arch", + "compose_id", + "date", + "disc_num", + "disc_type", + "label", + "label_major_version", + "release_short", + "respin", + "suffix", + "type", + "type_suffix", + "variant", + "version", + ] + format = "-".join(["%(" + k + ")s" for k in keys]) + name = compose.get_image_name( + "x86_64", + variant, + format=format, + disc_num=7, + disc_type="netinst", + suffix=".iso", + ) - self.assertEqual(name, '-'.join(['x86_64', 'compose_id', '20160107', '7', 'netinst', - 'RC-1.0', '1', 'rel_short', '2', '.iso', 'nightly', - '.n', 'Server', '3.0'])) + self.assertEqual( + name, + "-".join( + [ + "x86_64", + "compose_id", + "20160107", + "7", + "netinst", + "RC-1.0", + "1", + "rel_short", + "2", + ".iso", + "nightly", + ".n", + "Server", + "3.0", + ] + ), + ) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_image_release(self, ci): conf = {} ci.return_value.compose.respin = 2 - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" ci.return_value.compose.label = None compose = Compose(conf, self.tmp_dir) - self.assertEqual(compose.image_release, '20160107.n.2') + self.assertEqual(compose.image_release, "20160107.n.2") - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_image_release_production(self, ci): conf = {} ci.return_value.compose.respin = 2 - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'production' - ci.return_value.compose.type_suffix = '' + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "production" + ci.return_value.compose.type_suffix = "" ci.return_value.compose.label = None compose = Compose(conf, self.tmp_dir) - self.assertEqual(compose.image_release, '20160107.2') + self.assertEqual(compose.image_release, "20160107.2") - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_image_release_from_label(self, ci): conf = {} ci.return_value.compose.respin = 2 - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'production' - ci.return_value.compose.type_suffix = '.n' - ci.return_value.compose.label = 'Alpha-1.2' + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "production" + ci.return_value.compose.type_suffix = ".n" + ci.return_value.compose.label = "Alpha-1.2" compose = Compose(conf, self.tmp_dir) - self.assertEqual(compose.image_release, '1.2') + self.assertEqual(compose.image_release, "1.2") - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_image_version_without_label(self, ci): conf = {} ci.return_value.compose.respin = 2 - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" ci.return_value.compose.label = None - ci.return_value.release.version = '25' + ci.return_value.release.version = "25" compose = Compose(conf, self.tmp_dir) - self.assertEqual(compose.image_version, '25') + self.assertEqual(compose.image_version, "25") - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_image_version_with_label(self, ci): conf = {} ci.return_value.compose.respin = 2 - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' - ci.return_value.compose.label = 'Alpha-1.2' - ci.return_value.release.version = '25' + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" + ci.return_value.compose.label = "Alpha-1.2" + ci.return_value.release.version = "25" compose = Compose(conf, self.tmp_dir) - self.assertEqual(compose.image_version, '25_Alpha') + self.assertEqual(compose.image_version, "25_Alpha") - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_image_version_with_label_rc(self, ci): conf = {} ci.return_value.compose.respin = 2 - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' - ci.return_value.compose.label = 'RC-1.2' - ci.return_value.release.version = '25' + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" + ci.return_value.compose.label = "RC-1.2" + ci.return_value.release.version = "25" compose = Compose(conf, self.tmp_dir) - self.assertEqual(compose.image_version, '25') + self.assertEqual(compose.image_version, "25") - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_variant_arches_without_filter(self, ci): - ci.return_value.compose.id = 'composeid' + ci.return_value.compose.id = "composeid" conf = ConfigWrapper( - variants_file={'scm': 'file', - 'repo': None, - 'file': 'variants.xml'}, - release_name='Test', - release_version='1.0', - release_short='test', - release_type='ga', + variants_file={"scm": "file", "repo": None, "file": "variants.xml"}, + release_name="Test", + release_version="1.0", + release_short="test", + release_type="ga", release_internal=False, ) compose = Compose(conf, self.tmp_dir) compose.read_variants() - self.assertEqual(sorted(v.uid for v in compose.variants.values()), - ['Client', 'Crashy', 'Live', 'Server']) - self.assertEqual(sorted(v.uid for v in compose.variants['Server'].variants.values()), - ['Server-Gluster', 'Server-ResilientStorage', 'Server-optional']) + self.assertEqual( + sorted(v.uid for v in compose.variants.values()), + ["Client", "Crashy", "Live", "Server"], + ) + self.assertEqual( + sorted(v.uid for v in compose.variants["Server"].variants.values()), + ["Server-Gluster", "Server-ResilientStorage", "Server-optional"], + ) six.assertCountEqual( self, compose.variants["Client"].arches, ["i386", "x86_64"] ) @@ -303,37 +390,48 @@ class ComposeTestCase(unittest.TestCase): six.assertCountEqual( self, compose.variants["Server"].variants["optional"].arches, - ["s390x", "x86_64"] + ["s390x", "x86_64"], ) - self.assertEqual([v.uid for v in compose.get_variants()], - ['Client', 'Crashy', 'Live', 'Server', 'Server-Gluster', - 'Server-ResilientStorage', 'Server-optional']) - self.assertEqual(compose.get_arches(), ['i386', 'ppc64le', 's390x', 'x86_64']) + self.assertEqual( + [v.uid for v in compose.get_variants()], + [ + "Client", + "Crashy", + "Live", + "Server", + "Server-Gluster", + "Server-ResilientStorage", + "Server-optional", + ], + ) + self.assertEqual(compose.get_arches(), ["i386", "ppc64le", "s390x", "x86_64"]) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_variant_arches_with_arch_filter(self, ci): - ci.return_value.compose.id = 'composeid' + ci.return_value.compose.id = "composeid" conf = ConfigWrapper( - variants_file={'scm': 'file', - 'repo': None, - 'file': 'variants.xml'}, - release_name='Test', - release_version='1.0', - release_short='test', - release_type='ga', + variants_file={"scm": "file", "repo": None, "file": "variants.xml"}, + release_name="Test", + release_version="1.0", + release_short="test", + release_type="ga", release_internal=False, - tree_arches=['x86_64'], + tree_arches=["x86_64"], ) compose = Compose(conf, self.tmp_dir) compose.read_variants() - self.assertEqual(sorted(v.uid for v in compose.variants.values()), - ['Client', 'Live', 'Server']) - self.assertEqual(sorted(v.uid for v in compose.variants['Server'].variants.values()), - ['Server-Gluster', 'Server-ResilientStorage', 'Server-optional']) + self.assertEqual( + sorted(v.uid for v in compose.variants.values()), + ["Client", "Live", "Server"], + ) + self.assertEqual( + sorted(v.uid for v in compose.variants["Server"].variants.values()), + ["Server-Gluster", "Server-ResilientStorage", "Server-optional"], + ) self.assertEqual(compose.variants["Client"].arches, ["x86_64"]) self.assertEqual(compose.variants["Live"].arches, ["x86_64"]) self.assertEqual(compose.variants["Server"].arches, ["x86_64"]) @@ -347,36 +445,43 @@ class ComposeTestCase(unittest.TestCase): compose.variants["Server"].variants["optional"].arches, ["x86_64"] ) - self.assertEqual(compose.get_arches(), ['x86_64']) - self.assertEqual([v.uid for v in compose.get_variants()], - ['Client', 'Live', 'Server', 'Server-Gluster', - 'Server-ResilientStorage', 'Server-optional']) + self.assertEqual(compose.get_arches(), ["x86_64"]) + self.assertEqual( + [v.uid for v in compose.get_variants()], + [ + "Client", + "Live", + "Server", + "Server-Gluster", + "Server-ResilientStorage", + "Server-optional", + ], + ) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_variant_arches_with_variant_filter(self, ci): - ci.return_value.compose.id = 'composeid' + ci.return_value.compose.id = "composeid" ci.return_value.compose.respin = 2 - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'production' - ci.return_value.compose.type_suffix = '.n' + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "production" + ci.return_value.compose.type_suffix = ".n" conf = ConfigWrapper( - variants_file={'scm': 'file', - 'repo': None, - 'file': 'variants.xml'}, - release_name='Test', - release_version='1.0', - release_short='test', - release_type='ga', + variants_file={"scm": "file", "repo": None, "file": "variants.xml"}, + release_name="Test", + release_version="1.0", + release_short="test", + release_type="ga", release_internal=False, - tree_variants=['Server', 'Client', 'Server-Gluster'], + tree_variants=["Server", "Client", "Server-Gluster"], ) compose = Compose(conf, self.tmp_dir) compose.read_variants() - self.assertEqual(sorted(v.uid for v in compose.variants.values()), - ['Client', 'Server']) + self.assertEqual( + sorted(v.uid for v in compose.variants.values()), ["Client", "Server"] + ) six.assertCountEqual( self, compose.variants["Client"].arches, ["i386", "x86_64"] ) @@ -387,77 +492,84 @@ class ComposeTestCase(unittest.TestCase): compose.variants["Server"].variants["Gluster"].arches, ["x86_64"] ) - self.assertEqual(compose.get_arches(), ['i386', 's390x', 'x86_64']) - self.assertEqual([v.uid for v in compose.get_variants()], - ['Client', 'Server', 'Server-Gluster']) + self.assertEqual(compose.get_arches(), ["i386", "s390x", "x86_64"]) + self.assertEqual( + [v.uid for v in compose.get_variants()], + ["Client", "Server", "Server-Gluster"], + ) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_variant_arches_with_both_filters(self, ci): - ci.return_value.compose.id = 'composeid' + ci.return_value.compose.id = "composeid" ci.return_value.compose.respin = 2 - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'production' - ci.return_value.compose.type_suffix = '.n' + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "production" + ci.return_value.compose.type_suffix = ".n" logger = mock.Mock() logger.handlers = [] conf = ConfigWrapper( - variants_file={'scm': 'file', - 'repo': None, - 'file': 'variants.xml'}, - release_name='Test', - release_version='1.0', - release_short='test', - release_type='ga', + variants_file={"scm": "file", "repo": None, "file": "variants.xml"}, + release_name="Test", + release_version="1.0", + release_short="test", + release_type="ga", release_internal=False, - tree_variants=['Server', 'Client', 'Server-optional'], - tree_arches=['x86_64'], + tree_variants=["Server", "Client", "Server-optional"], + tree_arches=["x86_64"], ) compose = Compose(conf, self.tmp_dir, logger=logger) compose.read_variants() - self.assertEqual(sorted(v.uid for v in compose.variants.values()), - ['Client', 'Server']) + self.assertEqual( + sorted(v.uid for v in compose.variants.values()), ["Client", "Server"] + ) self.assertEqual(compose.variants["Client"].arches, ["x86_64"]) self.assertEqual(compose.variants["Server"].arches, ["x86_64"]) self.assertEqual( compose.variants["Server"].variants["optional"].arches, ["x86_64"] ) - self.assertEqual(compose.get_arches(), ['x86_64']) - self.assertEqual([v.uid for v in compose.get_variants()], - ['Client', 'Server', 'Server-optional']) + self.assertEqual(compose.get_arches(), ["x86_64"]) + self.assertEqual( + [v.uid for v in compose.get_variants()], + ["Client", "Server", "Server-optional"], + ) six.assertCountEqual( self, logger.info.call_args_list, - [mock.call('Excluding variant Live: filtered by configuration.'), - mock.call('Excluding variant Crashy: all its arches are filtered.'), - mock.call('Excluding variant Server-ResilientStorage: filtered by configuration.'), - mock.call('Excluding variant Server-Gluster: filtered by configuration.')] + [ + mock.call("Excluding variant Live: filtered by configuration."), + mock.call("Excluding variant Crashy: all its arches are filtered."), + mock.call( + "Excluding variant Server-ResilientStorage: filtered by configuration." + ), + mock.call( + "Excluding variant Server-Gluster: filtered by configuration." + ), + ], ) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_mkdtemp(self, ci): - ci.return_value.compose.id = 'composeid' + ci.return_value.compose.id = "composeid" conf = ConfigWrapper( - variants_file={'scm': 'file', - 'repo': None, - 'file': 'variants.xml'}, - release_name='Test', - release_version='1.0', - release_short='test', - release_type='ga', + variants_file={"scm": "file", "repo": None, "file": "variants.xml"}, + release_name="Test", + release_version="1.0", + release_short="test", + release_type="ga", release_internal=False, - tree_variants=['Server', 'Client', 'Server-optional'], - tree_arches=['x86_64'], + tree_variants=["Server", "Client", "Server-optional"], + tree_arches=["x86_64"], ) compose = Compose(conf, self.tmp_dir) d = compose.mkdtemp() self.assertTrue(os.path.isdir(d)) - d = compose.mkdtemp(prefix='tweak_buildinstall') + d = compose.mkdtemp(prefix="tweak_buildinstall") self.assertTrue(os.path.isdir(d)) @@ -466,7 +578,7 @@ class StatusTest(unittest.TestCase): self.tmp_dir = tempfile.mkdtemp() self.logger = mock.Mock() self.logger.handlers = [] - with mock.patch('pungi.compose.ComposeInfo'): + with mock.patch("pungi.compose.ComposeInfo"): self.compose = Compose({}, self.tmp_dir, logger=self.logger) def tearDown(self): @@ -477,78 +589,82 @@ class StatusTest(unittest.TestCase): self.assertIsNone(status) def test_get_status_existing(self): - with open(os.path.join(self.tmp_dir, 'STATUS'), 'w') as f: - f.write('FOOBAR') + with open(os.path.join(self.tmp_dir, "STATUS"), "w") as f: + f.write("FOOBAR") - self.assertEqual(self.compose.get_status(), 'FOOBAR') + self.assertEqual(self.compose.get_status(), "FOOBAR") def test_get_status_is_dir(self): - os.mkdir(os.path.join(self.tmp_dir, 'STATUS')) + os.mkdir(os.path.join(self.tmp_dir, "STATUS")) self.assertIsNone(self.compose.get_status()) def test_write_status(self): - self.compose.write_status('DOOMED') + self.compose.write_status("DOOMED") - with open(os.path.join(self.tmp_dir, 'STATUS'), 'r') as f: - self.assertEqual(f.read(), 'DOOMED\n') + with open(os.path.join(self.tmp_dir, "STATUS"), "r") as f: + self.assertEqual(f.read(), "DOOMED\n") def test_write_non_standard_status(self): - self.compose.write_status('FOOBAR') + self.compose.write_status("FOOBAR") self.assertEqual(self.logger.log.call_count, 1) - with open(os.path.join(self.tmp_dir, 'STATUS'), 'r') as f: - self.assertEqual(f.read(), 'FOOBAR\n') + with open(os.path.join(self.tmp_dir, "STATUS"), "r") as f: + self.assertEqual(f.read(), "FOOBAR\n") def test_write_status_on_finished(self): - self.compose.write_status('FINISHED') + self.compose.write_status("FINISHED") with self.assertRaises(RuntimeError): - self.compose.write_status('NOT REALLY') + self.compose.write_status("NOT REALLY") def test_write_status_with_failed_deliverables(self): self.compose.conf = { - 'failable_deliverables': [ - ('^.+$', { - '*': ['live', 'build-image'], - }) - ] + "failable_deliverables": [("^.+$", {"*": ["live", "build-image"]})] } - variant = mock.Mock(uid='Server') - self.compose.fail_deliverable(variant, 'x86_64', 'live') - self.compose.fail_deliverable(None, '*', 'build-image') + variant = mock.Mock(uid="Server") + self.compose.fail_deliverable(variant, "x86_64", "live") + self.compose.fail_deliverable(None, "*", "build-image") - self.compose.write_status('FINISHED') + self.compose.write_status("FINISHED") self.logger.log.assert_has_calls( - [mock.call(20, 'Failed build-image on variant <>, arch <*>, subvariant .'), - mock.call(20, 'Failed live on variant , arch , subvariant .')], - any_order=True) + [ + mock.call( + 20, "Failed build-image on variant <>, arch <*>, subvariant ." + ), + mock.call( + 20, + "Failed live on variant , arch , subvariant .", + ), + ], + any_order=True, + ) - with open(os.path.join(self.tmp_dir, 'STATUS'), 'r') as f: - self.assertEqual(f.read(), 'FINISHED_INCOMPLETE\n') + with open(os.path.join(self.tmp_dir, "STATUS"), "r") as f: + self.assertEqual(f.read(), "FINISHED_INCOMPLETE\n") def test_calls_notifier(self): self.compose.notifier = mock.Mock() - self.compose.write_status('FINISHED') + self.compose.write_status("FINISHED") self.assertTrue(self.compose.notifier.send.call_count, 1) def test_no_database_with_dnf_backend(self): - self.compose.conf['gather_backend'] = 'dnf' + self.compose.conf["gather_backend"] = "dnf" self.assertFalse(self.compose.should_create_yum_database) def test_no_database_with_dnf_backend_config_override(self): - self.compose.conf['gather_backend'] = 'dnf' - self.compose.conf['createrepo_database'] = True + self.compose.conf["gather_backend"] = "dnf" + self.compose.conf["createrepo_database"] = True self.assertTrue(self.compose.should_create_yum_database) def test_no_database_with_yum_backend(self): - self.compose.conf['gather_backend'] = 'yum' + self.compose.conf["gather_backend"] = "yum" self.assertTrue(self.compose.should_create_yum_database) def test_no_database_with_yum_backend_config_override(self): - self.compose.conf['gather_backend'] = 'yum' - self.compose.conf['createrepo_database'] = False + self.compose.conf["gather_backend"] = "yum" + self.compose.conf["createrepo_database"] = False self.assertFalse(self.compose.should_create_yum_database) diff --git a/tests/test_comps_wrapper.py b/tests/test_comps_wrapper.py index 943d73fb..2692a242 100644 --- a/tests/test_comps_wrapper.py +++ b/tests/test_comps_wrapper.py @@ -12,29 +12,40 @@ import sys from pungi.wrappers.comps import CompsWrapper, CompsFilter, CompsValidationError from tests.helpers import BaseTestCase, FIXTURE_DIR -COMPS_FILE = os.path.join(FIXTURE_DIR, 'comps.xml') -COMPS_FORMATTED_FILE = os.path.join(FIXTURE_DIR, 'comps-formatted.xml') -COMPS_GROUP_FILE = os.path.join(FIXTURE_DIR, 'comps-group.xml') -COMPS_ENVIRONMENT_FILE = os.path.join(FIXTURE_DIR, 'comps-env.xml') -COMPS_FILE_WITH_TYPO = os.path.join(FIXTURE_DIR, 'comps-typo.xml') -COMPS_FILE_WITH_WHITESPACE = os.path.join(FIXTURE_DIR, 'comps-ws.xml') +COMPS_FILE = os.path.join(FIXTURE_DIR, "comps.xml") +COMPS_FORMATTED_FILE = os.path.join(FIXTURE_DIR, "comps-formatted.xml") +COMPS_GROUP_FILE = os.path.join(FIXTURE_DIR, "comps-group.xml") +COMPS_ENVIRONMENT_FILE = os.path.join(FIXTURE_DIR, "comps-env.xml") +COMPS_FILE_WITH_TYPO = os.path.join(FIXTURE_DIR, "comps-typo.xml") +COMPS_FILE_WITH_WHITESPACE = os.path.join(FIXTURE_DIR, "comps-ws.xml") class CompsWrapperTest(BaseTestCase): def setUp(self): - self.file = tempfile.NamedTemporaryFile(prefix='comps-wrapper-test-') + self.file = tempfile.NamedTemporaryFile(prefix="comps-wrapper-test-") def test_get_groups(self): comps = CompsWrapper(COMPS_FILE) self.assertEqual( sorted(comps.get_comps_groups()), - sorted(['core', 'standard', 'text-internet', 'firefox', 'resilient-storage', 'basic-desktop'])) + sorted( + [ + "core", + "standard", + "text-internet", + "firefox", + "resilient-storage", + "basic-desktop", + ] + ), + ) def test_get_packages(self): comps = CompsWrapper(COMPS_FILE) self.assertEqual( - sorted(comps.get_packages('text-internet')), - sorted(['dummy-elinks', 'dummy-tftp'])) + sorted(comps.get_packages("text-internet")), + sorted(["dummy-elinks", "dummy-tftp"]), + ) def test_get_langpacks(self): comps = CompsWrapper(COMPS_FILE) @@ -44,13 +55,13 @@ class CompsWrapperTest(BaseTestCase): "aspell": "aspell-%s", "firefox": "firefox-langpack-%s", "kdelibs": "kde-l10n-%s", - } + }, ) def test_get_packages_for_non_existing_group(self): comps = CompsWrapper(COMPS_FILE) with self.assertRaises(KeyError): - comps.get_packages('foo') + comps.get_packages("foo") def test_write_comps(self): comps = CompsWrapper(COMPS_FILE) @@ -59,44 +70,44 @@ class CompsWrapperTest(BaseTestCase): def test_filter_groups(self): comps = CompsWrapper(COMPS_FILE) - unmatched = comps.filter_groups([ - {"name": "core", "glob": False, "default": False, "uservisible": True}, - {"name": "*a*", "glob": True, "default": None, "uservisible": None}, - ]) + unmatched = comps.filter_groups( + [ + {"name": "core", "glob": False, "default": False, "uservisible": True}, + {"name": "*a*", "glob": True, "default": None, "uservisible": None}, + ] + ) self.assertEqual(unmatched, set()) comps.write_comps(target_file=self.file.name) self.assertFilesEqual(COMPS_GROUP_FILE, self.file.name) def test_filter_groups_unused_filter(self): comps = CompsWrapper(COMPS_FILE) - unmatched = comps.filter_groups([ - {"name": "boom", "glob": False, "default": False, "uservisible": True}, - ]) + unmatched = comps.filter_groups( + [{"name": "boom", "glob": False, "default": False, "uservisible": True}] + ) self.assertEqual(unmatched, set(["boom"])) def test_filter_environments(self): comps = CompsWrapper(COMPS_FILE) - comps.filter_environments([ - {"name": "minimal", "display_order": 10} - ]) + comps.filter_environments([{"name": "minimal", "display_order": 10}]) comps.write_comps(target_file=self.file.name) self.assertFilesEqual(COMPS_ENVIRONMENT_FILE, self.file.name) def test_read_display_order(self): comps = CompsWrapper(COMPS_FILE) - groups = [ - {"name": "minimal", "display_order": None} - ] + groups = [{"name": "minimal", "display_order": None}] comps.filter_environments(groups) - self.assertEqual(groups, [{"name": "minimal", "display_order": 99, "groups": ["core"]}]) + self.assertEqual( + groups, [{"name": "minimal", "display_order": 99, "groups": ["core"]}] + ) def test_report_typo_in_package_type(self): comps = CompsWrapper(COMPS_FILE_WITH_TYPO) with self.assertRaises(RuntimeError) as ctx: comps.write_comps(target_file=self.file.name) self.assertIn( - 'Package dummy-bash in group core has unknown type', - str(ctx.exception)) + "Package dummy-bash in group core has unknown type", str(ctx.exception) + ) def test_validate_correct(self): comps = CompsWrapper(COMPS_FILE) @@ -121,81 +132,87 @@ class CompsWrapperTest(BaseTestCase): ) -COMPS_IN_FILE = os.path.join(FIXTURE_DIR, 'comps.xml.in') +COMPS_IN_FILE = os.path.join(FIXTURE_DIR, "comps.xml.in") class CompsFilterTest(unittest.TestCase): def setUp(self): self.filter = CompsFilter(COMPS_IN_FILE, reindent=True) - self.output = tempfile.NamedTemporaryFile(prefix='comps-filter-test-') + self.output = tempfile.NamedTemporaryFile(prefix="comps-filter-test-") def assertOutput(self, filepath): self.filter.write(self.output) self.output.flush() - with open(self.output.name, 'r') as f: - actual = f.read().strip().replace('utf-8', 'UTF-8') - with open(filepath, 'r') as f: + with open(self.output.name, "r") as f: + actual = f.read().strip().replace("utf-8", "UTF-8") + with open(filepath, "r") as f: expected = f.read().strip() self.maxDiff = None self.assertEqual(expected, actual) def test_filter_packages(self): - self.filter.filter_packages('ppc64le', None) - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-packages.xml')) + self.filter.filter_packages("ppc64le", None) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-filtered-packages.xml")) def test_filter_packages_with_variant(self): - self.filter.filter_packages('ppc64le', 'Server') - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-packages-variant.xml')) + self.filter.filter_packages("ppc64le", "Server") + self.assertOutput( + os.path.join(FIXTURE_DIR, "comps-filtered-packages-variant.xml") + ) def test_filter_groups(self): - self.filter.filter_groups('ppc64le', None) - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-groups.xml')) + self.filter.filter_groups("ppc64le", None) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-filtered-groups.xml")) def test_filter_groups_with_variant(self): - self.filter.filter_groups('ppc64le', 'Server') - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-groups-variant.xml')) + self.filter.filter_groups("ppc64le", "Server") + self.assertOutput( + os.path.join(FIXTURE_DIR, "comps-filtered-groups-variant.xml") + ) def test_filter_environments(self): - self.filter.filter_environments('ppc64le', None) - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-environments.xml')) + self.filter.filter_environments("ppc64le", None) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-filtered-environments.xml")) def test_filter_environments_variant(self): - self.filter.filter_environments('ppc64le', 'Client') - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-environments-variant.xml')) + self.filter.filter_environments("ppc64le", "Client") + self.assertOutput( + os.path.join(FIXTURE_DIR, "comps-filtered-environments-variant.xml") + ) def test_remove_categories(self): self.filter.remove_categories() - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-categories.xml')) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-removed-categories.xml")) def test_remove_langpacks(self): self.filter.remove_langpacks() - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-langpacks.xml')) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-removed-langpacks.xml")) def test_remove_translations(self): self.filter.remove_translations() - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-translations.xml')) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-removed-translations.xml")) def test_remove_environments(self): self.filter.remove_environments() - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-environments.xml')) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-removed-environments.xml")) def test_cleanup(self): self.filter.cleanup() - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup.xml')) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup.xml")) def test_cleanup_after_filter(self): - self.filter.filter_packages('ppc64le', None) + self.filter.filter_packages("ppc64le", None) self.filter.cleanup() - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-filter.xml')) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup-filter.xml")) def test_cleanup_after_filter_keep_group(self): - self.filter.filter_packages('ppc64le', None) - self.filter.cleanup(['standard']) - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-keep.xml')) + self.filter.filter_packages("ppc64le", None) + self.filter.cleanup(["standard"]) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup-keep.xml")) def test_cleanup_all(self): - self.filter.filter_packages('ppc64le', None) - self.filter.filter_groups('ppc64le', None) - self.filter.filter_environments('ppc64le', None) + self.filter.filter_packages("ppc64le", None) + self.filter.filter_groups("ppc64le", None) + self.filter.filter_environments("ppc64le", None) self.filter.cleanup() - self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-all.xml')) + self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup-all.xml")) diff --git a/tests/test_config.py b/tests/test_config.py index e34640b9..6493c8f1 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -23,49 +23,46 @@ class ConfigTestCase(unittest.TestCase): class PkgsetConfigTestCase(ConfigTestCase): - def test_validate_minimal_pkgset_koji(self): - cfg = load_config( - pkgset_source='koji', - ) + cfg = load_config(pkgset_source="koji",) self.assertValidation(cfg) def test_validate_minimal_pkgset_repos(self): cfg = load_config( - pkgset_source='repos', - pkgset_repos={'x86_64': '/first', 'ppc64': '/second'}, + pkgset_source="repos", + pkgset_repos={"x86_64": "/first", "ppc64": "/second"}, ) self.assertValidation(cfg) def test_pkgset_mismatch_repos(self): cfg = load_config( - pkgset_source='repos', - pkgset_koji_tag='f25', - pkgset_koji_inherit=False, + pkgset_source="repos", pkgset_koji_tag="f25", pkgset_koji_inherit=False, ) self.assertValidation( cfg, - [checks.REQUIRES.format('pkgset_source', 'repos', 'pkgset_repos'), - checks.CONFLICTS.format('pkgset_source', 'repos', 'pkgset_koji_tag'), - checks.CONFLICTS.format('pkgset_source', 'repos', 'pkgset_koji_inherit')]) + [ + checks.REQUIRES.format("pkgset_source", "repos", "pkgset_repos"), + checks.CONFLICTS.format("pkgset_source", "repos", "pkgset_koji_tag"), + checks.CONFLICTS.format( + "pkgset_source", "repos", "pkgset_koji_inherit" + ), + ], + ) def test_pkgset_mismatch_koji(self): - cfg = load_config( - pkgset_source='koji', - pkgset_repos={'whatever': '/foo'}, - ) + cfg = load_config(pkgset_source="koji", pkgset_repos={"whatever": "/foo"},) self.assertValidation( - cfg, - [checks.CONFLICTS.format('pkgset_source', 'koji', 'pkgset_repos')]) + cfg, [checks.CONFLICTS.format("pkgset_source", "koji", "pkgset_repos")] + ) def test_pkgset_multiple_koji_tags(self): cfg = load_config( - pkgset_source='koji', - pkgset_koji_tag=['f25', 'f25-extra'], + pkgset_source="koji", + pkgset_koji_tag=["f25", "f25-extra"], pkgset_koji_inherit=False, ) self.assertValidation(cfg) @@ -73,215 +70,222 @@ class PkgsetConfigTestCase(ConfigTestCase): class ReleaseConfigTestCase(ConfigTestCase): def test_set_release_is_layered(self): - cfg = load_config( - PKGSET_REPOS, - release_is_layered=True - ) + cfg = load_config(PKGSET_REPOS, release_is_layered=True) self.assertValidation( cfg, warnings=[ - "WARNING: Config option release_is_layered was removed and has no effect; remove it. It's layered if there's configuration for base product."]) + "WARNING: Config option release_is_layered was removed and has no effect; remove it. It's layered if there's configuration for base product." + ], + ) def test_only_config_base_product_name(self): - cfg = load_config( - PKGSET_REPOS, - base_product_name='Prod', - ) + cfg = load_config(PKGSET_REPOS, base_product_name="Prod",) self.assertValidation( cfg, - [checks.REQUIRES.format('base_product_name', 'Prod', 'base_product_short'), - checks.REQUIRES.format('base_product_name', 'Prod', 'base_product_version'), - checks.CONFLICTS.format('base_product_short', None, 'base_product_name'), - checks.CONFLICTS.format('base_product_version', None, 'base_product_name')]) + [ + checks.REQUIRES.format( + "base_product_name", "Prod", "base_product_short" + ), + checks.REQUIRES.format( + "base_product_name", "Prod", "base_product_version" + ), + checks.CONFLICTS.format( + "base_product_short", None, "base_product_name" + ), + checks.CONFLICTS.format( + "base_product_version", None, "base_product_name" + ), + ], + ) def test_only_config_base_product_short(self): - cfg = load_config( - PKGSET_REPOS, - base_product_short='bp', - ) + cfg = load_config(PKGSET_REPOS, base_product_short="bp",) self.assertValidation( cfg, - [checks.REQUIRES.format('base_product_short', 'bp', 'base_product_name'), - checks.REQUIRES.format('base_product_short', 'bp', 'base_product_version'), - checks.CONFLICTS.format('base_product_name', None, 'base_product_short'), - checks.CONFLICTS.format('base_product_version', None, 'base_product_short')]) + [ + checks.REQUIRES.format("base_product_short", "bp", "base_product_name"), + checks.REQUIRES.format( + "base_product_short", "bp", "base_product_version" + ), + checks.CONFLICTS.format( + "base_product_name", None, "base_product_short" + ), + checks.CONFLICTS.format( + "base_product_version", None, "base_product_short" + ), + ], + ) def test_only_config_base_product_version(self): - cfg = load_config( - PKGSET_REPOS, - base_product_version='1.0', - ) + cfg = load_config(PKGSET_REPOS, base_product_version="1.0",) self.assertValidation( cfg, - [checks.REQUIRES.format('base_product_version', '1.0', 'base_product_name'), - checks.REQUIRES.format('base_product_version', '1.0', 'base_product_short'), - checks.CONFLICTS.format('base_product_name', None, 'base_product_version'), - checks.CONFLICTS.format('base_product_short', None, 'base_product_version')]) + [ + checks.REQUIRES.format( + "base_product_version", "1.0", "base_product_name" + ), + checks.REQUIRES.format( + "base_product_version", "1.0", "base_product_short" + ), + checks.CONFLICTS.format( + "base_product_name", None, "base_product_version" + ), + checks.CONFLICTS.format( + "base_product_short", None, "base_product_version" + ), + ], + ) class ImageNameConfigTestCase(ConfigTestCase): def test_image_name_simple_string(self): - cfg = load_config( - PKGSET_REPOS, - image_name_format="foobar", - ) + cfg = load_config(PKGSET_REPOS, image_name_format="foobar",) self.assertValidation(cfg, []) def test_image_name_variant_mapping(self): - cfg = load_config( - PKGSET_REPOS, - image_name_format={"^Server$": "foobar"}, - ) + cfg = load_config(PKGSET_REPOS, image_name_format={"^Server$": "foobar"},) self.assertValidation(cfg, []) class RunrootConfigTestCase(ConfigTestCase): def test_set_runroot_true(self): - cfg = load_config( - PKGSET_REPOS, - runroot=True, - ) + cfg = load_config(PKGSET_REPOS, runroot=True,) self.assertValidation( cfg, - warnings=["WARNING: Config option runroot was removed and has no effect; remove it. Please specify 'runroot_method' if you want to enable runroot, otherwise run things locally."]) + warnings=[ + "WARNING: Config option runroot was removed and has no effect; remove it. Please specify 'runroot_method' if you want to enable runroot, otherwise run things locally." + ], + ) def test_set_runroot_false(self): - cfg = load_config( - PKGSET_REPOS, - runroot=False, - ) + cfg = load_config(PKGSET_REPOS, runroot=False,) self.assertValidation( cfg, - warnings=["WARNING: Config option runroot was removed and has no effect; remove it. Please specify 'runroot_method' if you want to enable runroot, otherwise run things locally."]) + warnings=[ + "WARNING: Config option runroot was removed and has no effect; remove it. Please specify 'runroot_method' if you want to enable runroot, otherwise run things locally." + ], + ) class BuildinstallConfigTestCase(ConfigTestCase): def test_bootable_deprecated(self): - cfg = load_config( - PKGSET_REPOS, - bootable=True, - ) + cfg = load_config(PKGSET_REPOS, bootable=True,) self.assertValidation( cfg, - warnings=['WARNING: Config option bootable was removed and has no effect; remove it. Setting buildinstall_method option if you want a bootable installer.']) + warnings=[ + "WARNING: Config option bootable was removed and has no effect; remove it. Setting buildinstall_method option if you want a bootable installer." + ], + ) def test_buildinstall_method_without_bootable(self): - cfg = load_config( - PKGSET_REPOS, - buildinstall_method='lorax', - ) + cfg = load_config(PKGSET_REPOS, buildinstall_method="lorax",) - self.assertValidation( - cfg, - []) + self.assertValidation(cfg, []) def test_buildinstall_with_lorax_options(self): cfg = load_config( PKGSET_REPOS, - buildinstall_method='buildinstall', - lorax_options=[('^Server$', {})] + buildinstall_method="buildinstall", + lorax_options=[("^Server$", {})], ) self.assertValidation( cfg, - [checks.CONFLICTS.format('buildinstall_method', 'buildinstall', 'lorax_options')]) + [ + checks.CONFLICTS.format( + "buildinstall_method", "buildinstall", "lorax_options" + ) + ], + ) def test_lorax_with_lorax_options(self): - cfg = load_config( - PKGSET_REPOS, - buildinstall_method='lorax', - lorax_options=[] - ) + cfg = load_config(PKGSET_REPOS, buildinstall_method="lorax", lorax_options=[]) self.assertValidation(cfg) def test_lorax_options_without_bootable_and_method(self): cfg = load_config( PKGSET_REPOS, - lorax_options=[('^Server$', {})], - buildinstall_kickstart='foo', + lorax_options=[("^Server$", {})], + buildinstall_kickstart="foo", ) self.assertValidation( cfg, - [checks.CONFLICTS.format('buildinstall_method', 'None', 'lorax_options'), - checks.CONFLICTS.format('buildinstall_method', 'None', 'buildinstall_kickstart')]) + [ + checks.CONFLICTS.format("buildinstall_method", "None", "lorax_options"), + checks.CONFLICTS.format( + "buildinstall_method", "None", "buildinstall_kickstart" + ), + ], + ) class CreaterepoConfigTestCase(ConfigTestCase): def test_validate_minimal_pkgset_koji(self): cfg = load_config( - pkgset_source='koji', - pkgset_koji_tag="f25", - product_id_allow_missing=True, + pkgset_source="koji", pkgset_koji_tag="f25", product_id_allow_missing=True, ) self.assertValidation( cfg, - [checks.CONFLICTS.format('product_id', 'None', 'product_id_allow_missing')]) + [checks.CONFLICTS.format("product_id", "None", "product_id_allow_missing")], + ) class GatherConfigTestCase(ConfigTestCase): def test_dnf_backend_is_default_on_py3(self): - cfg = load_config( - pkgset_source='koji', - pkgset_koji_tag='f27', - ) + cfg = load_config(pkgset_source="koji", pkgset_koji_tag="f27",) - with mock.patch('six.PY2', new=False): + with mock.patch("six.PY2", new=False): self.assertValidation(cfg, []) - self.assertEqual(cfg['gather_backend'], 'dnf') + self.assertEqual(cfg["gather_backend"], "dnf") def test_yum_backend_is_default_on_py2(self): - cfg = load_config( - pkgset_source='koji', - pkgset_koji_tag='f27', - ) + cfg = load_config(pkgset_source="koji", pkgset_koji_tag="f27",) - with mock.patch('six.PY2', new=True): + with mock.patch("six.PY2", new=True): self.assertValidation(cfg, []) - self.assertEqual(cfg['gather_backend'], 'yum') + self.assertEqual(cfg["gather_backend"], "yum") def test_yum_backend_is_rejected_on_py3(self): cfg = load_config( - pkgset_source='koji', - pkgset_koji_tag='f27', - gather_backend='yum', + pkgset_source="koji", pkgset_koji_tag="f27", gather_backend="yum", ) - with mock.patch('six.PY2', new=False): + with mock.patch("six.PY2", new=False): self.assertValidation( cfg, - ["Failed validation in gather_backend: 'yum' is not one of ['dnf']"]) + ["Failed validation in gather_backend: 'yum' is not one of ['dnf']"], + ) class OSBSConfigTestCase(ConfigTestCase): def test_validate(self): cfg = load_config( PKGSET_REPOS, - osbs={"^Server$": { - 'url': 'http://example.com', - 'target': 'f25-build', - 'git_branch': 'f25', - }} + osbs={ + "^Server$": { + "url": "http://example.com", + "target": "f25-build", + "git_branch": "f25", + } + }, ) self.assertValidation(cfg) def test_validate_bad_conf(self): - cfg = load_config( - PKGSET_REPOS, - osbs='yes please' - ) + cfg = load_config(PKGSET_REPOS, osbs="yes please") self.assertNotEqual(checks.validate(cfg), ([], [])) @@ -291,25 +295,25 @@ class OstreeConfigTestCase(ConfigTestCase): cfg = load_config( PKGSET_REPOS, ostree=[ - ("^Atomic$", { - "x86_64": { - "treefile": "fedora-atomic-docker-host.json", - "config_url": "https://git.fedorahosted.org/git/fedora-atomic.git", - "repo": "Everything", - "ostree_repo": "/mnt/koji/compose/atomic/Rawhide/", - "version": '!OSTREE_VERSION_FROM_LABEL_DATE_TYPE_RESPIN', - } - }) - ] + ( + "^Atomic$", + { + "x86_64": { + "treefile": "fedora-atomic-docker-host.json", + "config_url": "https://git.fedorahosted.org/git/fedora-atomic.git", + "repo": "Everything", + "ostree_repo": "/mnt/koji/compose/atomic/Rawhide/", + "version": "!OSTREE_VERSION_FROM_LABEL_DATE_TYPE_RESPIN", + } + }, + ) + ], ) self.assertValidation(cfg) def test_validate_bad_conf(self): - cfg = load_config( - PKGSET_REPOS, - ostree='yes please' - ) + cfg = load_config(PKGSET_REPOS, ostree="yes please") self.assertNotEqual(checks.validate(cfg), ([], [])) @@ -319,26 +323,33 @@ class OstreeInstallerConfigTestCase(ConfigTestCase): cfg = load_config( PKGSET_REPOS, ostree_installer=[ - ("^Atomic$", { - "x86_64": { - "repo": "Everything", - "release": None, - "installpkgs": ["fedora-productimg-atomic"], - "add_template": ["/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl"], - "add_template_var": [ - "ostree_osname=fedora-atomic", - "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", - ], - "add_arch_template": ["/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl"], - "rootfs_size": "3", - "add_arch_template_var": [ - "ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/", - "ostree_osname=fedora-atomic", - "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", - ] - } - }) - ] + ( + "^Atomic$", + { + "x86_64": { + "repo": "Everything", + "release": None, + "installpkgs": ["fedora-productimg-atomic"], + "add_template": [ + "/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl" + ], + "add_template_var": [ + "ostree_osname=fedora-atomic", + "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", + ], + "add_arch_template": [ + "/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl" + ], + "rootfs_size": "3", + "add_arch_template_var": [ + "ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/", + "ostree_osname=fedora-atomic", + "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", + ], + } + }, + ) + ], ) self.assertValidation(cfg) @@ -347,25 +358,30 @@ class OstreeInstallerConfigTestCase(ConfigTestCase): cfg = load_config( PKGSET_REPOS, ostree_installer=[ - ("^Atomic$", { - "x86_64": { - "repo": "Everything", - "release": None, - "installpkgs": ["fedora-productimg-atomic"], - "add_template": ["/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl"], - "add_template_var": [ - "ostree_osname=fedora-atomic", - "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", - ], - "add_arch_template": 15, - "add_arch_template_var": [ - "ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/", - "ostree_osname=fedora-atomic", - "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", - ] - } - }) - ] + ( + "^Atomic$", + { + "x86_64": { + "repo": "Everything", + "release": None, + "installpkgs": ["fedora-productimg-atomic"], + "add_template": [ + "/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl" + ], + "add_template_var": [ + "ostree_osname=fedora-atomic", + "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", + ], + "add_arch_template": 15, + "add_arch_template_var": [ + "ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/", + "ostree_osname=fedora-atomic", + "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", + ], + } + }, + ) + ], ) self.assertNotEqual(checks.validate(cfg), ([], [])) @@ -376,10 +392,10 @@ class LiveMediaConfigTestCase(ConfigTestCase): def test_global_config_validation(self, resolve_git_url): cfg = load_config( PKGSET_REPOS, - live_media_ksurl='git://example.com/repo.git#HEAD', - live_media_target='f24', - live_media_release='RRR', - live_media_version='Rawhide', + live_media_ksurl="git://example.com/repo.git#HEAD", + live_media_target="f24", + live_media_release="RRR", + live_media_version="Rawhide", ) resolve_git_url.side_effect = lambda x: x.replace("HEAD", "CAFE") @@ -388,53 +404,50 @@ class LiveMediaConfigTestCase(ConfigTestCase): self.assertEqual(cfg["live_media_ksurl"], "git://example.com/repo.git#CAFE") def test_global_config_null_release(self): - cfg = load_config( - PKGSET_REPOS, - live_media_release=None, - ) + cfg = load_config(PKGSET_REPOS, live_media_release=None,) self.assertValidation(cfg) class TestSuggestions(ConfigTestCase): def test_with_a_typo(self): - cfg = load_config(PKGSET_REPOS, - product_pid=None) + cfg = load_config(PKGSET_REPOS, product_pid=None) - self.assertValidation(cfg, [], [checks.UNKNOWN_SUGGEST.format('product_pid', 'product_id')]) + self.assertValidation( + cfg, [], [checks.UNKNOWN_SUGGEST.format("product_pid", "product_id")] + ) class TestRegexValidation(ConfigTestCase): def test_incorrect_regular_expression(self): - cfg = load_config(PKGSET_REPOS, - multilib=[('^*$', {'*': []})]) + cfg = load_config(PKGSET_REPOS, multilib=[("^*$", {"*": []})]) - msg = 'Failed validation in multilib.0.0: incorrect regular expression: nothing to repeat' + msg = "Failed validation in multilib.0.0: incorrect regular expression: nothing to repeat" if six.PY3: - msg += ' at position 1' + msg += " at position 1" self.assertValidation(cfg, [msg], []) class RepoclosureTestCase(ConfigTestCase): def test_invalid_backend(self): cfg = load_config( - PKGSET_REPOS, - repoclosure_backend='fnd', # Intentionally with a typo + PKGSET_REPOS, repoclosure_backend="fnd", # Intentionally with a typo ) - options = ['yum', 'dnf'] if six.PY2 else ['dnf'] + options = ["yum", "dnf"] if six.PY2 else ["dnf"] self.assertValidation( cfg, - ["Failed validation in repoclosure_backend: 'fnd' is not one of %s" % options]) + [ + "Failed validation in repoclosure_backend: 'fnd' is not one of %s" + % options + ], + ) class VariantAsLookasideTestCase(ConfigTestCase): def test_empty(self): variant_as_lookaside = [] - cfg = load_config( - PKGSET_REPOS, - variant_as_lookaside=variant_as_lookaside, - ) + cfg = load_config(PKGSET_REPOS, variant_as_lookaside=variant_as_lookaside,) self.assertValidation(cfg) def test_basic(self): @@ -443,20 +456,14 @@ class VariantAsLookasideTestCase(ConfigTestCase): ("Server", "Client"), ("Everything", "Spin"), ] - cfg = load_config( - PKGSET_REPOS, - variant_as_lookaside=variant_as_lookaside, - ) + cfg = load_config(PKGSET_REPOS, variant_as_lookaside=variant_as_lookaside,) self.assertValidation(cfg) class SkipPhasesTestCase(ConfigTestCase): def test_empty(self): skip_phases = [] - cfg = load_config( - PKGSET_REPOS, - skip_phases=skip_phases, - ) + cfg = load_config(PKGSET_REPOS, skip_phases=skip_phases,) self.assertValidation(cfg) def test_basic(self): @@ -464,10 +471,7 @@ class SkipPhasesTestCase(ConfigTestCase): "buildinstall", "gather", ] - cfg = load_config( - PKGSET_REPOS, - skip_phases=skip_phases, - ) + cfg = load_config(PKGSET_REPOS, skip_phases=skip_phases,) self.assertValidation(cfg) def test_bad_phase_name(self): @@ -475,8 +479,5 @@ class SkipPhasesTestCase(ConfigTestCase): "gather", "non-existing-phase_name", ] - cfg = load_config( - PKGSET_REPOS, - skip_phases=skip_phases, - ) + cfg = load_config(PKGSET_REPOS, skip_phases=skip_phases,) self.assertNotEqual(checks.validate(cfg), ([], [])) diff --git a/tests/test_createiso_phase.py b/tests/test_createiso_phase.py index c859368b..54838fe7 100644 --- a/tests/test_createiso_phase.py +++ b/tests/test_createiso_phase.py @@ -13,14 +13,11 @@ from pungi.phases import createiso class CreateisoPhaseTest(helpers.PungiTestCase): - - @mock.patch('pungi.phases.createiso.ThreadPool') + @mock.patch("pungi.phases.createiso.ThreadPool") def test_skip_all(self, ThreadPool): - compose = helpers.DummyCompose(self.topdir, { - 'createiso_skip': [ - ('^.*$', {'*': True, 'src': True}) - ] - }) + compose = helpers.DummyCompose( + self.topdir, {"createiso_skip": [("^.*$", {"*": True, "src": True})]} + ) pool = ThreadPool.return_value @@ -31,14 +28,12 @@ class CreateisoPhaseTest(helpers.PungiTestCase): self.assertEqual(len(pool.add.call_args_list), 0) self.assertEqual(pool.queue_put.call_args_list, []) - @mock.patch('pungi.phases.createiso.ThreadPool') + @mock.patch("pungi.phases.createiso.ThreadPool") def test_nothing_happens_without_rpms(self, ThreadPool): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'createiso_skip': [ - ] - }) + compose = helpers.DummyCompose( + self.topdir, + {"release_short": "test", "release_version": "1.0", "createiso_skip": []}, + ) pool = ThreadPool.return_value @@ -51,33 +46,36 @@ class CreateisoPhaseTest(helpers.PungiTestCase): six.assertCountEqual( self, phase.logger.warning.call_args_list, - [mock.call('No RPMs found for Everything.x86_64, skipping ISO'), - mock.call('No RPMs found for Everything.amd64, skipping ISO'), - mock.call('No RPMs found for Everything.src, skipping ISO'), - mock.call('No RPMs found for Client.amd64, skipping ISO'), - mock.call('No RPMs found for Client.src, skipping ISO'), - mock.call('No RPMs found for Server.x86_64, skipping ISO'), - mock.call('No RPMs found for Server.amd64, skipping ISO'), - mock.call('No RPMs found for Server.src, skipping ISO')] + [ + mock.call("No RPMs found for Everything.x86_64, skipping ISO"), + mock.call("No RPMs found for Everything.amd64, skipping ISO"), + mock.call("No RPMs found for Everything.src, skipping ISO"), + mock.call("No RPMs found for Client.amd64, skipping ISO"), + mock.call("No RPMs found for Client.src, skipping ISO"), + mock.call("No RPMs found for Server.x86_64, skipping ISO"), + mock.call("No RPMs found for Server.amd64, skipping ISO"), + mock.call("No RPMs found for Server.src, skipping ISO"), + ], ) - @mock.patch('pungi.createiso.write_script') - @mock.patch('pungi.phases.createiso.prepare_iso') - @mock.patch('pungi.phases.createiso.split_iso') - @mock.patch('pungi.phases.createiso.ThreadPool') + @mock.patch("pungi.createiso.write_script") + @mock.patch("pungi.phases.createiso.prepare_iso") + @mock.patch("pungi.phases.createiso.split_iso") + @mock.patch("pungi.phases.createiso.ThreadPool") def test_start_one_worker(self, ThreadPool, split_iso, prepare_iso, write_script): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'createiso_skip': [ - ] - }) - helpers.touch(os.path.join( - compose.paths.compose.os_tree('x86_64', compose.variants['Server']), - 'dummy.rpm')) + compose = helpers.DummyCompose( + self.topdir, + {"release_short": "test", "release_version": "1.0", "createiso_skip": []}, + ) + helpers.touch( + os.path.join( + compose.paths.compose.os_tree("x86_64", compose.variants["Server"]), + "dummy.rpm", + ) + ) disc_data = mock.Mock() split_iso.return_value = [disc_data] - prepare_iso.return_value = 'dummy-graft-points' + prepare_iso.return_value = "dummy-graft-points" pool = ThreadPool.return_value @@ -85,64 +83,105 @@ class CreateisoPhaseTest(helpers.PungiTestCase): phase.logger = mock.Mock() phase.run() - self.assertEqual(prepare_iso.call_args_list, - [mock.call(compose, 'x86_64', compose.variants['Server'], - disc_count=1, disc_num=1, split_iso_data=disc_data)]) - self.assertEqual(split_iso.call_args_list, - [mock.call(compose, 'x86_64', compose.variants['Server'], no_split=False, logger=phase.logger)]) + self.assertEqual( + prepare_iso.call_args_list, + [ + mock.call( + compose, + "x86_64", + compose.variants["Server"], + disc_count=1, + disc_num=1, + split_iso_data=disc_data, + ) + ], + ) + self.assertEqual( + split_iso.call_args_list, + [ + mock.call( + compose, + "x86_64", + compose.variants["Server"], + no_split=False, + logger=phase.logger, + ) + ], + ) self.assertEqual(len(pool.add.call_args_list), 1) self.maxDiff = None self.assertEqual( [x[0][0] for x in write_script.call_args_list], - [CreateIsoOpts( - output_dir='%s/compose/Server/x86_64/iso' % self.topdir, - iso_name='image-name', - volid='test-1.0 Server.x86_64', - graft_points='dummy-graft-points', - arch='x86_64', - supported=True, - jigdo_dir='%s/compose/Server/x86_64/jigdo' % self.topdir, - os_tree='%s/compose/Server/x86_64/os' % self.topdir, - hfs_compat=True, - )]) + [ + CreateIsoOpts( + output_dir="%s/compose/Server/x86_64/iso" % self.topdir, + iso_name="image-name", + volid="test-1.0 Server.x86_64", + graft_points="dummy-graft-points", + arch="x86_64", + supported=True, + jigdo_dir="%s/compose/Server/x86_64/jigdo" % self.topdir, + os_tree="%s/compose/Server/x86_64/os" % self.topdir, + hfs_compat=True, + ) + ], + ) self.assertEqual( pool.queue_put.call_args_list, - [mock.call(( - compose, - { - 'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': ['bash', self.topdir + '/work/x86_64/tmp-Server/createiso-image-name.sh'], - 'label': '', - 'disc_num': 1, - 'disc_count': 1, - }, - compose.variants['Server'], - 'x86_64' - ))] + [ + mock.call( + ( + compose, + { + "iso_path": "%s/compose/Server/x86_64/iso/image-name" + % self.topdir, + "bootable": False, + "cmd": [ + "bash", + self.topdir + + "/work/x86_64/tmp-Server/createiso-image-name.sh", + ], + "label": "", + "disc_num": 1, + "disc_count": 1, + }, + compose.variants["Server"], + "x86_64", + ) + ) + ], ) - @mock.patch('pungi.createiso.write_script') - @mock.patch('pungi.phases.createiso.prepare_iso') - @mock.patch('pungi.phases.createiso.split_iso') - @mock.patch('pungi.phases.createiso.ThreadPool') + @mock.patch("pungi.createiso.write_script") + @mock.patch("pungi.phases.createiso.prepare_iso") + @mock.patch("pungi.phases.createiso.split_iso") + @mock.patch("pungi.phases.createiso.ThreadPool") def test_bootable(self, ThreadPool, split_iso, prepare_iso, write_script): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'buildinstall_method': 'lorax', - 'bootable': True, - 'createiso_skip': [] - }) - helpers.touch(os.path.join( - compose.paths.compose.os_tree('x86_64', compose.variants['Server']), - 'dummy.rpm')) - helpers.touch(os.path.join( - compose.paths.compose.os_tree('src', compose.variants['Server']), - 'dummy.rpm')) + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "buildinstall_method": "lorax", + "bootable": True, + "createiso_skip": [], + }, + ) + helpers.touch( + os.path.join( + compose.paths.compose.os_tree("x86_64", compose.variants["Server"]), + "dummy.rpm", + ) + ) + helpers.touch( + os.path.join( + compose.paths.compose.os_tree("src", compose.variants["Server"]), + "dummy.rpm", + ) + ) disc_data = mock.Mock() split_iso.return_value = [disc_data] - prepare_iso.return_value = 'dummy-graft-points' + prepare_iso.return_value = "dummy-graft-points" pool = ThreadPool.return_value @@ -153,83 +192,155 @@ class CreateisoPhaseTest(helpers.PungiTestCase): six.assertCountEqual( self, prepare_iso.call_args_list, - [mock.call(compose, 'x86_64', compose.variants['Server'], - disc_count=1, disc_num=1, split_iso_data=disc_data), - mock.call(compose, 'src', compose.variants['Server'], - disc_count=1, disc_num=1, split_iso_data=disc_data)]) + [ + mock.call( + compose, + "x86_64", + compose.variants["Server"], + disc_count=1, + disc_num=1, + split_iso_data=disc_data, + ), + mock.call( + compose, + "src", + compose.variants["Server"], + disc_count=1, + disc_num=1, + split_iso_data=disc_data, + ), + ], + ) six.assertCountEqual( self, split_iso.call_args_list, - [mock.call(compose, 'x86_64', compose.variants['Server'], no_split=True, logger=phase.logger), - mock.call(compose, 'src', compose.variants['Server'], no_split=False, logger=phase.logger)]) + [ + mock.call( + compose, + "x86_64", + compose.variants["Server"], + no_split=True, + logger=phase.logger, + ), + mock.call( + compose, + "src", + compose.variants["Server"], + no_split=False, + logger=phase.logger, + ), + ], + ) self.assertEqual(len(pool.add.call_args_list), 2) self.maxDiff = None six.assertCountEqual( self, [x[0][0] for x in write_script.call_args_list], - [CreateIsoOpts(output_dir='%s/compose/Server/x86_64/iso' % self.topdir, - iso_name='image-name', - volid='test-1.0 Server.x86_64', - graft_points='dummy-graft-points', - arch='x86_64', - buildinstall_method='lorax', - supported=True, - jigdo_dir='%s/compose/Server/x86_64/jigdo' % self.topdir, - os_tree='%s/compose/Server/x86_64/os' % self.topdir, - hfs_compat=True), - CreateIsoOpts(output_dir='%s/compose/Server/source/iso' % self.topdir, - iso_name='image-name', - volid='test-1.0 Server.src', - graft_points='dummy-graft-points', - arch='src', - supported=True, - jigdo_dir='%s/compose/Server/source/jigdo' % self.topdir, - os_tree='%s/compose/Server/source/tree' % self.topdir, - hfs_compat=True)]) + [ + CreateIsoOpts( + output_dir="%s/compose/Server/x86_64/iso" % self.topdir, + iso_name="image-name", + volid="test-1.0 Server.x86_64", + graft_points="dummy-graft-points", + arch="x86_64", + buildinstall_method="lorax", + supported=True, + jigdo_dir="%s/compose/Server/x86_64/jigdo" % self.topdir, + os_tree="%s/compose/Server/x86_64/os" % self.topdir, + hfs_compat=True, + ), + CreateIsoOpts( + output_dir="%s/compose/Server/source/iso" % self.topdir, + iso_name="image-name", + volid="test-1.0 Server.src", + graft_points="dummy-graft-points", + arch="src", + supported=True, + jigdo_dir="%s/compose/Server/source/jigdo" % self.topdir, + os_tree="%s/compose/Server/source/tree" % self.topdir, + hfs_compat=True, + ), + ], + ) six.assertCountEqual( self, pool.queue_put.call_args_list, - [mock.call((compose, - {'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': True, - 'cmd': ['bash', self.topdir + '/work/x86_64/tmp-Server/createiso-image-name.sh'], - 'label': '', - 'disc_num': 1, - 'disc_count': 1}, - compose.variants['Server'], - 'x86_64')), - mock.call((compose, - {'iso_path': '%s/compose/Server/source/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': ['bash', self.topdir + '/work/src/tmp-Server/createiso-image-name.sh'], - 'label': '', - 'disc_num': 1, - 'disc_count': 1}, - compose.variants['Server'], - 'src'))] + [ + mock.call( + ( + compose, + { + "iso_path": "%s/compose/Server/x86_64/iso/image-name" + % self.topdir, + "bootable": True, + "cmd": [ + "bash", + self.topdir + + "/work/x86_64/tmp-Server/createiso-image-name.sh", + ], + "label": "", + "disc_num": 1, + "disc_count": 1, + }, + compose.variants["Server"], + "x86_64", + ) + ), + mock.call( + ( + compose, + { + "iso_path": "%s/compose/Server/source/iso/image-name" + % self.topdir, + "bootable": False, + "cmd": [ + "bash", + self.topdir + + "/work/src/tmp-Server/createiso-image-name.sh", + ], + "label": "", + "disc_num": 1, + "disc_count": 1, + }, + compose.variants["Server"], + "src", + ) + ), + ], ) - @mock.patch('pungi.createiso.write_script') - @mock.patch('pungi.phases.createiso.prepare_iso') - @mock.patch('pungi.phases.createiso.split_iso') - @mock.patch('pungi.phases.createiso.ThreadPool') - def test_bootable_but_failed(self, ThreadPool, split_iso, prepare_iso, write_script): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'buildinstall_method': 'lorax', - 'bootable': True, - 'createiso_skip': [] - }) - helpers.touch(os.path.join( - compose.paths.compose.os_tree('x86_64', compose.variants['Server']), - 'dummy.rpm')) - helpers.touch(os.path.join( - compose.paths.compose.os_tree('src', compose.variants['Server']), - 'dummy.rpm')) + @mock.patch("pungi.createiso.write_script") + @mock.patch("pungi.phases.createiso.prepare_iso") + @mock.patch("pungi.phases.createiso.split_iso") + @mock.patch("pungi.phases.createiso.ThreadPool") + def test_bootable_but_failed( + self, ThreadPool, split_iso, prepare_iso, write_script + ): + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "buildinstall_method": "lorax", + "bootable": True, + "createiso_skip": [], + }, + ) + helpers.touch( + os.path.join( + compose.paths.compose.os_tree("x86_64", compose.variants["Server"]), + "dummy.rpm", + ) + ) + helpers.touch( + os.path.join( + compose.paths.compose.os_tree("src", compose.variants["Server"]), + "dummy.rpm", + ) + ) disc_data = mock.Mock() split_iso.return_value = [disc_data] - prepare_iso.return_value = 'dummy-graft-points' + prepare_iso.return_value = "dummy-graft-points" pool = ThreadPool.return_value @@ -241,59 +352,101 @@ class CreateisoPhaseTest(helpers.PungiTestCase): self.assertEqual( prepare_iso.call_args_list, - [mock.call(compose, 'src', compose.variants['Server'], - disc_count=1, disc_num=1, split_iso_data=disc_data)]) + [ + mock.call( + compose, + "src", + compose.variants["Server"], + disc_count=1, + disc_num=1, + split_iso_data=disc_data, + ) + ], + ) self.assertEqual( split_iso.call_args_list, - [mock.call(compose, 'src', compose.variants['Server'], no_split=False, logger=phase.logger)]) + [ + mock.call( + compose, + "src", + compose.variants["Server"], + no_split=False, + logger=phase.logger, + ) + ], + ) self.assertEqual(len(pool.add.call_args_list), 1) self.maxDiff = None self.assertEqual( [x[0][0] for x in write_script.call_args_list], - [CreateIsoOpts(output_dir='%s/compose/Server/source/iso' % self.topdir, - iso_name='image-name', - volid='test-1.0 Server.src', - graft_points='dummy-graft-points', - arch='src', - supported=True, - jigdo_dir='%s/compose/Server/source/jigdo' % self.topdir, - os_tree='%s/compose/Server/source/tree' % self.topdir, - hfs_compat=True)]) + [ + CreateIsoOpts( + output_dir="%s/compose/Server/source/iso" % self.topdir, + iso_name="image-name", + volid="test-1.0 Server.src", + graft_points="dummy-graft-points", + arch="src", + supported=True, + jigdo_dir="%s/compose/Server/source/jigdo" % self.topdir, + os_tree="%s/compose/Server/source/tree" % self.topdir, + hfs_compat=True, + ) + ], + ) self.assertEqual( pool.queue_put.call_args_list, - [mock.call((compose, - {'iso_path': '%s/compose/Server/source/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': ['bash', self.topdir + '/work/src/tmp-Server/createiso-image-name.sh'], - 'label': '', - 'disc_num': 1, - 'disc_count': 1}, - compose.variants['Server'], - 'src'))] + [ + mock.call( + ( + compose, + { + "iso_path": "%s/compose/Server/source/iso/image-name" + % self.topdir, + "bootable": False, + "cmd": [ + "bash", + self.topdir + + "/work/src/tmp-Server/createiso-image-name.sh", + ], + "label": "", + "disc_num": 1, + "disc_count": 1, + }, + compose.variants["Server"], + "src", + ) + ) + ], ) - @mock.patch('pungi.createiso.write_script') - @mock.patch('pungi.phases.createiso.prepare_iso') - @mock.patch('pungi.phases.createiso.split_iso') - @mock.patch('pungi.phases.createiso.ThreadPool') + @mock.patch("pungi.createiso.write_script") + @mock.patch("pungi.phases.createiso.prepare_iso") + @mock.patch("pungi.phases.createiso.split_iso") + @mock.patch("pungi.phases.createiso.ThreadPool") def test_bootable_product_but_not_variant( self, ThreadPool, split_iso, prepare_iso, write_script ): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'buildinstall_method': 'lorax', - 'bootable': True, - 'createiso_skip': [], - 'buildinstall_skip': [('Server', {'*': True})], - "iso_hfs_ppc64le_compatible": False, - }) - helpers.touch(os.path.join( - compose.paths.compose.os_tree('x86_64', compose.variants['Server']), - 'dummy.rpm')) + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "buildinstall_method": "lorax", + "bootable": True, + "createiso_skip": [], + "buildinstall_skip": [("Server", {"*": True})], + "iso_hfs_ppc64le_compatible": False, + }, + ) + helpers.touch( + os.path.join( + compose.paths.compose.os_tree("x86_64", compose.variants["Server"]), + "dummy.rpm", + ) + ) disc_data = mock.Mock() split_iso.return_value = [disc_data] - prepare_iso.return_value = 'dummy-graft-points' + prepare_iso.return_value = "dummy-graft-points" pool = ThreadPool.return_value @@ -306,416 +459,543 @@ class CreateisoPhaseTest(helpers.PungiTestCase): self.maxDiff = None self.assertEqual( prepare_iso.call_args_list, - [mock.call(compose, 'x86_64', compose.variants['Server'], - disc_count=1, disc_num=1, split_iso_data=disc_data)]) + [ + mock.call( + compose, + "x86_64", + compose.variants["Server"], + disc_count=1, + disc_num=1, + split_iso_data=disc_data, + ) + ], + ) self.assertEqual( split_iso.call_args_list, - [mock.call(compose, 'x86_64', compose.variants['Server'], no_split=False, logger=phase.logger)]) + [ + mock.call( + compose, + "x86_64", + compose.variants["Server"], + no_split=False, + logger=phase.logger, + ) + ], + ) self.assertEqual(len(pool.add.call_args_list), 1) self.assertEqual( [x[0][0] for x in write_script.call_args_list], - [CreateIsoOpts(output_dir='%s/compose/Server/x86_64/iso' % self.topdir, - iso_name='image-name', - volid='test-1.0 Server.x86_64', - graft_points='dummy-graft-points', - arch='x86_64', - supported=True, - jigdo_dir='%s/compose/Server/x86_64/jigdo' % self.topdir, - os_tree='%s/compose/Server/x86_64/os' % self.topdir, - hfs_compat=False)]) + [ + CreateIsoOpts( + output_dir="%s/compose/Server/x86_64/iso" % self.topdir, + iso_name="image-name", + volid="test-1.0 Server.x86_64", + graft_points="dummy-graft-points", + arch="x86_64", + supported=True, + jigdo_dir="%s/compose/Server/x86_64/jigdo" % self.topdir, + os_tree="%s/compose/Server/x86_64/os" % self.topdir, + hfs_compat=False, + ) + ], + ) self.assertEqual( pool.queue_put.call_args_list, - [mock.call((compose, - {'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': ['bash', self.topdir + '/work/x86_64/tmp-Server/createiso-image-name.sh'], - 'label': '', - 'disc_num': 1, - 'disc_count': 1}, - compose.variants['Server'], - 'x86_64'))] + [ + mock.call( + ( + compose, + { + "iso_path": "%s/compose/Server/x86_64/iso/image-name" + % self.topdir, + "bootable": False, + "cmd": [ + "bash", + self.topdir + + "/work/x86_64/tmp-Server/createiso-image-name.sh", + ], + "label": "", + "disc_num": 1, + "disc_count": 1, + }, + compose.variants["Server"], + "x86_64", + ) + ) + ], ) class CreateisoThreadTest(helpers.PungiTestCase): - - @mock.patch('pungi.phases.createiso.iso') - @mock.patch('pungi.phases.createiso.get_mtime') - @mock.patch('pungi.phases.createiso.get_file_size') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.createiso.iso") + @mock.patch("pungi.phases.createiso.get_mtime") + @mock.patch("pungi.phases.createiso.get_file_size") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_process_in_runroot(self, KojiWrapper, get_file_size, get_mtime, iso): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'runroot_tag': 'f25-build', - 'koji_profile': 'koji', - }) + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "runroot_tag": "f25-build", + "koji_profile": "koji", + }, + ) cmd = { - 'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': mock.Mock(), - 'label': '', - 'disc_num': 1, - 'disc_count': 1, + "iso_path": "%s/compose/Server/x86_64/iso/image-name" % self.topdir, + "bootable": False, + "cmd": mock.Mock(), + "label": "", + "disc_num": 1, + "disc_count": 1, } get_file_size.return_value = 1024 get_mtime.return_value = 13579 getTag = KojiWrapper.return_value.koji_proxy.getTag - getTag.return_value = {'arches': 'x86_64'} + getTag.return_value = {"arches": "x86_64"} get_runroot_cmd = KojiWrapper.return_value.get_runroot_cmd run_runroot = KojiWrapper.return_value.run_runroot_cmd run_runroot.return_value = { - 'retcode': 0, - 'output': 'whatever', - 'task_id': 1234, + "retcode": 0, + "output": "whatever", + "task_id": 1234, } t = createiso.CreateIsoThread(mock.Mock()) - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Server"], "x86_64"), 1) - self.assertEqual(getTag.call_args_list, [mock.call('f25-build')]) - self.assertEqual(get_runroot_cmd.call_args_list, - [mock.call('f25-build', 'x86_64', cmd['cmd'], channel=None, - mounts=[self.topdir], - packages=['coreutils', 'genisoimage', 'isomd5sum', - 'jigdo'], - use_shell=True, weight=None)]) + self.assertEqual(getTag.call_args_list, [mock.call("f25-build")]) + self.assertEqual( + get_runroot_cmd.call_args_list, + [ + mock.call( + "f25-build", + "x86_64", + cmd["cmd"], + channel=None, + mounts=[self.topdir], + packages=["coreutils", "genisoimage", "isomd5sum", "jigdo"], + use_shell=True, + weight=None, + ) + ], + ) self.assertEqual( run_runroot.call_args_list, - [mock.call(get_runroot_cmd.return_value, - log_file='%s/logs/x86_64/createiso-image-name.x86_64.log' % self.topdir)]) - self.assertEqual(iso.get_implanted_md5.call_args_list, - [mock.call(cmd['iso_path'], logger=compose._logger)]) - self.assertEqual(iso.get_volume_id.call_args_list, - [mock.call(cmd['iso_path'])]) + [ + mock.call( + get_runroot_cmd.return_value, + log_file="%s/logs/x86_64/createiso-image-name.x86_64.log" + % self.topdir, + ) + ], + ) + self.assertEqual( + iso.get_implanted_md5.call_args_list, + [mock.call(cmd["iso_path"], logger=compose._logger)], + ) + self.assertEqual(iso.get_volume_id.call_args_list, [mock.call(cmd["iso_path"])]) self.assertEqual(len(compose.im.add.call_args_list), 1) args, _ = compose.im.add.call_args_list[0] - self.assertEqual(args[0], 'Server') - self.assertEqual(args[1], 'x86_64') + self.assertEqual(args[0], "Server") + self.assertEqual(args[1], "x86_64") image = args[2] - self.assertEqual(image.arch, 'x86_64') - self.assertEqual(image.path, 'Server/x86_64/iso/image-name') - self.assertEqual(image.format, 'iso') - self.assertEqual(image.type, 'dvd') - self.assertEqual(image.subvariant, 'Server') + self.assertEqual(image.arch, "x86_64") + self.assertEqual(image.path, "Server/x86_64/iso/image-name") + self.assertEqual(image.format, "iso") + self.assertEqual(image.type, "dvd") + self.assertEqual(image.subvariant, "Server") - @mock.patch('pungi.phases.createiso.iso') - @mock.patch('pungi.phases.createiso.get_mtime') - @mock.patch('pungi.phases.createiso.get_file_size') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.createiso.iso") + @mock.patch("pungi.phases.createiso.get_mtime") + @mock.patch("pungi.phases.createiso.get_file_size") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_process_source_iso(self, KojiWrapper, get_file_size, get_mtime, iso): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'runroot_tag': 'f25-build', - 'koji_profile': 'koji', - 'create_jigdo': False, - 'runroot_weights': {'createiso': 123}, - }) + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "runroot_tag": "f25-build", + "koji_profile": "koji", + "create_jigdo": False, + "runroot_weights": {"createiso": 123}, + }, + ) cmd = { - 'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': mock.Mock(), - 'label': '', - 'disc_num': 1, - 'disc_count': 1, + "iso_path": "%s/compose/Server/x86_64/iso/image-name" % self.topdir, + "bootable": False, + "cmd": mock.Mock(), + "label": "", + "disc_num": 1, + "disc_count": 1, } get_file_size.return_value = 1024 get_mtime.return_value = 13579 getTag = KojiWrapper.return_value.koji_proxy.getTag - getTag.return_value = {'arches': 'x86_64'} + getTag.return_value = {"arches": "x86_64"} get_runroot_cmd = KojiWrapper.return_value.get_runroot_cmd run_runroot = KojiWrapper.return_value.run_runroot_cmd run_runroot.return_value = { - 'retcode': 0, - 'output': 'whatever', - 'task_id': 1234, + "retcode": 0, + "output": "whatever", + "task_id": 1234, } t = createiso.CreateIsoThread(mock.Mock()) - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Server'], 'src'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Server"], "src"), 1) - self.assertEqual(getTag.call_args_list, [mock.call('f25-build')]) - self.assertEqual(get_runroot_cmd.call_args_list, - [mock.call('f25-build', 'x86_64', cmd['cmd'], channel=None, - mounts=[self.topdir], - packages=['coreutils', 'genisoimage', 'isomd5sum'], - use_shell=True, weight=123)]) + self.assertEqual(getTag.call_args_list, [mock.call("f25-build")]) + self.assertEqual( + get_runroot_cmd.call_args_list, + [ + mock.call( + "f25-build", + "x86_64", + cmd["cmd"], + channel=None, + mounts=[self.topdir], + packages=["coreutils", "genisoimage", "isomd5sum"], + use_shell=True, + weight=123, + ) + ], + ) self.assertEqual( run_runroot.call_args_list, - [mock.call(get_runroot_cmd.return_value, - log_file='%s/logs/src/createiso-image-name.src.log' % self.topdir)]) - self.assertEqual(iso.get_implanted_md5.call_args_list, - [mock.call(cmd['iso_path'], logger=compose._logger)]) - self.assertEqual(iso.get_volume_id.call_args_list, - [mock.call(cmd['iso_path'])]) + [ + mock.call( + get_runroot_cmd.return_value, + log_file="%s/logs/src/createiso-image-name.src.log" % self.topdir, + ) + ], + ) + self.assertEqual( + iso.get_implanted_md5.call_args_list, + [mock.call(cmd["iso_path"], logger=compose._logger)], + ) + self.assertEqual(iso.get_volume_id.call_args_list, [mock.call(cmd["iso_path"])]) self.assertEqual(len(compose.im.add.call_args_list), 2) for args, _ in compose.im.add.call_args_list: - self.assertEqual(args[0], 'Server') - self.assertIn(args[1], ['x86_64', 'amd64']) + self.assertEqual(args[0], "Server") + self.assertIn(args[1], ["x86_64", "amd64"]) image = args[2] - self.assertEqual(image.arch, 'src') - self.assertEqual(image.path, 'Server/x86_64/iso/image-name') - self.assertEqual(image.format, 'iso') - self.assertEqual(image.type, 'dvd') - self.assertEqual(image.subvariant, 'Server') + self.assertEqual(image.arch, "src") + self.assertEqual(image.path, "Server/x86_64/iso/image-name") + self.assertEqual(image.format, "iso") + self.assertEqual(image.type, "dvd") + self.assertEqual(image.subvariant, "Server") - @mock.patch('pungi.phases.createiso.iso') - @mock.patch('pungi.phases.createiso.get_mtime') - @mock.patch('pungi.phases.createiso.get_file_size') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.createiso.iso") + @mock.patch("pungi.phases.createiso.get_mtime") + @mock.patch("pungi.phases.createiso.get_file_size") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_process_bootable(self, KojiWrapper, get_file_size, get_mtime, iso): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'bootable': True, - 'buildinstall_method': 'lorax', - 'runroot_tag': 'f25-build', - 'koji_profile': 'koji', - }) + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "bootable": True, + "buildinstall_method": "lorax", + "runroot_tag": "f25-build", + "koji_profile": "koji", + }, + ) cmd = { - 'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': True, - 'cmd': mock.Mock(), - 'label': '', - 'disc_num': 1, - 'disc_count': 1, + "iso_path": "%s/compose/Server/x86_64/iso/image-name" % self.topdir, + "bootable": True, + "cmd": mock.Mock(), + "label": "", + "disc_num": 1, + "disc_count": 1, } get_file_size.return_value = 1024 get_mtime.return_value = 13579 getTag = KojiWrapper.return_value.koji_proxy.getTag - getTag.return_value = {'arches': 'x86_64'} + getTag.return_value = {"arches": "x86_64"} get_runroot_cmd = KojiWrapper.return_value.get_runroot_cmd run_runroot = KojiWrapper.return_value.run_runroot_cmd run_runroot.return_value = { - 'retcode': 0, - 'output': 'whatever', - 'task_id': 1234, + "retcode": 0, + "output": "whatever", + "task_id": 1234, } t = createiso.CreateIsoThread(mock.Mock()) - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Server"], "x86_64"), 1) # There is no need to call getTag if `bootable` is True. self.assertEqual(getTag.call_args_list, []) - self.assertEqual(get_runroot_cmd.call_args_list, - [mock.call('f25-build', 'x86_64', cmd['cmd'], channel=None, - mounts=[self.topdir], - packages=['coreutils', 'genisoimage', 'isomd5sum', - 'jigdo', 'lorax', 'which'], - use_shell=True, weight=None)]) + self.assertEqual( + get_runroot_cmd.call_args_list, + [ + mock.call( + "f25-build", + "x86_64", + cmd["cmd"], + channel=None, + mounts=[self.topdir], + packages=[ + "coreutils", + "genisoimage", + "isomd5sum", + "jigdo", + "lorax", + "which", + ], + use_shell=True, + weight=None, + ) + ], + ) self.assertEqual( run_runroot.call_args_list, - [mock.call(get_runroot_cmd.return_value, - log_file='%s/logs/x86_64/createiso-image-name.x86_64.log' % self.topdir)]) - self.assertEqual(iso.get_implanted_md5.call_args_list, - [mock.call(cmd['iso_path'], logger=compose._logger)]) - self.assertEqual(iso.get_volume_id.call_args_list, - [mock.call(cmd['iso_path'])]) + [ + mock.call( + get_runroot_cmd.return_value, + log_file="%s/logs/x86_64/createiso-image-name.x86_64.log" + % self.topdir, + ) + ], + ) + self.assertEqual( + iso.get_implanted_md5.call_args_list, + [mock.call(cmd["iso_path"], logger=compose._logger)], + ) + self.assertEqual(iso.get_volume_id.call_args_list, [mock.call(cmd["iso_path"])]) self.assertEqual(len(compose.im.add.call_args_list), 1) args, _ = compose.im.add.call_args_list[0] - self.assertEqual(args[0], 'Server') - self.assertEqual(args[1], 'x86_64') + self.assertEqual(args[0], "Server") + self.assertEqual(args[1], "x86_64") image = args[2] - self.assertEqual(image.arch, 'x86_64') - self.assertEqual(image.path, 'Server/x86_64/iso/image-name') - self.assertEqual(image.format, 'iso') - self.assertEqual(image.type, 'dvd') - self.assertEqual(image.subvariant, 'Server') + self.assertEqual(image.arch, "x86_64") + self.assertEqual(image.path, "Server/x86_64/iso/image-name") + self.assertEqual(image.format, "iso") + self.assertEqual(image.type, "dvd") + self.assertEqual(image.subvariant, "Server") - @mock.patch('pungi.phases.createiso.iso') - @mock.patch('pungi.phases.createiso.get_mtime') - @mock.patch('pungi.phases.createiso.get_file_size') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_process_in_runroot_non_existing_tag(self, KojiWrapper, get_file_size, - get_mtime, iso): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'runroot_tag': 'f25-build', - 'koji_profile': 'koji', - }) + @mock.patch("pungi.phases.createiso.iso") + @mock.patch("pungi.phases.createiso.get_mtime") + @mock.patch("pungi.phases.createiso.get_file_size") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + def test_process_in_runroot_non_existing_tag( + self, KojiWrapper, get_file_size, get_mtime, iso + ): + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "runroot_tag": "f25-build", + "koji_profile": "koji", + }, + ) cmd = { - 'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': mock.Mock(), - 'label': '', - 'disc_num': 1, - 'disc_count': 1, + "iso_path": "%s/compose/Server/x86_64/iso/image-name" % self.topdir, + "bootable": False, + "cmd": mock.Mock(), + "label": "", + "disc_num": 1, + "disc_count": 1, } getTag = KojiWrapper.return_value.koji_proxy.getTag getTag.return_value = None t = createiso.CreateIsoThread(mock.Mock()) with self.assertRaises(RuntimeError) as ctx: - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Server"], "x86_64"), 1) self.assertEqual('Tag "f25-build" does not exist.', str(ctx.exception)) - @mock.patch('pungi.phases.createiso.iso') - @mock.patch('pungi.phases.createiso.get_mtime') - @mock.patch('pungi.phases.createiso.get_file_size') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.createiso.iso") + @mock.patch("pungi.phases.createiso.get_mtime") + @mock.patch("pungi.phases.createiso.get_file_size") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_process_in_runroot_crash(self, KojiWrapper, get_file_size, get_mtime, iso): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'runroot_tag': 'f25-build', - 'koji_profile': 'koji', - 'failable_deliverables': [ - ('^.*$', {'*': 'iso'}) - ] - }) + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "runroot_tag": "f25-build", + "koji_profile": "koji", + "failable_deliverables": [("^.*$", {"*": "iso"})], + }, + ) cmd = { - 'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': mock.Mock(), - 'label': '', - 'disc_num': 1, - 'disc_count': 1, + "iso_path": "%s/compose/Server/x86_64/iso/image-name" % self.topdir, + "bootable": False, + "cmd": mock.Mock(), + "label": "", + "disc_num": 1, + "disc_count": 1, } getTag = KojiWrapper.return_value.koji_proxy.getTag - getTag.return_value = {'arches': 'x86_64'} + getTag.return_value = {"arches": "x86_64"} run_runroot = KojiWrapper.return_value.run_runroot_cmd run_runroot.side_effect = helpers.boom pool = mock.Mock() t = createiso.CreateIsoThread(pool) - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Server"], "x86_64"), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway.'), - mock.call('BOOM') - ]) - - @mock.patch('pungi.phases.createiso.iso') - @mock.patch('pungi.phases.createiso.get_mtime') - @mock.patch('pungi.phases.createiso.get_file_size') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_process_in_runroot_fail(self, KojiWrapper, get_file_size, get_mtime, iso): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'runroot_tag': 'f25-build', - 'koji_profile': 'koji', - 'failable_deliverables': [ - ('^.*$', {'*': 'iso'}) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway." + ), + mock.call("BOOM"), ] - }) + ) + + @mock.patch("pungi.phases.createiso.iso") + @mock.patch("pungi.phases.createiso.get_mtime") + @mock.patch("pungi.phases.createiso.get_file_size") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + def test_process_in_runroot_fail(self, KojiWrapper, get_file_size, get_mtime, iso): + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "runroot_tag": "f25-build", + "koji_profile": "koji", + "failable_deliverables": [("^.*$", {"*": "iso"})], + }, + ) cmd = { - 'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': mock.Mock(), - 'label': '', - 'disc_num': 1, - 'disc_count': 1, + "iso_path": "%s/compose/Server/x86_64/iso/image-name" % self.topdir, + "bootable": False, + "cmd": mock.Mock(), + "label": "", + "disc_num": 1, + "disc_count": 1, } getTag = KojiWrapper.return_value.koji_proxy.getTag - getTag.return_value = {'arches': 'x86_64'} + getTag.return_value = {"arches": "x86_64"} run_runroot = KojiWrapper.return_value.run_runroot_cmd run_runroot.return_value = { - 'retcode': 1, - 'output': 'Nope', - 'task_id': '1234', + "retcode": 1, + "output": "Nope", + "task_id": "1234", } pool = mock.Mock() t = createiso.CreateIsoThread(pool) - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Server"], "x86_64"), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway.'), - mock.call('Runroot task failed: 1234. See %s for more details.' - % (self.topdir + '/logs/x86_64/createiso-image-name.x86_64.log')) - ]) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway." + ), + mock.call( + "Runroot task failed: 1234. See %s for more details." + % (self.topdir + "/logs/x86_64/createiso-image-name.x86_64.log") + ), + ] + ) - @mock.patch('pungi.phases.createiso.iso') - @mock.patch('pungi.phases.createiso.get_mtime') - @mock.patch('pungi.phases.createiso.get_file_size') - @mock.patch('pungi.runroot.run') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.createiso.iso") + @mock.patch("pungi.phases.createiso.get_mtime") + @mock.patch("pungi.phases.createiso.get_file_size") + @mock.patch("pungi.runroot.run") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_process_locally(self, KojiWrapper, run, get_file_size, get_mtime, iso): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - }) + compose = helpers.DummyCompose( + self.topdir, {"release_short": "test", "release_version": "1.0"} + ) cmd = { - 'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': mock.Mock(), - 'label': '', - 'disc_num': 1, - 'disc_count': 1, + "iso_path": "%s/compose/Server/x86_64/iso/image-name" % self.topdir, + "bootable": False, + "cmd": mock.Mock(), + "label": "", + "disc_num": 1, + "disc_count": 1, } get_file_size.return_value = 1024 get_mtime.return_value = 13579 t = createiso.CreateIsoThread(mock.Mock()) - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Server"], "x86_64"), 1) self.assertEqual(KojiWrapper.return_value.mock_calls, []) self.assertEqual( run.call_args_list, - [mock.call(cmd['cmd'], show_cmd=True, - logfile='%s/logs/x86_64/createiso-image-name.x86_64.log' % self.topdir)]) - self.assertEqual(iso.get_implanted_md5.call_args_list, - [mock.call(cmd['iso_path'], logger=compose._logger)]) - self.assertEqual(iso.get_volume_id.call_args_list, - [mock.call(cmd['iso_path'])]) + [ + mock.call( + cmd["cmd"], + show_cmd=True, + logfile="%s/logs/x86_64/createiso-image-name.x86_64.log" + % self.topdir, + ) + ], + ) + self.assertEqual( + iso.get_implanted_md5.call_args_list, + [mock.call(cmd["iso_path"], logger=compose._logger)], + ) + self.assertEqual(iso.get_volume_id.call_args_list, [mock.call(cmd["iso_path"])]) self.assertEqual(len(compose.im.add.call_args_list), 1) args, _ = compose.im.add.call_args_list[0] - self.assertEqual(args[0], 'Server') - self.assertEqual(args[1], 'x86_64') + self.assertEqual(args[0], "Server") + self.assertEqual(args[1], "x86_64") image = args[2] - self.assertEqual(image.arch, 'x86_64') - self.assertEqual(image.path, 'Server/x86_64/iso/image-name') - self.assertEqual(image.format, 'iso') - self.assertEqual(image.type, 'dvd') - self.assertEqual(image.subvariant, 'Server') + self.assertEqual(image.arch, "x86_64") + self.assertEqual(image.path, "Server/x86_64/iso/image-name") + self.assertEqual(image.format, "iso") + self.assertEqual(image.type, "dvd") + self.assertEqual(image.subvariant, "Server") - @mock.patch('pungi.runroot.run') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.runroot.run") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_process_locally_crash(self, KojiWrapper, run): - compose = helpers.DummyCompose(self.topdir, { - 'release_short': 'test', - 'release_version': '1.0', - 'failable_deliverables': [ - ('^.*$', {'*': 'iso'}) - ] - }) + compose = helpers.DummyCompose( + self.topdir, + { + "release_short": "test", + "release_version": "1.0", + "failable_deliverables": [("^.*$", {"*": "iso"})], + }, + ) cmd = { - 'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir, - 'bootable': False, - 'cmd': mock.Mock(), - 'label': '', - 'disc_num': 1, - 'disc_count': 1, + "iso_path": "%s/compose/Server/x86_64/iso/image-name" % self.topdir, + "bootable": False, + "cmd": mock.Mock(), + "label": "", + "disc_num": 1, + "disc_count": 1, } run.side_effect = helpers.boom pool = mock.Mock() t = createiso.CreateIsoThread(pool) - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Server"], "x86_64"), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway.'), - mock.call('BOOM') - ]) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway." + ), + mock.call("BOOM"), + ] + ) -TREEINFO = ''' +TREEINFO = """ [header] version = 1.0 @@ -735,7 +1015,7 @@ id = Server uid = Server name = Server type = variant -''' +""" class DummySize(object): @@ -744,6 +1024,7 @@ class DummySize(object): predefined sizes. The argument to __init__ should be a mapping from substring of filepath to size. """ + def __init__(self, sizes): self.sizes = sizes @@ -757,144 +1038,240 @@ class DummySize(object): class SplitIsoTest(helpers.PungiTestCase): def test_split_fits_on_single_disc(self): compose = helpers.DummyCompose(self.topdir, {}) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/.treeinfo'), - TREEINFO) - helpers.touch(os.path.join(self.topdir, 'work/x86_64/Server/extra-files/GPL')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/GPL')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/repodata/repomd.xml')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/b/bash.rpm')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/n/media.repo')) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/.treeinfo"), TREEINFO + ) + helpers.touch(os.path.join(self.topdir, "work/x86_64/Server/extra-files/GPL")) + helpers.touch(os.path.join(self.topdir, "compose/Server/x86_64/os/GPL")) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/repodata/repomd.xml") + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/Packages/b/bash.rpm") + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/n/media.repo") + ) - with mock.patch('os.path.getsize', - DummySize({'GPL': 20 * 2048, 'bash': 150 * 2048, - 'media': 100 * 2048, 'treeinfo': 10 * 2048})): - data = createiso.split_iso(compose, 'x86_64', compose.variants['Server']) + with mock.patch( + "os.path.getsize", + DummySize( + { + "GPL": 20 * 2048, + "bash": 150 * 2048, + "media": 100 * 2048, + "treeinfo": 10 * 2048, + } + ), + ): + data = createiso.split_iso(compose, "x86_64", compose.variants["Server"]) - base_path = os.path.join(self.topdir, 'compose/Server/x86_64/os') + base_path = os.path.join(self.topdir, "compose/Server/x86_64/os") # GPL is sticky file, it should be first at all times. Files are # searched top-down, so nested ones are after top level ones. - self.assertEqual(data, - [{'files': [os.path.join(base_path, 'GPL'), - os.path.join(base_path, '.treeinfo'), - os.path.join(base_path, 'n/media.repo'), - os.path.join(base_path, 'Packages/b/bash.rpm')], - 'size': 573440}]) + self.assertEqual( + data, + [ + { + "files": [ + os.path.join(base_path, "GPL"), + os.path.join(base_path, ".treeinfo"), + os.path.join(base_path, "n/media.repo"), + os.path.join(base_path, "Packages/b/bash.rpm"), + ], + "size": 573440, + } + ], + ) def test_split_needs_two_discs(self): compose = helpers.DummyCompose(self.topdir, {}) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/.treeinfo'), - TREEINFO) - helpers.touch(os.path.join(self.topdir, 'work/x86_64/Server/extra-files/GPL')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/GPL')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/repodata/repomd.xml')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/b/bash.rpm')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/n/media.repo')) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/.treeinfo"), TREEINFO + ) + helpers.touch(os.path.join(self.topdir, "work/x86_64/Server/extra-files/GPL")) + helpers.touch(os.path.join(self.topdir, "compose/Server/x86_64/os/GPL")) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/repodata/repomd.xml") + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/Packages/b/bash.rpm") + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/n/media.repo") + ) M = 1024 ** 2 G = 1024 ** 3 - with mock.patch('os.path.getsize', - DummySize({'GPL': 20 * M, 'bash': 3 * G, - 'media': 2 * G, 'treeinfo': 10 * M})): - data = createiso.split_iso(compose, 'x86_64', compose.variants['Server']) + with mock.patch( + "os.path.getsize", + DummySize( + {"GPL": 20 * M, "bash": 3 * G, "media": 2 * G, "treeinfo": 10 * M} + ), + ): + data = createiso.split_iso(compose, "x86_64", compose.variants["Server"]) - base_path = os.path.join(self.topdir, 'compose/Server/x86_64/os') + base_path = os.path.join(self.topdir, "compose/Server/x86_64/os") # GPL is the only sticky file, it should be first at all times. # Files are searched top-down, so nested ones are after top level ones. - self.assertEqual(data, - [{'files': [os.path.join(base_path, 'GPL'), - os.path.join(base_path, '.treeinfo'), - os.path.join(base_path, 'n/media.repo')], - 'size': 2178940928}, - {'files': [os.path.join(base_path, 'GPL'), - os.path.join(base_path, 'Packages/b/bash.rpm')], - 'size': 3242196992}]) + self.assertEqual( + data, + [ + { + "files": [ + os.path.join(base_path, "GPL"), + os.path.join(base_path, ".treeinfo"), + os.path.join(base_path, "n/media.repo"), + ], + "size": 2178940928, + }, + { + "files": [ + os.path.join(base_path, "GPL"), + os.path.join(base_path, "Packages/b/bash.rpm"), + ], + "size": 3242196992, + }, + ], + ) def test_no_split_when_requested(self): compose = helpers.DummyCompose(self.topdir, {}) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/.treeinfo'), - TREEINFO) - helpers.touch(os.path.join(self.topdir, 'work/x86_64/Server/extra-files/GPL')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/GPL')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/repodata/repomd.xml')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/b/bash.rpm')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/n/media.repo')) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/.treeinfo"), TREEINFO + ) + helpers.touch(os.path.join(self.topdir, "work/x86_64/Server/extra-files/GPL")) + helpers.touch(os.path.join(self.topdir, "compose/Server/x86_64/os/GPL")) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/repodata/repomd.xml") + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/Packages/b/bash.rpm") + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/n/media.repo") + ) M = 1024 ** 2 G = 1024 ** 3 - with mock.patch('os.path.getsize', - DummySize({'GPL': 20 * M, 'bash': 3 * G, - 'media': 2 * G, 'treeinfo': 10 * M})): - data = createiso.split_iso(compose, 'x86_64', compose.variants['Server'], no_split=True) + with mock.patch( + "os.path.getsize", + DummySize( + {"GPL": 20 * M, "bash": 3 * G, "media": 2 * G, "treeinfo": 10 * M} + ), + ): + data = createiso.split_iso( + compose, "x86_64", compose.variants["Server"], no_split=True + ) - base_path = os.path.join(self.topdir, 'compose/Server/x86_64/os') + base_path = os.path.join(self.topdir, "compose/Server/x86_64/os") # GPL is the only sticky file, it should be first at all times. # Files are searched top-down, so nested ones are after top level ones. - self.assertEqual(data, - [{'files': [os.path.join(base_path, 'GPL'), - os.path.join(base_path, '.treeinfo'), - os.path.join(base_path, 'n/media.repo'), - os.path.join(base_path, 'Packages/b/bash.rpm')], - 'size': 5400166400}]) + self.assertEqual( + data, + [ + { + "files": [ + os.path.join(base_path, "GPL"), + os.path.join(base_path, ".treeinfo"), + os.path.join(base_path, "n/media.repo"), + os.path.join(base_path, "Packages/b/bash.rpm"), + ], + "size": 5400166400, + } + ], + ) self.assertEqual( compose._logger.warning.call_args_list, - [mock.call('ISO for Server.x86_64 does not fit on single media! ' - 'It is 710652160 bytes too big. (Total size: 5400166400 B)')] + [ + mock.call( + "ISO for Server.x86_64 does not fit on single media! " + "It is 710652160 bytes too big. (Total size: 5400166400 B)" + ) + ], ) def test_keeps_reserve(self): compose = helpers.DummyCompose(self.topdir, {}) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/.treeinfo'), - TREEINFO) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/spacer.rpm')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/x/pad.rpm')) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/.treeinfo"), TREEINFO + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/Packages/spacer.rpm") + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/Packages/x/pad.rpm") + ) M = 1024 ** 2 # treeinfo has size 0, spacer leaves 11M of free space, so with 10M # reserve the padding package should be on second disk - with mock.patch('os.path.getsize', DummySize({'spacer': 4688465664, 'pad': 5 * M})): - data = createiso.split_iso(compose, 'x86_64', compose.variants['Server']) + with mock.patch( + "os.path.getsize", DummySize({"spacer": 4688465664, "pad": 5 * M}) + ): + data = createiso.split_iso(compose, "x86_64", compose.variants["Server"]) - base_path = os.path.join(self.topdir, 'compose/Server/x86_64/os') + base_path = os.path.join(self.topdir, "compose/Server/x86_64/os") self.assertEqual(len(data), 2) - self.assertEqual(data[0]['files'], [os.path.join(base_path, '.treeinfo'), - os.path.join(base_path, 'Packages/spacer.rpm')]) - self.assertEqual(data[1]['files'], [os.path.join(base_path, 'Packages/x/pad.rpm')]) + self.assertEqual( + data[0]["files"], + [ + os.path.join(base_path, ".treeinfo"), + os.path.join(base_path, "Packages/spacer.rpm"), + ], + ) + self.assertEqual( + data[1]["files"], [os.path.join(base_path, "Packages/x/pad.rpm")] + ) def test_can_customize_reserve(self): - compose = helpers.DummyCompose(self.topdir, {'split_iso_reserve': 1024 ** 2}) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/.treeinfo'), - TREEINFO) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/spacer.rpm')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/x/pad.rpm')) + compose = helpers.DummyCompose(self.topdir, {"split_iso_reserve": 1024 ** 2}) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/.treeinfo"), TREEINFO + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/Packages/spacer.rpm") + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/Packages/x/pad.rpm") + ) M = 1024 ** 2 - with mock.patch('os.path.getsize', DummySize({'spacer': 4688465664, 'pad': 5 * M})): - data = createiso.split_iso(compose, 'x86_64', compose.variants['Server']) + with mock.patch( + "os.path.getsize", DummySize({"spacer": 4688465664, "pad": 5 * M}) + ): + data = createiso.split_iso(compose, "x86_64", compose.variants["Server"]) self.assertEqual(len(data), 1) def test_can_change_iso_size(self): - compose = helpers.DummyCompose(self.topdir, {'iso_size': '8G'}) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/.treeinfo'), - TREEINFO) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/spacer.rpm')) - helpers.touch(os.path.join(self.topdir, 'compose/Server/x86_64/os/Packages/x/pad.rpm')) + compose = helpers.DummyCompose(self.topdir, {"iso_size": "8G"}) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/.treeinfo"), TREEINFO + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/Packages/spacer.rpm") + ) + helpers.touch( + os.path.join(self.topdir, "compose/Server/x86_64/os/Packages/x/pad.rpm") + ) M = 1024 ** 2 - with mock.patch('os.path.getsize', DummySize({'spacer': 4688465664, 'pad': 5 * M})): - data = createiso.split_iso(compose, 'x86_64', compose.variants['Server']) + with mock.patch( + "os.path.getsize", DummySize({"spacer": 4688465664, "pad": 5 * M}) + ): + data = createiso.split_iso(compose, "x86_64", compose.variants["Server"]) self.assertEqual(len(data), 1) class BreakHardlinksTest(helpers.PungiTestCase): - def setUp(self): super(BreakHardlinksTest, self).setUp() self.src = os.path.join(self.topdir, "src") diff --git a/tests/test_createiso_script.py b/tests/test_createiso_script.py index b9bfc409..caad3229 100644 --- a/tests/test_createiso_script.py +++ b/tests/test_createiso_script.py @@ -11,206 +11,384 @@ from pungi import createiso class CreateIsoScriptTest(helpers.PungiTestCase): - def setUp(self): super(CreateIsoScriptTest, self).setUp() - self.outdir = os.path.join(self.topdir, 'isos') + self.outdir = os.path.join(self.topdir, "isos") self.out = StringIO() self.maxDiff = None def assertScript(self, cmds): - script = self.out.getvalue().strip().split('\n') - self.assertEqual(script[:3], - ['#!/bin/bash', - 'set -ex', - 'cd %s' % self.outdir]) + script = self.out.getvalue().strip().split("\n") + self.assertEqual(script[:3], ["#!/bin/bash", "set -ex", "cd %s" % self.outdir]) self.assertEqual(script[3:], cmds) def test_minimal_run(self): - createiso.write_script(createiso.CreateIsoOpts( - output_dir=self.outdir, - iso_name='DP-1.0-20160405.t.3-x86_64.iso', - volid='DP-1.0-20160405.t.3', - graft_points='graft-list', - arch='x86_64', - ), self.out) + createiso.write_script( + createiso.CreateIsoOpts( + output_dir=self.outdir, + iso_name="DP-1.0-20160405.t.3-x86_64.iso", + volid="DP-1.0-20160405.t.3", + graft_points="graft-list", + arch="x86_64", + ), + self.out, + ) self.assertScript( - [' '.join(['/usr/bin/genisoimage', '-untranslated-filenames', - '-volid', 'DP-1.0-20160405.t.3', '-J', '-joliet-long', - '-rational-rock', '-translation-table', - '-input-charset', 'utf-8', '-x', './lost+found', - '-o', 'DP-1.0-20160405.t.3-x86_64.iso', - '-graft-points', '-path-list', 'graft-list']), - ' '.join(['/usr/bin/implantisomd5', 'DP-1.0-20160405.t.3-x86_64.iso']), - 'isoinfo -R -f -i DP-1.0-20160405.t.3-x86_64.iso | grep -v \'/TRANS.TBL$\' | sort >> DP-1.0-20160405.t.3-x86_64.iso.manifest'] + [ + " ".join( + [ + "/usr/bin/genisoimage", + "-untranslated-filenames", + "-volid", + "DP-1.0-20160405.t.3", + "-J", + "-joliet-long", + "-rational-rock", + "-translation-table", + "-input-charset", + "utf-8", + "-x", + "./lost+found", + "-o", + "DP-1.0-20160405.t.3-x86_64.iso", + "-graft-points", + "-path-list", + "graft-list", + ] + ), + " ".join(["/usr/bin/implantisomd5", "DP-1.0-20160405.t.3-x86_64.iso"]), + "isoinfo -R -f -i DP-1.0-20160405.t.3-x86_64.iso | grep -v '/TRANS.TBL$' | sort >> DP-1.0-20160405.t.3-x86_64.iso.manifest", + ] ) def test_bootable_run(self): - createiso.write_script(createiso.CreateIsoOpts( - output_dir=self.outdir, - iso_name='DP-1.0-20160405.t.3-x86_64.iso', - volid='DP-1.0-20160405.t.3', - graft_points='graft-list', - arch='x86_64', - buildinstall_method='lorax', - ), self.out) + createiso.write_script( + createiso.CreateIsoOpts( + output_dir=self.outdir, + iso_name="DP-1.0-20160405.t.3-x86_64.iso", + volid="DP-1.0-20160405.t.3", + graft_points="graft-list", + arch="x86_64", + buildinstall_method="lorax", + ), + self.out, + ) self.assertScript( - [createiso.FIND_TEMPLATE_SNIPPET, - ' '.join(['/usr/bin/genisoimage', '-untranslated-filenames', - '-volid', 'DP-1.0-20160405.t.3', '-J', '-joliet-long', - '-rational-rock', '-translation-table', - '-input-charset', 'utf-8', '-x', './lost+found', - '-b', 'isolinux/isolinux.bin', '-c', 'isolinux/boot.cat', - '-no-emul-boot', - '-boot-load-size', '4', '-boot-info-table', - '-eltorito-alt-boot', '-e', 'images/efiboot.img', - '-no-emul-boot', - '-o', 'DP-1.0-20160405.t.3-x86_64.iso', - '-graft-points', '-path-list', 'graft-list']), - ' '.join(['/usr/bin/isohybrid', '--uefi', 'DP-1.0-20160405.t.3-x86_64.iso']), - ' '.join(['/usr/bin/implantisomd5', 'DP-1.0-20160405.t.3-x86_64.iso']), - 'isoinfo -R -f -i DP-1.0-20160405.t.3-x86_64.iso | grep -v \'/TRANS.TBL$\' | sort >> DP-1.0-20160405.t.3-x86_64.iso.manifest'] + [ + createiso.FIND_TEMPLATE_SNIPPET, + " ".join( + [ + "/usr/bin/genisoimage", + "-untranslated-filenames", + "-volid", + "DP-1.0-20160405.t.3", + "-J", + "-joliet-long", + "-rational-rock", + "-translation-table", + "-input-charset", + "utf-8", + "-x", + "./lost+found", + "-b", + "isolinux/isolinux.bin", + "-c", + "isolinux/boot.cat", + "-no-emul-boot", + "-boot-load-size", + "4", + "-boot-info-table", + "-eltorito-alt-boot", + "-e", + "images/efiboot.img", + "-no-emul-boot", + "-o", + "DP-1.0-20160405.t.3-x86_64.iso", + "-graft-points", + "-path-list", + "graft-list", + ] + ), + " ".join( + ["/usr/bin/isohybrid", "--uefi", "DP-1.0-20160405.t.3-x86_64.iso"] + ), + " ".join(["/usr/bin/implantisomd5", "DP-1.0-20160405.t.3-x86_64.iso"]), + "isoinfo -R -f -i DP-1.0-20160405.t.3-x86_64.iso | grep -v '/TRANS.TBL$' | sort >> DP-1.0-20160405.t.3-x86_64.iso.manifest", + ] ) def test_bootable_run_on_i386(self): # This will call isohybrid, but not with --uefi switch - createiso.write_script(createiso.CreateIsoOpts( - output_dir=self.outdir, - iso_name='DP-1.0-20160405.t.3-i386.iso', - volid='DP-1.0-20160405.t.3', - graft_points='graft-list', - arch='i386', - buildinstall_method='lorax', - ), self.out) + createiso.write_script( + createiso.CreateIsoOpts( + output_dir=self.outdir, + iso_name="DP-1.0-20160405.t.3-i386.iso", + volid="DP-1.0-20160405.t.3", + graft_points="graft-list", + arch="i386", + buildinstall_method="lorax", + ), + self.out, + ) self.assertScript( - [createiso.FIND_TEMPLATE_SNIPPET, - ' '.join(['/usr/bin/genisoimage', '-untranslated-filenames', - '-volid', 'DP-1.0-20160405.t.3', '-J', '-joliet-long', - '-rational-rock', '-translation-table', - '-input-charset', 'utf-8', '-x', './lost+found', - '-b', 'isolinux/isolinux.bin', '-c', 'isolinux/boot.cat', - '-no-emul-boot', - '-boot-load-size', '4', '-boot-info-table', - '-o', 'DP-1.0-20160405.t.3-i386.iso', - '-graft-points', '-path-list', 'graft-list']), - ' '.join(['/usr/bin/isohybrid', 'DP-1.0-20160405.t.3-i386.iso']), - ' '.join(['/usr/bin/implantisomd5', 'DP-1.0-20160405.t.3-i386.iso']), - 'isoinfo -R -f -i DP-1.0-20160405.t.3-i386.iso | grep -v \'/TRANS.TBL$\' | sort >> DP-1.0-20160405.t.3-i386.iso.manifest'] + [ + createiso.FIND_TEMPLATE_SNIPPET, + " ".join( + [ + "/usr/bin/genisoimage", + "-untranslated-filenames", + "-volid", + "DP-1.0-20160405.t.3", + "-J", + "-joliet-long", + "-rational-rock", + "-translation-table", + "-input-charset", + "utf-8", + "-x", + "./lost+found", + "-b", + "isolinux/isolinux.bin", + "-c", + "isolinux/boot.cat", + "-no-emul-boot", + "-boot-load-size", + "4", + "-boot-info-table", + "-o", + "DP-1.0-20160405.t.3-i386.iso", + "-graft-points", + "-path-list", + "graft-list", + ] + ), + " ".join(["/usr/bin/isohybrid", "DP-1.0-20160405.t.3-i386.iso"]), + " ".join(["/usr/bin/implantisomd5", "DP-1.0-20160405.t.3-i386.iso"]), + "isoinfo -R -f -i DP-1.0-20160405.t.3-i386.iso | grep -v '/TRANS.TBL$' | sort >> DP-1.0-20160405.t.3-i386.iso.manifest", + ] ) def test_bootable_run_ppc64(self): - createiso.write_script(createiso.CreateIsoOpts( - output_dir=self.outdir, - iso_name='DP-1.0-20160405.t.3-ppc64.iso', - volid='DP-1.0-20160405.t.3', - graft_points='graft-list', - arch='ppc64', - buildinstall_method='lorax', - ), self.out) + createiso.write_script( + createiso.CreateIsoOpts( + output_dir=self.outdir, + iso_name="DP-1.0-20160405.t.3-ppc64.iso", + volid="DP-1.0-20160405.t.3", + graft_points="graft-list", + arch="ppc64", + buildinstall_method="lorax", + ), + self.out, + ) self.assertScript( - [createiso.FIND_TEMPLATE_SNIPPET, - ' '.join(['/usr/bin/genisoimage', '-untranslated-filenames', - '-volid', 'DP-1.0-20160405.t.3', '-J', '-joliet-long', - '-rational-rock', '-translation-table', - '-x', './lost+found', - '-part', '-hfs', '-r', '-l', '-sysid', 'PPC', '-no-desktop', - '-allow-multidot', '-chrp-boot', '-map', '$TEMPLATE/config_files/ppc/mapping', - '-hfs-bless', '/ppc/mac', - '-o', 'DP-1.0-20160405.t.3-ppc64.iso', - '-graft-points', '-path-list', 'graft-list']), - ' '.join(['/usr/bin/implantisomd5', 'DP-1.0-20160405.t.3-ppc64.iso']), - 'isoinfo -R -f -i DP-1.0-20160405.t.3-ppc64.iso | grep -v \'/TRANS.TBL$\' | sort >> DP-1.0-20160405.t.3-ppc64.iso.manifest'] + [ + createiso.FIND_TEMPLATE_SNIPPET, + " ".join( + [ + "/usr/bin/genisoimage", + "-untranslated-filenames", + "-volid", + "DP-1.0-20160405.t.3", + "-J", + "-joliet-long", + "-rational-rock", + "-translation-table", + "-x", + "./lost+found", + "-part", + "-hfs", + "-r", + "-l", + "-sysid", + "PPC", + "-no-desktop", + "-allow-multidot", + "-chrp-boot", + "-map", + "$TEMPLATE/config_files/ppc/mapping", + "-hfs-bless", + "/ppc/mac", + "-o", + "DP-1.0-20160405.t.3-ppc64.iso", + "-graft-points", + "-path-list", + "graft-list", + ] + ), + " ".join(["/usr/bin/implantisomd5", "DP-1.0-20160405.t.3-ppc64.iso"]), + "isoinfo -R -f -i DP-1.0-20160405.t.3-ppc64.iso | grep -v '/TRANS.TBL$' | sort >> DP-1.0-20160405.t.3-ppc64.iso.manifest", + ] ) def test_bootable_run_on_s390x(self): - createiso.write_script(createiso.CreateIsoOpts( - output_dir=self.outdir, - iso_name='DP-1.0-20160405.t.3-s390x.iso', - volid='DP-1.0-20160405.t.3', - graft_points='graft-list', - arch='s390x', - buildinstall_method='lorax', - ), self.out) + createiso.write_script( + createiso.CreateIsoOpts( + output_dir=self.outdir, + iso_name="DP-1.0-20160405.t.3-s390x.iso", + volid="DP-1.0-20160405.t.3", + graft_points="graft-list", + arch="s390x", + buildinstall_method="lorax", + ), + self.out, + ) self.assertScript( - [createiso.FIND_TEMPLATE_SNIPPET, - ' '.join(['/usr/bin/genisoimage', '-untranslated-filenames', - '-volid', 'DP-1.0-20160405.t.3', '-J', '-joliet-long', - '-rational-rock', '-translation-table', - '-input-charset', 'utf-8', - '-x', './lost+found', - '-eltorito-boot images/cdboot.img', '-no-emul-boot', - '-o', 'DP-1.0-20160405.t.3-s390x.iso', - '-graft-points', '-path-list', 'graft-list']), - ' '.join(['/usr/bin/implantisomd5', 'DP-1.0-20160405.t.3-s390x.iso']), - 'isoinfo -R -f -i DP-1.0-20160405.t.3-s390x.iso | grep -v \'/TRANS.TBL$\' | sort >> DP-1.0-20160405.t.3-s390x.iso.manifest'] + [ + createiso.FIND_TEMPLATE_SNIPPET, + " ".join( + [ + "/usr/bin/genisoimage", + "-untranslated-filenames", + "-volid", + "DP-1.0-20160405.t.3", + "-J", + "-joliet-long", + "-rational-rock", + "-translation-table", + "-input-charset", + "utf-8", + "-x", + "./lost+found", + "-eltorito-boot images/cdboot.img", + "-no-emul-boot", + "-o", + "DP-1.0-20160405.t.3-s390x.iso", + "-graft-points", + "-path-list", + "graft-list", + ] + ), + " ".join(["/usr/bin/implantisomd5", "DP-1.0-20160405.t.3-s390x.iso"]), + "isoinfo -R -f -i DP-1.0-20160405.t.3-s390x.iso | grep -v '/TRANS.TBL$' | sort >> DP-1.0-20160405.t.3-s390x.iso.manifest", + ] ) def test_bootable_run_buildinstall(self): - createiso.write_script(createiso.CreateIsoOpts( - output_dir=self.outdir, - iso_name='DP-1.0-20160405.t.3-ppc64.iso', - volid='DP-1.0-20160405.t.3', - graft_points='graft-list', - arch='ppc64', - buildinstall_method='buildinstall', - ), self.out) - - self.assertScript( - [' '.join(['/usr/bin/genisoimage', '-untranslated-filenames', - '-volid', 'DP-1.0-20160405.t.3', '-J', '-joliet-long', - '-rational-rock', '-translation-table', - '-x', './lost+found', - '-part', '-hfs', '-r', '-l', '-sysid', 'PPC', '-no-desktop', - '-allow-multidot', '-chrp-boot', - '-map', '/usr/lib/anaconda-runtime/boot/mapping', - '-hfs-bless', '/ppc/mac', - '-o', 'DP-1.0-20160405.t.3-ppc64.iso', - '-graft-points', '-path-list', 'graft-list']), - ' '.join(['/usr/bin/implantisomd5', 'DP-1.0-20160405.t.3-ppc64.iso']), - 'isoinfo -R -f -i DP-1.0-20160405.t.3-ppc64.iso | grep -v \'/TRANS.TBL$\' | sort >> DP-1.0-20160405.t.3-ppc64.iso.manifest'] + createiso.write_script( + createiso.CreateIsoOpts( + output_dir=self.outdir, + iso_name="DP-1.0-20160405.t.3-ppc64.iso", + volid="DP-1.0-20160405.t.3", + graft_points="graft-list", + arch="ppc64", + buildinstall_method="buildinstall", + ), + self.out, ) - @mock.patch('sys.stderr') - @mock.patch('kobo.shortcuts.run') + self.assertScript( + [ + " ".join( + [ + "/usr/bin/genisoimage", + "-untranslated-filenames", + "-volid", + "DP-1.0-20160405.t.3", + "-J", + "-joliet-long", + "-rational-rock", + "-translation-table", + "-x", + "./lost+found", + "-part", + "-hfs", + "-r", + "-l", + "-sysid", + "PPC", + "-no-desktop", + "-allow-multidot", + "-chrp-boot", + "-map", + "/usr/lib/anaconda-runtime/boot/mapping", + "-hfs-bless", + "/ppc/mac", + "-o", + "DP-1.0-20160405.t.3-ppc64.iso", + "-graft-points", + "-path-list", + "graft-list", + ] + ), + " ".join(["/usr/bin/implantisomd5", "DP-1.0-20160405.t.3-ppc64.iso"]), + "isoinfo -R -f -i DP-1.0-20160405.t.3-ppc64.iso | grep -v '/TRANS.TBL$' | sort >> DP-1.0-20160405.t.3-ppc64.iso.manifest", + ] + ) + + @mock.patch("sys.stderr") + @mock.patch("kobo.shortcuts.run") def test_run_with_jigdo_bad_args(self, run, stderr): with self.assertRaises(RuntimeError): - createiso.write_script(createiso.CreateIsoOpts( - output_dir=self.outdir, - iso_name='DP-1.0-20160405.t.3-x86_64.iso', - volid='DP-1.0-20160405.t.3', - graft_points='graft-list', - arch='x86_64', - jigdo_dir='%s/jigdo' % self.topdir, - ), self.out) + createiso.write_script( + createiso.CreateIsoOpts( + output_dir=self.outdir, + iso_name="DP-1.0-20160405.t.3-x86_64.iso", + volid="DP-1.0-20160405.t.3", + graft_points="graft-list", + arch="x86_64", + jigdo_dir="%s/jigdo" % self.topdir, + ), + self.out, + ) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_run_with_jigdo(self, run): - createiso.write_script(createiso.CreateIsoOpts( - output_dir=self.outdir, - iso_name='DP-1.0-20160405.t.3-x86_64.iso', - volid='DP-1.0-20160405.t.3', - graft_points='graft-list', - arch='x86_64', - jigdo_dir='%s/jigdo' % self.topdir, - os_tree='%s/os' % self.topdir, - ), self.out) + createiso.write_script( + createiso.CreateIsoOpts( + output_dir=self.outdir, + iso_name="DP-1.0-20160405.t.3-x86_64.iso", + volid="DP-1.0-20160405.t.3", + graft_points="graft-list", + arch="x86_64", + jigdo_dir="%s/jigdo" % self.topdir, + os_tree="%s/os" % self.topdir, + ), + self.out, + ) self.assertScript( - [' '.join(['/usr/bin/genisoimage', '-untranslated-filenames', - '-volid', 'DP-1.0-20160405.t.3', '-J', '-joliet-long', - '-rational-rock', '-translation-table', - '-input-charset', 'utf-8', '-x', './lost+found', - '-o', 'DP-1.0-20160405.t.3-x86_64.iso', - '-graft-points', '-path-list', 'graft-list']), - ' '.join(['/usr/bin/implantisomd5', 'DP-1.0-20160405.t.3-x86_64.iso']), - 'isoinfo -R -f -i DP-1.0-20160405.t.3-x86_64.iso | grep -v \'/TRANS.TBL$\' | sort >> DP-1.0-20160405.t.3-x86_64.iso.manifest', - ' '.join(['jigdo-file', 'make-template', '--force', - '--image=%s/isos/DP-1.0-20160405.t.3-x86_64.iso' % self.topdir, - '--jigdo=%s/jigdo/DP-1.0-20160405.t.3-x86_64.iso.jigdo' % self.topdir, - '--template=%s/jigdo/DP-1.0-20160405.t.3-x86_64.iso.template' % self.topdir, - '--no-servers-section', '--report=noprogress', self.topdir + '/os//'])] + [ + " ".join( + [ + "/usr/bin/genisoimage", + "-untranslated-filenames", + "-volid", + "DP-1.0-20160405.t.3", + "-J", + "-joliet-long", + "-rational-rock", + "-translation-table", + "-input-charset", + "utf-8", + "-x", + "./lost+found", + "-o", + "DP-1.0-20160405.t.3-x86_64.iso", + "-graft-points", + "-path-list", + "graft-list", + ] + ), + " ".join(["/usr/bin/implantisomd5", "DP-1.0-20160405.t.3-x86_64.iso"]), + "isoinfo -R -f -i DP-1.0-20160405.t.3-x86_64.iso | grep -v '/TRANS.TBL$' | sort >> DP-1.0-20160405.t.3-x86_64.iso.manifest", + " ".join( + [ + "jigdo-file", + "make-template", + "--force", + "--image=%s/isos/DP-1.0-20160405.t.3-x86_64.iso" % self.topdir, + "--jigdo=%s/jigdo/DP-1.0-20160405.t.3-x86_64.iso.jigdo" + % self.topdir, + "--template=%s/jigdo/DP-1.0-20160405.t.3-x86_64.iso.template" + % self.topdir, + "--no-servers-section", + "--report=noprogress", + self.topdir + "/os//", + ] + ), + ] ) diff --git a/tests/test_createrepo_wrapper.py b/tests/test_createrepo_wrapper.py index 27de37fc..b9015b5a 100644 --- a/tests/test_createrepo_wrapper.py +++ b/tests/test_createrepo_wrapper.py @@ -14,12 +14,11 @@ from pungi.wrappers.createrepo import CreaterepoWrapper class CreateRepoWrapperTest(unittest.TestCase): - def test_get_createrepo_c_cmd_minimal(self): repo = CreaterepoWrapper() - cmd = repo.get_createrepo_cmd('/test/dir') + cmd = repo.get_createrepo_cmd("/test/dir") - self.assertEqual(cmd[:2], ['createrepo_c', '/test/dir']) + self.assertEqual(cmd[:2], ["createrepo_c", "/test/dir"]) six.assertCountEqual( self, cmd[2:], ["--update", "--database", "--unique-md-filenames"] ) @@ -27,35 +26,75 @@ class CreateRepoWrapperTest(unittest.TestCase): def test_get_createrepo_c_cmd_full(self): repo = CreaterepoWrapper() cmd = repo.get_createrepo_cmd( - '/test/dir', baseurl='http://base.example.com', excludes=['abc', 'xyz'], - pkglist='/test/pkglist', groupfile='/test/comps', cachedir='/test/cache', - update=False, update_md_path='/test/md_path', skip_stat=True, checkts=True, - split=True, pretty=False, database=False, checksum='sha256', unique_md_filenames=False, - distro='Fedora', content=['c1', 'c2'], repo=['r1', 'r2'], revision='rev', deltas=True, - oldpackagedirs='/test/old', num_deltas=2, workers=3, outputdir='/test/output', + "/test/dir", + baseurl="http://base.example.com", + excludes=["abc", "xyz"], + pkglist="/test/pkglist", + groupfile="/test/comps", + cachedir="/test/cache", + update=False, + update_md_path="/test/md_path", + skip_stat=True, + checkts=True, + split=True, + pretty=False, + database=False, + checksum="sha256", + unique_md_filenames=False, + distro="Fedora", + content=["c1", "c2"], + repo=["r1", "r2"], + revision="rev", + deltas=True, + oldpackagedirs="/test/old", + num_deltas=2, + workers=3, + outputdir="/test/output", use_xz=True, extra_args=["--zck", "--zck-primary-dict=/foo/bar"], ) self.maxDiff = None - self.assertEqual(cmd[:2], ['createrepo_c', '/test/dir']) + self.assertEqual(cmd[:2], ["createrepo_c", "/test/dir"]) six.assertCountEqual( self, cmd[2:], - ["--baseurl=http://base.example.com", "--excludes=abc", "--excludes=xyz", - "--pkglist=/test/pkglist", "--groupfile=/test/comps", "--cachedir=/test/cache", - "--skip-stat", "--update-md-path=/test/md_path", "--split", "--checkts", - "--checksum=sha256", "--distro=Fedora", "--simple-md-filenames", "--no-database", - "--content=c1", "--content=c2", "--repo=r1", "--repo=r2", "--revision=rev", - "--deltas", "--oldpackagedirs=/test/old", "--num-deltas=2", "--workers=3", - "--outputdir=/test/output", "--xz", "--zck", "--zck-primary-dict=/foo/bar"], + [ + "--baseurl=http://base.example.com", + "--excludes=abc", + "--excludes=xyz", + "--pkglist=/test/pkglist", + "--groupfile=/test/comps", + "--cachedir=/test/cache", + "--skip-stat", + "--update-md-path=/test/md_path", + "--split", + "--checkts", + "--checksum=sha256", + "--distro=Fedora", + "--simple-md-filenames", + "--no-database", + "--content=c1", + "--content=c2", + "--repo=r1", + "--repo=r2", + "--revision=rev", + "--deltas", + "--oldpackagedirs=/test/old", + "--num-deltas=2", + "--workers=3", + "--outputdir=/test/output", + "--xz", + "--zck", + "--zck-primary-dict=/foo/bar", + ], ) def test_get_createrepo_cmd_minimal(self): repo = CreaterepoWrapper(False) - cmd = repo.get_createrepo_cmd('/test/dir') + cmd = repo.get_createrepo_cmd("/test/dir") - self.assertEqual(cmd[:2], ['createrepo', '/test/dir']) + self.assertEqual(cmd[:2], ["createrepo", "/test/dir"]) six.assertCountEqual( self, cmd[2:], @@ -65,24 +104,61 @@ class CreateRepoWrapperTest(unittest.TestCase): def test_get_createrepo_cmd_full(self): repo = CreaterepoWrapper(False) cmd = repo.get_createrepo_cmd( - '/test/dir', baseurl='http://base.example.com', excludes=['abc', 'xyz'], - pkglist='/test/pkglist', groupfile='/test/comps', cachedir='/test/cache', - update=False, update_md_path='/test/md_path', skip_stat=True, checkts=True, - split=True, pretty=False, database=False, checksum='sha256', unique_md_filenames=False, - distro='Fedora', content=['c1', 'c2'], repo=['r1', 'r2'], revision='rev', deltas=True, - oldpackagedirs='/test/old', num_deltas=2, workers=3, outputdir='/test/output' + "/test/dir", + baseurl="http://base.example.com", + excludes=["abc", "xyz"], + pkglist="/test/pkglist", + groupfile="/test/comps", + cachedir="/test/cache", + update=False, + update_md_path="/test/md_path", + skip_stat=True, + checkts=True, + split=True, + pretty=False, + database=False, + checksum="sha256", + unique_md_filenames=False, + distro="Fedora", + content=["c1", "c2"], + repo=["r1", "r2"], + revision="rev", + deltas=True, + oldpackagedirs="/test/old", + num_deltas=2, + workers=3, + outputdir="/test/output", ) self.maxDiff = None - self.assertEqual(cmd[:2], ['createrepo', '/test/dir']) + self.assertEqual(cmd[:2], ["createrepo", "/test/dir"]) six.assertCountEqual( self, cmd[2:], - ["--baseurl=http://base.example.com", "--excludes=abc", "--excludes=xyz", - "--pkglist=/test/pkglist", "--groupfile=/test/comps", "--cachedir=/test/cache", - "--skip-stat", "--update-md-path=/test/md_path", "--split", "--checkts", - "--checksum=sha256", "--distro=Fedora", "--simple-md-filenames", "--no-database", - "--content=c1", "--content=c2", "--repo=r1", "--repo=r2", "--revision=rev", - "--deltas", "--oldpackagedirs=/test/old", "--num-deltas=2", "--workers=3", - "--outputdir=/test/output"], + [ + "--baseurl=http://base.example.com", + "--excludes=abc", + "--excludes=xyz", + "--pkglist=/test/pkglist", + "--groupfile=/test/comps", + "--cachedir=/test/cache", + "--skip-stat", + "--update-md-path=/test/md_path", + "--split", + "--checkts", + "--checksum=sha256", + "--distro=Fedora", + "--simple-md-filenames", + "--no-database", + "--content=c1", + "--content=c2", + "--repo=r1", + "--repo=r2", + "--revision=rev", + "--deltas", + "--oldpackagedirs=/test/old", + "--num-deltas=2", + "--workers=3", + "--outputdir=/test/output", + ], ) diff --git a/tests/test_createrepophase.py b/tests/test_createrepophase.py index bd0c63bb..355aaa2b 100644 --- a/tests/test_createrepophase.py +++ b/tests/test_createrepophase.py @@ -12,55 +12,57 @@ import os import six import sys -from pungi.phases.createrepo import (CreaterepoPhase, - create_variant_repo, - get_productids_from_scm, - ModulesMetadata) +from pungi.phases.createrepo import ( + CreaterepoPhase, + create_variant_repo, + get_productids_from_scm, + ModulesMetadata, +) from tests.helpers import DummyCompose, PungiTestCase, copy_fixture, touch from pungi.module_util import Modulemd class TestCreaterepoPhase(PungiTestCase): - @mock.patch('pungi.phases.createrepo.ThreadPool') + @mock.patch("pungi.phases.createrepo.ThreadPool") def test_validates_without_option(self, ThreadPoolCls): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - }) + compose = DummyCompose(self.topdir, {"createrepo_checksum": "sha256"}) phase = CreaterepoPhase(compose) try: phase.validate() except ValueError: - self.fail('Missing delta config should not fail validation') + self.fail("Missing delta config should not fail validation") - @mock.patch('pungi.phases.createrepo.ThreadPool') + @mock.patch("pungi.phases.createrepo.ThreadPool") def test_fails_deltas_without_old_compose(self, ThreadPoolCls): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': True, - }) + compose = DummyCompose( + self.topdir, {"createrepo_checksum": "sha256", "createrepo_deltas": True} + ) phase = CreaterepoPhase(compose) with self.assertRaises(ValueError) as ctx: phase.validate() - self.assertIn('deltas', str(ctx.exception)) + self.assertIn("deltas", str(ctx.exception)) - @mock.patch('pungi.phases.createrepo.ThreadPool') + @mock.patch("pungi.phases.createrepo.ThreadPool") def test_fails_deltas_without_old_compose_granular_config(self, ThreadPoolCls): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': [('^Everything$', {'*': True})], - }) + compose = DummyCompose( + self.topdir, + { + "createrepo_checksum": "sha256", + "createrepo_deltas": [("^Everything$", {"*": True})], + }, + ) phase = CreaterepoPhase(compose) with self.assertRaises(ValueError) as ctx: phase.validate() - self.assertIn('deltas', str(ctx.exception)) + self.assertIn("deltas", str(ctx.exception)) - @mock.patch('pungi.checks.get_num_cpus') - @mock.patch('pungi.phases.createrepo.ThreadPool') + @mock.patch("pungi.checks.get_num_cpus") + @mock.patch("pungi.phases.createrepo.ThreadPool") def test_starts_jobs(self, ThreadPoolCls, get_num_cpus): get_num_cpus.return_value = 5 compose = DummyCompose(self.topdir, {}) @@ -94,12 +96,12 @@ class TestCreaterepoPhase(PungiTestCase): ], ) - @mock.patch('pungi.checks.get_num_cpus') - @mock.patch('pungi.phases.createrepo.ThreadPool') + @mock.patch("pungi.checks.get_num_cpus") + @mock.patch("pungi.phases.createrepo.ThreadPool") def test_skips_empty_variants(self, ThreadPoolCls, get_num_cpus): get_num_cpus.return_value = 5 compose = DummyCompose(self.topdir, {}) - compose.variants['Client'].is_empty = True + compose.variants["Client"].is_empty = True pool = ThreadPoolCls.return_value @@ -141,182 +143,249 @@ def make_mocked_modifyrepo_cmd(tc, module_artifacts): for ms in module_streams: tc.assertIn(ms.get_stream_name(), module_artifacts) six.assertCountEqual( - tc, - ms.get_rpm_artifacts(), - module_artifacts[ms.get_stream_name()], + tc, ms.get_rpm_artifacts(), module_artifacts[ms.get_stream_name()], ) + return mocked_modifyrepo_cmd class TestCreateVariantRepo(PungiTestCase): - def setUp(self): super(TestCreateVariantRepo, self).setUp() self.pkgset = mock.Mock( paths={"x86_64": "/repo/x86_64", "global": "/repo/global"} ) - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_rpms(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - }) + compose = DummyCompose(self.topdir, {"createrepo_checksum": "sha256"}) compose.has_comps = False repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_rpms_without_database(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - }) + compose = DummyCompose(self.topdir, {"createrepo_checksum": "sha256"}) compose.should_create_yum_database = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=False, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=False, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_source(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - }) + compose = DummyCompose(self.topdir, {"createrepo_checksum": "sha256"}) compose.has_comps = False repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, None, compose.variants["Server"], "srpm", self.pkgset ) - list_file = self.topdir + '/work/global/repo_package_list/Server.None.srpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = self.topdir + "/work/global/repo_package_list/Server.None.srpm.conf" + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/source/tree', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/source/tree', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/global", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/source/tree", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/source/tree", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/global", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.src.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_debug(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - }) + compose = DummyCompose(self.topdir, {"createrepo_checksum": "sha256"}) compose.has_comps = False repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "debuginfo", self.pkgset ) self.maxDiff = None - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.debuginfo.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.debuginfo.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/debug/tree', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/debug/tree', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/debug/tree", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/debug/tree", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent( - list_file, 'Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n' + list_file, "Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n" ) - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_no_createrepo_c(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_c': False, - 'createrepo_checksum': 'sha256', - }) + compose = DummyCompose( + self.topdir, {"createrepo_c": False, "createrepo_checksum": "sha256"} + ) compose.has_comps = False repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=False)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=False) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_is_idepotent(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_num_workers': 10, - }) + compose = DummyCompose( + self.topdir, + {"createrepo_checksum": "sha256", "createrepo_num_workers": 10}, + ) compose.has_comps = False repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) # Running the same thing twice only creates repo once. create_variant_repo( @@ -326,465 +395,730 @@ class TestCreateVariantRepo(PungiTestCase): compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=10, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=10, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_rpms_with_xz(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_use_xz': True, - }) + compose = DummyCompose( + self.topdir, {"createrepo_checksum": "sha256", "createrepo_use_xz": True} + ) compose.has_comps = False repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", deltas=False, - oldpackagedirs=None, use_xz=True, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=True, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_rpms_with_deltas(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': True, - }) + compose = DummyCompose( + self.topdir, {"createrepo_checksum": "sha256", "createrepo_deltas": True} + ) compose.has_comps = False - compose.old_composes = [self.topdir + '/old'] - touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') + compose.old_composes = [self.topdir + "/old"] + touch( + os.path.join(self.topdir, "old", "test-1.0-20151203.0", "STATUS"), + "FINISHED", + ) repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path=None, deltas=True, - oldpackagedirs=self.topdir + '/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages', - use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path=None, + deltas=True, + oldpackagedirs=self.topdir + + "/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages", + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') - def test_variant_repo_rpms_with_deltas_granular_config(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': [('^Server$', {'*': True})], - }) + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") + def test_variant_repo_rpms_with_deltas_granular_config( + self, CreaterepoWrapperCls, run + ): + compose = DummyCompose( + self.topdir, + { + "createrepo_checksum": "sha256", + "createrepo_deltas": [("^Server$", {"*": True})], + }, + ) compose.has_comps = False - compose.old_composes = [self.topdir + '/old'] - touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') + compose.old_composes = [self.topdir + "/old"] + touch( + os.path.join(self.topdir, "old", "test-1.0-20151203.0", "STATUS"), + "FINISHED", + ) repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path=None, deltas=True, - oldpackagedirs=self.topdir + '/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages', - use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path=None, + deltas=True, + oldpackagedirs=self.topdir + + "/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages", + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') - def test_variant_repo_rpms_with_deltas_granular_config_no_match(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': [('^Everything$', {'x86_64': True})], - }) + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") + def test_variant_repo_rpms_with_deltas_granular_config_no_match( + self, CreaterepoWrapperCls, run + ): + compose = DummyCompose( + self.topdir, + { + "createrepo_checksum": "sha256", + "createrepo_deltas": [("^Everything$", {"x86_64": True})], + }, + ) compose.has_comps = False - compose.old_composes = [self.topdir + '/old'] - touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') + compose.old_composes = [self.topdir + "/old"] + touch( + os.path.join(self.topdir, "old", "test-1.0-20151203.0", "STATUS"), + "FINISHED", + ) repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_rpms_with_deltas_granular_config_no_match_on_arch( - self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': [('^Server$', {'s390x': True})], - }) + self, CreaterepoWrapperCls, run + ): + compose = DummyCompose( + self.topdir, + { + "createrepo_checksum": "sha256", + "createrepo_deltas": [("^Server$", {"s390x": True})], + }, + ) compose.has_comps = False - compose.old_composes = [self.topdir + '/old'] - touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') + compose.old_composes = [self.topdir + "/old"] + touch( + os.path.join(self.topdir, "old", "test-1.0-20151203.0", "STATUS"), + "FINISHED", + ) repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_rpms_with_deltas_hashed_dirs(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': True, - 'hashed_directories': True, - }) + compose = DummyCompose( + self.topdir, + { + "createrepo_checksum": "sha256", + "createrepo_deltas": True, + "hashed_directories": True, + }, + ) compose.has_comps = False - compose.old_composes = [self.topdir + '/old'] - touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') + compose.old_composes = [self.topdir + "/old"] + touch( + os.path.join(self.topdir, "old", "test-1.0-20151203.0", "STATUS"), + "FINISHED", + ) self.maxDiff = None - for f in ['a/a.rpm', 'b/b.rpm', 'foo']: - touch(self.topdir + '/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages/' + f) + for f in ["a/a.rpm", "b/b.rpm", "foo"]: + touch( + self.topdir + + "/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages/" + + f + ) repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path=None, deltas=True, - oldpackagedirs=[ - self.topdir + '/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages/a', - self.topdir + '/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages/b', - ], - use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path=None, + deltas=True, + oldpackagedirs=[ + self.topdir + + "/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages/a", + self.topdir + + "/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages/b", + ], + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') - def test_variant_repo_rpms_with_deltas_hashed_dirs_but_old_doesnt_exist(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': True, - 'hashed_directories': True, - }) + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") + def test_variant_repo_rpms_with_deltas_hashed_dirs_but_old_doesnt_exist( + self, CreaterepoWrapperCls, run + ): + compose = DummyCompose( + self.topdir, + { + "createrepo_checksum": "sha256", + "createrepo_deltas": True, + "hashed_directories": True, + }, + ) compose.has_comps = False - compose.old_composes = [self.topdir + '/old'] - touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') + compose.old_composes = [self.topdir + "/old"] + touch( + os.path.join(self.topdir, "old", "test-1.0-20151203.0", "STATUS"), + "FINISHED", + ) self.maxDiff = None repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", deltas=True, - oldpackagedirs=[], - use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=True, + oldpackagedirs=[], + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_source_with_deltas(self, CreaterepoWrapperCls, run): # This should not actually create deltas, only binary repos do. - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': True, - }) + compose = DummyCompose( + self.topdir, {"createrepo_checksum": "sha256", "createrepo_deltas": True} + ) compose.has_comps = False - compose.old_composes = [self.topdir + '/old'] - touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') + compose.old_composes = [self.topdir + "/old"] + touch( + os.path.join(self.topdir, "old", "test-1.0-20151203.0", "STATUS"), + "FINISHED", + ) repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, None, compose.variants["Server"], "srpm", self.pkgset ) - list_file = self.topdir + '/work/global/repo_package_list/Server.None.srpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = self.topdir + "/work/global/repo_package_list/Server.None.srpm.conf" + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/source/tree', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/source/tree', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/global", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/source/tree", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/source/tree", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/global", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.src.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_debug_with_deltas(self, CreaterepoWrapperCls, run): # This should not actually create deltas, only binary repos do. - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'createrepo_deltas': True, - }) + compose = DummyCompose( + self.topdir, {"createrepo_checksum": "sha256", "createrepo_deltas": True} + ) compose.has_comps = False - compose.old_composes = [self.topdir + '/old'] - touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') + compose.old_composes = [self.topdir + "/old"] + touch( + os.path.join(self.topdir, "old", "test-1.0-20151203.0", "STATUS"), + "FINISHED", + ) repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "debuginfo", self.pkgset ) - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.debuginfo.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.debuginfo.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/debug/tree', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/debug/tree', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", - deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/debug/tree", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/debug/tree", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent( list_file, "Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n" ) - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_rpms_with_productid(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'product_id': 'yes', # Truthy value is enough for this test - }) + compose = DummyCompose( + self.topdir, + { + "createrepo_checksum": "sha256", + "product_id": "yes", # Truthy value is enough for this test + }, + ) compose.has_comps = False - product_id = compose.paths.work.product_id('x86_64', compose.variants['Server']) + product_id = compose.paths.work.product_id("x86_64", compose.variants["Server"]) repodata_dir = os.path.join( - compose.paths.compose.os_tree('x86_64', compose.variants['Server']), - 'repodata') + compose.paths.compose.os_tree("x86_64", compose.variants["Server"]), + "repodata", + ) touch(product_id) os.mkdir(repodata_dir) repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset ) self.maxDiff = None - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.rpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.rpm.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/os', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/os', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", deltas=False, - oldpackagedirs=None, - use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/os", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/os", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual( repo.get_modifyrepo_cmd.mock_calls, - [mock.call(repodata_dir, product_id, compress_type="gz")] + [mock.call(repodata_dir, product_id, compress_type="gz")], ) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_debug_with_productid(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'product_id': 'yes', # Truthy value is enough for this test - }) + compose = DummyCompose( + self.topdir, + { + "createrepo_checksum": "sha256", + "product_id": "yes", # Truthy value is enough for this test + }, + ) compose.has_comps = False repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, "x86_64", compose.variants["Server"], "debuginfo", self.pkgset ) self.maxDiff = None - list_file = self.topdir + '/work/x86_64/repo_package_list/Server.x86_64.debuginfo.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = ( + self.topdir + "/work/x86_64/repo_package_list/Server.x86_64.debuginfo.conf" + ) + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/x86_64/debug/tree', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/x86_64/debug/tree', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/x86_64", deltas=False, - oldpackagedirs=None, - use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/x86_64/debug/tree", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/x86_64/debug/tree", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/x86_64", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent( list_file, "Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n" ) - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_source_with_productid(self, CreaterepoWrapperCls, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - 'product_id': 'yes', # Truthy value is enough for this test - }) + compose = DummyCompose( + self.topdir, + { + "createrepo_checksum": "sha256", + "product_id": "yes", # Truthy value is enough for this test + }, + ) compose.has_comps = False repo = CreaterepoWrapperCls.return_value - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) create_variant_repo( compose, None, compose.variants["Server"], "srpm", self.pkgset ) self.maxDiff = None - list_file = self.topdir + '/work/global/repo_package_list/Server.None.srpm.conf' - self.assertEqual(CreaterepoWrapperCls.mock_calls[0], - mock.call(createrepo_c=True)) + list_file = self.topdir + "/work/global/repo_package_list/Server.None.srpm.conf" + self.assertEqual( + CreaterepoWrapperCls.mock_calls[0], mock.call(createrepo_c=True) + ) self.assertEqual( repo.get_createrepo_cmd.mock_calls, - [mock.call(self.topdir + '/compose/Server/source/tree', checksum='sha256', - database=True, groupfile=None, workers=3, - outputdir=self.topdir + '/compose/Server/source/tree', - pkglist=list_file, skip_stat=True, update=True, - update_md_path="/repo/global", deltas=False, - oldpackagedirs=None, - use_xz=False, extra_args=[])]) + [ + mock.call( + self.topdir + "/compose/Server/source/tree", + checksum="sha256", + database=True, + groupfile=None, + workers=3, + outputdir=self.topdir + "/compose/Server/source/tree", + pkglist=list_file, + skip_stat=True, + update=True, + update_md_path="/repo/global", + deltas=False, + oldpackagedirs=None, + use_xz=False, + extra_args=[], + ) + ], + ) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.src.rpm\n") - @unittest.skipUnless(Modulemd is not None, 'Skipped test, no module support.') - @mock.patch('pungi.phases.createrepo.find_file_in_repodata') - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @unittest.skipUnless(Modulemd is not None, "Skipped test, no module support.") + @mock.patch("pungi.phases.createrepo.find_file_in_repodata") + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_modules_artifacts_not_in_compose( - self, CreaterepoWrapperCls, run, modulemd_filename + self, CreaterepoWrapperCls, run, modulemd_filename ): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - }) + compose = DummyCompose(self.topdir, {"createrepo_checksum": "sha256"}) compose.has_comps = False - variant = compose.variants['Server'] + variant = compose.variants["Server"] variant.arch_mmds["x86_64"] = {} variant.arch_mmds["x86_64"]["test:f27:1:2017"] = variant.add_fake_module( - "test:f27:1:2017", rpm_nvrs=["pkg-0:1.0.0-1.x86_64"]) + "test:f27:1:2017", rpm_nvrs=["pkg-0:1.0.0-1.x86_64"] + ) variant.arch_mmds["x86_64"]["test:f28:1:2017"] = variant.add_fake_module( - "test:f28:1:2017", rpm_nvrs=["pkg-0:2.0.0-1.x86_64"]) + "test:f28:1:2017", rpm_nvrs=["pkg-0:2.0.0-1.x86_64"] + ) repo = CreaterepoWrapperCls.return_value repo.get_modifyrepo_cmd.side_effect = make_mocked_modifyrepo_cmd( self, {"f27": [], "f28": []} ) - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) repodata_dir = os.path.join( - compose.paths.compose.os_tree('x86_64', compose.variants['Server']), - 'repodata') - modulemd_filename.return_value = "Server/x86_64/os/repodata/3511d16a7-modules.yaml.gz" + compose.paths.compose.os_tree("x86_64", compose.variants["Server"]), + "repodata", + ) + modulemd_filename.return_value = ( + "Server/x86_64/os/repodata/3511d16a7-modules.yaml.gz" + ) modules_metadata = mock.Mock() create_variant_repo( - compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset, modules_metadata + compose, + "x86_64", + compose.variants["Server"], + "rpm", + self.pkgset, + modules_metadata, ) self.assertEqual( @@ -792,18 +1126,17 @@ class TestCreateVariantRepo(PungiTestCase): [mock.call(repodata_dir, mock.ANY, compress_type="gz", mdtype="modules")], ) - @unittest.skipUnless(Modulemd is not None, 'Skipped test, no module support.') - @mock.patch('pungi.phases.createrepo.find_file_in_repodata') - @mock.patch('pungi.phases.createrepo.run') - @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') + @unittest.skipUnless(Modulemd is not None, "Skipped test, no module support.") + @mock.patch("pungi.phases.createrepo.find_file_in_repodata") + @mock.patch("pungi.phases.createrepo.run") + @mock.patch("pungi.phases.createrepo.CreaterepoWrapper") def test_variant_repo_modules_artifacts( - self, CreaterepoWrapperCls, run, modulemd_filename): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - }) + self, CreaterepoWrapperCls, run, modulemd_filename + ): + compose = DummyCompose(self.topdir, {"createrepo_checksum": "sha256"}) compose.has_comps = False - variant = compose.variants['Server'] + variant = compose.variants["Server"] variant.arch_mmds["x86_64"] = { "test:f27:2018:cafe": variant.add_fake_module( "test:f27:2018:cafe", @@ -827,17 +1160,23 @@ class TestCreateVariantRepo(PungiTestCase): {"f27": ["bash-0:4.3.30-2.fc21.x86_64"], "f28": ["pkg-0:2.0.0-1.x86_64"]}, ) - copy_fixture('server-rpms.json', compose.paths.compose.metadata('rpms.json')) + copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json")) repodata_dir = os.path.join( - compose.paths.compose.os_tree('x86_64', compose.variants['Server']), - 'repodata') + compose.paths.compose.os_tree("x86_64", compose.variants["Server"]), + "repodata", + ) modules_metadata = ModulesMetadata(compose) modulemd_filename.return_value = "Server/x86_64/os/repodata/3511d16a723e1bd69826e591508f07e377d2212769b59178a9-modules.yaml.gz" create_variant_repo( - compose, "x86_64", compose.variants["Server"], "rpm", self.pkgset, modules_metadata + compose, + "x86_64", + compose.variants["Server"], + "rpm", + self.pkgset, + modules_metadata, ) self.assertEqual( @@ -851,78 +1190,80 @@ class TestGetProductIds(PungiTestCase): def _mock_get(scm, dest): for filename in filenames: touch(os.path.join(dest, filename)) + return _mock_get def assertProductIds(self, mapping): - pids = glob.glob(self.compose.paths.work.product_id('*', '*')) + pids = glob.glob(self.compose.paths.work.product_id("*", "*")) expected = set() for variant, arches in mapping.items(): for arch in arches: - expected.add(os.path.join(self.topdir, 'work', arch, - 'product_id', - '%s.%s.pem' % (variant, arch), - 'productid')) + expected.add( + os.path.join( + self.topdir, + "work", + arch, + "product_id", + "%s.%s.pem" % (variant, arch), + "productid", + ) + ) six.assertCountEqual(self, pids, expected) - @mock.patch('pungi.phases.createrepo.get_dir_from_scm') + @mock.patch("pungi.phases.createrepo.get_dir_from_scm") def test_not_configured(self, get_dir_from_scm): self.compose = DummyCompose(self.topdir, {}) get_productids_from_scm(self.compose) self.assertEqual(get_dir_from_scm.call_args_list, []) self.assertProductIds({}) - @mock.patch('pungi.phases.createrepo.get_dir_from_scm') + @mock.patch("pungi.phases.createrepo.get_dir_from_scm") def test_correct(self, get_dir_from_scm): cfg = mock.Mock() - self.compose = DummyCompose(self.topdir, { - 'product_id': cfg, - }) - get_dir_from_scm.side_effect = self.mock_get([ - 'Client-amd64-cert.pem', - 'Everything-amd64-cert.pem', - 'Server-amd64-cert.pem', - 'Everything-x86_64-cert.pem', - 'Server-x86_64-cert.pem', - ]) + self.compose = DummyCompose(self.topdir, {"product_id": cfg}) + get_dir_from_scm.side_effect = self.mock_get( + [ + "Client-amd64-cert.pem", + "Everything-amd64-cert.pem", + "Server-amd64-cert.pem", + "Everything-x86_64-cert.pem", + "Server-x86_64-cert.pem", + ] + ) get_productids_from_scm(self.compose) self.assertEqual(get_dir_from_scm.call_args_list, [mock.call(cfg, mock.ANY)]) - self.assertProductIds({ - 'Client': ['amd64'], - 'Everything': ['amd64', 'x86_64'], - 'Server': ['amd64', 'x86_64'], - }) + self.assertProductIds( + { + "Client": ["amd64"], + "Everything": ["amd64", "x86_64"], + "Server": ["amd64", "x86_64"], + } + ) - @mock.patch('pungi.phases.createrepo.get_dir_from_scm') + @mock.patch("pungi.phases.createrepo.get_dir_from_scm") def test_allow_missing(self, get_dir_from_scm): cfg = mock.Mock() - self.compose = DummyCompose(self.topdir, { - 'product_id': cfg, - 'product_id_allow_missing': True, - }) - get_dir_from_scm.side_effect = self.mock_get([ - 'Server-amd64-cert.pem', - 'Server-x86_64-cert.pem', - ]) + self.compose = DummyCompose( + self.topdir, {"product_id": cfg, "product_id_allow_missing": True} + ) + get_dir_from_scm.side_effect = self.mock_get( + ["Server-amd64-cert.pem", "Server-x86_64-cert.pem"] + ) get_productids_from_scm(self.compose) self.assertEqual(get_dir_from_scm.call_args_list, [mock.call(cfg, mock.ANY)]) - self.assertProductIds({ - 'Server': ['amd64', 'x86_64'], - }) + self.assertProductIds({"Server": ["amd64", "x86_64"]}) - @mock.patch('pungi.phases.createrepo.get_dir_from_scm') + @mock.patch("pungi.phases.createrepo.get_dir_from_scm") def test_missing_fails(self, get_dir_from_scm): cfg = mock.Mock() - self.compose = DummyCompose(self.topdir, { - 'product_id': cfg, - }) - get_dir_from_scm.side_effect = self.mock_get([ - 'Server-amd64-cert.pem', - 'Server-x86_64-cert.pem', - ]) + self.compose = DummyCompose(self.topdir, {"product_id": cfg}) + get_dir_from_scm.side_effect = self.mock_get( + ["Server-amd64-cert.pem", "Server-x86_64-cert.pem"] + ) with self.assertRaises(RuntimeError) as ctx: get_productids_from_scm(self.compose) @@ -930,27 +1271,28 @@ class TestGetProductIds(PungiTestCase): self.assertEqual(get_dir_from_scm.call_args_list, [mock.call(cfg, mock.ANY)]) self.assertRegexpMatches( str(ctx.exception), - r'No product certificate found \(arch: amd64, variant: (Everything|Client)\)') + r"No product certificate found \(arch: amd64, variant: (Everything|Client)\)", + ) - @mock.patch('pungi.phases.createrepo.get_dir_from_scm') + @mock.patch("pungi.phases.createrepo.get_dir_from_scm") def test_multiple_matching(self, get_dir_from_scm): cfg = mock.Mock() - self.compose = DummyCompose(self.topdir, { - 'product_id': cfg, - }) - get_dir_from_scm.side_effect = self.mock_get([ - 'Client-amd64-cert.pem', - 'Client-amd64-cert-duplicate.pem', - 'Everything-amd64-cert.pem', - 'Server-amd64-cert.pem', - 'Everything-x86_64-cert.pem', - 'Server-x86_64-cert.pem', - ]) + self.compose = DummyCompose(self.topdir, {"product_id": cfg}) + get_dir_from_scm.side_effect = self.mock_get( + [ + "Client-amd64-cert.pem", + "Client-amd64-cert-duplicate.pem", + "Everything-amd64-cert.pem", + "Server-amd64-cert.pem", + "Everything-x86_64-cert.pem", + "Server-x86_64-cert.pem", + ] + ) with self.assertRaises(RuntimeError) as ctx: get_productids_from_scm(self.compose) self.assertEqual(get_dir_from_scm.call_args_list, [mock.call(cfg, mock.ANY)]) self.assertRegexpMatches( - str(ctx.exception), - 'Multiple product certificates found.+') + str(ctx.exception), "Multiple product certificates found.+" + ) diff --git a/tests/test_extra_files_phase.py b/tests/test_extra_files_phase.py index 86ef8476..21d67dab 100644 --- a/tests/test_extra_files_phase.py +++ b/tests/test_extra_files_phase.py @@ -13,8 +13,7 @@ from tests import helpers class TestExtraFilePhase(helpers.PungiTestCase): - - @mock.patch('pungi.phases.extra_files.copy_extra_files') + @mock.patch("pungi.phases.extra_files.copy_extra_files") def test_skips_unless_has_config(self, copy_extra_files): compose = helpers.DummyCompose(self.topdir, {}) compose.just_phases = None @@ -22,15 +21,13 @@ class TestExtraFilePhase(helpers.PungiTestCase): phase = extra_files.ExtraFilesPhase(compose, mock.Mock()) self.assertTrue(phase.skip()) - @mock.patch('pungi.phases.extra_files.copy_extra_files') + @mock.patch("pungi.phases.extra_files.copy_extra_files") def test_runs_copy_files_for_each_variant(self, copy_extra_files): cfg = mock.Mock() pkgset_phase = mock.Mock() - compose = helpers.DummyCompose(self.topdir, { - 'extra_files': [ - ('^.+$', {'x86_64': [cfg]}) - ] - }) + compose = helpers.DummyCompose( + self.topdir, {"extra_files": [("^.+$", {"x86_64": [cfg]})]} + ) phase = extra_files.ExtraFilesPhase(compose, pkgset_phase) phase.run() @@ -61,7 +58,6 @@ class TestExtraFilePhase(helpers.PungiTestCase): class TestCopyFiles(helpers.PungiTestCase): - def setUp(self): super(TestCopyFiles, self).setUp() self.metadata = ExtraFiles() @@ -69,24 +65,27 @@ class TestCopyFiles(helpers.PungiTestCase): self.variant = self.compose.variants["Server"] def test_copy_local_file(self): - tgt = os.path.join(self.topdir, 'file') + tgt = os.path.join(self.topdir, "file") helpers.touch(tgt) - cfg = {'scm': 'file', 'file': tgt, 'repo': None} + cfg = {"scm": "file", "file": tgt, "repo": None} extra_files.copy_extra_files( self.compose, [cfg], "x86_64", self.variant, mock.Mock(), self.metadata ) - self.assertTrue(os.path.isfile(os.path.join( - self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file'))) + self.assertTrue( + os.path.isfile( + os.path.join(self.topdir, "compose", "Server", "x86_64", "os", "file") + ) + ) def test_copy_multiple_sources(self): - tgt1 = os.path.join(self.topdir, 'file') - tgt2 = os.path.join(self.topdir, 'gpl') + tgt1 = os.path.join(self.topdir, "file") + tgt2 = os.path.join(self.topdir, "gpl") helpers.touch(tgt1) helpers.touch(tgt2) - cfg1 = {'scm': 'file', 'file': tgt1, 'repo': None} - cfg2 = {'scm': 'file', 'file': tgt2, 'repo': None, 'target': 'license'} + cfg1 = {"scm": "file", "file": tgt1, "repo": None} + cfg2 = {"scm": "file", "file": tgt2, "repo": None, "target": "license"} extra_files.copy_extra_files( self.compose, @@ -94,32 +93,64 @@ class TestCopyFiles(helpers.PungiTestCase): "x86_64", self.variant, mock.Mock(), - self.metadata + self.metadata, ) - self.assertTrue(os.path.isfile(os.path.join( - self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file'))) - self.assertTrue(os.path.isfile(os.path.join( - self.topdir, 'compose', 'Server', 'x86_64', 'os', 'license', 'gpl'))) + self.assertTrue( + os.path.isfile( + os.path.join(self.topdir, "compose", "Server", "x86_64", "os", "file") + ) + ) + self.assertTrue( + os.path.isfile( + os.path.join( + self.topdir, "compose", "Server", "x86_64", "os", "license", "gpl" + ) + ) + ) def test_copy_local_dir(self): - helpers.touch(os.path.join(self.topdir, 'src', 'file')) - helpers.touch(os.path.join(self.topdir, 'src', 'another')) - cfg = {'scm': 'file', 'dir': os.path.join(self.topdir, 'src'), - 'repo': None, 'target': 'subdir'} + helpers.touch(os.path.join(self.topdir, "src", "file")) + helpers.touch(os.path.join(self.topdir, "src", "another")) + cfg = { + "scm": "file", + "dir": os.path.join(self.topdir, "src"), + "repo": None, + "target": "subdir", + } extra_files.copy_extra_files( self.compose, [cfg], "x86_64", self.variant, mock.Mock(), self.metadata ) - self.assertTrue(os.path.isfile(os.path.join( - self.topdir, 'compose', 'Server', 'x86_64', 'os', 'subdir', 'file'))) - self.assertTrue(os.path.isfile(os.path.join( - self.topdir, 'compose', 'Server', 'x86_64', 'os', 'subdir', 'another'))) + self.assertTrue( + os.path.isfile( + os.path.join( + self.topdir, "compose", "Server", "x86_64", "os", "subdir", "file" + ) + ) + ) + self.assertTrue( + os.path.isfile( + os.path.join( + self.topdir, + "compose", + "Server", + "x86_64", + "os", + "subdir", + "another", + ) + ) + ) - @mock.patch('pungi.phases.extra_files.get_file_from_scm') - @mock.patch('pungi.phases.extra_files.get_dir_from_scm') + @mock.patch("pungi.phases.extra_files.get_file_from_scm") + @mock.patch("pungi.phases.extra_files.get_dir_from_scm") def test_copy_from_external_rpm(self, get_dir_from_scm, get_file_from_scm): - cfg = {'scm': 'rpm', 'file': 'file.txt', 'repo': 'http://example.com/package.rpm'} + cfg = { + "scm": "rpm", + "file": "file.txt", + "repo": "http://example.com/package.rpm", + } get_file_from_scm.side_effect = self.fake_get_file @@ -129,26 +160,41 @@ class TestCopyFiles(helpers.PungiTestCase): self.assertEqual(len(get_file_from_scm.call_args_list), 1) self.assertEqual(get_dir_from_scm.call_args_list, []) - self.assertEqual(self.scm_dict, - {'scm': 'rpm', 'file': 'file.txt', 'repo': 'http://example.com/package.rpm'}) + self.assertEqual( + self.scm_dict, + { + "scm": "rpm", + "file": "file.txt", + "repo": "http://example.com/package.rpm", + }, + ) - self.assertTrue(os.path.isfile(os.path.join( - self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file.txt'))) + self.assertTrue( + os.path.isfile( + os.path.join( + self.topdir, "compose", "Server", "x86_64", "os", "file.txt" + ) + ) + ) - @mock.patch('pungi.phases.extra_files.get_file_from_scm') - @mock.patch('pungi.phases.extra_files.get_dir_from_scm') + @mock.patch("pungi.phases.extra_files.get_file_from_scm") + @mock.patch("pungi.phases.extra_files.get_dir_from_scm") def test_copy_from_rpm_in_compose(self, get_dir_from_scm, get_file_from_scm): - cfg = {'scm': 'rpm', 'file': 'file.txt', 'repo': '%(variant_uid)s-data*'} + cfg = {"scm": "rpm", "file": "file.txt", "repo": "%(variant_uid)s-data*"} server_po, client_po, src_po = mock.Mock(), mock.Mock(), mock.Mock() - server_po.configure_mock(name='Server-data-1.1-1.fc24.x86_64.rpm', - file_path='/server/location', - arch='x86_64') - client_po.configure_mock(name='Client-data-1.1-1.fc24.x86_64.rpm', - file_path='/client/location', - arch='x86_64') - src_po.configure_mock(name='extra-data-1.1-1.fc24.src.rpm', - file_path='/src/location', - arch='src') + server_po.configure_mock( + name="Server-data-1.1-1.fc24.x86_64.rpm", + file_path="/server/location", + arch="x86_64", + ) + client_po.configure_mock( + name="Client-data-1.1-1.fc24.x86_64.rpm", + file_path="/client/location", + arch="x86_64", + ) + src_po.configure_mock( + name="extra-data-1.1-1.fc24.src.rpm", file_path="/src/location", arch="src" + ) package_sets = [ { "x86_64": { @@ -168,21 +214,30 @@ class TestCopyFiles(helpers.PungiTestCase): self.assertEqual(len(get_file_from_scm.call_args_list), 1) self.assertEqual(get_dir_from_scm.call_args_list, []) - self.assertEqual(self.scm_dict, - {'scm': 'rpm', 'file': 'file.txt', 'repo': ['/server/location']}) + self.assertEqual( + self.scm_dict, + {"scm": "rpm", "file": "file.txt", "repo": ["/server/location"]}, + ) - self.assertTrue(os.path.isfile(os.path.join( - self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file.txt'))) + self.assertTrue( + os.path.isfile( + os.path.join( + self.topdir, "compose", "Server", "x86_64", "os", "file.txt" + ) + ) + ) def fake_get_file(self, scm_dict, dest, compose): self.scm_dict = scm_dict - helpers.touch(os.path.join(dest, scm_dict['file'])) - return [scm_dict['file']] + helpers.touch(os.path.join(dest, scm_dict["file"])) + return [scm_dict["file"]] - @mock.patch('pungi.phases.extra_files.get_file_from_scm') - @mock.patch('pungi.phases.extra_files.get_dir_from_scm') - def test_copy_from_non_existing_rpm_in_compose(self, get_dir_from_scm, get_file_from_scm): - cfg = {'scm': 'rpm', 'file': 'file.txt', 'repo': 'bad-%(variant_uid_lower)s*'} + @mock.patch("pungi.phases.extra_files.get_file_from_scm") + @mock.patch("pungi.phases.extra_files.get_dir_from_scm") + def test_copy_from_non_existing_rpm_in_compose( + self, get_dir_from_scm, get_file_from_scm + ): + cfg = {"scm": "rpm", "file": "file.txt", "repo": "bad-%(variant_uid_lower)s*"} package_sets = [{"x86_64": {}}] with self.assertRaises(RuntimeError) as ctx: @@ -191,7 +246,7 @@ class TestCopyFiles(helpers.PungiTestCase): ) self.assertRegexpMatches( - str(ctx.exception), r'No.*package.*matching bad-server\*.*' + str(ctx.exception), r"No.*package.*matching bad-server\*.*" ) self.assertEqual(len(get_file_from_scm.call_args_list), 0) diff --git a/tests/test_extra_isos_phase.py b/tests/test_extra_isos_phase.py index 5fce3b20..ee3a62ba 100644 --- a/tests/test_extra_isos_phase.py +++ b/tests/test_extra_isos_phase.py @@ -11,19 +11,14 @@ from tests import helpers from pungi.phases import extra_isos -@mock.patch('pungi.phases.extra_isos.ThreadPool') +@mock.patch("pungi.phases.extra_isos.ThreadPool") class ExtraIsosPhaseTest(helpers.PungiTestCase): - def test_logs_extra_arches(self, ThreadPool): cfg = { - 'include_variants': ['Client'], - 'arches': ['x86_64', 'ppc64le', 'aarch64'], + "include_variants": ["Client"], + "arches": ["x86_64", "ppc64le", "aarch64"], } - compose = helpers.DummyCompose(self.topdir, { - 'extra_isos': { - '^Server$': [cfg] - } - }) + compose = helpers.DummyCompose(self.topdir, {"extra_isos": {"^Server$": [cfg]}}) phase = extra_isos.ExtraIsosPhase(compose) phase.validate() @@ -32,13 +27,9 @@ class ExtraIsosPhaseTest(helpers.PungiTestCase): def test_one_task_for_each_arch(self, ThreadPool): cfg = { - 'include_variants': ['Client'], + "include_variants": ["Client"], } - compose = helpers.DummyCompose(self.topdir, { - 'extra_isos': { - '^Server$': [cfg] - } - }) + compose = helpers.DummyCompose(self.topdir, {"extra_isos": {"^Server$": [cfg]}}) phase = extra_isos.ExtraIsosPhase(compose) phase.run() @@ -47,21 +38,19 @@ class ExtraIsosPhaseTest(helpers.PungiTestCase): six.assertCountEqual( self, ThreadPool.return_value.queue_put.call_args_list, - [mock.call((compose, cfg, compose.variants['Server'], 'x86_64')), - mock.call((compose, cfg, compose.variants['Server'], 'amd64')), - mock.call((compose, cfg, compose.variants['Server'], 'src'))] + [ + mock.call((compose, cfg, compose.variants["Server"], "x86_64")), + mock.call((compose, cfg, compose.variants["Server"], "amd64")), + mock.call((compose, cfg, compose.variants["Server"], "src")), + ], ) def test_filter_arches(self, ThreadPool): cfg = { - 'include_variants': ['Client'], - 'arches': ['x86_64'], + "include_variants": ["Client"], + "arches": ["x86_64"], } - compose = helpers.DummyCompose(self.topdir, { - 'extra_isos': { - '^Server$': [cfg] - } - }) + compose = helpers.DummyCompose(self.topdir, {"extra_isos": {"^Server$": [cfg]}}) phase = extra_isos.ExtraIsosPhase(compose) phase.run() @@ -70,20 +59,18 @@ class ExtraIsosPhaseTest(helpers.PungiTestCase): six.assertCountEqual( self, ThreadPool.return_value.queue_put.call_args_list, - [mock.call((compose, cfg, compose.variants['Server'], 'x86_64')), - mock.call((compose, cfg, compose.variants['Server'], 'src'))] + [ + mock.call((compose, cfg, compose.variants["Server"], "x86_64")), + mock.call((compose, cfg, compose.variants["Server"], "src")), + ], ) def test_skip_source(self, ThreadPool): cfg = { - 'include_variants': ['Client'], - 'skip_src': True, + "include_variants": ["Client"], + "skip_src": True, } - compose = helpers.DummyCompose(self.topdir, { - 'extra_isos': { - '^Server$': [cfg] - } - }) + compose = helpers.DummyCompose(self.topdir, {"extra_isos": {"^Server$": [cfg]}}) phase = extra_isos.ExtraIsosPhase(compose) phase.run() @@ -92,140 +79,28 @@ class ExtraIsosPhaseTest(helpers.PungiTestCase): six.assertCountEqual( self, ThreadPool.return_value.queue_put.call_args_list, - [mock.call((compose, cfg, compose.variants['Server'], 'x86_64')), - mock.call((compose, cfg, compose.variants['Server'], 'amd64'))] + [ + mock.call((compose, cfg, compose.variants["Server"], "x86_64")), + mock.call((compose, cfg, compose.variants["Server"], "amd64")), + ], ) -@mock.patch('pungi.phases.extra_isos.prepare_media_metadata') -@mock.patch('pungi.phases.extra_isos.get_volume_id') -@mock.patch('pungi.phases.extra_isos.get_filename') -@mock.patch('pungi.phases.extra_isos.get_iso_contents') -@mock.patch('pungi.phases.extra_isos.get_extra_files') -@mock.patch('pungi.phases.extra_isos.run_createiso_command') -@mock.patch('pungi.phases.extra_isos.add_iso_to_metadata') +@mock.patch("pungi.phases.extra_isos.prepare_media_metadata") +@mock.patch("pungi.phases.extra_isos.get_volume_id") +@mock.patch("pungi.phases.extra_isos.get_filename") +@mock.patch("pungi.phases.extra_isos.get_iso_contents") +@mock.patch("pungi.phases.extra_isos.get_extra_files") +@mock.patch("pungi.phases.extra_isos.run_createiso_command") +@mock.patch("pungi.phases.extra_isos.add_iso_to_metadata") class ExtraIsosThreadTest(helpers.PungiTestCase): - def test_binary_bootable_image(self, aitm, rcc, gef, gic, gfn, gvi, pmm): - compose = helpers.DummyCompose(self.topdir, { - 'bootable': True, - 'buildinstall_method': 'lorax' - }) - server = compose.variants['Server'] - cfg = { - 'include_variants': ['Client'], - } - - gfn.return_value = 'my.iso' - gvi.return_value = 'my volume id' - gic.return_value = '/tmp/iso-graft-points' - - t = extra_isos.ExtraIsosThread(mock.Mock()) - with mock.patch('time.sleep'): - t.process((compose, cfg, server, 'x86_64'), 1) - - self.assertEqual(gfn.call_args_list, - [mock.call(compose, server, 'x86_64', None)]) - self.assertEqual(gvi.call_args_list, - [mock.call(compose, server, 'x86_64', [])]) - self.assertEqual(gef.call_args_list, - [mock.call(compose, server, 'x86_64', [])]) - self.assertEqual( - gic.call_args_list, - [ - mock.call( - compose, - server, - 'x86_64', - ['Client'], - 'my.iso', - bootable=True, - inherit_extra_files=False, - ), - ], + compose = helpers.DummyCompose( + self.topdir, {"bootable": True, "buildinstall_method": "lorax"} ) - self.assertEqual( - rcc.call_args_list, - [mock.call(1, compose, True, 'x86_64', - ['bash', os.path.join(self.topdir, 'work/x86_64/tmp-Server/extraiso-my.iso.sh')], - [self.topdir], - log_file=os.path.join(self.topdir, 'logs/x86_64/extraiso-my.iso.x86_64.log'), - with_jigdo=True)] - - ) - self.assertEqual( - aitm.call_args_list, - [mock.call(compose, server, 'x86_64', - os.path.join(self.topdir, 'compose/Server/x86_64/iso/my.iso'), - True, additional_variants=["Client"])] - ) - self.assertEqual(pmm.call_args_list, [mock.call(compose, server, "x86_64")]) - - def test_binary_bootable_image_without_jigdo(self, aitm, rcc, gef, gic, gfn, gvi, pmm): - compose = helpers.DummyCompose(self.topdir, { - 'bootable': True, - 'buildinstall_method': 'lorax', - 'create_jigdo': False, - }) - server = compose.variants['Server'] - cfg = { - 'include_variants': ['Client'], - } - - gfn.return_value = 'my.iso' - gvi.return_value = 'my volume id' - gic.return_value = '/tmp/iso-graft-points' - - t = extra_isos.ExtraIsosThread(mock.Mock()) - with mock.patch('time.sleep'): - t.process((compose, cfg, server, 'x86_64'), 1) - - self.assertEqual(gfn.call_args_list, - [mock.call(compose, server, 'x86_64', None)]) - self.assertEqual(gvi.call_args_list, - [mock.call(compose, server, 'x86_64', [])]) - self.assertEqual(gef.call_args_list, - [mock.call(compose, server, 'x86_64', [])]) - self.assertEqual( - gic.call_args_list, - [ - mock.call( - compose, - server, - 'x86_64', - ['Client'], - 'my.iso', - bootable=True, - inherit_extra_files=False, - ), - ], - ) - self.assertEqual( - rcc.call_args_list, - [mock.call(1, compose, True, 'x86_64', - ['bash', os.path.join(self.topdir, 'work/x86_64/tmp-Server/extraiso-my.iso.sh')], - [self.topdir], - log_file=os.path.join(self.topdir, 'logs/x86_64/extraiso-my.iso.x86_64.log'), - with_jigdo=False)] - - ) - self.assertEqual( - aitm.call_args_list, - [mock.call(compose, server, 'x86_64', - os.path.join(self.topdir, 'compose/Server/x86_64/iso/my.iso'), - True, additional_variants=["Client"])] - ) - self.assertEqual(pmm.call_args_list, [mock.call(compose, server, "x86_64")]) - - def test_image_with_max_size(self, aitm, rcc, gef, gic, gfn, gvi, pmm): - compose = helpers.DummyCompose(self.topdir, { - "bootable": True, - "buildinstall_method": "lorax" - }) server = compose.variants["Server"] cfg = { "include_variants": ["Client"], - "max_size": 15, } gfn.return_value = "my.iso" @@ -236,12 +111,11 @@ class ExtraIsosThreadTest(helpers.PungiTestCase): with mock.patch("time.sleep"): t.process((compose, cfg, server, "x86_64"), 1) - self.assertEqual(gfn.call_args_list, - [mock.call(compose, server, "x86_64", None)]) - self.assertEqual(gvi.call_args_list, - [mock.call(compose, server, "x86_64", [])]) - self.assertEqual(gef.call_args_list, - [mock.call(compose, server, "x86_64", [])]) + self.assertEqual( + gfn.call_args_list, [mock.call(compose, server, "x86_64", None)] + ) + self.assertEqual(gvi.call_args_list, [mock.call(compose, server, "x86_64", [])]) + self.assertEqual(gef.call_args_list, [mock.call(compose, server, "x86_64", [])]) self.assertEqual( gic.call_args_list, [ @@ -258,54 +132,225 @@ class ExtraIsosThreadTest(helpers.PungiTestCase): ) self.assertEqual( rcc.call_args_list, - [mock.call(1, compose, True, "x86_64", - ["bash", os.path.join(self.topdir, "work/x86_64/tmp-Server/extraiso-my.iso.sh")], - [self.topdir], - log_file=os.path.join(self.topdir, "logs/x86_64/extraiso-my.iso.x86_64.log"), - with_jigdo=True)] - + [ + mock.call( + 1, + compose, + True, + "x86_64", + [ + "bash", + os.path.join( + self.topdir, "work/x86_64/tmp-Server/extraiso-my.iso.sh" + ), + ], + [self.topdir], + log_file=os.path.join( + self.topdir, "logs/x86_64/extraiso-my.iso.x86_64.log" + ), + with_jigdo=True, + ) + ], ) self.assertEqual( aitm.call_args_list, - [mock.call(compose, server, "x86_64", - os.path.join(self.topdir, "compose/Server/x86_64/iso/my.iso"), - True, additional_variants=["Client"])] + [ + mock.call( + compose, + server, + "x86_64", + os.path.join(self.topdir, "compose/Server/x86_64/iso/my.iso"), + True, + additional_variants=["Client"], + ) + ], + ) + self.assertEqual(pmm.call_args_list, [mock.call(compose, server, "x86_64")]) + + def test_binary_bootable_image_without_jigdo( + self, aitm, rcc, gef, gic, gfn, gvi, pmm + ): + compose = helpers.DummyCompose( + self.topdir, + {"bootable": True, "buildinstall_method": "lorax", "create_jigdo": False}, + ) + server = compose.variants["Server"] + cfg = { + "include_variants": ["Client"], + } + + gfn.return_value = "my.iso" + gvi.return_value = "my volume id" + gic.return_value = "/tmp/iso-graft-points" + + t = extra_isos.ExtraIsosThread(mock.Mock()) + with mock.patch("time.sleep"): + t.process((compose, cfg, server, "x86_64"), 1) + + self.assertEqual( + gfn.call_args_list, [mock.call(compose, server, "x86_64", None)] + ) + self.assertEqual(gvi.call_args_list, [mock.call(compose, server, "x86_64", [])]) + self.assertEqual(gef.call_args_list, [mock.call(compose, server, "x86_64", [])]) + self.assertEqual( + gic.call_args_list, + [ + mock.call( + compose, + server, + "x86_64", + ["Client"], + "my.iso", + bootable=True, + inherit_extra_files=False, + ), + ], + ) + self.assertEqual( + rcc.call_args_list, + [ + mock.call( + 1, + compose, + True, + "x86_64", + [ + "bash", + os.path.join( + self.topdir, "work/x86_64/tmp-Server/extraiso-my.iso.sh" + ), + ], + [self.topdir], + log_file=os.path.join( + self.topdir, "logs/x86_64/extraiso-my.iso.x86_64.log" + ), + with_jigdo=False, + ) + ], + ) + self.assertEqual( + aitm.call_args_list, + [ + mock.call( + compose, + server, + "x86_64", + os.path.join(self.topdir, "compose/Server/x86_64/iso/my.iso"), + True, + additional_variants=["Client"], + ) + ], + ) + self.assertEqual(pmm.call_args_list, [mock.call(compose, server, "x86_64")]) + + def test_image_with_max_size(self, aitm, rcc, gef, gic, gfn, gvi, pmm): + compose = helpers.DummyCompose( + self.topdir, {"bootable": True, "buildinstall_method": "lorax"} + ) + server = compose.variants["Server"] + cfg = { + "include_variants": ["Client"], + "max_size": 15, + } + + gfn.return_value = "my.iso" + gvi.return_value = "my volume id" + gic.return_value = "/tmp/iso-graft-points" + + t = extra_isos.ExtraIsosThread(mock.Mock()) + with mock.patch("time.sleep"): + t.process((compose, cfg, server, "x86_64"), 1) + + self.assertEqual( + gfn.call_args_list, [mock.call(compose, server, "x86_64", None)] + ) + self.assertEqual(gvi.call_args_list, [mock.call(compose, server, "x86_64", [])]) + self.assertEqual(gef.call_args_list, [mock.call(compose, server, "x86_64", [])]) + self.assertEqual( + gic.call_args_list, + [ + mock.call( + compose, + server, + "x86_64", + ["Client"], + "my.iso", + bootable=True, + inherit_extra_files=False, + ), + ], + ) + self.assertEqual( + rcc.call_args_list, + [ + mock.call( + 1, + compose, + True, + "x86_64", + [ + "bash", + os.path.join( + self.topdir, "work/x86_64/tmp-Server/extraiso-my.iso.sh" + ), + ], + [self.topdir], + log_file=os.path.join( + self.topdir, "logs/x86_64/extraiso-my.iso.x86_64.log" + ), + with_jigdo=True, + ) + ], + ) + self.assertEqual( + aitm.call_args_list, + [ + mock.call( + compose, + server, + "x86_64", + os.path.join(self.topdir, "compose/Server/x86_64/iso/my.iso"), + True, + additional_variants=["Client"], + ) + ], ) self.assertEqual(aitm.return_value._max_size, 15) self.assertEqual(pmm.call_args_list, [mock.call(compose, server, "x86_64")]) def test_binary_image_custom_naming(self, aitm, rcc, gef, gic, gfn, gvi, pmm): compose = helpers.DummyCompose(self.topdir, {}) - server = compose.variants['Server'] + server = compose.variants["Server"] cfg = { - 'include_variants': ['Client'], - 'filename': 'fn', - 'volid': ['v1', 'v2'], + "include_variants": ["Client"], + "filename": "fn", + "volid": ["v1", "v2"], } - gfn.return_value = 'my.iso' - gvi.return_value = 'my volume id' - gic.return_value = '/tmp/iso-graft-points' + gfn.return_value = "my.iso" + gvi.return_value = "my volume id" + gic.return_value = "/tmp/iso-graft-points" t = extra_isos.ExtraIsosThread(mock.Mock()) - with mock.patch('time.sleep'): - t.process((compose, cfg, server, 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cfg, server, "x86_64"), 1) - self.assertEqual(gfn.call_args_list, - [mock.call(compose, server, 'x86_64', 'fn')]) - self.assertEqual(gvi.call_args_list, - [mock.call(compose, server, 'x86_64', ['v1', 'v2'])]) - self.assertEqual(gef.call_args_list, - [mock.call(compose, server, 'x86_64', [])]) + self.assertEqual( + gfn.call_args_list, [mock.call(compose, server, "x86_64", "fn")] + ) + self.assertEqual( + gvi.call_args_list, [mock.call(compose, server, "x86_64", ["v1", "v2"])] + ) + self.assertEqual(gef.call_args_list, [mock.call(compose, server, "x86_64", [])]) self.assertEqual( gic.call_args_list, [ mock.call( compose, server, - 'x86_64', - ['Client'], - 'my.iso', + "x86_64", + ["Client"], + "my.iso", bootable=False, inherit_extra_files=False, ), @@ -313,54 +358,70 @@ class ExtraIsosThreadTest(helpers.PungiTestCase): ) self.assertEqual( rcc.call_args_list, - [mock.call(1, compose, False, 'x86_64', - ['bash', os.path.join(self.topdir, 'work/x86_64/tmp-Server/extraiso-my.iso.sh')], - [self.topdir], - log_file=os.path.join(self.topdir, 'logs/x86_64/extraiso-my.iso.x86_64.log'), - with_jigdo=True)] - + [ + mock.call( + 1, + compose, + False, + "x86_64", + [ + "bash", + os.path.join( + self.topdir, "work/x86_64/tmp-Server/extraiso-my.iso.sh" + ), + ], + [self.topdir], + log_file=os.path.join( + self.topdir, "logs/x86_64/extraiso-my.iso.x86_64.log" + ), + with_jigdo=True, + ) + ], ) self.assertEqual( aitm.call_args_list, - [mock.call(compose, server, 'x86_64', - os.path.join(self.topdir, 'compose/Server/x86_64/iso/my.iso'), - False, additional_variants=["Client"])] + [ + mock.call( + compose, + server, + "x86_64", + os.path.join(self.topdir, "compose/Server/x86_64/iso/my.iso"), + False, + additional_variants=["Client"], + ) + ], ) self.assertEqual(pmm.call_args_list, [mock.call(compose, server, "x86_64")]) def test_source_is_not_bootable(self, aitm, rcc, gef, gic, gfn, gvi, pmm): - compose = helpers.DummyCompose(self.topdir, { - 'bootable': True, - 'buildinstall_method': 'lorax' - }) - server = compose.variants['Server'] + compose = helpers.DummyCompose( + self.topdir, {"bootable": True, "buildinstall_method": "lorax"} + ) + server = compose.variants["Server"] cfg = { - 'include_variants': ['Client'], + "include_variants": ["Client"], } - gfn.return_value = 'my.iso' - gvi.return_value = 'my volume id' - gic.return_value = '/tmp/iso-graft-points' + gfn.return_value = "my.iso" + gvi.return_value = "my volume id" + gic.return_value = "/tmp/iso-graft-points" t = extra_isos.ExtraIsosThread(mock.Mock()) - with mock.patch('time.sleep'): - t.process((compose, cfg, server, 'src'), 1) + with mock.patch("time.sleep"): + t.process((compose, cfg, server, "src"), 1) - self.assertEqual(gfn.call_args_list, - [mock.call(compose, server, 'src', None)]) - self.assertEqual(gvi.call_args_list, - [mock.call(compose, server, 'src', [])]) - self.assertEqual(gef.call_args_list, - [mock.call(compose, server, 'src', [])]) + self.assertEqual(gfn.call_args_list, [mock.call(compose, server, "src", None)]) + self.assertEqual(gvi.call_args_list, [mock.call(compose, server, "src", [])]) + self.assertEqual(gef.call_args_list, [mock.call(compose, server, "src", [])]) self.assertEqual( gic.call_args_list, [ mock.call( compose, server, - 'src', - ['Client'], - 'my.iso', + "src", + ["Client"], + "my.iso", bootable=False, inherit_extra_files=False, ), @@ -368,70 +429,89 @@ class ExtraIsosThreadTest(helpers.PungiTestCase): ) self.assertEqual( rcc.call_args_list, - [mock.call(1, compose, False, 'src', - ['bash', os.path.join(self.topdir, 'work/src/tmp-Server/extraiso-my.iso.sh')], - [self.topdir], - log_file=os.path.join(self.topdir, 'logs/src/extraiso-my.iso.src.log'), - with_jigdo=True)] - + [ + mock.call( + 1, + compose, + False, + "src", + [ + "bash", + os.path.join( + self.topdir, "work/src/tmp-Server/extraiso-my.iso.sh" + ), + ], + [self.topdir], + log_file=os.path.join( + self.topdir, "logs/src/extraiso-my.iso.src.log" + ), + with_jigdo=True, + ) + ], ) self.assertEqual( aitm.call_args_list, - [mock.call(compose, server, 'src', - os.path.join(self.topdir, 'compose/Server/source/iso/my.iso'), - False, additional_variants=["Client"])] + [ + mock.call( + compose, + server, + "src", + os.path.join(self.topdir, "compose/Server/source/iso/my.iso"), + False, + additional_variants=["Client"], + ) + ], ) self.assertEqual(pmm.call_args_list, [mock.call(compose, server, "src")]) def test_failable_failed(self, aitm, rcc, gef, gic, gfn, gvi, pmm): compose = helpers.DummyCompose(self.topdir, {}) - server = compose.variants['Server'] + server = compose.variants["Server"] cfg = { - 'include_variants': ['Client'], - 'failable_arches': ['x86_64'], + "include_variants": ["Client"], + "failable_arches": ["x86_64"], } - gfn.return_value = 'my.iso' - gvi.return_value = 'my volume id' - gic.return_value = '/tmp/iso-graft-points' + gfn.return_value = "my.iso" + gvi.return_value = "my volume id" + gic.return_value = "/tmp/iso-graft-points" rcc.side_effect = helpers.mk_boom() t = extra_isos.ExtraIsosThread(mock.Mock()) - with mock.patch('time.sleep'): - t.process((compose, cfg, server, 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cfg, server, "x86_64"), 1) self.assertEqual(aitm.call_args_list, []) def test_non_failable_failed(self, aitm, rcc, gef, gic, gfn, gvi, pmm): compose = helpers.DummyCompose(self.topdir, {}) - server = compose.variants['Server'] + server = compose.variants["Server"] cfg = { - 'include_variants': ['Client'], + "include_variants": ["Client"], } - gfn.return_value = 'my.iso' - gvi.return_value = 'my volume id' - gic.return_value = '/tmp/iso-graft-points' + gfn.return_value = "my.iso" + gvi.return_value = "my volume id" + gic.return_value = "/tmp/iso-graft-points" rcc.side_effect = helpers.mk_boom(RuntimeError) t = extra_isos.ExtraIsosThread(mock.Mock()) with self.assertRaises(RuntimeError): - with mock.patch('time.sleep'): - t.process((compose, cfg, server, 'x86_64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cfg, server, "x86_64"), 1) self.assertEqual(aitm.call_args_list, []) @mock.patch("pungi.metadata.populate_extra_files_metadata") -@mock.patch('pungi.phases.extra_isos.get_file_from_scm') -@mock.patch('pungi.phases.extra_isos.get_dir_from_scm') +@mock.patch("pungi.phases.extra_isos.get_file_from_scm") +@mock.patch("pungi.phases.extra_isos.get_dir_from_scm") class GetExtraFilesTest(helpers.PungiTestCase): - def setUp(self): super(GetExtraFilesTest, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) - self.variant = self.compose.variants['Server'] - self.arch = 'x86_64' + self.variant = self.compose.variants["Server"] + self.arch = "x86_64" self.dir = os.path.join( self.topdir, "work", self.arch, self.variant.uid, "extra-iso-extra-files" ) @@ -446,21 +526,17 @@ class GetExtraFilesTest(helpers.PungiTestCase): def test_get_file(self, get_dir, get_file, populate_md): get_file.return_value = ["GPL"] cfg = { - 'scm': 'git', - 'repo': 'https://pagure.io/pungi.git', - 'file': 'GPL', - 'target': 'legalese', + "scm": "git", + "repo": "https://pagure.io/pungi.git", + "file": "GPL", + "target": "legalese", } extra_isos.get_extra_files(self.compose, self.variant, self.arch, [cfg]) self.assertEqual(get_dir.call_args_list, []) self.assertEqual( get_file.call_args_list, - [ - mock.call( - cfg, os.path.join(self.dir, "legalese"), compose=self.compose - ), - ], + [mock.call(cfg, os.path.join(self.dir, "legalese"), compose=self.compose)], ) self.assertEqual( populate_md.call_args_list, @@ -479,10 +555,10 @@ class GetExtraFilesTest(helpers.PungiTestCase): def test_get_dir(self, get_dir, get_file, populate_md): get_dir.return_value = ["a", "b"] cfg = { - 'scm': 'git', - 'repo': 'https://pagure.io/pungi.git', - 'dir': 'docs', - 'target': 'foo', + "scm": "git", + "repo": "https://pagure.io/pungi.git", + "dir": "docs", + "target": "foo", } extra_isos.get_extra_files(self.compose, self.variant, self.arch, [cfg]) @@ -508,10 +584,10 @@ class GetExtraFilesTest(helpers.PungiTestCase): def test_get_multiple_files(self, get_dir, get_file, populate_md): get_file.side_effect = [["GPL"], ["setup.py"]] cfg1 = { - 'scm': 'git', - 'repo': 'https://pagure.io/pungi.git', - 'file': 'GPL', - 'target': 'legalese', + "scm": "git", + "repo": "https://pagure.io/pungi.git", + "file": "GPL", + "target": "legalese", } cfg2 = {"scm": "git", "repo": "https://pagure.io/pungi.git", "file": "setup.py"} extra_isos.get_extra_files(self.compose, self.variant, self.arch, [cfg1, cfg2]) @@ -521,9 +597,7 @@ class GetExtraFilesTest(helpers.PungiTestCase): get_file.call_args_list, [ mock.call( - cfg1, - os.path.join(self.dir, "legalese"), - compose=self.compose, + cfg1, os.path.join(self.dir, "legalese"), compose=self.compose, ), mock.call(cfg2, self.dir, compose=self.compose), ], @@ -544,34 +618,37 @@ class GetExtraFilesTest(helpers.PungiTestCase): @mock.patch("pungi.phases.extra_isos.tweak_treeinfo") -@mock.patch('pungi.wrappers.iso.write_graft_points') -@mock.patch('pungi.wrappers.iso.get_graft_points') +@mock.patch("pungi.wrappers.iso.write_graft_points") +@mock.patch("pungi.wrappers.iso.get_graft_points") class GetIsoContentsTest(helpers.PungiTestCase): - def setUp(self): super(GetIsoContentsTest, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) - self.variant = self.compose.variants['Server'] + self.variant = self.compose.variants["Server"] def test_non_bootable_binary(self, ggp, wgp, tt): gp = { - 'compose/Client/x86_64/os/Packages': {'f/foo.rpm': '/mnt/f/foo.rpm'}, - 'compose/Client/x86_64/os/repodata': {'primary.xml': '/mnt/repodata/primary.xml'}, - 'compose/Server/x86_64/os/Packages': {'b/bar.rpm': '/mnt/b/bar.rpm'}, - 'compose/Server/x86_64/os/repodata': {'repomd.xml': '/mnt/repodata/repomd.xml'}, - 'work/x86_64/Server/extra-iso-extra-files': {'EULA': '/mnt/EULA'}, + "compose/Client/x86_64/os/Packages": {"f/foo.rpm": "/mnt/f/foo.rpm"}, + "compose/Client/x86_64/os/repodata": { + "primary.xml": "/mnt/repodata/primary.xml" + }, + "compose/Server/x86_64/os/Packages": {"b/bar.rpm": "/mnt/b/bar.rpm"}, + "compose/Server/x86_64/os/repodata": { + "repomd.xml": "/mnt/repodata/repomd.xml" + }, + "work/x86_64/Server/extra-iso-extra-files": {"EULA": "/mnt/EULA"}, } - ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1:]] - gp_file = os.path.join(self.topdir, 'work/x86_64/iso/my.iso-graft-points') + ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1 :]] + gp_file = os.path.join(self.topdir, "work/x86_64/iso/my.iso-graft-points") self.assertEqual( extra_isos.get_iso_contents( self.compose, self.variant, - 'x86_64', - ['Client'], - 'my.iso', + "x86_64", + ["Client"], + "my.iso", False, inherit_extra_files=False, ), @@ -579,22 +656,24 @@ class GetIsoContentsTest(helpers.PungiTestCase): ) expected = { - 'Client/Packages/f/foo.rpm': '/mnt/f/foo.rpm', - 'Client/repodata/primary.xml': '/mnt/repodata/primary.xml', - 'EULA': '/mnt/EULA', - 'Server/Packages/b/bar.rpm': '/mnt/b/bar.rpm', - 'Server/repodata/repomd.xml': '/mnt/repodata/repomd.xml', + "Client/Packages/f/foo.rpm": "/mnt/f/foo.rpm", + "Client/repodata/primary.xml": "/mnt/repodata/primary.xml", + "EULA": "/mnt/EULA", + "Server/Packages/b/bar.rpm": "/mnt/b/bar.rpm", + "Server/repodata/repomd.xml": "/mnt/repodata/repomd.xml", } six.assertCountEqual( self, ggp.call_args_list, - [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp] + [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp], ) self.assertEqual(len(wgp.call_args_list), 1) self.assertEqual(wgp.call_args_list[0][0][0], gp_file) self.assertDictEqual(dict(wgp.call_args_list[0][0][1]), expected) - self.assertEqual(wgp.call_args_list[0][1], {'exclude': ["*/lost+found", "*/boot.iso"]}) + self.assertEqual( + wgp.call_args_list[0][1], {"exclude": ["*/lost+found", "*/boot.iso"]} + ) # Check correct call to tweak_treeinfo self.assertEqual( @@ -607,7 +686,7 @@ class GetIsoContentsTest(helpers.PungiTestCase): os.path.join( self.topdir, "work/x86_64/Server/extra-iso-extra-files/.treeinfo", - ) + ), ), ], ) @@ -615,15 +694,19 @@ class GetIsoContentsTest(helpers.PungiTestCase): def test_inherit_extra_files(self, ggp, wgp, tt): gp = { "compose/Client/x86_64/os/Packages": {"f/foo.rpm": "/mnt/f/foo.rpm"}, - "compose/Client/x86_64/os/repodata": {"primary.xml": "/mnt/repodata/primary.xml"}, + "compose/Client/x86_64/os/repodata": { + "primary.xml": "/mnt/repodata/primary.xml" + }, "compose/Server/x86_64/os/Packages": {"b/bar.rpm": "/mnt/b/bar.rpm"}, - "compose/Server/x86_64/os/repodata": {"repomd.xml": "/mnt/repodata/repomd.xml"}, + "compose/Server/x86_64/os/repodata": { + "repomd.xml": "/mnt/repodata/repomd.xml" + }, "work/x86_64/Client/extra-files": {"GPL": "/mnt/GPL"}, "work/x86_64/Server/extra-files": {"AUTHORS": "/mnt/AUTHORS"}, "work/x86_64/Server/extra-iso-extra-files": {"EULA": "/mnt/EULA"}, } - ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1:]] + ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1 :]] gp_file = os.path.join(self.topdir, "work/x86_64/iso/my.iso-graft-points") self.assertEqual( @@ -652,12 +735,14 @@ class GetIsoContentsTest(helpers.PungiTestCase): six.assertCountEqual( self, ggp.call_args_list, - [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp] + [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp], ) self.assertEqual(len(wgp.call_args_list), 1) self.assertEqual(wgp.call_args_list[0][0][0], gp_file) self.assertDictEqual(dict(wgp.call_args_list[0][0][1]), expected) - self.assertEqual(wgp.call_args_list[0][1], {"exclude": ["*/lost+found", "*/boot.iso"]}) + self.assertEqual( + wgp.call_args_list[0][1], {"exclude": ["*/lost+found", "*/boot.iso"]} + ) # Check correct call to tweak_treeinfo self.assertEqual( @@ -670,30 +755,34 @@ class GetIsoContentsTest(helpers.PungiTestCase): os.path.join( self.topdir, "work/x86_64/Server/extra-iso-extra-files/.treeinfo", - ) + ), ), ], ) def test_source(self, ggp, wgp, tt): gp = { - 'compose/Client/source/tree/Packages': {'f/foo.rpm': '/mnt/f/foo.rpm'}, - 'compose/Client/source/tree/repodata': {'primary.xml': '/mnt/repodata/primary.xml'}, - 'compose/Server/source/tree/Packages': {'b/bar.rpm': '/mnt/b/bar.rpm'}, - 'compose/Server/source/tree/repodata': {'repomd.xml': '/mnt/repodata/repomd.xml'}, - 'work/src/Server/extra-iso-extra-files': {'EULA': '/mnt/EULA'}, + "compose/Client/source/tree/Packages": {"f/foo.rpm": "/mnt/f/foo.rpm"}, + "compose/Client/source/tree/repodata": { + "primary.xml": "/mnt/repodata/primary.xml" + }, + "compose/Server/source/tree/Packages": {"b/bar.rpm": "/mnt/b/bar.rpm"}, + "compose/Server/source/tree/repodata": { + "repomd.xml": "/mnt/repodata/repomd.xml" + }, + "work/src/Server/extra-iso-extra-files": {"EULA": "/mnt/EULA"}, } - ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1:]] - gp_file = os.path.join(self.topdir, 'work/src/iso/my.iso-graft-points') + ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1 :]] + gp_file = os.path.join(self.topdir, "work/src/iso/my.iso-graft-points") self.assertEqual( extra_isos.get_iso_contents( self.compose, self.variant, - 'src', - ['Client'], - 'my.iso', + "src", + ["Client"], + "my.iso", bootable=False, inherit_extra_files=False, ), @@ -701,22 +790,24 @@ class GetIsoContentsTest(helpers.PungiTestCase): ) expected = { - 'Client/Packages/f/foo.rpm': '/mnt/f/foo.rpm', - 'Client/repodata/primary.xml': '/mnt/repodata/primary.xml', - 'EULA': '/mnt/EULA', - 'Server/Packages/b/bar.rpm': '/mnt/b/bar.rpm', - 'Server/repodata/repomd.xml': '/mnt/repodata/repomd.xml', + "Client/Packages/f/foo.rpm": "/mnt/f/foo.rpm", + "Client/repodata/primary.xml": "/mnt/repodata/primary.xml", + "EULA": "/mnt/EULA", + "Server/Packages/b/bar.rpm": "/mnt/b/bar.rpm", + "Server/repodata/repomd.xml": "/mnt/repodata/repomd.xml", } six.assertCountEqual( self, ggp.call_args_list, - [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp] + [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp], ) self.assertEqual(len(wgp.call_args_list), 1) self.assertEqual(wgp.call_args_list[0][0][0], gp_file) self.assertDictEqual(dict(wgp.call_args_list[0][0][1]), expected) - self.assertEqual(wgp.call_args_list[0][1], {'exclude': ["*/lost+found", "*/boot.iso"]}) + self.assertEqual( + wgp.call_args_list[0][1], {"exclude": ["*/lost+found", "*/boot.iso"]} + ) # Check correct call to tweak_treeinfo self.assertEqual( @@ -727,45 +818,52 @@ class GetIsoContentsTest(helpers.PungiTestCase): ["Client"], os.path.join(self.topdir, "compose/Server/source/tree/.treeinfo"), os.path.join( - self.topdir, - "work/src/Server/extra-iso-extra-files/.treeinfo", - ) + self.topdir, "work/src/Server/extra-iso-extra-files/.treeinfo", + ), ), ], ) def test_bootable(self, ggp, wgp, tt): - self.compose.conf['buildinstall_method'] = 'lorax' + self.compose.conf["buildinstall_method"] = "lorax" - bi_dir = os.path.join(self.topdir, 'work/x86_64/buildinstall/Server') - iso_dir = os.path.join(self.topdir, 'work/x86_64/iso/my.iso') - helpers.touch(os.path.join(bi_dir, 'isolinux/isolinux.bin')) - helpers.touch(os.path.join(bi_dir, 'images/boot.img')) - helpers.touch(os.path.join(bi_dir, 'images/efiboot.img')) + bi_dir = os.path.join(self.topdir, "work/x86_64/buildinstall/Server") + iso_dir = os.path.join(self.topdir, "work/x86_64/iso/my.iso") + helpers.touch(os.path.join(bi_dir, "isolinux/isolinux.bin")) + helpers.touch(os.path.join(bi_dir, "images/boot.img")) + helpers.touch(os.path.join(bi_dir, "images/efiboot.img")) gp = { - 'compose/Client/x86_64/os/Packages': {'f/foo.rpm': '/mnt/f/foo.rpm'}, - 'compose/Client/x86_64/os/repodata': {'primary.xml': '/mnt/repodata/primary.xml'}, - 'compose/Server/x86_64/os/Packages': {'b/bar.rpm': '/mnt/b/bar.rpm'}, - 'compose/Server/x86_64/os/repodata': {'repomd.xml': '/mnt/repodata/repomd.xml'}, - 'work/x86_64/Server/extra-iso-extra-files': {'EULA': '/mnt/EULA'}, + "compose/Client/x86_64/os/Packages": {"f/foo.rpm": "/mnt/f/foo.rpm"}, + "compose/Client/x86_64/os/repodata": { + "primary.xml": "/mnt/repodata/primary.xml" + }, + "compose/Server/x86_64/os/Packages": {"b/bar.rpm": "/mnt/b/bar.rpm"}, + "compose/Server/x86_64/os/repodata": { + "repomd.xml": "/mnt/repodata/repomd.xml" + }, + "work/x86_64/Server/extra-iso-extra-files": {"EULA": "/mnt/EULA"}, } bi_gp = { - 'isolinux/isolinux.bin': os.path.join(iso_dir, 'isolinux/isolinux.bin'), - 'images/boot.img': os.path.join(iso_dir, 'images/boot.img'), - 'images/efiboot.img': os.path.join(iso_dir, 'images/efiboot.img'), + "isolinux/isolinux.bin": os.path.join(iso_dir, "isolinux/isolinux.bin"), + "images/boot.img": os.path.join(iso_dir, "images/boot.img"), + "images/efiboot.img": os.path.join(iso_dir, "images/efiboot.img"), } - ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1:]] if len(x) == 1 else bi_gp - gp_file = os.path.join(self.topdir, 'work/x86_64/iso/my.iso-graft-points') + ggp.side_effect = ( + lambda compose, x: gp[x[0][len(self.topdir) + 1 :]] + if len(x) == 1 + else bi_gp + ) + gp_file = os.path.join(self.topdir, "work/x86_64/iso/my.iso-graft-points") self.assertEqual( extra_isos.get_iso_contents( self.compose, self.variant, - 'x86_64', - ['Client'], - 'my.iso', + "x86_64", + ["Client"], + "my.iso", bootable=True, inherit_extra_files=False, ), @@ -775,32 +873,37 @@ class GetIsoContentsTest(helpers.PungiTestCase): self.maxDiff = None expected = { - 'Client/Packages/f/foo.rpm': '/mnt/f/foo.rpm', - 'Client/repodata/primary.xml': '/mnt/repodata/primary.xml', - 'EULA': '/mnt/EULA', - 'Server/Packages/b/bar.rpm': '/mnt/b/bar.rpm', - 'Server/repodata/repomd.xml': '/mnt/repodata/repomd.xml', - 'isolinux/isolinux.bin': os.path.join(iso_dir, 'isolinux/isolinux.bin'), - 'images/boot.img': os.path.join(iso_dir, 'images/boot.img'), - 'images/efiboot.img': os.path.join( - self.topdir, 'compose', self.variant.uid, 'x86_64/os/images/efiboot.img', + "Client/Packages/f/foo.rpm": "/mnt/f/foo.rpm", + "Client/repodata/primary.xml": "/mnt/repodata/primary.xml", + "EULA": "/mnt/EULA", + "Server/Packages/b/bar.rpm": "/mnt/b/bar.rpm", + "Server/repodata/repomd.xml": "/mnt/repodata/repomd.xml", + "isolinux/isolinux.bin": os.path.join(iso_dir, "isolinux/isolinux.bin"), + "images/boot.img": os.path.join(iso_dir, "images/boot.img"), + "images/efiboot.img": os.path.join( + self.topdir, + "compose", + self.variant.uid, + "x86_64/os/images/efiboot.img", ), } six.assertCountEqual( self, ggp.call_args_list, - [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp] + [ - mock.call(self.compose, [bi_dir, iso_dir])] + [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp] + + [mock.call(self.compose, [bi_dir, iso_dir])], ) self.assertEqual(len(wgp.call_args_list), 1) self.assertEqual(wgp.call_args_list[0][0][0], gp_file) self.assertDictEqual(dict(wgp.call_args_list[0][0][1]), expected) - self.assertEqual(wgp.call_args_list[0][1], {'exclude': ["*/lost+found", "*/boot.iso"]}) + self.assertEqual( + wgp.call_args_list[0][1], {"exclude": ["*/lost+found", "*/boot.iso"]} + ) # Check files were copied to temp directory - self.assertTrue(os.path.exists(os.path.join(iso_dir, 'isolinux/isolinux.bin'))) - self.assertTrue(os.path.exists(os.path.join(iso_dir, 'images/boot.img'))) + self.assertTrue(os.path.exists(os.path.join(iso_dir, "isolinux/isolinux.bin"))) + self.assertTrue(os.path.exists(os.path.join(iso_dir, "images/boot.img"))) # Check correct call to tweak_treeinfo self.assertEqual( @@ -813,7 +916,7 @@ class GetIsoContentsTest(helpers.PungiTestCase): os.path.join( self.topdir, "work/x86_64/Server/extra-iso-extra-files/.treeinfo", - ) + ), ), ], ) @@ -823,56 +926,66 @@ class GetFilenameTest(helpers.PungiTestCase): def test_use_original_name(self): compose = helpers.DummyCompose(self.topdir, {}) - fn = extra_isos.get_filename(compose, compose.variants['Server'], 'x86_64', - 'foo-{variant}-{arch}-{filename}') + fn = extra_isos.get_filename( + compose, + compose.variants["Server"], + "x86_64", + "foo-{variant}-{arch}-{filename}", + ) - self.assertEqual(fn, 'foo-Server-x86_64-image-name') + self.assertEqual(fn, "foo-Server-x86_64-image-name") def test_use_default_without_format(self): compose = helpers.DummyCompose(self.topdir, {}) - fn = extra_isos.get_filename(compose, compose.variants['Server'], 'x86_64', - None) + fn = extra_isos.get_filename( + compose, compose.variants["Server"], "x86_64", None + ) - self.assertEqual(fn, 'image-name') + self.assertEqual(fn, "image-name") def test_reports_unknown_placeholder(self): compose = helpers.DummyCompose(self.topdir, {}) with self.assertRaises(RuntimeError) as ctx: - extra_isos.get_filename(compose, compose.variants['Server'], 'x86_64', - 'foo-{boom}') + extra_isos.get_filename( + compose, compose.variants["Server"], "x86_64", "foo-{boom}" + ) - self.assertIn('boom', str(ctx.exception)) + self.assertIn("boom", str(ctx.exception)) class GetVolumeIDTest(helpers.PungiTestCase): def test_use_original_volume_id(self): compose = helpers.DummyCompose(self.topdir, {}) - volid = extra_isos.get_volume_id(compose, compose.variants['Server'], - 'x86_64', - 'f-{volid}') + volid = extra_isos.get_volume_id( + compose, compose.variants["Server"], "x86_64", "f-{volid}" + ) - self.assertEqual(volid, 'f-test-1.0 Server.x86_64') + self.assertEqual(volid, "f-test-1.0 Server.x86_64") def test_falls_back_to_shorter(self): compose = helpers.DummyCompose(self.topdir, {}) - volid = extra_isos.get_volume_id(compose, compose.variants['Server'], - 'x86_64', - ['long-foobar-{volid}', 'f-{volid}']) + volid = extra_isos.get_volume_id( + compose, + compose.variants["Server"], + "x86_64", + ["long-foobar-{volid}", "f-{volid}"], + ) - self.assertEqual(volid, 'f-test-1.0 Server.x86_64') + self.assertEqual(volid, "f-test-1.0 Server.x86_64") def test_reports_unknown_placeholder(self): compose = helpers.DummyCompose(self.topdir, {}) with self.assertRaises(RuntimeError) as ctx: - extra_isos.get_volume_id(compose, compose.variants['Server'], - 'x86_64', 'f-{boom}') + extra_isos.get_volume_id( + compose, compose.variants["Server"], "x86_64", "f-{boom}" + ) - self.assertIn('boom', str(ctx.exception)) + self.assertIn("boom", str(ctx.exception)) class TweakTreeinfoTest(helpers.PungiTestCase): diff --git a/tests/test_fus_wrapper.py b/tests/test_fus_wrapper.py index 0daf31fe..d8bf9e43 100644 --- a/tests/test_fus_wrapper.py +++ b/tests/test_fus_wrapper.py @@ -101,12 +101,11 @@ class TestGetCmd(unittest.TestCase): "x86_64", "--repo=lookaside-0,lookaside,http:///tmp", "@conf", - ] + ], ) class TestWriteConfig(PungiTestCase): - def test_write_sorted_mix(self): f = os.path.join(self.topdir, "solvables") fus.write_config(f, ["moda:master"], ["pkg", "foo"]) @@ -149,8 +148,7 @@ class TestParseOutput(unittest.TestCase): touch(self.file, "*pkg-1.0-1.x86_64@repo-0\n") packages, modules = fus.parse_output(self.file) self.assertEqual( - packages, - set([("pkg-1.0-1", "x86_64", frozenset(["modular"]))]), + packages, set([("pkg-1.0-1", "x86_64", frozenset(["modular"]))]), ) self.assertEqual(modules, set()) diff --git a/tests/test_gather.py b/tests/test_gather.py index cab1e31a..40f4764b 100644 --- a/tests/test_gather.py +++ b/tests/test_gather.py @@ -16,9 +16,11 @@ import logging from six.moves import cStringIO from pungi.wrappers.pungi import PungiWrapper + try: from pungi.dnf_wrapper import DnfWrapper, Conf from pungi.gather_dnf import Gather, GatherOptions, PkgFlag + HAS_DNF = True except ImportError: HAS_DNF = False @@ -36,18 +38,19 @@ def convert_pkg_map(data): """ result = {} for pkg_type in data: - result[pkg_type] = sorted(set([os.path.basename(pkg['path']) - for pkg in data[pkg_type]])) + result[pkg_type] = sorted( + set([os.path.basename(pkg["path"]) for pkg in data[pkg_type]]) + ) return result class DepsolvingBase(object): - def setUp(self): self.tmp_dir = tempfile.mkdtemp(prefix="test_compose_") self.repo = os.path.join(os.path.dirname(__file__), "fixtures/repos/repo") - self.lookaside = os.path.join(os.path.dirname(__file__), - "fixtures/repos/repo-krb5-lookaside") + self.lookaside = os.path.join( + os.path.dirname(__file__), "fixtures/repos/repo-krb5-lookaside" + ) def tearDown(self): shutil.rmtree(self.tmp_dir) @@ -76,7 +79,7 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-kernel-3.1.0-1.x86_64.rpm", # Important + "dummy-kernel-3.1.0-1.x86_64.rpm", # Important "dummy-kernel-headers-3.1.0-1.x86_64.rpm", "dummy-kernel-doc-3.1.0-1.noarch.rpm", ], @@ -88,8 +91,13 @@ class DepsolvingBase(object): packages = [ "dummy-kernel", ] - pkg_map = self.go(packages, None, greedy="none", fulltree=True, - fulltree_excludes=['dummy-kernel']) + pkg_map = self.go( + packages, + None, + greedy="none", + fulltree=True, + fulltree_excludes=["dummy-kernel"], + ) self.assertNotIn("dummy-kernel-3.1.0-1.i686.rpm", pkg_map["rpm"]) @@ -109,9 +117,9 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-kernel-3.1.0-1.x86_64.rpm", # Important + "dummy-kernel-3.1.0-1.x86_64.rpm", # Important "dummy-kernel-headers-3.1.0-1.x86_64.rpm", - "dummy-kernel-doc-3.1.0-1.noarch.rpm", # Important + "dummy-kernel-doc-3.1.0-1.noarch.rpm", # Important ], ) self.assertEqual(pkg_map["srpm"], ["dummy-kernel-3.1.0-1.src.rpm"]) @@ -131,8 +139,8 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-6.ppc64.rpm", # Important - "dummy-bash-doc-4.2.37-6.noarch.rpm", # Important + "dummy-bash-4.2.37-6.ppc64.rpm", # Important + "dummy-bash-doc-4.2.37-6.noarch.rpm", # Important "dummy-filesystem-4.2.37-6.ppc64.rpm", "dummy-glibc-2.14-5.ppc.rpm", "dummy-glibc-2.14-5.ppc64.rpm", @@ -172,8 +180,8 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-foo32-1-1.i686.rpm", # Important - "dummy-foo32-doc-1-1.noarch.rpm", # Important + "dummy-foo32-1-1.i686.rpm", # Important + "dummy-foo32-doc-1-1.noarch.rpm", # Important ], ) self.assertEqual(pkg_map["srpm"], ["dummy-foo32-1-1.src.rpm"]) @@ -181,9 +189,9 @@ class DepsolvingBase(object): def test_bash_exclude_debuginfo(self): packages = [ - 'dummy-bash', - '-dummy-bash-debuginfo', - '-dummy-bash-debugsource', + "dummy-bash", + "-dummy-bash-debuginfo", + "-dummy-bash-debugsource", ] pkg_map = self.go(packages, None, greedy="none") @@ -219,9 +227,9 @@ class DepsolvingBase(object): def test_bash_multilib_exclude_debuginfo(self): packages = [ - 'dummy-bash.+', - '-dummy-bash-debuginfo', - '-dummy-bash-debugsource', + "dummy-bash.+", + "-dummy-bash-debuginfo", + "-dummy-bash-debugsource", ] pkg_map = self.go(packages, None, greedy="none") @@ -272,7 +280,7 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-6.x86_64.rpm", # Important + "dummy-bash-4.2.37-6.x86_64.rpm", # Important "dummy-filesystem-4.2.37-6.x86_64.rpm", "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", @@ -314,7 +322,7 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-6.s390x.rpm", # Important + "dummy-bash-4.2.37-6.s390x.rpm", # Important "dummy-filesystem-4.2.37-6.s390x.rpm", "dummy-glibc-2.14-5.s390x.rpm", "dummy-glibc-common-2.14-5.s390x.rpm", @@ -356,8 +364,8 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-6.i686.rpm", # Important - "dummy-bash-4.2.37-6.x86_64.rpm", # Important + "dummy-bash-4.2.37-6.i686.rpm", # Important + "dummy-bash-4.2.37-6.x86_64.rpm", # Important "dummy-filesystem-4.2.37-6.i686.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", "dummy-glibc-2.14-5.i686.rpm", @@ -406,7 +414,7 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-5.x86_64.rpm", # Important + "dummy-bash-4.2.37-5.x86_64.rpm", # Important "dummy-filesystem-4.2.37-6.x86_64.rpm", "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", @@ -439,8 +447,12 @@ class DepsolvingBase(object): ] pkg_map = self.go(packages, None, greedy="none") - self.assertNotIn("dummy-release-client-workstation-1.0.0-1.i686.rpm", pkg_map["rpm"]) - self.assertNotIn("dummy-release-client-workstation-1.0.0-1.x86_64.rpm", pkg_map["rpm"]) + self.assertNotIn( + "dummy-release-client-workstation-1.0.0-1.i686.rpm", pkg_map["rpm"] + ) + self.assertNotIn( + "dummy-release-client-workstation-1.0.0-1.x86_64.rpm", pkg_map["rpm"] + ) self.assertNotIn("dummy-release-client-1.0.0-1.i686.rpm", pkg_map["rpm"]) self.assertNotIn("dummy-release-client-1.0.0-1.x86_64.rpm", pkg_map["rpm"]) self.assertNotIn("dummy-release-server-1.0.0-1.i686.rpm", pkg_map["rpm"]) @@ -463,12 +475,12 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-release-client-1.0.0-1.i686.rpm", # Important - "dummy-release-client-1.0.0-1.x86_64.rpm", # Important - "dummy-release-client-workstation-1.0.0-1.i686.rpm", # Important + "dummy-release-client-1.0.0-1.i686.rpm", # Important + "dummy-release-client-1.0.0-1.x86_64.rpm", # Important + "dummy-release-client-workstation-1.0.0-1.i686.rpm", # Important "dummy-release-client-workstation-1.0.0-1.x86_64.rpm", # Important - "dummy-release-server-1.0.0-1.i686.rpm", # Important - "dummy-release-server-1.0.0-1.x86_64.rpm", # Important + "dummy-release-server-1.0.0-1.i686.rpm", # Important + "dummy-release-server-1.0.0-1.x86_64.rpm", # Important ], ) six.assertCountEqual( @@ -500,7 +512,7 @@ class DepsolvingBase(object): "dummy-filesystem-4.2.37-6.x86_64.rpm", "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", - "dummy-postfix-2.9.2-2.x86_64.rpm", # Important + "dummy-postfix-2.9.2-2.x86_64.rpm", # Important "dummy-vacation-1.2.7.1-1.x86_64.rpm", ], ) @@ -545,7 +557,7 @@ class DepsolvingBase(object): "dummy-filesystem-4.2.37-6.x86_64.rpm", "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", - "dummy-sendmail-8.14.5-12.x86_64.rpm", # Important + "dummy-sendmail-8.14.5-12.x86_64.rpm", # Important "dummy-vacation-1.2.7.1-1.x86_64.rpm", ], ) @@ -588,10 +600,10 @@ class DepsolvingBase(object): "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.i686.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", - "dummy-postfix-2.9.2-2.i686.rpm", # Important - "dummy-postfix-2.9.2-2.x86_64.rpm", # Important - "dummy-sendmail-8.14.5-12.i686.rpm", # Important - "dummy-sendmail-8.14.5-12.x86_64.rpm", # Important + "dummy-postfix-2.9.2-2.i686.rpm", # Important + "dummy-postfix-2.9.2-2.x86_64.rpm", # Important + "dummy-sendmail-8.14.5-12.i686.rpm", # Important + "dummy-sendmail-8.14.5-12.x86_64.rpm", # Important "dummy-vacation-1.2.7.1-1.i686.rpm", "dummy-vacation-1.2.7.1-1.x86_64.rpm", ], @@ -756,7 +768,7 @@ class DepsolvingBase(object): [ "dummy-basesystem-10.0-6.noarch.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", - "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important + "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", "Dummy-xulrunner-16.0.1-1.x86_64.rpm", @@ -802,11 +814,11 @@ class DepsolvingBase(object): "dummy-bash-4.2.37-6.x86_64.rpm", "dummy-basesystem-10.0-6.noarch.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", - "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important + "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", "dummy-krb5-1.10-5.x86_64.rpm", - "dummy-krb5-devel-1.10-5.x86_64.rpm", # Important + "dummy-krb5-devel-1.10-5.x86_64.rpm", # Important "dummy-krb5-libs-1.10-5.x86_64.rpm", "Dummy-xulrunner-16.0.1-1.x86_64.rpm", ], @@ -831,8 +843,8 @@ class DepsolvingBase(object): "dummy-bash-debuginfo-4.2.37-6.x86_64.rpm", "dummy-bash-debugsource-4.2.37-6.x86_64.rpm", "Dummy-firefox-debuginfo-16.0.1-1.x86_64.rpm", - "dummy-glibc-debuginfo-2.14-5.x86_64.rpm", # Important - "dummy-glibc-debuginfo-common-2.14-5.x86_64.rpm", # Important + "dummy-glibc-debuginfo-2.14-5.x86_64.rpm", # Important + "dummy-glibc-debuginfo-common-2.14-5.x86_64.rpm", # Important "dummy-krb5-debuginfo-1.10-5.x86_64.rpm", "Dummy-xulrunner-debuginfo-16.0.1-1.x86_64.rpm", ], @@ -855,7 +867,7 @@ class DepsolvingBase(object): [ "dummy-basesystem-10.0-6.noarch.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", - "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important + "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", "Dummy-xulrunner-16.0.1-1.x86_64.rpm", @@ -892,10 +904,11 @@ class DepsolvingBase(object): # # By default newer version should be pulled in. self.repo = os.path.join(os.path.dirname(__file__), "fixtures/repos/cockpit") - self.lookaside = os.path.join(os.path.dirname(__file__), - "fixtures/repos/cockpit-lookaside") + self.lookaside = os.path.join( + os.path.dirname(__file__), "fixtures/repos/cockpit-lookaside" + ) packages = [ - 'dummy-cockpit-docker', + "dummy-cockpit-docker", ] pkg_map = self.go(packages, None, lookaside=self.lookaside) @@ -920,11 +933,12 @@ class DepsolvingBase(object): # satisfied by the older version in lookaside. No broken dependencies # should be reported. self.repo = os.path.join(os.path.dirname(__file__), "fixtures/repos/cockpit") - self.lookaside = os.path.join(os.path.dirname(__file__), - "fixtures/repos/cockpit-lookaside") + self.lookaside = os.path.join( + os.path.dirname(__file__), "fixtures/repos/cockpit-lookaside" + ) packages = [ - 'dummy-cockpit-docker', - '-dummy-cockpit-system', + "dummy-cockpit-docker", + "-dummy-cockpit-system", ] pkg_map = self.go(packages, None, lookaside=self.lookaside) @@ -949,7 +963,7 @@ class DepsolvingBase(object): [ "dummy-basesystem-10.0-6.noarch.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", - "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important + "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", "dummy-nscd-2.14-5.x86_64.rpm", @@ -982,7 +996,9 @@ class DepsolvingBase(object): packages = [ "Dummy-firefox", ] - pkg_map = self.go(packages, None, greedy="none", selfhosting=True, fulltree=True) + pkg_map = self.go( + packages, None, greedy="none", selfhosting=True, fulltree=True + ) self.assertNotIn("Dummy-firefox-16.0.1-2.i686.rpm", pkg_map["rpm"]) self.assertNotIn("dummy-krb5-devel-1.10-5.i686.rpm", pkg_map["rpm"]) @@ -996,13 +1012,13 @@ class DepsolvingBase(object): "dummy-bash-doc-4.2.37-6.noarch.rpm", "dummy-basesystem-10.0-6.noarch.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", - "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important + "Dummy-firefox-16.0.1-1.x86_64.rpm", # Important "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", "dummy-krb5-1.10-5.x86_64.rpm", - "dummy-krb5-devel-1.10-5.x86_64.rpm", # Important + "dummy-krb5-devel-1.10-5.x86_64.rpm", # Important "dummy-krb5-libs-1.10-5.x86_64.rpm", - "dummy-krb5-workstation-1.10-5.x86_64.rpm", # Important + "dummy-krb5-workstation-1.10-5.x86_64.rpm", # Important "dummy-nscd-2.14-5.x86_64.rpm", "Dummy-xulrunner-16.0.1-1.x86_64.rpm", ], @@ -1052,9 +1068,9 @@ class DepsolvingBase(object): "dummy-glibc-2.14-5.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", "dummy-krb5-1.10-5.x86_64.rpm", - "dummy-krb5-devel-1.10-5.x86_64.rpm", # Important + "dummy-krb5-devel-1.10-5.x86_64.rpm", # Important "dummy-krb5-libs-1.10-5.x86_64.rpm", - "dummy-krb5-workstation-1.10-5.x86_64.rpm", # Important + "dummy-krb5-workstation-1.10-5.x86_64.rpm", # Important "dummy-nscd-2.14-5.x86_64.rpm", ], ) @@ -1092,7 +1108,7 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-6.i686.rpm", # Important + "dummy-bash-4.2.37-6.i686.rpm", # Important "dummy-bash-doc-4.2.37-6.noarch.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", "dummy-glibc-2.14-5.i686.rpm", @@ -1128,7 +1144,7 @@ class DepsolvingBase(object): packages = [ "dummy-glibc*", ] - pkg_map = self.go(packages, None, multilib_blacklist=['dummy-glibc*']) + pkg_map = self.go(packages, None, multilib_blacklist=["dummy-glibc*"]) six.assertCountEqual( self, @@ -1175,7 +1191,7 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-6.i686.rpm", # Important + "dummy-bash-4.2.37-6.i686.rpm", # Important "dummy-filesystem-4.2.37-6.x86_64.rpm", "dummy-glibc-2.14-5.i686.rpm", "dummy-glibc-2.14-5.x86_64.rpm", @@ -1259,8 +1275,8 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-6.i686.rpm", # Important - "dummy-bash-4.2.37-6.x86_64.rpm", # Important + "dummy-bash-4.2.37-6.i686.rpm", # Important + "dummy-bash-4.2.37-6.x86_64.rpm", # Important "dummy-bash-doc-4.2.37-6.noarch.rpm", "dummy-filesystem-4.2.37-6.i686.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", @@ -1297,7 +1313,7 @@ class DepsolvingBase(object): ], ) - @unittest.skip('This test is broken') + @unittest.skip("This test is broken") def test_bash_multilib_nogreedy(self): packages = [ "dummy-bash.+", @@ -1311,7 +1327,7 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-6.i686.rpm", # Important + "dummy-bash-4.2.37-6.i686.rpm", # Important "dummy-bash-doc-4.2.37-6.noarch.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", # "dummy-glibc-2.14-5.i686.rpm", @@ -1357,7 +1373,7 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-basesystem-10.0-6.noarch.rpm", - "dummy-bash-4.2.37-6.x86_64.rpm", # Important + "dummy-bash-4.2.37-6.x86_64.rpm", # Important "dummy-bash-doc-4.2.37-6.noarch.rpm", "dummy-filesystem-4.2.37-6.i686.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", @@ -1425,13 +1441,11 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-kmod-ipw3945-1.2.0-4.20.x86_64.rpm", # Important + "dummy-kmod-ipw3945-1.2.0-4.20.x86_64.rpm", # Important "dummy-kmod-ipw3945-xen-1.2.0-4.20.x86_64.rpm", ], ) - self.assertEqual( - pkg_map["srpm"], ["dummy-ipw3945-kmod-1.2.0-4.20.src.rpm"] - ) + self.assertEqual(pkg_map["srpm"], ["dummy-ipw3945-kmod-1.2.0-4.20.src.rpm"]) self.assertEqual( pkg_map["debuginfo"], ["dummy-ipw3945-kmod-debuginfo-1.2.0-4.20.x86_64.rpm"] ) @@ -1440,8 +1454,13 @@ class DepsolvingBase(object): packages = [ "dummy-lvm2-devel", ] - pkg_map = self.go(packages, None, greedy="none", fulltree=False, - multilib_methods=["devel", "runtime"]) + pkg_map = self.go( + packages, + None, + greedy="none", + fulltree=False, + multilib_methods=["devel", "runtime"], + ) six.assertCountEqual( self, @@ -1453,8 +1472,8 @@ class DepsolvingBase(object): "dummy-glibc-2.14-5.i686.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", "dummy-lvm2-2.02.84-4.x86_64.rpm", - "dummy-lvm2-devel-2.02.84-4.i686.rpm", # Important - "dummy-lvm2-devel-2.02.84-4.x86_64.rpm", # Important + "dummy-lvm2-devel-2.02.84-4.i686.rpm", # Important + "dummy-lvm2-devel-2.02.84-4.x86_64.rpm", # Important "dummy-lvm2-libs-2.02.84-4.x86_64.rpm", ], ) @@ -1491,8 +1510,8 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-freeipa-server-2.2.0-1.ppc64.rpm", # Important - "dummy-selinux-policy-mls-3.10.0-121.noarch.rpm", # Important + "dummy-freeipa-server-2.2.0-1.ppc64.rpm", # Important + "dummy-selinux-policy-mls-3.10.0-121.noarch.rpm", # Important ], ) six.assertCountEqual( @@ -1515,10 +1534,10 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-freeipa-server-2.2.0-1.ppc64.rpm", # Important + "dummy-freeipa-server-2.2.0-1.ppc64.rpm", # Important "dummy-selinux-policy-minimal-3.10.0-121.noarch.rpm", - "dummy-selinux-policy-mls-3.10.0-121.noarch.rpm", # Important - "dummy-selinux-policy-targeted-3.10.0-121.noarch.rpm" + "dummy-selinux-policy-mls-3.10.0-121.noarch.rpm", # Important + "dummy-selinux-policy-targeted-3.10.0-121.noarch.rpm", ], ) six.assertCountEqual( @@ -1538,13 +1557,15 @@ class DepsolvingBase(object): ] pkg_map = self.go(packages, None, greedy="none", fulltree=False, arch="ppc64") - self.assertNotIn("dummy-selinux-policy-mls-3.10.0-121.noarch.rpm", pkg_map["rpm"]) + self.assertNotIn( + "dummy-selinux-policy-mls-3.10.0-121.noarch.rpm", pkg_map["rpm"] + ) six.assertCountEqual( self, pkg_map["rpm"], [ - "dummy-freeipa-server-2.2.0-1.ppc64.rpm", # Important + "dummy-freeipa-server-2.2.0-1.ppc64.rpm", # Important "dummy-selinux-policy-targeted-3.10.0-121.noarch.rpm", # Important ], ) @@ -1559,9 +1580,7 @@ class DepsolvingBase(object): self.assertEqual(pkg_map["debuginfo"], []) def test_selinux_policy_doc_fulltree(self): - packages = [ - "dummy-selinux-policy-doc" - ] + packages = ["dummy-selinux-policy-doc"] pkg_map = self.go(packages, None, fulltree=True) six.assertCountEqual( @@ -1587,7 +1606,7 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-AdobeReader_enu-9.5.1-1.i486.rpm", # Important + "dummy-AdobeReader_enu-9.5.1-1.i486.rpm", # Important "dummy-basesystem-10.0-6.noarch.rpm", "dummy-filesystem-4.2.37-6.x86_64.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", @@ -1626,8 +1645,8 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-imsettings-1.2.9-1.x86_64.rpm", # Important - "dummy-imsettings-qt-1.2.9-1.x86_64.rpm", # Important + "dummy-imsettings-1.2.9-1.x86_64.rpm", # Important + "dummy-imsettings-qt-1.2.9-1.x86_64.rpm", # Important ], ) self.assertEqual(pkg_map["srpm"], ["dummy-imsettings-1.2.9-1.src.rpm"]) @@ -1637,10 +1656,10 @@ class DepsolvingBase(object): packages = [ "dummy-imsettings", ] - groups = [ - "basic-desktop" - ] - pkg_map = self.go(packages, groups, greedy="none", fulltree=False, arch="x86_64") + groups = ["basic-desktop"] + pkg_map = self.go( + packages, groups, greedy="none", fulltree=False, arch="x86_64" + ) self.assertNotIn("dummy-imsettings-qt-1.2.9-1.x86_64.rpm", pkg_map["rpm"]) # prefers gnome over qt (condrequires in @basic-desktop) @@ -1649,8 +1668,8 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-imsettings-1.2.9-1.x86_64.rpm", # Important - "dummy-imsettings-gnome-1.2.9-1.x86_64.rpm", # Important + "dummy-imsettings-1.2.9-1.x86_64.rpm", # Important + "dummy-imsettings-gnome-1.2.9-1.x86_64.rpm", # Important ], ) self.assertEqual(pkg_map["srpm"], ["dummy-imsettings-1.2.9-1.src.rpm"]) @@ -1660,11 +1679,10 @@ class DepsolvingBase(object): packages = [ "dummy-imsettings", ] - groups = [ - "basic-desktop" - ] - pkg_map = self.go(packages, groups, greedy="none", fulltree=False, nodeps=True, - arch="x86_64") + groups = ["basic-desktop"] + pkg_map = self.go( + packages, groups, greedy="none", fulltree=False, nodeps=True, arch="x86_64" + ) self.assertNotIn("dummy-imsettings-gnome-1.2.9-1.x86_64.rpm", pkg_map["rpm"]) self.assertNotIn("dummy-imsettings-qt-1.2.9-1.x86_64.rpm", pkg_map["rpm"]) @@ -1679,19 +1697,19 @@ class DepsolvingBase(object): "dummy-imsettings", "dummy-imsettings-qt", ] - groups = [ - "basic-desktop" - ] - pkg_map = self.go(packages, groups, greedy="none", fulltree=False, arch="x86_64") + groups = ["basic-desktop"] + pkg_map = self.go( + packages, groups, greedy="none", fulltree=False, arch="x86_64" + ) # prefers gnome over qt (condrequires in @basic-desktop) six.assertCountEqual( self, pkg_map["rpm"], [ - "dummy-imsettings-1.2.9-1.x86_64.rpm", # Important - "dummy-imsettings-gnome-1.2.9-1.x86_64.rpm", # Important - "dummy-imsettings-qt-1.2.9-1.x86_64.rpm", # Important + "dummy-imsettings-1.2.9-1.x86_64.rpm", # Important + "dummy-imsettings-gnome-1.2.9-1.x86_64.rpm", # Important + "dummy-imsettings-qt-1.2.9-1.x86_64.rpm", # Important ], ) self.assertEqual(pkg_map["srpm"], ["dummy-imsettings-1.2.9-1.src.rpm"]) @@ -1732,7 +1750,7 @@ class DepsolvingBase(object): self, pkg_map["rpm"], [ - "dummy-bash-4.2.37-6.x86_64.rpm", # Important + "dummy-bash-4.2.37-6.x86_64.rpm", # Important "dummy-bash-doc-4.2.37-6.noarch.rpm", ], ) @@ -1751,8 +1769,9 @@ class DepsolvingBase(object): packages = [ "*", ] - pkg_map = self.go(packages, None, lookaside=self.repo, - nodeps=True, fulltree=True) + pkg_map = self.go( + packages, None, lookaside=self.repo, nodeps=True, fulltree=True + ) self.assertEqual(pkg_map["rpm"], []) self.assertEqual(pkg_map["srpm"], []) @@ -1764,8 +1783,7 @@ class DepsolvingBase(object): "-dummy-bas*", "dummy-glibc", ] - pkg_map = self.go(packages, None, - greedy="none", nodeps=True, fulltree=True) + pkg_map = self.go(packages, None, greedy="none", nodeps=True, fulltree=True) # neither dummy-bash or dummy-basesystem is pulled in six.assertCountEqual( @@ -1796,10 +1814,7 @@ class DepsolvingBase(object): six.assertCountEqual( self, pkg_map["rpm"], - [ - "dummy-atlas-3.8.4-7.x86_64.rpm", - "dummy-atlas-devel-3.8.4-7.x86_64.rpm", - ], + ["dummy-atlas-3.8.4-7.x86_64.rpm", "dummy-atlas-devel-3.8.4-7.x86_64.rpm"], ) self.assertEqual(pkg_map["srpm"], ["dummy-atlas-3.8.4-7.src.rpm"]) self.assertEqual(pkg_map["debuginfo"], []) @@ -1827,8 +1842,14 @@ class DepsolvingBase(object): packages = [ "dummy-atlas-devel", ] - pkg_map = self.go(packages, None, greedy="build", multilib_methods=["devel", "runtime"], - fulltree=False, arch="x86_64") + pkg_map = self.go( + packages, + None, + greedy="build", + multilib_methods=["devel", "runtime"], + fulltree=False, + arch="x86_64", + ) six.assertCountEqual( self, @@ -1847,8 +1868,14 @@ class DepsolvingBase(object): packages = [ "dummy-atlas-devel.+", ] - pkg_map = self.go(packages, None, greedy="build", multilib_methods=["devel", "runtime"], - fulltree=False, arch="x86_64") + pkg_map = self.go( + packages, + None, + greedy="build", + multilib_methods=["devel", "runtime"], + fulltree=False, + arch="x86_64", + ) six.assertCountEqual( self, @@ -1878,7 +1905,6 @@ class DepsolvingBase(object): "dummy-atlas-sse-3.8.4-7.i686.rpm", "dummy-atlas-sse2-3.8.4-7.i686.rpm", "dummy-atlas-sse3-3.8.4-7.i686.rpm", - "dummy-atlas-3.8.4-7.x86_64.rpm", "dummy-atlas-devel-3.8.4-7.x86_64.rpm", "dummy-atlas-sse3-3.8.4-7.x86_64.rpm", @@ -2052,7 +2078,7 @@ class DepsolvingBase(object): self.assertEqual(pkg_map["srpm"], ["dummy-mingw-qt5-qtbase-5.6.0-1.src.rpm"]) self.assertEqual( pkg_map["debuginfo"], - ["dummy-mingw32-qt5-qtbase-debuginfo-5.6.0-1.noarch.rpm"] + ["dummy-mingw32-qt5-qtbase-debuginfo-5.6.0-1.noarch.rpm"], ) def test_input_by_wildcard(self): @@ -2083,9 +2109,7 @@ class DepsolvingBase(object): self.assertEqual(pkg_map["debuginfo"], []) def test_requires_pre_post(self): - packages = [ - "dummy-perl" - ] + packages = ["dummy-perl"] pkg_map = self.go(packages, None) six.assertCountEqual( @@ -2093,8 +2117,8 @@ class DepsolvingBase(object): pkg_map["rpm"], [ "dummy-perl-1.0.0-1.x86_64.rpm", - "dummy-perl-macros-1.0.0-1.x86_64.rpm", # Requires(pre) - "dummy-perl-utils-1.0.0-1.x86_64.rpm", # Requires(post) + "dummy-perl-macros-1.0.0-1.x86_64.rpm", # Requires(pre) + "dummy-perl-utils-1.0.0-1.x86_64.rpm", # Requires(post) ], ) self.assertEqual(pkg_map["srpm"], ["dummy-perl-1.0.0-1.src.rpm"]) @@ -2102,8 +2126,8 @@ class DepsolvingBase(object): def test_multilib_exclude_pattern_does_not_match_noarch(self): packages = [ - 'dummy-release-notes-en-US', - '-dummy-release-notes-en*.+', + "dummy-release-notes-en-US", + "-dummy-release-notes-en*.+", ] pkg_map = self.go(packages, None) @@ -2113,9 +2137,8 @@ class DepsolvingBase(object): self.assertEqual(pkg_map["debuginfo"], []) -@unittest.skipUnless(HAS_YUM, 'YUM only available on Python 2') +@unittest.skipUnless(HAS_YUM, "YUM only available on Python 2") class PungiYumDepsolvingTestCase(DepsolvingBase, unittest.TestCase): - def setUp(self): super(PungiYumDepsolvingTestCase, self).setUp() self.ks = os.path.join(self.tmp_dir, "ks") @@ -2125,9 +2148,9 @@ class PungiYumDepsolvingTestCase(DepsolvingBase, unittest.TestCase): self.old_cwd = os.getcwd() os.chdir(self.cwd) - logger = logging.getLogger('Pungi') + logger = logging.getLogger("Pungi") if not logger.handlers: - formatter = logging.Formatter('%(name)s:%(levelname)s: %(message)s') + formatter = logging.Formatter("%(name)s:%(levelname)s: %(message)s") console = logging.StreamHandler(sys.stdout) console.setFormatter(formatter) console.setLevel(logging.INFO) @@ -2137,9 +2160,17 @@ class PungiYumDepsolvingTestCase(DepsolvingBase, unittest.TestCase): os.chdir(self.old_cwd) super(PungiYumDepsolvingTestCase, self).tearDown() - def go(self, packages, groups, lookaside=None, prepopulate=None, - fulltree_excludes=None, multilib_blacklist=None, - multilib_whitelist=None, **kwargs): + def go( + self, + packages, + groups, + lookaside=None, + prepopulate=None, + fulltree_excludes=None, + multilib_blacklist=None, + multilib_whitelist=None, + **kwargs + ): """ Write a kickstart with given packages and groups, then run the depsolving and parse the output. @@ -2147,19 +2178,25 @@ class PungiYumDepsolvingTestCase(DepsolvingBase, unittest.TestCase): p = PungiWrapper() repos = {"repo": self.repo} if lookaside: - repos['lookaside'] = lookaside - kwargs['lookaside_repos'] = ['lookaside'] - p.write_kickstart(self.ks, repos, groups, packages, prepopulate=prepopulate, - multilib_whitelist=multilib_whitelist, - multilib_blacklist=multilib_blacklist, - fulltree_excludes=fulltree_excludes) - kwargs.setdefault('cache_dir', self.tmp_dir) + repos["lookaside"] = lookaside + kwargs["lookaside_repos"] = ["lookaside"] + p.write_kickstart( + self.ks, + repos, + groups, + packages, + prepopulate=prepopulate, + multilib_whitelist=multilib_whitelist, + multilib_blacklist=multilib_blacklist, + fulltree_excludes=fulltree_excludes, + ) + kwargs.setdefault("cache_dir", self.tmp_dir) # Unless the test specifies an arch, we need to default to x86_64. # Otherwise the arch of current machine will be used, which will cause # failure most of the time. - kwargs.setdefault('arch', 'x86_64') + kwargs.setdefault("arch", "x86_64") - p.run_pungi(self.ks, self.tmp_dir, 'DP', **kwargs) + p.run_pungi(self.ks, self.tmp_dir, "DP", **kwargs) with open(self.out, "r") as f: pkg_map, self.broken_deps, _ = p.parse_log(f) return convert_pkg_map(pkg_map) @@ -2168,7 +2205,7 @@ class PungiYumDepsolvingTestCase(DepsolvingBase, unittest.TestCase): def convert_dnf_packages(pkgs, flags): convert_table = { # Hawkey returns nosrc package as src - 'dummy-AdobeReader_enu-9.5.1-1.src': 'dummy-AdobeReader_enu-9.5.1-1.nosrc', + "dummy-AdobeReader_enu-9.5.1-1.src": "dummy-AdobeReader_enu-9.5.1-1.nosrc", } result = set() for p in pkgs: @@ -2178,20 +2215,20 @@ def convert_dnf_packages(pkgs, flags): # Package is coming from lookaside repo, we don't want those in # output. continue - result.add(name + '.rpm') + result.add(name + ".rpm") return sorted(result) -@unittest.skipUnless(HAS_DNF, 'Dependencies are not available') +@unittest.skipUnless(HAS_DNF, "Dependencies are not available") class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): def setUp(self): super(DNFDepsolvingTestCase, self).setUp() - self.cachedir = os.path.join(self.tmp_dir, 'pungi_dnf_cache') + self.cachedir = os.path.join(self.tmp_dir, "pungi_dnf_cache") self.get_langpacks = False - logger = logging.getLogger('gather_dnf') + logger = logging.getLogger("gather_dnf") if not logger.handlers: - formatter = logging.Formatter('%(name)s:%(levelname)s: %(message)s') + formatter = logging.Formatter("%(name)s:%(levelname)s: %(message)s") console = logging.StreamHandler(sys.stdout) console.setFormatter(formatter) console.setLevel(logging.INFO) @@ -2200,29 +2237,32 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): self.maxDiff = None def go(self, packages, groups, lookaside=None, **kwargs): - arch = kwargs.pop('arch', 'x86_64') - if 'greedy' in kwargs: - kwargs['greedy_method'] = kwargs.pop('greedy') - if 'nodeps' in kwargs: - kwargs['resolve_deps'] = not kwargs.pop('nodeps') + arch = kwargs.pop("arch", "x86_64") + if "greedy" in kwargs: + kwargs["greedy_method"] = kwargs.pop("greedy") + if "nodeps" in kwargs: + kwargs["resolve_deps"] = not kwargs.pop("nodeps") if lookaside: - kwargs['lookaside_repos'] = ['lookaside'] + kwargs["lookaside_repos"] = ["lookaside"] self.dnf = self.dnf_instance(arch, lookaside=lookaside, persistdir=self.tmp_dir) if self.get_langpacks: - kwargs['langpacks'] = self.dnf.comps_wrapper.get_langpacks() + kwargs["langpacks"] = self.dnf.comps_wrapper.get_langpacks() groups = groups or [] exclude_groups = [] - _, conditional_packages = self.dnf.comps_wrapper.get_comps_packages(groups, exclude_groups) + _, conditional_packages = self.dnf.comps_wrapper.get_comps_packages( + groups, exclude_groups + ) self.g = Gather(self.dnf, GatherOptions(**kwargs)) - self.g.logger.handlers = [h for h in self.g.logger.handlers - if h.name != 'capture-logs'] + self.g.logger.handlers = [ + h for h in self.g.logger.handlers if h.name != "capture-logs" + ] log_output = cStringIO() handler = logging.StreamHandler(log_output) - handler.name = 'capture-logs' + handler.name = "capture-logs" handler.setLevel(logging.WARNING) self.g.logger.addHandler(handler) @@ -2231,12 +2271,15 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): _, self.broken_deps, _ = PungiWrapper().parse_log(log_output) return { - 'debuginfo': convert_dnf_packages(self.g.result_debug_packages, - self.g.result_package_flags), - 'srpm': convert_dnf_packages(self.g.result_source_packages, - self.g.result_package_flags), - 'rpm': convert_dnf_packages(self.g.result_binary_packages, - self.g.result_package_flags), + "debuginfo": convert_dnf_packages( + self.g.result_debug_packages, self.g.result_package_flags + ), + "srpm": convert_dnf_packages( + self.g.result_source_packages, self.g.result_package_flags + ), + "rpm": convert_dnf_packages( + self.g.result_binary_packages, self.g.result_package_flags + ), } def dnf_instance(self, base_arch, exclude=None, lookaside=False, persistdir=None): @@ -2262,25 +2305,33 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): for pkg, flags in self.g.result_package_flags.items(): if nvra == "%s-%s-%s.%s" % (pkg.name, pkg.version, pkg.release, pkg.arch): self.assertEqual( - flags, expected_flags, - "pkg: %s; flags: %s; expected flags: %s" % (nvra, flags, expected_flags)) + flags, + expected_flags, + "pkg: %s; flags: %s; expected flags: %s" + % (nvra, flags, expected_flags), + ) found = True if not found: flags = set() self.assertEqual( - flags, expected_flags, - "pkg: %s; flags: %s; expected flags: %s" % (nvra, flags, expected_flags)) + flags, + expected_flags, + "pkg: %s; flags: %s; expected flags: %s" + % (nvra, flags, expected_flags), + ) def test_langpacks(self): self.get_langpacks = True super(DNFDepsolvingTestCase, self).test_langpacks() - @unittest.skip('DNF code does not support NVR as input') + @unittest.skip("DNF code does not support NVR as input") def test_bash_older(self): pass def test_firefox_selfhosting_with_krb5_lookaside(self): - super(DNFDepsolvingTestCase, self).test_firefox_selfhosting_with_krb5_lookaside() + super( + DNFDepsolvingTestCase, self + ).test_firefox_selfhosting_with_krb5_lookaside() self.assertFlags("dummy-krb5-devel-1.10-5.x86_64", [PkgFlag.lookaside]) self.assertFlags("dummy-krb5-1.10-5.src", [PkgFlag.lookaside]) @@ -2343,9 +2394,9 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): def test_bash_multilib_exclude_debuginfo(self): packages = [ - 'dummy-bash.+', - '-dummy-bash-debuginfo', - '-dummy-bash-debugsource', + "dummy-bash.+", + "-dummy-bash-debuginfo", + "-dummy-bash-debugsource", ] pkg_map = self.go(packages, None, greedy="none") @@ -2385,8 +2436,7 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): "-dummy-bas*", "dummy-glibc", ] - pkg_map = self.go(packages, None, - greedy="none", nodeps=True, fulltree=True) + pkg_map = self.go(packages, None, greedy="none", nodeps=True, fulltree=True) # neither dummy-bash or dummy-basesystem is pulled in six.assertCountEqual( @@ -2454,7 +2504,7 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): self, pkg_map["rpm"], [ - "dummy-kmod-ipw3945-1.2.0-4.20.x86_64.rpm", # Important + "dummy-kmod-ipw3945-1.2.0-4.20.x86_64.rpm", # Important "dummy-kmod-ipw3945-xen-1.2.0-4.20.x86_64.rpm", ], ) @@ -2465,8 +2515,13 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): packages = [ "dummy-lvm2-devel", ] - pkg_map = self.go(packages, None, greedy="none", fulltree=False, - multilib_methods=["devel", "runtime"]) + pkg_map = self.go( + packages, + None, + greedy="none", + fulltree=False, + multilib_methods=["devel", "runtime"], + ) six.assertCountEqual( self, @@ -2478,8 +2533,8 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): "dummy-glibc-2.14-5.i686.rpm", "dummy-glibc-common-2.14-5.x86_64.rpm", "dummy-lvm2-2.02.84-4.x86_64.rpm", - "dummy-lvm2-devel-2.02.84-4.i686.rpm", # Important - "dummy-lvm2-devel-2.02.84-4.x86_64.rpm", # Important + "dummy-lvm2-devel-2.02.84-4.i686.rpm", # Important + "dummy-lvm2-devel-2.02.84-4.x86_64.rpm", # Important "dummy-lvm2-libs-2.02.84-4.x86_64.rpm", ], ) diff --git a/tests/test_gather_method_deps.py b/tests/test_gather_method_deps.py index 2de8c8c2..e6c1324e 100644 --- a/tests/test_gather_method_deps.py +++ b/tests/test_gather_method_deps.py @@ -16,32 +16,46 @@ class TestWritePungiConfig(helpers.PungiTestCase): def assertWritten(self, PungiWrapper, **kwargs): wrapper = PungiWrapper.return_value - self.assertEqual(wrapper.mock_calls, - [mock.call.write_kickstart(**kwargs)]) + self.assertEqual(wrapper.mock_calls, [mock.call.write_kickstart(**kwargs)]) - @mock.patch('pungi.phases.gather.methods.method_deps.PungiWrapper') + @mock.patch("pungi.phases.gather.methods.method_deps.PungiWrapper") def test_correct(self, PungiWrapper): - pkgs = [('pkg1', None), ('pkg2', 'x86_64')] - grps = ['grp1'] - filter = [('pkg3', None), ('pkg4', 'x86_64')] + pkgs = [("pkg1", None), ("pkg2", "x86_64")] + grps = ["grp1"] + filter = [("pkg3", None), ("pkg4", "x86_64")] white = mock.Mock() black = mock.Mock() prepopulate = mock.Mock() fulltree = mock.Mock() deps.write_pungi_config( - self.compose, 'x86_64', self.compose.variants['Server'], - pkgs, grps, filter, white, black, - prepopulate=prepopulate, fulltree_excludes=fulltree, + self.compose, + "x86_64", + self.compose.variants["Server"], + pkgs, + grps, + filter, + white, + black, + prepopulate=prepopulate, + fulltree_excludes=fulltree, package_sets=self.package_sets, ) - self.assertWritten(PungiWrapper, packages=['pkg1', 'pkg2.x86_64'], - ks_path=self.topdir + '/work/x86_64/pungi/Server.x86_64.conf', - lookaside_repos={}, multilib_whitelist=white, multilib_blacklist=black, - groups=['grp1'], prepopulate=prepopulate, - repos={"pungi-repo-0": self.topdir + "/work/x86_64/repo/p1", - 'comps-repo': self.topdir + '/work/x86_64/comps_repo_Server'}, - exclude_packages=['pkg3', 'pkg4.x86_64'], - fulltree_excludes=fulltree) + self.assertWritten( + PungiWrapper, + packages=["pkg1", "pkg2.x86_64"], + ks_path=self.topdir + "/work/x86_64/pungi/Server.x86_64.conf", + lookaside_repos={}, + multilib_whitelist=white, + multilib_blacklist=black, + groups=["grp1"], + prepopulate=prepopulate, + repos={ + "pungi-repo-0": self.topdir + "/work/x86_64/repo/p1", + "comps-repo": self.topdir + "/work/x86_64/comps_repo_Server", + }, + exclude_packages=["pkg3", "pkg4.x86_64"], + fulltree_excludes=fulltree, + ) @mock.patch("pungi.phases.gather.methods.method_deps.PungiWrapper") def test_duplicated_package_name(self, PungiWrapper): @@ -53,73 +67,114 @@ class TestWritePungiConfig(helpers.PungiTestCase): prepopulate = mock.Mock() fulltree = mock.Mock() deps.write_pungi_config( - self.compose, "x86_64", self.compose.variants["Server"], - pkgs, grps, filter, white, black, - prepopulate=prepopulate, fulltree_excludes=fulltree, + self.compose, + "x86_64", + self.compose.variants["Server"], + pkgs, + grps, + filter, + white, + black, + prepopulate=prepopulate, + fulltree_excludes=fulltree, package_sets=self.package_sets, ) - self.assertWritten(PungiWrapper, packages=["pkg1", "pkg1.x86_64"], - ks_path=self.topdir + "/work/x86_64/pungi/Server.x86_64.conf", - lookaside_repos={}, multilib_whitelist=white, multilib_blacklist=black, - groups=[], prepopulate=prepopulate, - repos={"pungi-repo-0": self.topdir + "/work/x86_64/repo/p1", - "comps-repo": self.topdir + "/work/x86_64/comps_repo_Server"}, - exclude_packages=["pkg2", "pkg2.x86_64"], - fulltree_excludes=fulltree) + self.assertWritten( + PungiWrapper, + packages=["pkg1", "pkg1.x86_64"], + ks_path=self.topdir + "/work/x86_64/pungi/Server.x86_64.conf", + lookaside_repos={}, + multilib_whitelist=white, + multilib_blacklist=black, + groups=[], + prepopulate=prepopulate, + repos={ + "pungi-repo-0": self.topdir + "/work/x86_64/repo/p1", + "comps-repo": self.topdir + "/work/x86_64/comps_repo_Server", + }, + exclude_packages=["pkg2", "pkg2.x86_64"], + fulltree_excludes=fulltree, + ) - @mock.patch('pungi.phases.gather.get_lookaside_repos') - @mock.patch('pungi.phases.gather.methods.method_deps.PungiWrapper') + @mock.patch("pungi.phases.gather.get_lookaside_repos") + @mock.patch("pungi.phases.gather.methods.method_deps.PungiWrapper") def test_with_lookaside(self, PungiWrapper, glr): - glr.return_value = ['http://example.com/repo'] - pkgs = [('pkg1', None)] + glr.return_value = ["http://example.com/repo"] + pkgs = [("pkg1", None)] deps.write_pungi_config( - self.compose, 'x86_64', self.compose.variants['Server'], - pkgs, [], [], [], [], + self.compose, + "x86_64", + self.compose.variants["Server"], + pkgs, + [], + [], + [], + [], package_sets=self.package_sets, ) - self.assertWritten(PungiWrapper, packages=['pkg1'], - ks_path=self.topdir + '/work/x86_64/pungi/Server.x86_64.conf', - lookaside_repos={'lookaside-repo-0': 'http://example.com/repo'}, - multilib_whitelist=[], multilib_blacklist=[], - groups=[], prepopulate=None, - repos={"pungi-repo-0": self.topdir + "/work/x86_64/repo/p1", - 'comps-repo': self.topdir + '/work/x86_64/comps_repo_Server'}, - exclude_packages=[], fulltree_excludes=None) - self.assertEqual(glr.call_args_list, - [mock.call(self.compose, 'x86_64', self.compose.variants['Server'])]) + self.assertWritten( + PungiWrapper, + packages=["pkg1"], + ks_path=self.topdir + "/work/x86_64/pungi/Server.x86_64.conf", + lookaside_repos={"lookaside-repo-0": "http://example.com/repo"}, + multilib_whitelist=[], + multilib_blacklist=[], + groups=[], + prepopulate=None, + repos={ + "pungi-repo-0": self.topdir + "/work/x86_64/repo/p1", + "comps-repo": self.topdir + "/work/x86_64/comps_repo_Server", + }, + exclude_packages=[], + fulltree_excludes=None, + ) + self.assertEqual( + glr.call_args_list, + [mock.call(self.compose, "x86_64", self.compose.variants["Server"])], + ) - @mock.patch('pungi.phases.gather.methods.method_deps.PungiWrapper') + @mock.patch("pungi.phases.gather.methods.method_deps.PungiWrapper") def test_without_input(self, PungiWrapper): with self.assertRaises(RuntimeError) as ctx: - deps.write_pungi_config(self.compose, 'x86_64', self.compose.variants['Server'], - [], [], [], [], []) + deps.write_pungi_config( + self.compose, + "x86_64", + self.compose.variants["Server"], + [], + [], + [], + [], + [], + ) self.assertEqual( str(ctx.exception), - 'No packages included in Server.x86_64 (no comps groups, no input packages, no prepopulate)') + "No packages included in Server.x86_64 (no comps groups, no input packages, no prepopulate)", + ) self.assertEqual(PungiWrapper.return_value.mock_calls, []) class TestRaiseOnInvalidSigkeys(helpers.PungiTestCase): - def test_raise_on_invalid_sigkeys(self): pkgset = { "global": mock.Mock(), } - pkgset["global"].invalid_sigkey_rpms = [{'name': 'pkg1'}] - pkgset["global"].raise_invalid_sigkeys_exception = mock.Mock(side_effect=RuntimeError()) + pkgset["global"].invalid_sigkey_rpms = [{"name": "pkg1"}] + pkgset["global"].raise_invalid_sigkeys_exception = mock.Mock( + side_effect=RuntimeError() + ) result = { - 'rpm': [{'path': 'pkg1-1-1.el7'}], + "rpm": [{"path": "pkg1-1-1.el7"}], } with self.assertRaises(RuntimeError): - deps.raise_on_invalid_sigkeys('', '', [pkgset], result) + deps.raise_on_invalid_sigkeys("", "", [pkgset], result) + class TestCheckDeps(helpers.PungiTestCase): - def setUp(self): super(TestCheckDeps, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) - self.arch = 'x86_64' - self.variant = self.compose.variants['Server'] + self.arch = "x86_64" + self.variant = self.compose.variants["Server"] def test_not_check_deps(self): self.compose.conf["check_deps"] = False @@ -127,15 +182,16 @@ class TestCheckDeps(helpers.PungiTestCase): def test_missing_deps(self): self.compose.conf["check_deps"] = True - missing_deps = {'foo.noarch': set(['bar = 1.1'])} + missing_deps = {"foo.noarch": set(["bar = 1.1"])} with self.assertRaises(RuntimeError) as ctx: deps.check_deps(self.compose, self.arch, self.variant, missing_deps) - self.assertEqual(str(ctx.exception), 'Unresolved dependencies detected') + self.assertEqual(str(ctx.exception), "Unresolved dependencies detected") self.assertEqual( self.compose.log_error.call_args_list, [ mock.call( - "Unresolved dependencies for %s.%s in package foo.noarch: ['bar = 1.1']" % (self.variant, self.arch) + "Unresolved dependencies for %s.%s in package foo.noarch: ['bar = 1.1']" + % (self.variant, self.arch) ) - ] + ], ) diff --git a/tests/test_gather_method_hybrid.py b/tests/test_gather_method_hybrid.py index 8cfb225f..34a8b913 100644 --- a/tests/test_gather_method_hybrid.py +++ b/tests/test_gather_method_hybrid.py @@ -244,6 +244,7 @@ class MockModule(object): def get_runtime_streams(platform): assert platform == "platform" return [self.platform] + return [mock.Mock(get_runtime_streams=get_runtime_streams)] def get_rpm_artifacts(self): @@ -368,9 +369,9 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): self.assertEqual( self.compose.log_debug.call_args_list, [ - mock.call('[BEGIN] Running fus (arch: x86_64, variant: Server)'), - mock.call('[DONE ] Running fus (arch: x86_64, variant: Server)') - ] + mock.call("[BEGIN] Running fus (arch: x86_64, variant: Server)"), + mock.call("[DONE ] Running fus (arch: x86_64, variant: Server)"), + ], ) def test_with_modules_with_devel(self, run, gc, po, wc): @@ -481,9 +482,7 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): "pkg-debuginfo-1.0-2.x86_64": dbg2, } self.phase.debuginfo = { - "x86_64": { - "pkg-debuginfo": [dbg1, dbg2], - }, + "x86_64": {"pkg-debuginfo": [dbg1, dbg2]}, } po.side_effect = [ ([("pkg-1.0-1", "x86_64", frozenset())], []), @@ -639,15 +638,11 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): ( [ ("pkg-devel-1.0-1", "x86_64", frozenset()), - ("foo-1.0-1", "x86_64", frozenset()) + ("foo-1.0-1", "x86_64", frozenset()), ], - frozenset()), - ( - [ - ("pkg-devel-1.0-1", "i686", frozenset()), - ], - [], + frozenset(), ), + ([("pkg-devel-1.0-1", "i686", frozenset())], []), ] res = self.phase.run_solver( @@ -666,7 +661,7 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): ("pkg-devel-1.0-1", "x86_64", frozenset()), ("foo-1.0-1", "x86_64", frozenset()), ("pkg-devel-1.0-1", "i686", frozenset()), - ] + ], ) self.assertEqual(res[1], set()) self.assertEqual( @@ -761,16 +756,11 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): ( [ ("pkg-devel-1.0-1", "x86_64", frozenset()), - ("foo-1.0-1", "x86_64", frozenset()) - ], - [], - ), - ( - [ - ("foo-1.0-1", "i686", frozenset()), + ("foo-1.0-1", "x86_64", frozenset()), ], [], ), + ([("foo-1.0-1", "i686", frozenset())], []), ] res = self.phase.run_solver( @@ -856,7 +846,7 @@ class TestExpandPackages(helpers.PungiTestCase): nevra_to_pkg["pkg-debuginfo-3:1-2.%s" % debug_arch] = pkg._replace( name="pkg-debuginfo", arch=debug_arch, - file_path="/tmp/pkg-debuginfo.%s.rpm" % debug_arch + file_path="/tmp/pkg-debuginfo.%s.rpm" % debug_arch, ) return nevra_to_pkg diff --git a/tests/test_gather_method_nodeps.py b/tests/test_gather_method_nodeps.py index 26b72eac..94822791 100644 --- a/tests/test_gather_method_nodeps.py +++ b/tests/test_gather_method_nodeps.py @@ -9,7 +9,7 @@ import six from pungi.phases.gather.methods import method_nodeps as nodeps from tests import helpers -COMPS_FILE = os.path.join(helpers.FIXTURE_DIR, 'comps.xml') +COMPS_FILE = os.path.join(helpers.FIXTURE_DIR, "comps.xml") class TestWritePungiConfig(helpers.PungiTestCase): @@ -19,7 +19,9 @@ class TestWritePungiConfig(helpers.PungiTestCase): self.compose.paths.work.comps = mock.Mock(return_value=COMPS_FILE) def test_expand_group(self): - packages = nodeps.expand_groups(self.compose, 'x86_64', None, ['core', 'text-internet']) + packages = nodeps.expand_groups( + self.compose, "x86_64", None, ["core", "text-internet"] + ) six.assertCountEqual( self, packages, diff --git a/tests/test_gather_phase.py b/tests/test_gather_phase.py index 5c1fdcfe..c2e9cc52 100644 --- a/tests/test_gather_phase.py +++ b/tests/test_gather_phase.py @@ -29,8 +29,8 @@ class MockPkg(object): self.path = path self.is_system_release = is_system_release filename = os.path.basename(path) - self.nvr, self.arch, _ = filename.rsplit('.', 2) - self.name, self.version, self.release = self.nvr.rsplit('-', 2) + self.nvr, self.arch, _ = filename.rsplit(".", 2) + self.name, self.version, self.release = self.nvr.rsplit("-", 2) def __repr__(self): return self.nvr @@ -48,146 +48,255 @@ def _join(a, *rest): class TestGatherWrapper(helpers.PungiTestCase): - def setUp(self): super(TestGatherWrapper, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) self.package_set = mock.Mock() self.variant = helpers.MockVariant( - uid='Server', arches=['x86_64'], type='variant') + uid="Server", arches=["x86_64"], type="variant" + ) self.optional = helpers.MockVariant( - uid='Server-optional', arches=['x86_64'], type='optional', parent=self.variant) + uid="Server-optional", + arches=["x86_64"], + type="optional", + parent=self.variant, + ) self.addon = helpers.MockVariant( - uid='Server-HA', arches=['x86_64'], type='addon', parent=self.variant) + uid="Server-HA", arches=["x86_64"], type="addon", parent=self.variant + ) self.lp = helpers.MockVariant( - uid='Server-LP', arches=['x86_64'], type='layered-product', parent=self.variant) + uid="Server-LP", + arches=["x86_64"], + type="layered-product", + parent=self.variant, + ) self.server_packages = { - "rpm": [{'path': '/build/foo-1.0-1.x86_64.rpm', 'flags': ['input']}], - "srpm": [{'path': '/build/foo-1.0-1.src.rpm', 'flags': []}], - "debuginfo": [{'path': '/build/foo-debuginfo-1.0-1.x86_64.rpm', 'flags': []}], + "rpm": [{"path": "/build/foo-1.0-1.x86_64.rpm", "flags": ["input"]}], + "srpm": [{"path": "/build/foo-1.0-1.src.rpm", "flags": []}], + "debuginfo": [ + {"path": "/build/foo-debuginfo-1.0-1.x86_64.rpm", "flags": []} + ], } self.maxDiff = None def _dummy_gather(self, compose, arch, variant, package_sets, **kwargs): self.assertEqual( - package_sets, self.package_set, - 'Called gather_packages on %s.%s with bad package sets' % (variant.uid, arch)) - if variant.uid == 'Server': + package_sets, + self.package_set, + "Called gather_packages on %s.%s with bad package sets" + % (variant.uid, arch), + ) + if variant.uid == "Server": return self.server_packages - if variant.uid == 'Server-optional': + if variant.uid == "Server-optional": return self.optional_packages - if variant.uid == 'Server-HA': + if variant.uid == "Server-HA": return self.addon_packages - if variant.uid == 'Server-LP': + if variant.uid == "Server-LP": return self.lp_packages - self.assertFalse('This should not be reached - variant %s' % variant.uid) + self.assertFalse("This should not be reached - variant %s" % variant.uid) - @mock.patch('pungi.phases.gather.write_packages') - @mock.patch('pungi.phases.gather.gather_packages') + @mock.patch("pungi.phases.gather.write_packages") + @mock.patch("pungi.phases.gather.gather_packages") def test_single_variant(self, gather_packages, write_packages): # There is only one variant: exactly the packages returned by gather # method should be returned without modifications. - self.compose.all_variants = {'Server': self.variant} + self.compose.all_variants = {"Server": self.variant} expected_server_packages = copy.deepcopy(self.server_packages) gather_packages.side_effect = self._dummy_gather - result = gather.gather_wrapper(self.compose, self.package_set, '/build') + result = gather.gather_wrapper(self.compose, self.package_set, "/build") - self.assertEqual(result, {'x86_64': {'Server': expected_server_packages}}) + self.assertEqual(result, {"x86_64": {"Server": expected_server_packages}}) self.assertEqual( write_packages.call_args_list, - [mock.call(self.compose, 'x86_64', self.variant, - expected_server_packages, path_prefix='/build')]) + [ + mock.call( + self.compose, + "x86_64", + self.variant, + expected_server_packages, + path_prefix="/build", + ) + ], + ) - @mock.patch('pungi.phases.gather.write_packages') - @mock.patch('pungi.phases.gather.gather_packages') + @mock.patch("pungi.phases.gather.write_packages") + @mock.patch("pungi.phases.gather.gather_packages") def test_addon(self, gather_packages, write_packages): # Addon has all packages that parent has, plus one extra input package # and one fulltree-exclude package. Only the input one should remain in # addon, and the fulltree one should move to parent. - self.compose.all_variants = {'Server': self.variant, 'Server-HA': self.addon} + self.compose.all_variants = {"Server": self.variant, "Server-HA": self.addon} - move_to_parent = {'path': '/build/foo-common-1.0-1.x86_64.rpm', 'flags': ['fulltree-exclude']} - keep_in_addon = {'path': '/build/bar-1.0-1.x86_64.rpm', 'flags': ['input']} - expected_server_packages = _join(self.server_packages, _mk_pkg_map([move_to_parent])) - self.addon_packages = _join(self.server_packages, _mk_pkg_map([keep_in_addon, move_to_parent])) + move_to_parent = { + "path": "/build/foo-common-1.0-1.x86_64.rpm", + "flags": ["fulltree-exclude"], + } + keep_in_addon = {"path": "/build/bar-1.0-1.x86_64.rpm", "flags": ["input"]} + expected_server_packages = _join( + self.server_packages, _mk_pkg_map([move_to_parent]) + ) + self.addon_packages = _join( + self.server_packages, _mk_pkg_map([keep_in_addon, move_to_parent]) + ) expected_addon_packages = _mk_pkg_map( - [{'path': '/build/bar-1.0-1.x86_64.rpm', 'flags': ['input']}]) + [{"path": "/build/bar-1.0-1.x86_64.rpm", "flags": ["input"]}] + ) gather_packages.side_effect = self._dummy_gather - result = gather.gather_wrapper(self.compose, self.package_set, '/build') + result = gather.gather_wrapper(self.compose, self.package_set, "/build") - self.assertEqual(result, {'x86_64': {'Server': expected_server_packages, - 'Server-HA': expected_addon_packages}}) + self.assertEqual( + result, + { + "x86_64": { + "Server": expected_server_packages, + "Server-HA": expected_addon_packages, + } + }, + ) six.assertCountEqual( self, write_packages.call_args_list, - [mock.call(self.compose, 'x86_64', self.variant, - expected_server_packages, path_prefix='/build'), - mock.call(self.compose, 'x86_64', self.addon, - expected_addon_packages, path_prefix='/build')]) + [ + mock.call( + self.compose, + "x86_64", + self.variant, + expected_server_packages, + path_prefix="/build", + ), + mock.call( + self.compose, + "x86_64", + self.addon, + expected_addon_packages, + path_prefix="/build", + ), + ], + ) - @mock.patch('pungi.phases.gather.write_packages') - @mock.patch('pungi.phases.gather.gather_packages') + @mock.patch("pungi.phases.gather.write_packages") + @mock.patch("pungi.phases.gather.gather_packages") def test_layered_product(self, gather_packages, write_packages): # This test is pretty much identical to the one for addon. - self.compose.all_variants = {'Server': self.variant, 'Server-LP': self.lp} + self.compose.all_variants = {"Server": self.variant, "Server-LP": self.lp} - move_to_parent = {'path': '/build/foo-common-1.0-1.x86_64.rpm', 'flags': ['fulltree-exclude']} - keep_in_lp = {'path': '/build/bar-1.0-1.x86_64.rpm', 'flags': ['input']} + move_to_parent = { + "path": "/build/foo-common-1.0-1.x86_64.rpm", + "flags": ["fulltree-exclude"], + } + keep_in_lp = {"path": "/build/bar-1.0-1.x86_64.rpm", "flags": ["input"]} expected_server_packages = copy.deepcopy(self.server_packages) - expected_server_packages['rpm'].append(move_to_parent) - self.lp_packages = _join(self.server_packages, _mk_pkg_map([keep_in_lp, move_to_parent])) + expected_server_packages["rpm"].append(move_to_parent) + self.lp_packages = _join( + self.server_packages, _mk_pkg_map([keep_in_lp, move_to_parent]) + ) expected_lp_packages = _mk_pkg_map( - [{'path': '/build/bar-1.0-1.x86_64.rpm', 'flags': ['input']}]) + [{"path": "/build/bar-1.0-1.x86_64.rpm", "flags": ["input"]}] + ) gather_packages.side_effect = self._dummy_gather - result = gather.gather_wrapper(self.compose, self.package_set, '/build') + result = gather.gather_wrapper(self.compose, self.package_set, "/build") - self.assertEqual(result, {'x86_64': {'Server': expected_server_packages, - 'Server-LP': expected_lp_packages}}) + self.assertEqual( + result, + { + "x86_64": { + "Server": expected_server_packages, + "Server-LP": expected_lp_packages, + } + }, + ) six.assertCountEqual( self, write_packages.call_args_list, - [mock.call(self.compose, 'x86_64', self.variant, - expected_server_packages, path_prefix='/build'), - mock.call(self.compose, 'x86_64', self.lp, - expected_lp_packages, path_prefix='/build')]) + [ + mock.call( + self.compose, + "x86_64", + self.variant, + expected_server_packages, + path_prefix="/build", + ), + mock.call( + self.compose, + "x86_64", + self.lp, + expected_lp_packages, + path_prefix="/build", + ), + ], + ) - @mock.patch('pungi.phases.gather.write_packages') - @mock.patch('pungi.phases.gather.gather_packages') + @mock.patch("pungi.phases.gather.write_packages") + @mock.patch("pungi.phases.gather.gather_packages") def test_optional(self, gather_packages, write_packages): # All packages in optional that are present in parent should be removed # from optional. There is no move to parent here. - self.compose.all_variants = {'Server': self.variant, 'Server-optional': self.optional} + self.compose.all_variants = { + "Server": self.variant, + "Server-optional": self.optional, + } expected_server_packages = copy.deepcopy(self.server_packages) - self.optional_packages = _join(self.server_packages, _mk_pkg_map( - [{'path': '/build/bar-1.0-1.x86_64.rpm', 'flags': ['input']}, - {'path': '/build/foo-common-1.0-1.x86_64.rpm', 'flags': ['fulltree-exclude']}])) + self.optional_packages = _join( + self.server_packages, + _mk_pkg_map( + [ + {"path": "/build/bar-1.0-1.x86_64.rpm", "flags": ["input"]}, + { + "path": "/build/foo-common-1.0-1.x86_64.rpm", + "flags": ["fulltree-exclude"], + }, + ] + ), + ) expected_optional_packages = _mk_pkg_map( - [{'path': '/build/bar-1.0-1.x86_64.rpm', 'flags': ['input']}]) + [{"path": "/build/bar-1.0-1.x86_64.rpm", "flags": ["input"]}] + ) gather_packages.side_effect = self._dummy_gather - result = gather.gather_wrapper(self.compose, self.package_set, '/build') + result = gather.gather_wrapper(self.compose, self.package_set, "/build") - self.assertEqual(result, {'x86_64': {'Server': expected_server_packages, - 'Server-optional': expected_optional_packages}}) + self.assertEqual( + result, + { + "x86_64": { + "Server": expected_server_packages, + "Server-optional": expected_optional_packages, + } + }, + ) six.assertCountEqual( self, write_packages.call_args_list, - [mock.call(self.compose, 'x86_64', self.variant, - expected_server_packages, path_prefix='/build'), - mock.call(self.compose, 'x86_64', self.optional, - expected_optional_packages, path_prefix='/build')]) + [ + mock.call( + self.compose, + "x86_64", + self.variant, + expected_server_packages, + path_prefix="/build", + ), + mock.call( + self.compose, + "x86_64", + self.optional, + expected_optional_packages, + path_prefix="/build", + ), + ], + ) - @mock.patch('pungi.phases.gather.write_packages') - @mock.patch('pungi.phases.gather.gather_packages') + @mock.patch("pungi.phases.gather.write_packages") + @mock.patch("pungi.phases.gather.gather_packages") def test_all(self, gather_packages, write_packages): # Addon contains an extra package compared to parent. Layered product # contains an extra package compared to addon. Optional has one extra @@ -196,86 +305,170 @@ class TestGatherWrapper(helpers.PungiTestCase): # # There are also two packages that should move to parent variant. Addon # has one of them, layered product has both. - self.compose.all_variants = {'Server': self.variant, 'Server-optional': self.optional, - 'Server-HA': self.addon, 'Server-LP': self.lp} + self.compose.all_variants = { + "Server": self.variant, + "Server-optional": self.optional, + "Server-HA": self.addon, + "Server-LP": self.lp, + } - addon_extra_package = {'path': '/build/foo-addon-1.0.1-1.noarch.rpm', 'flags': []} - lp_extra_package = {'path': '/build/foo-layer-1.0.1-1.noarch.rpm', 'flags': []} - optional_extra_package = {'path': '/build/foo-optional-1.0.1-1.noarch.rpm', 'flags': []} - move_from_addon = {'path': '/build/foo-addon-contrib-1.0-1.noarch.rpm', 'flags': ['fulltree-exclude']} - move_from_lp = {'path': '/build/foo-layer-contrib-1.0-1.noarch.rpm', 'flags': ['fulltree-exclude']} + addon_extra_package = { + "path": "/build/foo-addon-1.0.1-1.noarch.rpm", + "flags": [], + } + lp_extra_package = {"path": "/build/foo-layer-1.0.1-1.noarch.rpm", "flags": []} + optional_extra_package = { + "path": "/build/foo-optional-1.0.1-1.noarch.rpm", + "flags": [], + } + move_from_addon = { + "path": "/build/foo-addon-contrib-1.0-1.noarch.rpm", + "flags": ["fulltree-exclude"], + } + move_from_lp = { + "path": "/build/foo-layer-contrib-1.0-1.noarch.rpm", + "flags": ["fulltree-exclude"], + } - self.addon_packages = _join(self.server_packages, _mk_pkg_map( - [addon_extra_package, move_from_addon])) - self.lp_packages = _join(self.addon_packages, _mk_pkg_map( - [lp_extra_package, move_from_lp])) - self.optional_packages = _join(self.lp_packages, _mk_pkg_map( - [optional_extra_package])) + self.addon_packages = _join( + self.server_packages, _mk_pkg_map([addon_extra_package, move_from_addon]) + ) + self.lp_packages = _join( + self.addon_packages, _mk_pkg_map([lp_extra_package, move_from_lp]) + ) + self.optional_packages = _join( + self.lp_packages, _mk_pkg_map([optional_extra_package]) + ) - expected_server_packages = _join(self.server_packages, _mk_pkg_map( - [move_from_addon, move_from_lp])) + expected_server_packages = _join( + self.server_packages, _mk_pkg_map([move_from_addon, move_from_lp]) + ) expected_addon_packages = _mk_pkg_map([addon_extra_package]) expected_lp_packages = _mk_pkg_map([lp_extra_package]) expected_optional_packages = _mk_pkg_map([optional_extra_package]) gather_packages.side_effect = self._dummy_gather - result = gather.gather_wrapper(self.compose, self.package_set, '/build') + result = gather.gather_wrapper(self.compose, self.package_set, "/build") - self.assertEqual(result, {'x86_64': {'Server': expected_server_packages, - 'Server-optional': expected_optional_packages, - 'Server-HA': expected_addon_packages, - 'Server-LP': expected_lp_packages}}) + self.assertEqual( + result, + { + "x86_64": { + "Server": expected_server_packages, + "Server-optional": expected_optional_packages, + "Server-HA": expected_addon_packages, + "Server-LP": expected_lp_packages, + } + }, + ) six.assertCountEqual( self, write_packages.call_args_list, - [mock.call(self.compose, 'x86_64', self.compose.all_variants['Server'], - expected_server_packages, path_prefix='/build'), - mock.call(self.compose, 'x86_64', self.compose.all_variants['Server-optional'], - expected_optional_packages, path_prefix='/build'), - mock.call(self.compose, 'x86_64', self.compose.all_variants['Server-HA'], - expected_addon_packages, path_prefix='/build'), - mock.call(self.compose, 'x86_64', self.compose.all_variants['Server-LP'], - expected_lp_packages, path_prefix='/build')]) + [ + mock.call( + self.compose, + "x86_64", + self.compose.all_variants["Server"], + expected_server_packages, + path_prefix="/build", + ), + mock.call( + self.compose, + "x86_64", + self.compose.all_variants["Server-optional"], + expected_optional_packages, + path_prefix="/build", + ), + mock.call( + self.compose, + "x86_64", + self.compose.all_variants["Server-HA"], + expected_addon_packages, + path_prefix="/build", + ), + mock.call( + self.compose, + "x86_64", + self.compose.all_variants["Server-LP"], + expected_lp_packages, + path_prefix="/build", + ), + ], + ) - @mock.patch('pungi.phases.gather.write_packages') - @mock.patch('pungi.phases.gather.gather_packages') + @mock.patch("pungi.phases.gather.write_packages") + @mock.patch("pungi.phases.gather.gather_packages") def test_keep_srpm_in_lp(self, gather_packages, write_packages): # There is one binary and source package in addon and lp but not in # parent. Addon should remain unchanged and the binary package should # disappear from lp. # This seems peculiar and may not be correct. - self.compose.all_variants = {'Server': self.variant, - 'Server-HA': self.addon, - 'Server-LP': self.lp} + self.compose.all_variants = { + "Server": self.variant, + "Server-HA": self.addon, + "Server-LP": self.lp, + } - addon_extra_package = {'path': '/build/foo-addon-1.0.1-1.noarch.rpm', 'flags': []} - addon_extra_source = {'path': '/build/foo-addon-1.0.1-1.src.rpm', 'flags': []} + addon_extra_package = { + "path": "/build/foo-addon-1.0.1-1.noarch.rpm", + "flags": [], + } + addon_extra_source = {"path": "/build/foo-addon-1.0.1-1.src.rpm", "flags": []} - self.addon_packages = _join(self.server_packages, _mk_pkg_map( - [addon_extra_package], [addon_extra_source])) + self.addon_packages = _join( + self.server_packages, + _mk_pkg_map([addon_extra_package], [addon_extra_source]), + ) self.lp_packages = _join(self.addon_packages) expected_server_packages = _join(self.server_packages) - expected_addon_packages = _mk_pkg_map([addon_extra_package], [addon_extra_source]) + expected_addon_packages = _mk_pkg_map( + [addon_extra_package], [addon_extra_source] + ) expected_lp_packages = _mk_pkg_map([], [addon_extra_source]) gather_packages.side_effect = self._dummy_gather - result = gather.gather_wrapper(self.compose, self.package_set, '/build') + result = gather.gather_wrapper(self.compose, self.package_set, "/build") - self.assertEqual(result, {'x86_64': {'Server': expected_server_packages, - 'Server-HA': expected_addon_packages, - 'Server-LP': expected_lp_packages}}) + self.assertEqual( + result, + { + "x86_64": { + "Server": expected_server_packages, + "Server-HA": expected_addon_packages, + "Server-LP": expected_lp_packages, + } + }, + ) six.assertCountEqual( self, write_packages.call_args_list, - [mock.call(self.compose, 'x86_64', self.compose.all_variants['Server'], - expected_server_packages, path_prefix='/build'), - mock.call(self.compose, 'x86_64', self.compose.all_variants['Server-HA'], - expected_addon_packages, path_prefix='/build'), - mock.call(self.compose, 'x86_64', self.compose.all_variants['Server-LP'], - expected_lp_packages, path_prefix='/build')]) + [ + mock.call( + self.compose, + "x86_64", + self.compose.all_variants["Server"], + expected_server_packages, + path_prefix="/build", + ), + mock.call( + self.compose, + "x86_64", + self.compose.all_variants["Server-HA"], + expected_addon_packages, + path_prefix="/build", + ), + mock.call( + self.compose, + "x86_64", + self.compose.all_variants["Server-LP"], + expected_lp_packages, + path_prefix="/build", + ), + ], + ) def _make_materialized_pkgsets(pkgsets): @@ -285,28 +478,31 @@ def _make_materialized_pkgsets(pkgsets): class TestGetSystemRelease(unittest.TestCase): def setUp(self): self.compose = mock.Mock() - self.variant = helpers.MockVariant(uid='Server', arches=['x86_64'], - type='variant') - self.addon = helpers.MockVariant(uid='Server-HA', arches=['x86_64'], - type='addon', parent=self.variant) + self.variant = helpers.MockVariant( + uid="Server", arches=["x86_64"], type="variant" + ) + self.addon = helpers.MockVariant( + uid="Server-HA", arches=["x86_64"], type="addon", parent=self.variant + ) def test_no_package_set(self): self.assertEqual( - gather.get_system_release_packages(self.compose, 'x86_64', - self.variant, None), - (set(), set()) + gather.get_system_release_packages( + self.compose, "x86_64", self.variant, None + ), + (set(), set()), ) def test_no_arch_in_package_set(self): self.assertEqual( gather.get_system_release_packages( - self.compose, 'x86_64', self.variant, _make_materialized_pkgsets({}) + self.compose, "x86_64", self.variant, _make_materialized_pkgsets({}) ), - (set(), set()) + (set(), set()), ) def test_no_system_release_package(self): - pkgset = MockPackageSet(MockPkg('/build/bash-1.0.0-1.x86_64.rpm')) + pkgset = MockPackageSet(MockPkg("/build/bash-1.0.0-1.x86_64.rpm")) packages, filter_packages = gather.get_system_release_packages( self.compose, "x86_64", @@ -319,7 +515,7 @@ class TestGetSystemRelease(unittest.TestCase): def test_picks_single(self): pkgset = MockPackageSet( - MockPkg('/build/dummy-1.0.0-1.x86_64.rpm', is_system_release=True), + MockPkg("/build/dummy-1.0.0-1.x86_64.rpm", is_system_release=True), ) packages, filter_packages = gather.get_system_release_packages( self.compose, @@ -333,8 +529,11 @@ class TestGetSystemRelease(unittest.TestCase): def test_prefers_variant(self): pkgset = MockPackageSet( - MockPkg('/build/system-release-1.0.0-1.x86_64.rpm', is_system_release=True), - MockPkg('/build/system-release-server-1.0.0-1.x86_64.rpm', is_system_release=True), + MockPkg("/build/system-release-1.0.0-1.x86_64.rpm", is_system_release=True), + MockPkg( + "/build/system-release-server-1.0.0-1.x86_64.rpm", + is_system_release=True, + ), ) packages, filter_packages = gather.get_system_release_packages( self.compose, @@ -348,8 +547,12 @@ class TestGetSystemRelease(unittest.TestCase): def test_no_best_match(self): pkgset = MockPackageSet( - MockPkg('/build/system-release-foo-1.0.0-1.x86_64.rpm', is_system_release=True), - MockPkg('/build/system-release-bar-1.0.0-1.x86_64.rpm', is_system_release=True), + MockPkg( + "/build/system-release-foo-1.0.0-1.x86_64.rpm", is_system_release=True + ), + MockPkg( + "/build/system-release-bar-1.0.0-1.x86_64.rpm", is_system_release=True + ), ) packages, filter_packages = gather.get_system_release_packages( self.compose, @@ -366,9 +569,15 @@ class TestGetSystemRelease(unittest.TestCase): def test_optional_picks_parent(self): pkgset = MockPackageSet( - MockPkg('/build/system-release-1.0.0-1.x86_64.rpm', is_system_release=True), - MockPkg('/build/system-release-server-1.0.0-1.x86_64.rpm', is_system_release=True), - MockPkg('/build/system-release-client-1.0.0-1.x86_64.rpm', is_system_release=True), + MockPkg("/build/system-release-1.0.0-1.x86_64.rpm", is_system_release=True), + MockPkg( + "/build/system-release-server-1.0.0-1.x86_64.rpm", + is_system_release=True, + ), + MockPkg( + "/build/system-release-client-1.0.0-1.x86_64.rpm", + is_system_release=True, + ), ) packages, filter_packages = gather.get_system_release_packages( self.compose, @@ -388,37 +597,43 @@ class TestGetSystemRelease(unittest.TestCase): class TestTrimPackages(unittest.TestCase): def setUp(self): self.compose = mock.Mock() - self.variant = helpers.MockVariant(uid='Server', arches=['x86_64'], - type='variant') - self.addon = helpers.MockVariant(uid='Server-HA', arches=['x86_64'], - type='addon', parent=self.variant) + self.variant = helpers.MockVariant( + uid="Server", arches=["x86_64"], type="variant" + ) + self.addon = helpers.MockVariant( + uid="Server-HA", arches=["x86_64"], type="addon", parent=self.variant + ) def test_trim_toplevel(self): - self.assertIsNone(gather.trim_packages(self.compose, 'x86_64', self.variant, {})) + self.assertIsNone( + gather.trim_packages(self.compose, "x86_64", self.variant, {}) + ) def test_remove_package_explicitly(self): - to_remove = {'path': '/build/required-1.0.0-1.x86_64.rpm', 'flags': ['input']} - to_keep = {'path': '/build/empty-1.0.0-1.x86_64.rpm', 'flags': []} + to_remove = {"path": "/build/required-1.0.0-1.x86_64.rpm", "flags": ["input"]} + to_keep = {"path": "/build/empty-1.0.0-1.x86_64.rpm", "flags": []} pkg_map = _mk_pkg_map([to_remove, to_keep]) addon_pkgs, moved_to_parent, removed_pkgs = gather.trim_packages( - self.compose, 'x86_64', self.addon, pkg_map, remove_pkgs={'rpm': ['required']}) + self.compose, + "x86_64", + self.addon, + pkg_map, + remove_pkgs={"rpm": ["required"]}, + ) self.assertEqual(removed_pkgs, _mk_pkg_map([to_remove])) - self.assertEqual(addon_pkgs, _mk_pkg_map(set(['empty']), iterable_class=set)) + self.assertEqual(addon_pkgs, _mk_pkg_map(set(["empty"]), iterable_class=set)) self.assertEqual(moved_to_parent, _mk_pkg_map()) self.assertEqual(pkg_map, _mk_pkg_map([to_keep])) def test_remove_package_present_in_parent(self): # packages present in parent will be removed from addon - parent_pkgs = { - 'rpm': [ - ('wanted', 'x86_64'), - ] - } - to_remove = {'path': '/build/wanted-1.0.0-1.x86_64.rpm', 'flags': []} + parent_pkgs = {"rpm": [("wanted", "x86_64")]} + to_remove = {"path": "/build/wanted-1.0.0-1.x86_64.rpm", "flags": []} pkg_map = _mk_pkg_map([to_remove]) addon_pkgs, moved_to_parent, removed_pkgs = gather.trim_packages( - self.compose, 'x86_64', self.addon, pkg_map, parent_pkgs=parent_pkgs) + self.compose, "x86_64", self.addon, pkg_map, parent_pkgs=parent_pkgs + ) self.assertEqual(removed_pkgs, _mk_pkg_map([to_remove])) self.assertEqual(addon_pkgs, _mk_pkg_map(iterable_class=set)) @@ -427,10 +642,14 @@ class TestTrimPackages(unittest.TestCase): def test_move_package_to_parent(self): # fulltree-exclude packages in addon only will move to parent - to_move = {'path': '/build/wanted-1.0.0-1.x86_64.rpm', 'flags': ['fulltree-exclude']} + to_move = { + "path": "/build/wanted-1.0.0-1.x86_64.rpm", + "flags": ["fulltree-exclude"], + } pkg_map = _mk_pkg_map([to_move]) addon_pkgs, moved_to_parent, removed_pkgs = gather.trim_packages( - self.compose, 'x86_64', self.addon, pkg_map, parent_pkgs={'rpm': []}) + self.compose, "x86_64", self.addon, pkg_map, parent_pkgs={"rpm": []} + ) self.assertEqual(removed_pkgs, _mk_pkg_map()) self.assertEqual(addon_pkgs, _mk_pkg_map(iterable_class=set)) @@ -439,14 +658,18 @@ class TestTrimPackages(unittest.TestCase): def test_keep_explicit_input_in_addon(self): # fulltree-exclude packages explictly in addon will be kept in addon - parent_pkgs = {'rpm': []} - pkg = {'path': '/build/wanted-1.0.0-1.x86_64.rpm', 'flags': ['fulltree-exclude', 'input']} + parent_pkgs = {"rpm": []} + pkg = { + "path": "/build/wanted-1.0.0-1.x86_64.rpm", + "flags": ["fulltree-exclude", "input"], + } pkg_map = _mk_pkg_map([pkg]) addon_pkgs, moved_to_parent, removed_pkgs = gather.trim_packages( - self.compose, 'x86_64', self.addon, pkg_map, parent_pkgs=parent_pkgs) + self.compose, "x86_64", self.addon, pkg_map, parent_pkgs=parent_pkgs + ) self.assertEqual(removed_pkgs, _mk_pkg_map()) - self.assertEqual(addon_pkgs, _mk_pkg_map(set(['wanted']), iterable_class=set)) + self.assertEqual(addon_pkgs, _mk_pkg_map(set(["wanted"]), iterable_class=set)) self.assertEqual(moved_to_parent, _mk_pkg_map()) self.assertEqual(pkg_map, _mk_pkg_map([pkg])) @@ -455,41 +678,58 @@ class TestWritePackages(helpers.PungiTestCase): def test_write_packages(self): self.compose = helpers.DummyCompose(self.topdir, {}) pkg_map = { - 'rpm': [ - {'path': '/build/foo-1.0-1.x86_64.rpm', 'flags': []}, - {'path': '/build/foo-common-1.0-1.x86_64.rpm', 'flags': []}, - {'path': '/alt/build/bar-1.0-1.noarch.rpm', 'flags': []}, + "rpm": [ + {"path": "/build/foo-1.0-1.x86_64.rpm", "flags": []}, + {"path": "/build/foo-common-1.0-1.x86_64.rpm", "flags": []}, + {"path": "/alt/build/bar-1.0-1.noarch.rpm", "flags": []}, ], - 'srpm': [ - {'path': '/build/foo-1.0-1.src.rpm', 'flags': []}, - {'path': '/alt/build/bar-1.0-1.src.rpm', 'flags': []}, + "srpm": [ + {"path": "/build/foo-1.0-1.src.rpm", "flags": []}, + {"path": "/alt/build/bar-1.0-1.src.rpm", "flags": []}, ], - 'debuginfo': [ - {'path': '/build/foo-debuginfo-1.0-1.x86_64.rpm', 'flags': []}, + "debuginfo": [ + {"path": "/build/foo-debuginfo-1.0-1.x86_64.rpm", "flags": []}, ], } - gather.write_packages(self.compose, 'x86_64', self.compose.variants['Server'], pkg_map, '/alt') + gather.write_packages( + self.compose, "x86_64", self.compose.variants["Server"], pkg_map, "/alt" + ) - with open(os.path.join(self.topdir, 'work', 'x86_64', 'package_list', - 'Server.x86_64.rpm.conf')) as f: + with open( + os.path.join( + self.topdir, "work", "x86_64", "package_list", "Server.x86_64.rpm.conf" + ) + ) as f: six.assertCountEqual( self, f.read().strip().split("\n"), - ["/build/foo-1.0-1.x86_64.rpm", - "/build/foo-common-1.0-1.x86_64.rpm", - "/build/bar-1.0-1.noarch.rpm"] + [ + "/build/foo-1.0-1.x86_64.rpm", + "/build/foo-common-1.0-1.x86_64.rpm", + "/build/bar-1.0-1.noarch.rpm", + ], ) - with open(os.path.join(self.topdir, 'work', 'x86_64', 'package_list', - 'Server.x86_64.srpm.conf')) as f: + with open( + os.path.join( + self.topdir, "work", "x86_64", "package_list", "Server.x86_64.srpm.conf" + ) + ) as f: six.assertCountEqual( self, f.read().strip().split("\n"), ["/build/foo-1.0-1.src.rpm", "/build/bar-1.0-1.src.rpm"], ) - with open(os.path.join(self.topdir, 'work', 'x86_64', 'package_list', - 'Server.x86_64.debuginfo.conf')) as f: + with open( + os.path.join( + self.topdir, + "work", + "x86_64", + "package_list", + "Server.x86_64.debuginfo.conf", + ) + ) as f: self.assertEqual(f.read(), "/build/foo-debuginfo-1.0-1.x86_64.rpm\n") @@ -497,56 +737,65 @@ class TestGetVariantPackages(helpers.PungiTestCase): def test_no_variant(self): compose = helpers.DummyCompose(self.topdir, {}) packages, groups, filter_packages = gather.get_variant_packages( - compose, 'x86_64', None, 'comps') + compose, "x86_64", None, "comps" + ) self.assertEqual(packages, set()) self.assertEqual(groups, set()) self.assertEqual(filter_packages, set()) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_just_source(self, get_gather_source): get_gather_source.return_value = mock.Mock( - return_value=mock.Mock(return_value=(set(['foo']), set(['core']))) + return_value=mock.Mock(return_value=(set(["foo"]), set(["core"]))) ) compose = helpers.DummyCompose(self.topdir, {}) packages, groups, filter_packages = gather.get_variant_packages( - compose, 'x86_64', compose.variants['Server'], 'comps') + compose, "x86_64", compose.variants["Server"], "comps" + ) self.assertEqual(packages, set(["foo"])) self.assertEqual(groups, set(["core"])) self.assertEqual(filter_packages, set()) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_filter_system_release(self, get_gather_source): get_gather_source.return_value = mock.Mock( return_value=mock.Mock(return_value=(set(), set())) ) compose = helpers.DummyCompose(self.topdir, {}) pkgset = MockPackageSet( - MockPkg('/build/system-release-1.0.0-1.x86_64.rpm', is_system_release=True), - MockPkg('/build/system-release-server-1.0.0-1.x86_64.rpm', is_system_release=True), + MockPkg("/build/system-release-1.0.0-1.x86_64.rpm", is_system_release=True), + MockPkg( + "/build/system-release-server-1.0.0-1.x86_64.rpm", + is_system_release=True, + ), ) packages, groups, filter_packages = gather.get_variant_packages( compose, "x86_64", - compose.variants["Server"], "comps", + compose.variants["Server"], + "comps", package_sets=[MaterializedPackageSet({"x86_64": pkgset}, {})], ) self.assertEqual(packages, set([("system-release-server", None)])) self.assertEqual(groups, set()) self.assertEqual(filter_packages, set([("system-release", None)])) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_disable_filter_system_release(self, get_gather_source): get_gather_source.return_value = mock.Mock( return_value=mock.Mock(return_value=(set([]), set([]))) ) - compose = helpers.DummyCompose(self.topdir, { - 'filter_system_release_packages': False - }) + compose = helpers.DummyCompose( + self.topdir, {"filter_system_release_packages": False} + ) pkgset = MockPackageSet( - MockPkg('/build/system-release-1.0.0-1.x86_64.rpm', is_system_release=True), - MockPkg('/build/system-release-server-1.0.0-1.x86_64.rpm', is_system_release=True), + MockPkg("/build/system-release-1.0.0-1.x86_64.rpm", is_system_release=True), + MockPkg( + "/build/system-release-server-1.0.0-1.x86_64.rpm", + is_system_release=True, + ), ) packages, groups, filter_packages = gather.get_variant_packages( @@ -560,38 +809,38 @@ class TestGetVariantPackages(helpers.PungiTestCase): self.assertEqual(groups, set()) self.assertEqual(filter_packages, set()) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_optional_gets_parent_and_addon(self, get_gather_source): compose = helpers.DummyCompose(self.topdir, {}) compose.setup_optional() compose.setup_addon() def dummy_source(arch, variant): - if variant.uid == 'Server': - return (set(['server-pkg']), set(['server-group'])) - if variant.uid == 'Server-HA': - return (set(['addon-pkg']), set(['addon-group'])) - if variant.uid == 'Server-optional': - return (set(['opt-pkg']), set(['opt-group'])) - self.assertFalse('This should not be reached') + if variant.uid == "Server": + return (set(["server-pkg"]), set(["server-group"])) + if variant.uid == "Server-HA": + return (set(["addon-pkg"]), set(["addon-group"])) + if variant.uid == "Server-optional": + return (set(["opt-pkg"]), set(["opt-group"])) + self.assertFalse("This should not be reached") get_gather_source.return_value = mock.Mock( return_value=mock.Mock(side_effect=dummy_source) ) packages, groups, filter_packages = gather.get_variant_packages( - compose, 'x86_64', compose.all_variants['Server-optional'], 'comps') + compose, "x86_64", compose.all_variants["Server-optional"], "comps" + ) six.assertCountEqual(self, packages, ["server-pkg", "addon-pkg", "opt-pkg"]) six.assertCountEqual(self, groups, ["server-group", "addon-group", "opt-group"]) self.assertEqual(filter_packages, set()) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_optional_does_not_inherit_filters(self, get_gather_source): - compose = helpers.DummyCompose(self.topdir, { - 'filter_packages': [ - ('^Server(-HA)?$', {'*': ['filter-me']}), - ] - }) + compose = helpers.DummyCompose( + self.topdir, + {"filter_packages": [("^Server(-HA)?$", {"*": ["filter-me"]})]}, + ) compose.setup_optional() compose.setup_addon() @@ -600,36 +849,35 @@ class TestGetVariantPackages(helpers.PungiTestCase): ) packages, groups, filter_packages = gather.get_variant_packages( - compose, 'x86_64', compose.all_variants['Server-optional'], 'comps') + compose, "x86_64", compose.all_variants["Server-optional"], "comps" + ) self.assertEqual(packages, set()) self.assertEqual(groups, set()) self.assertEqual(filter_packages, set()) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_additional_packages(self, get_gather_source): - compose = helpers.DummyCompose(self.topdir, { - 'additional_packages': [ - ('.*', {'*': ['pkg', 'foo.x86_64']}), - ] - }) + compose = helpers.DummyCompose( + self.topdir, + {"additional_packages": [(".*", {"*": ["pkg", "foo.x86_64"]})]}, + ) get_gather_source.return_value = mock.Mock( return_value=mock.Mock(return_value=(set(), set())) ) packages, groups, filter_packages = gather.get_variant_packages( - compose, 'x86_64', compose.all_variants['Server'], 'comps') + compose, "x86_64", compose.all_variants["Server"], "comps" + ) six.assertCountEqual(self, packages, [("pkg", None), ("foo", "x86_64")]) self.assertEqual(groups, set()) self.assertEqual(filter_packages, set()) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_additional_packages_incompatible_arch(self, get_gather_source): - compose = helpers.DummyCompose(self.topdir, { - 'additional_packages': [ - ('.*', {'*': ['foo.ppc64']}), - ] - }) + compose = helpers.DummyCompose( + self.topdir, {"additional_packages": [(".*", {"*": ["foo.ppc64"]})]} + ) get_gather_source.return_value = mock.Mock( return_value=mock.Mock(return_value=(set(), set())) @@ -637,133 +885,192 @@ class TestGetVariantPackages(helpers.PungiTestCase): with self.assertRaises(ValueError) as ctx: packages, groups, filter_packages = gather.get_variant_packages( - compose, 'x86_64', compose.all_variants['Server'], 'comps') + compose, "x86_64", compose.all_variants["Server"], "comps" + ) - self.assertIn('Incompatible package arch', str(ctx.exception)) + self.assertIn("Incompatible package arch", str(ctx.exception)) class TestGetParentPkgs(unittest.TestCase): def setUp(self): - self.variant = helpers.MockVariant(uid='Server', arches=['x86_64'], - type='variant') - self.addon = helpers.MockVariant(uid='Server-HA', arches=['x86_64'], - type='addon', parent=self.variant) + self.variant = helpers.MockVariant( + uid="Server", arches=["x86_64"], type="variant" + ) + self.addon = helpers.MockVariant( + uid="Server-HA", arches=["x86_64"], type="addon", parent=self.variant + ) def test_returns_empty_for_toplevel(self): pkg_map = mock.Mock() - result = gather.get_parent_pkgs('x86_64', self.variant, pkg_map) + result = gather.get_parent_pkgs("x86_64", self.variant, pkg_map) self.assertEqual(result, _mk_pkg_map(iterable_class=set)) def test_on_addon(self): pkg_map = { - 'x86_64': { - 'Server': { - 'rpm': [ - {'path': '/build/foo-1.0-1.x86_64.rpm', 'flags': []}, - ], - 'srpm': [ - {'path': '/build/foo-1.0-1.src.rpm', 'flags': []}, - ], - 'debuginfo': [ - {'path': '/build/foo-debuginfo-1.0-1.x86_64.rpm', 'flags': []}, + "x86_64": { + "Server": { + "rpm": [{"path": "/build/foo-1.0-1.x86_64.rpm", "flags": []}], + "srpm": [{"path": "/build/foo-1.0-1.src.rpm", "flags": []}], + "debuginfo": [ + {"path": "/build/foo-debuginfo-1.0-1.x86_64.rpm", "flags": []}, ], } } } - result = gather.get_parent_pkgs('x86_64', self.addon, pkg_map) - self.assertEqual(result, - {'rpm': set([('foo', 'x86_64')]), - 'srpm': set([('foo', 'src')]), - 'debuginfo': set([('foo-debuginfo', 'x86_64')])}) + result = gather.get_parent_pkgs("x86_64", self.addon, pkg_map) + self.assertEqual( + result, + { + "rpm": set([("foo", "x86_64")]), + "srpm": set([("foo", "src")]), + "debuginfo": set([("foo-debuginfo", "x86_64")]), + }, + ) class TestGatherPackages(helpers.PungiTestCase): - @mock.patch('pungi.phases.gather.get_variant_packages') - @mock.patch('pungi.phases.gather.get_gather_method') + @mock.patch("pungi.phases.gather.get_variant_packages") + @mock.patch("pungi.phases.gather.get_gather_method") def test_no_extra_options(self, get_gather_method, get_variant_packages): packages, groups, filters = mock.Mock(), mock.Mock(), mock.Mock() get_variant_packages.return_value = (packages, groups, filters) compose = helpers.DummyCompose(self.topdir, {}) pkg_set = mock.Mock() self.assertEqual( - gather.gather_packages(compose, 'x86_64', compose.variants['Server'], pkg_set), - {'rpm': [], 'srpm': [], 'debuginfo': []} + gather.gather_packages( + compose, "x86_64", compose.variants["Server"], pkg_set + ), + {"rpm": [], "srpm": [], "debuginfo": []}, + ) + self.assertEqual( + get_gather_method.call_args_list, + [mock.call(compose.conf["gather_method"])] * 3, ) - self.assertEqual(get_gather_method.call_args_list, - [mock.call(compose.conf['gather_method'])] * 3) self.assertEqual( get_variant_packages.call_args_list, [ - mock.call(compose, 'x86_64', compose.variants['Server'], 'module', pkg_set), - mock.call(compose, 'x86_64', compose.variants['Server'], 'comps', pkg_set), - mock.call(compose, 'x86_64', compose.variants['Server'], 'json', pkg_set), + mock.call( + compose, "x86_64", compose.variants["Server"], "module", pkg_set + ), + mock.call( + compose, "x86_64", compose.variants["Server"], "comps", pkg_set + ), + mock.call( + compose, "x86_64", compose.variants["Server"], "json", pkg_set + ), ], ) self.assertEqual( get_gather_method.return_value.return_value.call_args_list, - [mock.call('x86_64', compose.variants['Server'], packages, groups, - filters, set(), set(), pkg_set, fulltree_excludes=set(), - prepopulate=set())] * 3 + [ + mock.call( + "x86_64", + compose.variants["Server"], + packages, + groups, + filters, + set(), + set(), + pkg_set, + fulltree_excludes=set(), + prepopulate=set(), + ) + ] + * 3, ) - @mock.patch('pungi.phases.gather.get_variant_packages') + @mock.patch("pungi.phases.gather.get_variant_packages") def test_empty_variant(self, get_variant_packages): packages, groups, filters = mock.Mock(), mock.Mock(), mock.Mock() get_variant_packages.return_value = (packages, groups, filters) compose = helpers.DummyCompose(self.topdir, {}) - compose.variants['Server'].is_empty = True + compose.variants["Server"].is_empty = True pkg_set = mock.Mock() self.assertEqual( - gather.gather_packages(compose, 'x86_64', compose.variants['Server'], pkg_set), - _mk_pkg_map() + gather.gather_packages( + compose, "x86_64", compose.variants["Server"], pkg_set + ), + _mk_pkg_map(), ) self.assertEqual(get_variant_packages.call_args_list, []) - @mock.patch('pungi.phases.gather.get_variant_packages') - @mock.patch('pungi.phases.gather.get_gather_method') + @mock.patch("pungi.phases.gather.get_variant_packages") + @mock.patch("pungi.phases.gather.get_gather_method") def test_multilib_white_black_list(self, get_gather_method, get_variant_packages): packages, groups, filters = mock.Mock(), mock.Mock(), mock.Mock() get_variant_packages.return_value = (packages, groups, filters) - compose = helpers.DummyCompose(self.topdir, { - 'multilib_whitelist': {'*': ['white']}, - 'multilib_blacklist': {'*': ['black']}, - }) + compose = helpers.DummyCompose( + self.topdir, + { + "multilib_whitelist": {"*": ["white"]}, + "multilib_blacklist": {"*": ["black"]}, + }, + ) pkg_set = mock.Mock() self.assertEqual( - gather.gather_packages(compose, 'x86_64', compose.variants['Server'], pkg_set), - {'rpm': [], 'srpm': [], 'debuginfo': []} + gather.gather_packages( + compose, "x86_64", compose.variants["Server"], pkg_set + ), + {"rpm": [], "srpm": [], "debuginfo": []}, + ) + self.assertEqual( + get_gather_method.call_args_list, + [mock.call(compose.conf["gather_method"])] * 3, ) - self.assertEqual(get_gather_method.call_args_list, - [mock.call(compose.conf['gather_method'])] * 3) self.assertEqual( get_variant_packages.call_args_list, [ - mock.call(compose, 'x86_64', compose.variants['Server'], 'module', pkg_set), - mock.call(compose, 'x86_64', compose.variants['Server'], 'comps', pkg_set), - mock.call(compose, 'x86_64', compose.variants['Server'], 'json', pkg_set), + mock.call( + compose, "x86_64", compose.variants["Server"], "module", pkg_set + ), + mock.call( + compose, "x86_64", compose.variants["Server"], "comps", pkg_set + ), + mock.call( + compose, "x86_64", compose.variants["Server"], "json", pkg_set + ), ], ) self.assertEqual( get_gather_method.return_value.return_value.call_args_list, - [mock.call('x86_64', compose.variants['Server'], packages, groups, - filters, set(['white']), set(['black']), pkg_set, - fulltree_excludes=set(), prepopulate=set())] * 3 + [ + mock.call( + "x86_64", + compose.variants["Server"], + packages, + groups, + filters, + set(["white"]), + set(["black"]), + pkg_set, + fulltree_excludes=set(), + prepopulate=set(), + ) + ] + * 3, ) - @mock.patch('pungi.phases.gather.get_variant_packages') - @mock.patch('pungi.phases.gather.get_gather_method') + @mock.patch("pungi.phases.gather.get_variant_packages") + @mock.patch("pungi.phases.gather.get_gather_method") def test_per_source_method(self, get_gather_method, get_variant_packages): packages, groups, filters = mock.Mock(), mock.Mock(), mock.Mock() get_variant_packages.return_value = (packages, groups, filters) - compose = helpers.DummyCompose(self.topdir, { - 'multilib_whitelist': {'*': ['white']}, - 'multilib_blacklist': {'*': ['black']}, - 'gather_method': {'^Server$': {'comps': 'deps', 'module': 'nodeps', 'json': 'deps'}}, - }) + compose = helpers.DummyCompose( + self.topdir, + { + "multilib_whitelist": {"*": ["white"]}, + "multilib_blacklist": {"*": ["black"]}, + "gather_method": { + "^Server$": {"comps": "deps", "module": "nodeps", "json": "deps"} + }, + }, + ) pkg_set = mock.Mock() - gather.gather_packages(compose, 'x86_64', compose.variants['Server'], pkg_set), - self.assertEqual(get_gather_method.call_args_list, - [mock.call('nodeps'), mock.call('deps'), mock.call('deps')]) + gather.gather_packages(compose, "x86_64", compose.variants["Server"], pkg_set), + self.assertEqual( + get_gather_method.call_args_list, + [mock.call("nodeps"), mock.call("deps"), mock.call("deps")], + ) @mock.patch("pungi.phases.gather.get_variant_packages") @mock.patch("pungi.phases.gather.get_gather_method") @@ -780,9 +1087,7 @@ class TestGatherPackages(helpers.PungiTestCase): gather.gather_packages(compose, "x86_64", variant, pkg_set), self.assertEqual( get_variant_packages.call_args_list, - [ - mock.call(compose, "x86_64", variant, "comps", pkg_set) - ], + [mock.call(compose, "x86_64", variant, "comps", pkg_set)], ) self.assertEqual(get_gather_method.call_args_list, [mock.call("hybrid")]) method_kwargs = get_gather_method.return_value.return_value.call_args_list[0][1] @@ -794,31 +1099,50 @@ class TestWritePrepopulate(helpers.PungiTestCase): def test_without_config(self): compose = helpers.DummyCompose(self.topdir, {}) gather.write_prepopulate_file(compose) - self.assertFalse(os.path.isfile(os.path.join(self.topdir, 'work', 'global', 'prepopulate.json'))) + self.assertFalse( + os.path.isfile( + os.path.join(self.topdir, "work", "global", "prepopulate.json") + ) + ) def test_copy_by_filename(self): - compose = helpers.DummyCompose(self.topdir, { - 'gather_prepopulate': 'input-prepopulate.json', - }) + compose = helpers.DummyCompose( + self.topdir, {"gather_prepopulate": "input-prepopulate.json"} + ) compose.config_dir = self.topdir - helpers.copy_fixture('prepopulate.json', os.path.join(self.topdir, 'input-prepopulate.json')) + helpers.copy_fixture( + "prepopulate.json", os.path.join(self.topdir, "input-prepopulate.json") + ) gather.write_prepopulate_file(compose) - self.assertTrue(os.path.isfile(os.path.join(self.topdir, 'work', 'global', 'prepopulate.json'))) + self.assertTrue( + os.path.isfile( + os.path.join(self.topdir, "work", "global", "prepopulate.json") + ) + ) def test_copy_local_by_scm_dict(self): - compose = helpers.DummyCompose(self.topdir, { - 'gather_prepopulate': { - 'file': 'input-prepopulate.json', - 'scm': 'file', - 'repo': None, - } - }) + compose = helpers.DummyCompose( + self.topdir, + { + "gather_prepopulate": { + "file": "input-prepopulate.json", + "scm": "file", + "repo": None, + } + }, + ) compose.config_dir = self.topdir - helpers.copy_fixture('prepopulate.json', os.path.join(self.topdir, 'input-prepopulate.json')) + helpers.copy_fixture( + "prepopulate.json", os.path.join(self.topdir, "input-prepopulate.json") + ) gather.write_prepopulate_file(compose) - self.assertTrue(os.path.isfile(os.path.join(self.topdir, 'work', 'global', 'prepopulate.json'))) + self.assertTrue( + os.path.isfile( + os.path.join(self.topdir, "work", "global", "prepopulate.json") + ) + ) class TestGetPrepopulate(helpers.PungiTestCase): @@ -828,78 +1152,96 @@ class TestGetPrepopulate(helpers.PungiTestCase): def test_no_file(self): self.assertEqual( - gather.get_prepopulate_packages(self.compose, 'x86_64', self.compose.variants['Server']), - set() + gather.get_prepopulate_packages( + self.compose, "x86_64", self.compose.variants["Server"] + ), + set(), ) def test_for_one_variant(self): - helpers.copy_fixture('prepopulate.json', - os.path.join(self.topdir, 'work', 'global', 'prepopulate.json')) + helpers.copy_fixture( + "prepopulate.json", + os.path.join(self.topdir, "work", "global", "prepopulate.json"), + ) six.assertCountEqual( self, - gather.get_prepopulate_packages(self.compose, 'x86_64', self.compose.variants['Server']), - ["foo-common.noarch", - "foo.i686", - "foo.x86_64"] + gather.get_prepopulate_packages( + self.compose, "x86_64", self.compose.variants["Server"] + ), + ["foo-common.noarch", "foo.i686", "foo.x86_64"], ) def test_for_all_variants(self): - helpers.copy_fixture('prepopulate.json', - os.path.join(self.topdir, 'work', 'global', 'prepopulate.json')) + helpers.copy_fixture( + "prepopulate.json", + os.path.join(self.topdir, "work", "global", "prepopulate.json"), + ) six.assertCountEqual( self, - gather.get_prepopulate_packages(self.compose, 'x86_64', None), - ["foo-common.noarch", - "foo.i686", - "foo.x86_64", - "bar.x86_64"] + gather.get_prepopulate_packages(self.compose, "x86_64", None), + ["foo-common.noarch", "foo.i686", "foo.x86_64", "bar.x86_64"], ) def test_for_all_variants_include_arch_set_to_false(self): - helpers.copy_fixture('prepopulate.json', - os.path.join(self.topdir, 'work', 'global', 'prepopulate.json')) + helpers.copy_fixture( + "prepopulate.json", + os.path.join(self.topdir, "work", "global", "prepopulate.json"), + ) six.assertCountEqual( self, - gather.get_prepopulate_packages(self.compose, 'x86_64', None, - include_arch=False), - ["foo-common", - "foo", - "bar"] + gather.get_prepopulate_packages( + self.compose, "x86_64", None, include_arch=False + ), + ["foo-common", "foo", "bar"], ) class TestGatherPhase(helpers.PungiTestCase): - @mock.patch('pungi.phases.gather.link_files') - @mock.patch('pungi.phases.gather.gather_wrapper') + @mock.patch("pungi.phases.gather.link_files") + @mock.patch("pungi.phases.gather.gather_wrapper") def test_run(self, gather_wrapper, link_files): pkgset_phase = mock.Mock() compose = helpers.DummyCompose(self.topdir, {}) compose.notifier = mock.Mock() - compose.all_variants['Client'].is_empty = True + compose.all_variants["Client"].is_empty = True pkg_map = gather_wrapper.return_value def _mk_link_call(arch, variant): - return mock.call(compose, arch, compose.all_variants[variant], - pkg_map[arch][variant], - pkgset_phase.package_sets, manifest=phase.manifest) + return mock.call( + compose, + arch, + compose.all_variants[variant], + pkg_map[arch][variant], + pkgset_phase.package_sets, + manifest=phase.manifest, + ) phase = gather.GatherPhase(compose, pkgset_phase) phase.run() phase.stop() - self.assertEqual(gather_wrapper.call_args_list, - [mock.call(compose, pkgset_phase.package_sets, pkgset_phase.path_prefix)]) + self.assertEqual( + gather_wrapper.call_args_list, + [mock.call(compose, pkgset_phase.package_sets, pkgset_phase.path_prefix)], + ) six.assertCountEqual( self, link_files.call_args_list, - [_mk_link_call('x86_64', 'Server'), - _mk_link_call('amd64', 'Server'), - _mk_link_call('amd64', 'Everything'), - _mk_link_call('x86_64', 'Everything')]) - self.assertTrue(os.path.isfile(os.path.join(self.topdir, 'compose', 'metadata', 'rpms.json'))) + [ + _mk_link_call("x86_64", "Server"), + _mk_link_call("amd64", "Server"), + _mk_link_call("amd64", "Everything"), + _mk_link_call("x86_64", "Everything"), + ], + ) + self.assertTrue( + os.path.isfile( + os.path.join(self.topdir, "compose", "metadata", "rpms.json") + ) + ) - @mock.patch('pungi.phases.gather.link_files') - @mock.patch('pungi.phases.gather.gather_wrapper') + @mock.patch("pungi.phases.gather.link_files") + @mock.patch("pungi.phases.gather.gather_wrapper") def test_writes_manifest_when_skipped(self, gather_wrapper, link_files): pkgset_phase = mock.Mock() compose = helpers.DummyCompose(self.topdir, {}) @@ -909,7 +1251,11 @@ class TestGatherPhase(helpers.PungiTestCase): phase.stop() self.assertEqual(gather_wrapper.call_args_list, []) - self.assertFalse(os.path.isfile(os.path.join(self.topdir, 'compose', 'metadata', 'rpms.json'))) + self.assertFalse( + os.path.isfile( + os.path.join(self.topdir, "compose", "metadata", "rpms.json") + ) + ) def test_validates_wrong_requiring_variant(self): pkgset_phase = mock.Mock() @@ -942,18 +1288,19 @@ class TestGatherPhase(helpers.PungiTestCase): class TestGetPackagesToGather(helpers.PungiTestCase): def setUp(self): super(TestGetPackagesToGather, self).setUp() - self.compose = helpers.DummyCompose(self.topdir, { - 'additional_packages': [ - ('.*', {'*': ['pkg', 'foo2.x86_64']}), - ] - }) - helpers.copy_fixture('prepopulate.json', - os.path.join(self.topdir, 'work', 'global', 'prepopulate.json')) + self.compose = helpers.DummyCompose( + self.topdir, + {"additional_packages": [(".*", {"*": ["pkg", "foo2.x86_64"]})]}, + ) + helpers.copy_fixture( + "prepopulate.json", + os.path.join(self.topdir, "work", "global", "prepopulate.json"), + ) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_all_arches(self, get_gather_source): get_gather_source.return_value = mock.Mock( - return_value=mock.Mock(return_value=(set([('foo', None)]), set(['core']))) + return_value=mock.Mock(return_value=(set([("foo", None)]), set(["core"]))) ) packages, groups = gather.get_packages_to_gather(self.compose) @@ -961,51 +1308,63 @@ class TestGetPackagesToGather(helpers.PungiTestCase): six.assertCountEqual(self, packages, ["foo", "foo2.x86_64", "pkg"]) self.assertEqual(groups, ["core"]) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_all_include_arch_set_to_false(self, get_gather_source): get_gather_source.return_value = mock.Mock( - return_value=mock.Mock(return_value=(set([('foo', None)]), set(['core']))) + return_value=mock.Mock(return_value=(set([("foo", None)]), set(["core"]))) ) - packages, groups = gather.get_packages_to_gather(self.compose, include_arch=False) + packages, groups = gather.get_packages_to_gather( + self.compose, include_arch=False + ) six.assertCountEqual(self, packages, ["foo", "foo2", "pkg"]) self.assertEqual(groups, ["core"]) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_all_include_prepopulated(self, get_gather_source): get_gather_source.return_value = mock.Mock( - return_value=mock.Mock(return_value=(set([('foo', None)]), set(['core']))) + return_value=mock.Mock(return_value=(set([("foo", None)]), set(["core"]))) ) - packages, groups = gather.get_packages_to_gather(self.compose, include_prepopulated=True) + packages, groups = gather.get_packages_to_gather( + self.compose, include_prepopulated=True + ) six.assertCountEqual( self, packages, - ["foo", "pkg", "foo-common.noarch", "foo.x86_64", "foo.i686", "foo2.x86_64", - "bar.x86_64"], + [ + "foo", + "pkg", + "foo-common.noarch", + "foo.x86_64", + "foo.i686", + "foo2.x86_64", + "bar.x86_64", + ], ) self.assertEqual(groups, ["core"]) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_all_include_prepopulated_no_include_arch(self, get_gather_source): get_gather_source.return_value = mock.Mock( - return_value=mock.Mock(return_value=(set([('foo', None)]), set(['core']))) + return_value=mock.Mock(return_value=(set([("foo", None)]), set(["core"]))) ) - packages, groups = gather.get_packages_to_gather(self.compose, include_prepopulated=True, - include_arch=False) + packages, groups = gather.get_packages_to_gather( + self.compose, include_prepopulated=True, include_arch=False + ) six.assertCountEqual( self, packages, ["foo", "pkg", "foo-common", "foo2", "bar"] ) self.assertEqual(groups, ["core"]) - @mock.patch('pungi.phases.gather.get_gather_source') + @mock.patch("pungi.phases.gather.get_gather_source") def test_all_one_arch(self, get_gather_source): get_gather_source.return_value = mock.Mock( - return_value=mock.Mock(return_value=(set([('foo', None)]), set(['core']))) + return_value=mock.Mock(return_value=(set([("foo", None)]), set(["core"]))) ) packages, groups = gather.get_packages_to_gather(self.compose, "x86_64") @@ -1015,94 +1374,113 @@ class TestGetPackagesToGather(helpers.PungiTestCase): class TestUpdateConfig(unittest.TestCase): - def test_add_to_empty(self): compose = mock.Mock(conf={}) - gather._update_config(compose, 'Server', 'x86_64', '/tmp/foo') - self.assertEqual(compose.conf, - {'gather_lookaside_repos': [ - ('^Server$', {'x86_64': '/tmp/foo'}) - ]}) + gather._update_config(compose, "Server", "x86_64", "/tmp/foo") + self.assertEqual( + compose.conf, + {"gather_lookaside_repos": [("^Server$", {"x86_64": "/tmp/foo"})]}, + ) def test_add_to_existing(self): - compose = mock.Mock(conf={'gather_lookaside_repos': [ - ('^Server$', {'x86_64': '/tmp/bar'}), - ]}) - gather._update_config(compose, 'Server', 'x86_64', '/tmp/foo') - self.assertEqual(compose.conf, - {'gather_lookaside_repos': [ - ('^Server$', {'x86_64': '/tmp/bar'}), - ('^Server$', {'x86_64': '/tmp/foo'}) - ]}) + compose = mock.Mock( + conf={"gather_lookaside_repos": [("^Server$", {"x86_64": "/tmp/bar"})]} + ) + gather._update_config(compose, "Server", "x86_64", "/tmp/foo") + self.assertEqual( + compose.conf, + { + "gather_lookaside_repos": [ + ("^Server$", {"x86_64": "/tmp/bar"}), + ("^Server$", {"x86_64": "/tmp/foo"}), + ] + }, + ) class TestUpdateLookasideConfig(helpers.PungiTestCase): - def setUp(self): super(TestUpdateLookasideConfig, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) self.pkg_map = mock.Mock() - @mock.patch('pungi.phases.gather._update_config') - @mock.patch('pungi.phases.gather._make_lookaside_repo') + @mock.patch("pungi.phases.gather._update_config") + @mock.patch("pungi.phases.gather._make_lookaside_repo") def test_no_config(self, mock_make_repo, mock_update_config): - gather._update_lookaside_config(self.compose, self.compose.variants['Server'], - 'x86_64', self.pkg_map) + gather._update_lookaside_config( + self.compose, self.compose.variants["Server"], "x86_64", self.pkg_map + ) self.assertEqual(mock_make_repo.call_args_list, []) self.assertEqual(mock_update_config.call_args_list, []) - @mock.patch('pungi.phases.gather._update_config') - @mock.patch('pungi.phases.gather._make_lookaside_repo') + @mock.patch("pungi.phases.gather._update_config") + @mock.patch("pungi.phases.gather._make_lookaside_repo") def test_no_matching_config(self, mock_make_repo, mock_update_config): - self.compose.conf['variant_as_lookaside'] = [('Everything', 'Client')] - gather._update_lookaside_config(self.compose, self.compose.variants['Server'], - 'x86_64', self.pkg_map) + self.compose.conf["variant_as_lookaside"] = [("Everything", "Client")] + gather._update_lookaside_config( + self.compose, self.compose.variants["Server"], "x86_64", self.pkg_map + ) self.assertEqual(mock_make_repo.call_args_list, []) self.assertEqual(mock_update_config.call_args_list, []) - @mock.patch('pungi.phases.gather._update_config') - @mock.patch('pungi.phases.gather._make_lookaside_repo') + @mock.patch("pungi.phases.gather._update_config") + @mock.patch("pungi.phases.gather._make_lookaside_repo") def test_missing_arch(self, mock_make_repo, mock_update_config): # Client only has amd64 - self.compose.conf['variant_as_lookaside'] = [('Server', 'Client')] - gather._update_lookaside_config(self.compose, self.compose.variants['Server'], - 'x86_64', self.pkg_map) + self.compose.conf["variant_as_lookaside"] = [("Server", "Client")] + gather._update_lookaside_config( + self.compose, self.compose.variants["Server"], "x86_64", self.pkg_map + ) self.assertEqual(len(self.compose.log_warning.call_args_list), 1) self.assertEqual(mock_make_repo.call_args_list, []) self.assertEqual(mock_update_config.call_args_list, []) - @mock.patch('pungi.phases.gather._update_config') - @mock.patch('pungi.phases.gather._make_lookaside_repo') + @mock.patch("pungi.phases.gather._update_config") + @mock.patch("pungi.phases.gather._make_lookaside_repo") def test_match(self, mock_make_repo, mock_update_config): - self.compose.conf['variant_as_lookaside'] = [('Server', 'Everything')] - gather._update_lookaside_config(self.compose, self.compose.variants['Server'], - 'x86_64', self.pkg_map) + self.compose.conf["variant_as_lookaside"] = [("Server", "Everything")] + gather._update_lookaside_config( + self.compose, self.compose.variants["Server"], "x86_64", self.pkg_map + ) self.assertEqual(len(self.compose.log_warning.call_args_list), 0) - self.assertEqual(mock_make_repo.call_args_list, - [mock.call(self.compose, - self.compose.variants['Everything'], - 'x86_64', - self.pkg_map, None)]) - self.assertEqual(mock_update_config.call_args_list, - [mock.call(self.compose, 'Server', 'x86_64', - mock_make_repo.return_value)]) + self.assertEqual( + mock_make_repo.call_args_list, + [ + mock.call( + self.compose, + self.compose.variants["Everything"], + "x86_64", + self.pkg_map, + None, + ) + ], + ) + self.assertEqual( + mock_update_config.call_args_list, + [mock.call(self.compose, "Server", "x86_64", mock_make_repo.return_value)], + ) class TestMakeLookasideRepo(helpers.PungiTestCase): - def setUp(self): super(TestMakeLookasideRepo, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) - self.variant = self.compose.variants['Server'] - self.arch = 'x86_64' - self.repodir = self.compose.paths.work.lookaside_repo(self.arch, self.variant, create_dir=False) - self.pkglist = self.compose.paths.work.lookaside_package_list(self.arch, self.variant) + self.variant = self.compose.variants["Server"] + self.arch = "x86_64" + self.repodir = self.compose.paths.work.lookaside_repo( + self.arch, self.variant, create_dir=False + ) + self.pkglist = self.compose.paths.work.lookaside_package_list( + self.arch, self.variant + ) self.package_sets = self._make_pkgset_phase(["p1", "p2"]).package_sets - @mock.patch('pungi.phases.gather.run') + @mock.patch("pungi.phases.gather.run") def test_existing_repo(self, mock_run): - helpers.touch(os.path.join(self.repodir, 'repodata', 'primary.xml')) - repopath = gather._make_lookaside_repo(self.compose, self.variant, self.arch, {}) + helpers.touch(os.path.join(self.repodir, "repodata", "primary.xml")) + repopath = gather._make_lookaside_repo( + self.compose, self.variant, self.arch, {} + ) self.assertEqual(self.repodir, repopath) self.assertFalse(os.path.exists(self.pkglist)) self.assertEqual(mock_run.call_args_list, []) @@ -1121,65 +1499,90 @@ class TestMakeLookasideRepo(helpers.PungiTestCase): ) self.assertEqual(self.repodir, repopath) - self.assertEqual(MockCR.return_value.get_createrepo_cmd.call_args_list, - [mock.call(path_prefix, update=True, database=True, skip_stat=True, - pkglist=self.pkglist, outputdir=repopath, - baseurl="file://%s" % path_prefix, workers=3, - update_md_path=self.compose.paths.work.pkgset_repo("p2", self.arch))]) - self.assertEqual(mock_run.call_args_list, - [mock.call(MockCR.return_value.get_createrepo_cmd.return_value, - logfile=os.path.join( - self.topdir, 'logs', self.arch, - 'lookaside_repo_Server.%s.log' % self.arch), - show_cmd=True)]) + self.assertEqual( + MockCR.return_value.get_createrepo_cmd.call_args_list, + [ + mock.call( + path_prefix, + update=True, + database=True, + skip_stat=True, + pkglist=self.pkglist, + outputdir=repopath, + baseurl="file://%s" % path_prefix, + workers=3, + update_md_path=self.compose.paths.work.pkgset_repo("p2", self.arch), + ) + ], + ) + self.assertEqual( + mock_run.call_args_list, + [ + mock.call( + MockCR.return_value.get_createrepo_cmd.return_value, + logfile=os.path.join( + self.topdir, + "logs", + self.arch, + "lookaside_repo_Server.%s.log" % self.arch, + ), + show_cmd=True, + ) + ], + ) - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - @mock.patch('pungi.phases.gather.CreaterepoWrapper') - @mock.patch('pungi.phases.gather.run') + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + @mock.patch("pungi.phases.gather.CreaterepoWrapper") + @mock.patch("pungi.phases.gather.run") def test_create_repo_koji_pkgset(self, mock_run, MockCR, MockKW): - self.compose.conf.update({ - 'pkgset_source': 'koji', - 'koji_profile': 'koji', - }) + self.compose.conf.update({"pkgset_source": "koji", "koji_profile": "koji"}) pkg_map = { self.arch: { self.variant.uid: { - 'rpm': [{'path': '/tmp/packages/pkg/pkg-1.0-1.x86_64.rpm'}], - 'debuginfo': [{'path': '/tmp/packages/pkg/pkg-debuginfo-1.0-1.x86_64.rpm'}], - 'srpm': [{'path': '/tmp/packages/pkg/pkg-1.0-1.src.rpm'}], + "rpm": [{"path": "/tmp/packages/pkg/pkg-1.0-1.x86_64.rpm"}], + "debuginfo": [ + {"path": "/tmp/packages/pkg/pkg-debuginfo-1.0-1.x86_64.rpm"} + ], + "srpm": [{"path": "/tmp/packages/pkg/pkg-1.0-1.src.rpm"}], } } } - MockKW.return_value.koji_module.config.topdir = '/tmp/packages' + MockKW.return_value.koji_module.config.topdir = "/tmp/packages" repopath = gather._make_lookaside_repo( self.compose, self.variant, self.arch, pkg_map, self.package_sets ) - self.assertCorrect(repopath, '/tmp/packages/', MockCR, mock_run) + self.assertCorrect(repopath, "/tmp/packages/", MockCR, mock_run) - @mock.patch('pungi.phases.gather.CreaterepoWrapper') - @mock.patch('pungi.phases.gather.run') + @mock.patch("pungi.phases.gather.CreaterepoWrapper") + @mock.patch("pungi.phases.gather.run") def test_create_repo_repos_pkgset(self, mock_run, MockCR): - self.compose.conf.update({ - 'pkgset_source': 'repos', - }) + self.compose.conf.update({"pkgset_source": "repos"}) - dl_dir = self.compose.paths.work.topdir('global') + dl_dir = self.compose.paths.work.topdir("global") pkg_map = { self.arch: { self.variant.uid: { - 'rpm': [ - {'path': os.path.join(dl_dir, 'download/pkg/pkg-1.0-1.x86_64.rpm')} + "rpm": [ + { + "path": os.path.join( + dl_dir, "download/pkg/pkg-1.0-1.x86_64.rpm" + ) + } ], - 'debuginfo': [ - {'path': os.path.join(dl_dir, 'download/pkg/pkg-debuginfo-1.0-1.x86_64.rpm')} + "debuginfo": [ + { + "path": os.path.join( + dl_dir, "download/pkg/pkg-debuginfo-1.0-1.x86_64.rpm" + ) + } ], - 'srpm': [ - {'path': os.path.join(dl_dir, 'download/pkg/pkg-1.0-1.src.rpm')} + "srpm": [ + {"path": os.path.join(dl_dir, "download/pkg/pkg-1.0-1.src.rpm")} ], } } @@ -1189,4 +1592,4 @@ class TestMakeLookasideRepo(helpers.PungiTestCase): self.compose, self.variant, self.arch, pkg_map, self.package_sets ) - self.assertCorrect(repopath, dl_dir + '/download/', MockCR, mock_run) + self.assertCorrect(repopath, dl_dir + "/download/", MockCR, mock_run) diff --git a/tests/test_graph.py b/tests/test_graph.py index b22fc0e6..ad8ebd3d 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -12,15 +12,14 @@ from pungi.graph import SimpleAcyclicOrientedGraph class SimpleAcyclicOrientedGraphTestCase(unittest.TestCase): - def setUp(self): self.g = SimpleAcyclicOrientedGraph() def test_simple_graph(self): graph_data = ( - ('Client', 'Base'), - ('Server', 'Base'), - ('Workstation', 'Base'), + ("Client", "Base"), + ("Server", "Base"), + ("Workstation", "Base"), ) for start, end in graph_data: @@ -33,13 +32,13 @@ class SimpleAcyclicOrientedGraphTestCase(unittest.TestCase): def test_complex_graph(self): graph_data = ( - ('1', '3'), # 1 --> 3 --> 4 --> 5 ... - ('3', '4'), - ('4', '5'), - ('4', '6'), - ('2', '4'), - ('7', '6'), - ('6', '5'), + ("1", "3"), # 1 --> 3 --> 4 --> 5 ... + ("3", "4"), + ("4", "5"), + ("4", "6"), + ("2", "4"), + ("7", "6"), + ("6", "5"), ) for start, end in graph_data: @@ -47,13 +46,13 @@ class SimpleAcyclicOrientedGraphTestCase(unittest.TestCase): spanning_line = self.g.prune_graph() # spanning line have to match completely to given graph - self.assertEqual(['1', '3', '2', '4', '7', '6', '5'], spanning_line) + self.assertEqual(["1", "3", "2", "4", "7", "6", "5"], spanning_line) def test_cyclic_graph(self): graph_data = ( - ('1', '2'), - ('2', '3'), - ('3', '1'), + ("1", "2"), + ("2", "3"), + ("3", "1"), ) with self.assertRaises(ValueError): @@ -62,28 +61,28 @@ class SimpleAcyclicOrientedGraphTestCase(unittest.TestCase): def test_two_separate_graph_lines(self): graph_data = ( - ('1', '3'), # 1st graph - ('3', '2'), # 1st graph - ('6', '5'), # 2nd graph + ("1", "3"), # 1st graph + ("3", "2"), # 1st graph + ("6", "5"), # 2nd graph ) for start, end in graph_data: self.g.add_edge(start, end) spanning_line = self.g.prune_graph() - spanning_line_str = ''.join(spanning_line) + spanning_line_str = "".join(spanning_line) self.assertEqual(5, len(spanning_line)) # Particular parts should match. Order of these parts is not crucial. self.assertTrue( "132" in spanning_line_str and "65" in spanning_line_str, - "Spanning line '%s' does not match to graphs" % spanning_line_str + "Spanning line '%s' does not match to graphs" % spanning_line_str, ) def alternative_route_in_graph(self): graph_data = ( - ('1', '3'), - ('3', '2'), - ('1', '2'), + ("1", "3"), + ("3", "2"), + ("1", "2"), ) for start, end in graph_data: @@ -91,4 +90,4 @@ class SimpleAcyclicOrientedGraphTestCase(unittest.TestCase): spanning_line = self.g.prune_graph() # spanning line have to match completely to given graph - self.assertEqual(['1', '3', '2'], spanning_line) + self.assertEqual(["1", "3", "2"], spanning_line) diff --git a/tests/test_imagebuildphase.py b/tests/test_imagebuildphase.py index 81f85c80..9fba191e 100644 --- a/tests/test_imagebuildphase.py +++ b/tests/test_imagebuildphase.py @@ -12,33 +12,35 @@ from tests.helpers import DummyCompose, PungiTestCase, boom class TestImageBuildPhase(PungiTestCase): - def setUp(self): super(TestImageBuildPhase, self).setUp() self.maxDiff = None - @mock.patch('pungi.phases.image_build.ThreadPool') + @mock.patch("pungi.phases.image_build.ThreadPool") def test_image_build(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Client|Server$': [ - { - 'image-build': { - 'format': [('docker', 'tar.xz')], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'failable': ['x86_64'], + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Client|Server$": [ + { + "image-build": { + "format": [("docker", "tar.xz")], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "failable": ["x86_64"], + } } - } - ] + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) self.assertValidConfig(compose.conf) @@ -50,50 +52,52 @@ class TestImageBuildPhase(PungiTestCase): self.assertTrue(phase.pool.add.called) client_args = { "image_conf": { - 'image-build': { - 'install_tree': self.topdir + '/compose/Client/$arch/os', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker'], - 'repo': self.topdir + '/compose/Client/$arch/os', - 'variant': compose.variants['Client'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['amd64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - 'can_fail': ['x86_64'], + "image-build": { + "install_tree": self.topdir + "/compose/Client/$arch/os", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": self.topdir + "/compose/Client/$arch/os", + "variant": compose.variants["Client"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["amd64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + "can_fail": ["x86_64"], } }, - "conf_file": self.topdir + '/work/image-build/Client/docker_Fedora-Docker-Base_amd64.cfg', - "image_dir": self.topdir + '/compose/Client/%(arch)s/images', - "relative_image_dir": 'Client/%(arch)s/images', - "link_type": 'hardlink-or-copy', + "conf_file": self.topdir + + "/work/image-build/Client/docker_Fedora-Docker-Base_amd64.cfg", + "image_dir": self.topdir + "/compose/Client/%(arch)s/images", + "relative_image_dir": "Client/%(arch)s/images", + "link_type": "hardlink-or-copy", "scratch": False, } server_args = { "image_conf": { - 'image-build': { - 'install_tree': self.topdir + '/compose/Server/$arch/os', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker'], - 'repo': self.topdir + '/compose/Server/$arch/os', - 'variant': compose.variants['Server'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['amd64', 'x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - 'can_fail': ['x86_64'], + "image-build": { + "install_tree": self.topdir + "/compose/Server/$arch/os", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": self.topdir + "/compose/Server/$arch/os", + "variant": compose.variants["Server"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["amd64", "x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + "can_fail": ["x86_64"], } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg', - "image_dir": self.topdir + '/compose/Server/%(arch)s/images', - "relative_image_dir": 'Server/%(arch)s/images', - "link_type": 'hardlink-or-copy', + "conf_file": self.topdir + + "/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg", + "image_dir": self.topdir + "/compose/Server/%(arch)s/images", + "relative_image_dir": "Server/%(arch)s/images", + "link_type": "hardlink-or-copy", "scratch": False, } six.assertCountEqual( @@ -102,28 +106,31 @@ class TestImageBuildPhase(PungiTestCase): [mock.call((compose, client_args)), mock.call((compose, server_args))], ) - @mock.patch('pungi.phases.image_build.ThreadPool') + @mock.patch("pungi.phases.image_build.ThreadPool") def test_image_build_phase_global_options(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build_ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'image_build_release': '!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN', - 'image_build_target': 'f24', - 'image_build_version': 'Rawhide', - 'image_build': { - '^Server$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3 + compose = DummyCompose( + self.topdir, + { + "image_build_ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "image_build_release": "!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN", + "image_build_target": "f24", + "image_build_version": "Rawhide", + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + } } - } - ] + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) self.assertValidConfig(compose.conf) @@ -135,53 +142,57 @@ class TestImageBuildPhase(PungiTestCase): self.assertTrue(phase.pool.add.called) server_args = { "image_conf": { - 'image-build': { - 'install_tree': self.topdir + '/compose/Server/$arch/os', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker'], - 'repo': self.topdir + '/compose/Server/$arch/os', - 'variant': compose.variants['Server'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['amd64', 'x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - 'release': '20151203.t.0', + "image-build": { + "install_tree": self.topdir + "/compose/Server/$arch/os", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": self.topdir + "/compose/Server/$arch/os", + "variant": compose.variants["Server"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["amd64", "x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + "release": "20151203.t.0", } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg', - "image_dir": self.topdir + '/compose/Server/%(arch)s/images', - "relative_image_dir": 'Server/%(arch)s/images', - "link_type": 'hardlink-or-copy', + "conf_file": self.topdir + + "/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg", + "image_dir": self.topdir + "/compose/Server/%(arch)s/images", + "relative_image_dir": "Server/%(arch)s/images", + "link_type": "hardlink-or-copy", "scratch": False, } self.assertEqual( phase.pool.queue_put.mock_calls, [mock.call((compose, server_args))] ) - @mock.patch('pungi.phases.image_build.ThreadPool') + @mock.patch("pungi.phases.image_build.ThreadPool") def test_image_build_phase_missing_version(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build_ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'image_build_release': '!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN', - 'image_build_target': 'f24', - 'image_build': { - '^Server$': [ - { - 'image-build': { - 'format': 'docker', - 'name': 'Fedora-Docker-Base', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3 + compose = DummyCompose( + self.topdir, + { + "image_build_ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "image_build_release": "!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN", + "image_build_target": "f24", + "image_build": { + "^Server$": [ + { + "image-build": { + "format": "docker", + "name": "Fedora-Docker-Base", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + } } - } - ] + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) phase = ImageBuildPhase(compose) @@ -191,54 +202,58 @@ class TestImageBuildPhase(PungiTestCase): self.assertTrue(phase.pool.add.called) server_args = { "image_conf": { - 'image-build': { - 'install_tree': self.topdir + '/compose/Server/$arch/os', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker'], - 'repo': self.topdir + '/compose/Server/$arch/os', - 'variant': compose.variants['Server'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['amd64', 'x86_64'], - 'version': '25', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - 'release': '20151203.t.0', + "image-build": { + "install_tree": self.topdir + "/compose/Server/$arch/os", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": self.topdir + "/compose/Server/$arch/os", + "variant": compose.variants["Server"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["amd64", "x86_64"], + "version": "25", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + "release": "20151203.t.0", } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg', - "image_dir": self.topdir + '/compose/Server/%(arch)s/images', - "relative_image_dir": 'Server/%(arch)s/images', - "link_type": 'hardlink-or-copy', + "conf_file": self.topdir + + "/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg", + "image_dir": self.topdir + "/compose/Server/%(arch)s/images", + "relative_image_dir": "Server/%(arch)s/images", + "link_type": "hardlink-or-copy", "scratch": False, } self.assertEqual( phase.pool.queue_put.mock_calls, [mock.call((compose, server_args))] ) - @mock.patch('pungi.phases.image_build.ThreadPool') + @mock.patch("pungi.phases.image_build.ThreadPool") def test_image_build_filter_all_variants(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Client|Server$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'arches': ['non-existing'], + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Client|Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "arches": ["non-existing"], + } } - } - ] + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) self.assertValidConfig(compose.conf) @@ -250,29 +265,32 @@ class TestImageBuildPhase(PungiTestCase): self.assertFalse(phase.pool.add.called) self.assertFalse(phase.pool.queue_put.called) - @mock.patch('pungi.phases.image_build.ThreadPool') + @mock.patch("pungi.phases.image_build.ThreadPool") def test_image_build_set_install_tree(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Server$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'arches': ['x86_64'], - 'install_tree_from': 'Server-optional', + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "arches": ["x86_64"], + "install_tree_from": "Server-optional", + } } - } - ] + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) compose.setup_optional() self.assertValidConfig(compose.conf) @@ -287,54 +305,62 @@ class TestImageBuildPhase(PungiTestCase): self.assertTrue(phase.pool.queue_put.called_once) args, kwargs = phase.pool.queue_put.call_args self.assertEqual(args[0][0], compose) - self.assertDictEqual(args[0][1], { - "image_conf": { - 'image-build': { - 'install_tree': self.topdir + '/compose/Server-optional/$arch/os', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker'], - 'repo': self.topdir + '/compose/Server/$arch/os', - 'variant': compose.variants['Server'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - } + self.assertDictEqual( + args[0][1], + { + "image_conf": { + "image-build": { + "install_tree": self.topdir + + "/compose/Server-optional/$arch/os", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": self.topdir + "/compose/Server/$arch/os", + "variant": compose.variants["Server"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + } + }, + "conf_file": self.topdir + + "/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg", + "image_dir": self.topdir + "/compose/Server/%(arch)s/images", + "relative_image_dir": "Server/%(arch)s/images", + "link_type": "hardlink-or-copy", + "scratch": False, }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg', - "image_dir": self.topdir + '/compose/Server/%(arch)s/images', - "relative_image_dir": 'Server/%(arch)s/images', - "link_type": 'hardlink-or-copy', - "scratch": False, - }) + ) @mock.patch("pungi.phases.image_build.ThreadPool") def test_image_build_set_install_tree_from_path(self, ThreadPool): - compose = DummyCompose(self.topdir, { - "image_build": { - "^Server$": [ - { - "image-build": { - "format": ["docker"], - "name": "Fedora-Docker-Base", - "target": "f24", - "version": "Rawhide", - "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", - "kickstart": "fedora-docker-base.ks", - "distro": "Fedora-20", - "disk_size": 3, - "arches": ["x86_64"], - "install_tree_from": "/my/tree", + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "arches": ["x86_64"], + "install_tree_from": "/my/tree", + } } - } - ] + ] + }, + "koji_profile": "koji", + "translate_paths": [("/my", "http://example.com")], }, - "koji_profile": "koji", - "translate_paths": [("/my", "http://example.com")], - }) + ) self.assertValidConfig(compose.conf) @@ -348,14 +374,344 @@ class TestImageBuildPhase(PungiTestCase): self.assertTrue(phase.pool.queue_put.called_once) args, kwargs = phase.pool.queue_put.call_args self.assertEqual(args[0][0], compose) - self.assertDictEqual(args[0][1], { + self.assertDictEqual( + args[0][1], + { + "image_conf": { + "image-build": { + "install_tree": "http://example.com/tree", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": self.topdir + "/compose/Server/$arch/os", + "variant": compose.variants["Server"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + } + }, + "conf_file": self.topdir + + "/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg", + "image_dir": self.topdir + "/compose/Server/%(arch)s/images", + "relative_image_dir": "Server/%(arch)s/images", + "link_type": "hardlink-or-copy", + "scratch": False, + }, + ) + + @mock.patch("pungi.phases.image_build.ThreadPool") + def test_image_build_set_extra_repos(self, ThreadPool): + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "arches": ["x86_64"], + "repo_from": ["Everything", "Server-optional"], + } + } + ] + }, + "koji_profile": "koji", + }, + ) + compose.setup_optional() + + self.assertValidConfig(compose.conf) + + phase = ImageBuildPhase(compose) + + phase.run() + + # assert at least one thread was started + self.assertTrue(phase.pool.add.called) + + self.assertTrue(phase.pool.queue_put.called_once) + args, kwargs = phase.pool.queue_put.call_args + self.assertEqual(args[0][0], compose) + self.assertDictEqual( + args[0][1], + { + "image_conf": { + "image-build": { + "install_tree": self.topdir + "/compose/Server/$arch/os", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": ",".join( + [ + self.topdir + "/compose/Everything/$arch/os", + self.topdir + "/compose/Server-optional/$arch/os", + self.topdir + "/compose/Server/$arch/os", + ] + ), + "variant": compose.variants["Server"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + } + }, + "conf_file": self.topdir + + "/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg", + "image_dir": self.topdir + "/compose/Server/%(arch)s/images", + "relative_image_dir": "Server/%(arch)s/images", + "link_type": "hardlink-or-copy", + "scratch": False, + }, + ) + + @mock.patch("pungi.phases.image_build.ThreadPool") + def test_image_build_set_external_install_tree(self, ThreadPool): + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "arches": ["x86_64"], + "install_tree_from": "http://example.com/install-tree/", + } + } + ] + }, + "koji_profile": "koji", + }, + ) + + self.assertValidConfig(compose.conf) + + phase = ImageBuildPhase(compose) + + phase.run() + + # assert at least one thread was started + self.assertTrue(phase.pool.add.called) + + self.assertTrue(phase.pool.queue_put.called_once) + args, kwargs = phase.pool.queue_put.call_args + self.assertEqual(args[0][0], compose) + self.assertDictEqual( + args[0][1], + { + "image_conf": { + "image-build": { + "install_tree": "http://example.com/install-tree/", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": ",".join([self.topdir + "/compose/Server/$arch/os"]), + "variant": compose.variants["Server"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + } + }, + "conf_file": self.topdir + + "/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg", + "image_dir": self.topdir + "/compose/Server/%(arch)s/images", + "relative_image_dir": "Server/%(arch)s/images", + "link_type": "hardlink-or-copy", + "scratch": False, + }, + ) + + @mock.patch("pungi.phases.image_build.ThreadPool") + def test_image_build_create_release(self, ThreadPool): + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "arches": ["x86_64"], + "release": None, + } + } + ] + }, + "koji_profile": "koji", + }, + ) + + self.assertValidConfig(compose.conf) + + phase = ImageBuildPhase(compose) + + phase.run() + + # assert at least one thread was started + self.assertTrue(phase.pool.add.called) + + self.assertTrue(phase.pool.queue_put.called_once) + args, kwargs = phase.pool.queue_put.call_args + self.assertEqual( + args[0][1].get("image_conf", {}).get("image-build", {}).get("release"), + "20151203.t.0", + ) + + @mock.patch("pungi.phases.image_build.ThreadPool") + def test_image_build_create_release_with_explicit_config(self, ThreadPool): + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "arches": ["x86_64"], + "release": "!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN", + } + } + ] + }, + "koji_profile": "koji", + }, + ) + + self.assertValidConfig(compose.conf) + + phase = ImageBuildPhase(compose) + + phase.run() + + # assert at least one thread was started + self.assertTrue(phase.pool.add.called) + + self.assertTrue(phase.pool.queue_put.called_once) + args, kwargs = phase.pool.queue_put.call_args + self.assertEqual( + args[0][1].get("image_conf", {}).get("image-build", {}).get("release"), + "20151203.t.0", + ) + + @mock.patch("pungi.phases.image_build.ThreadPool") + def test_image_build_scratch_build(self, ThreadPool): + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "arches": ["x86_64"], + "scratch": True, + } + } + ] + }, + "koji_profile": "koji", + }, + ) + + self.assertValidConfig(compose.conf) + + phase = ImageBuildPhase(compose) + + phase.run() + + # assert at least one thread was started + self.assertTrue(phase.pool.add.called) + + self.assertTrue(phase.pool.queue_put.called_once) + args, kwargs = phase.pool.queue_put.call_args + self.assertTrue(args[0][1].get("scratch")) + + @mock.patch("pungi.phases.image_build.ThreadPool") + def test_image_build_optional(self, ThreadPool): + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Server-optional$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "failable": ["x86_64"], + } + } + ] + }, + "koji_profile": "koji", + }, + ) + compose.setup_optional() + + self.assertValidConfig(compose.conf) + + phase = ImageBuildPhase(compose) + + phase.run() + + # assert at least one thread was started + self.assertTrue(phase.pool.add.called) + server_args = { "image_conf": { "image-build": { - "install_tree": "http://example.com/tree", + "install_tree": self.topdir + "/compose/Server/$arch/os", "kickstart": "fedora-docker-base.ks", "format": ["docker"], - "repo": self.topdir + "/compose/Server/$arch/os", - "variant": compose.variants["Server"], + "repo": self.topdir + "/compose/Server-optional/$arch/os", + "variant": compose.all_variants["Server-optional"], "target": "f24", "disk_size": 3, "name": "Fedora-Docker-Base", @@ -363,333 +719,45 @@ class TestImageBuildPhase(PungiTestCase): "version": "Rawhide", "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", "distro": "Fedora-20", + "can_fail": ["x86_64"], } }, - "conf_file": self.topdir + "/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg", - "image_dir": self.topdir + "/compose/Server/%(arch)s/images", - "relative_image_dir": "Server/%(arch)s/images", + "conf_file": self.topdir + + "/work/image-build/Server-optional/docker_Fedora-Docker-Base_x86_64.cfg", + "image_dir": self.topdir + "/compose/Server-optional/%(arch)s/images", + "relative_image_dir": "Server-optional/%(arch)s/images", "link_type": "hardlink-or-copy", "scratch": False, - }) - - @mock.patch('pungi.phases.image_build.ThreadPool') - def test_image_build_set_extra_repos(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Server$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'arches': ['x86_64'], - 'repo_from': ['Everything', 'Server-optional'], - } - } - ] - }, - 'koji_profile': 'koji', - }) - compose.setup_optional() - - self.assertValidConfig(compose.conf) - - phase = ImageBuildPhase(compose) - - phase.run() - - # assert at least one thread was started - self.assertTrue(phase.pool.add.called) - - self.assertTrue(phase.pool.queue_put.called_once) - args, kwargs = phase.pool.queue_put.call_args - self.assertEqual(args[0][0], compose) - self.assertDictEqual(args[0][1], { - "image_conf": { - 'image-build': { - 'install_tree': self.topdir + '/compose/Server/$arch/os', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker'], - 'repo': ','.join([self.topdir + '/compose/Everything/$arch/os', - self.topdir + '/compose/Server-optional/$arch/os', - self.topdir + '/compose/Server/$arch/os']), - 'variant': compose.variants['Server'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - } - }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg', - "image_dir": self.topdir + '/compose/Server/%(arch)s/images', - "relative_image_dir": 'Server/%(arch)s/images', - "link_type": 'hardlink-or-copy', - "scratch": False, - }) - - @mock.patch('pungi.phases.image_build.ThreadPool') - def test_image_build_set_external_install_tree(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Server$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'arches': ['x86_64'], - 'install_tree_from': 'http://example.com/install-tree/', - } - } - ] - }, - 'koji_profile': 'koji', - }) - - self.assertValidConfig(compose.conf) - - phase = ImageBuildPhase(compose) - - phase.run() - - # assert at least one thread was started - self.assertTrue(phase.pool.add.called) - - self.assertTrue(phase.pool.queue_put.called_once) - args, kwargs = phase.pool.queue_put.call_args - self.assertEqual(args[0][0], compose) - self.assertDictEqual(args[0][1], { - "image_conf": { - 'image-build': { - 'install_tree': 'http://example.com/install-tree/', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker'], - 'repo': ','.join([self.topdir + '/compose/Server/$arch/os']), - 'variant': compose.variants['Server'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - } - }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg', - "image_dir": self.topdir + '/compose/Server/%(arch)s/images', - "relative_image_dir": 'Server/%(arch)s/images', - "link_type": 'hardlink-or-copy', - "scratch": False, - }) - - @mock.patch('pungi.phases.image_build.ThreadPool') - def test_image_build_create_release(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Server$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'arches': ['x86_64'], - 'release': None, - } - } - ] - }, - 'koji_profile': 'koji', - }) - - self.assertValidConfig(compose.conf) - - phase = ImageBuildPhase(compose) - - phase.run() - - # assert at least one thread was started - self.assertTrue(phase.pool.add.called) - - self.assertTrue(phase.pool.queue_put.called_once) - args, kwargs = phase.pool.queue_put.call_args - self.assertEqual(args[0][1].get('image_conf', {}).get('image-build', {}).get('release'), - '20151203.t.0') - - @mock.patch('pungi.phases.image_build.ThreadPool') - def test_image_build_create_release_with_explicit_config(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Server$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'arches': ['x86_64'], - 'release': '!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN', - } - } - ] - }, - 'koji_profile': 'koji', - }) - - self.assertValidConfig(compose.conf) - - phase = ImageBuildPhase(compose) - - phase.run() - - # assert at least one thread was started - self.assertTrue(phase.pool.add.called) - - self.assertTrue(phase.pool.queue_put.called_once) - args, kwargs = phase.pool.queue_put.call_args - self.assertEqual(args[0][1].get('image_conf', {}).get('image-build', {}).get('release'), - '20151203.t.0') - - @mock.patch('pungi.phases.image_build.ThreadPool') - def test_image_build_scratch_build(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Server$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'arches': ['x86_64'], - 'scratch': True, - } - } - ] - }, - 'koji_profile': 'koji', - }) - - self.assertValidConfig(compose.conf) - - phase = ImageBuildPhase(compose) - - phase.run() - - # assert at least one thread was started - self.assertTrue(phase.pool.add.called) - - self.assertTrue(phase.pool.queue_put.called_once) - args, kwargs = phase.pool.queue_put.call_args - self.assertTrue(args[0][1].get('scratch')) - - @mock.patch('pungi.phases.image_build.ThreadPool') - def test_image_build_optional(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Server-optional$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'failable': ['x86_64'], - } - } - ] - }, - 'koji_profile': 'koji', - }) - compose.setup_optional() - - self.assertValidConfig(compose.conf) - - phase = ImageBuildPhase(compose) - - phase.run() - - # assert at least one thread was started - self.assertTrue(phase.pool.add.called) - server_args = { - "image_conf": { - 'image-build': { - 'install_tree': self.topdir + '/compose/Server/$arch/os', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker'], - 'repo': self.topdir + '/compose/Server-optional/$arch/os', - 'variant': compose.all_variants['Server-optional'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - 'can_fail': ['x86_64'], - } - }, - "conf_file": self.topdir + '/work/image-build/Server-optional/docker_Fedora-Docker-Base_x86_64.cfg', - "image_dir": self.topdir + '/compose/Server-optional/%(arch)s/images', - "relative_image_dir": 'Server-optional/%(arch)s/images', - "link_type": 'hardlink-or-copy', - "scratch": False, } self.assertEqual( phase.pool.queue_put.mock_calls, [mock.call((compose, server_args))] ) - @mock.patch('pungi.phases.image_build.ThreadPool') + @mock.patch("pungi.phases.image_build.ThreadPool") def test_failable_star(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'image_build': { - '^Server$': [ - { - 'image-build': { - 'format': ['docker'], - 'name': 'Fedora-Docker-Base', - 'target': 'f24', - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'kickstart': "fedora-docker-base.ks", - 'distro': 'Fedora-20', - 'disk_size': 3, - 'failable': ['*'], + compose = DummyCompose( + self.topdir, + { + "image_build": { + "^Server$": [ + { + "image-build": { + "format": ["docker"], + "name": "Fedora-Docker-Base", + "target": "f24", + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "kickstart": "fedora-docker-base.ks", + "distro": "Fedora-20", + "disk_size": 3, + "failable": ["*"], + } } - } - ] + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) compose.setup_optional() self.assertValidConfig(compose.conf) @@ -702,26 +770,27 @@ class TestImageBuildPhase(PungiTestCase): self.assertTrue(phase.pool.add.called) server_args = { "image_conf": { - 'image-build': { - 'install_tree': self.topdir + '/compose/Server/$arch/os', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker'], - 'repo': self.topdir + '/compose/Server/$arch/os', - 'variant': compose.all_variants['Server'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['amd64', 'x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - 'can_fail': ['amd64', 'x86_64'], + "image-build": { + "install_tree": self.topdir + "/compose/Server/$arch/os", + "kickstart": "fedora-docker-base.ks", + "format": ["docker"], + "repo": self.topdir + "/compose/Server/$arch/os", + "variant": compose.all_variants["Server"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["amd64", "x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + "can_fail": ["amd64", "x86_64"], } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg', - "image_dir": self.topdir + '/compose/Server/%(arch)s/images', - "relative_image_dir": 'Server/%(arch)s/images', - "link_type": 'hardlink-or-copy', + "conf_file": self.topdir + + "/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg", + "image_dir": self.topdir + "/compose/Server/%(arch)s/images", + "relative_image_dir": "Server/%(arch)s/images", + "link_type": "hardlink-or-copy", "scratch": False, } self.assertEqual( @@ -730,38 +799,35 @@ class TestImageBuildPhase(PungiTestCase): class TestCreateImageBuildThread(PungiTestCase): - - @mock.patch('pungi.phases.image_build.get_mtime') - @mock.patch('pungi.phases.image_build.get_file_size') - @mock.patch('pungi.phases.image_build.KojiWrapper') - @mock.patch('pungi.phases.image_build.Linker') + @mock.patch("pungi.phases.image_build.get_mtime") + @mock.patch("pungi.phases.image_build.get_file_size") + @mock.patch("pungi.phases.image_build.KojiWrapper") + @mock.patch("pungi.phases.image_build.Linker") def test_process(self, Linker, KojiWrapper, get_file_size, get_mtime): - compose = DummyCompose(self.topdir, { - 'koji_profile': 'koji' - }) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) pool = mock.Mock() cmd = { "image_conf": { - 'image-build': { - 'install_tree': '/ostree/$arch/Client', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker', 'qcow2'], - 'repo': '/ostree/$arch/Client', - 'variant': compose.variants['Client'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['amd64', 'x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - 'subvariant': 'KDE', + "image-build": { + "install_tree": "/ostree/$arch/Client", + "kickstart": "fedora-docker-base.ks", + "format": ["docker", "qcow2"], + "repo": "/ostree/$arch/Client", + "variant": compose.variants["Client"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["amd64", "x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + "subvariant": "KDE", } }, - "conf_file": 'amd64,x86_64-Client-Fedora-Docker-Base-docker', - "image_dir": self.topdir + '/compose/Client/%(arch)s/images', - "relative_image_dir": 'image_dir/Client/%(arch)s', - "link_type": 'hardlink-or-copy', + "conf_file": "amd64,x86_64-Client-Fedora-Docker-Base-docker", + "image_dir": self.topdir + "/compose/Client/%(arch)s/images", + "relative_image_dir": "image_dir/Client/%(arch)s", + "link_type": "hardlink-or-copy", "scratch": False, } koji_wrapper = KojiWrapper.return_value @@ -771,16 +837,16 @@ class TestCreateImageBuildThread(PungiTestCase): "task_id": 1234, } koji_wrapper.get_image_paths.return_value = { - 'amd64': [ - '/koji/task/1235/tdl-amd64.xml', - '/koji/task/1235/Fedora-Docker-Base-20160103.amd64.qcow2', - '/koji/task/1235/Fedora-Docker-Base-20160103.amd64.tar.gz' + "amd64": [ + "/koji/task/1235/tdl-amd64.xml", + "/koji/task/1235/Fedora-Docker-Base-20160103.amd64.qcow2", + "/koji/task/1235/Fedora-Docker-Base-20160103.amd64.tar.gz", + ], + "x86_64": [ + "/koji/task/1235/tdl-x86_64.xml", + "/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.qcow2", + "/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.tar.gz", ], - 'x86_64': [ - '/koji/task/1235/tdl-x86_64.xml', - '/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.qcow2', - '/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.tar.gz' - ] } linker = Linker.return_value @@ -788,62 +854,82 @@ class TestCreateImageBuildThread(PungiTestCase): get_mtime.return_value = 13579 t = CreateImageBuildThread(pool) - with mock.patch('time.sleep'): + with mock.patch("time.sleep"): t.process((compose, cmd), 1) self.assertEqual( koji_wrapper.get_image_build_cmd.call_args_list, - [mock.call(cmd['image_conf'], - conf_file_dest='amd64,x86_64-Client-Fedora-Docker-Base-docker', - scratch=False)] + [ + mock.call( + cmd["image_conf"], + conf_file_dest="amd64,x86_64-Client-Fedora-Docker-Base-docker", + scratch=False, + ) + ], ) self.assertEqual( koji_wrapper.run_blocking_cmd.call_args_list, - [mock.call(koji_wrapper.get_image_build_cmd.return_value, - log_file=self.topdir + '/logs/amd64-x86_64/imagebuild-Client-KDE-docker-qcow2.amd64-x86_64.log')] + [ + mock.call( + koji_wrapper.get_image_build_cmd.return_value, + log_file=self.topdir + + "/logs/amd64-x86_64/imagebuild-Client-KDE-docker-qcow2.amd64-x86_64.log", + ) + ], ) six.assertCountEqual( self, linker.mock_calls, - [mock.call.link( - '/koji/task/1235/Fedora-Docker-Base-20160103.amd64.qcow2', - self.topdir + '/compose/Client/amd64/images/Fedora-Docker-Base-20160103.amd64.qcow2', - link_type='hardlink-or-copy'), - mock.call.link( - '/koji/task/1235/Fedora-Docker-Base-20160103.amd64.tar.gz', - self.topdir + '/compose/Client/amd64/images/Fedora-Docker-Base-20160103.amd64.tar.gz', - link_type='hardlink-or-copy'), - mock.call.link( - '/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.qcow2', - self.topdir + '/compose/Client/x86_64/images/Fedora-Docker-Base-20160103.x86_64.qcow2', - link_type='hardlink-or-copy'), - mock.call.link( - '/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.tar.gz', - self.topdir + '/compose/Client/x86_64/images/Fedora-Docker-Base-20160103.x86_64.tar.gz', - link_type='hardlink-or-copy')]) + [ + mock.call.link( + "/koji/task/1235/Fedora-Docker-Base-20160103.amd64.qcow2", + self.topdir + + "/compose/Client/amd64/images/Fedora-Docker-Base-20160103.amd64.qcow2", + link_type="hardlink-or-copy", + ), + mock.call.link( + "/koji/task/1235/Fedora-Docker-Base-20160103.amd64.tar.gz", + self.topdir + + "/compose/Client/amd64/images/Fedora-Docker-Base-20160103.amd64.tar.gz", + link_type="hardlink-or-copy", + ), + mock.call.link( + "/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.qcow2", + self.topdir + + "/compose/Client/x86_64/images/Fedora-Docker-Base-20160103.x86_64.qcow2", + link_type="hardlink-or-copy", + ), + mock.call.link( + "/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.tar.gz", + self.topdir + + "/compose/Client/x86_64/images/Fedora-Docker-Base-20160103.x86_64.tar.gz", + link_type="hardlink-or-copy", + ), + ], + ) image_relative_paths = { - 'image_dir/Client/amd64/Fedora-Docker-Base-20160103.amd64.qcow2': { - 'format': 'qcow2', - 'type': 'qcow2', - 'arch': 'amd64', + "image_dir/Client/amd64/Fedora-Docker-Base-20160103.amd64.qcow2": { + "format": "qcow2", + "type": "qcow2", + "arch": "amd64", }, - 'image_dir/Client/amd64/Fedora-Docker-Base-20160103.amd64.tar.gz': { - 'format': 'tar.gz', - 'type': 'docker', - 'arch': 'amd64', + "image_dir/Client/amd64/Fedora-Docker-Base-20160103.amd64.tar.gz": { + "format": "tar.gz", + "type": "docker", + "arch": "amd64", }, - 'image_dir/Client/x86_64/Fedora-Docker-Base-20160103.x86_64.qcow2': { - 'format': 'qcow2', - 'type': 'qcow2', - 'arch': 'x86_64', + "image_dir/Client/x86_64/Fedora-Docker-Base-20160103.x86_64.qcow2": { + "format": "qcow2", + "type": "qcow2", + "arch": "x86_64", }, - 'image_dir/Client/x86_64/Fedora-Docker-Base-20160103.x86_64.tar.gz': { - 'format': 'tar.gz', - 'type': 'docker', - 'arch': 'x86_64', + "image_dir/Client/x86_64/Fedora-Docker-Base-20160103.x86_64.tar.gz": { + "format": "tar.gz", + "type": "docker", + "arch": "x86_64", }, } @@ -851,47 +937,47 @@ class TestCreateImageBuildThread(PungiTestCase): self.assertEqual(len(compose.im.add.call_args_list), 4) for call in compose.im.add.call_args_list: _, kwargs = call - image = kwargs['image'] - self.assertEqual(kwargs['variant'], 'Client') - self.assertIn(kwargs['arch'], ('amd64', 'x86_64')) - self.assertEqual(kwargs['arch'], image.arch) + image = kwargs["image"] + self.assertEqual(kwargs["variant"], "Client") + self.assertIn(kwargs["arch"], ("amd64", "x86_64")) + self.assertEqual(kwargs["arch"], image.arch) self.assertIn(image.path, image_relative_paths) data = image_relative_paths.pop(image.path) - self.assertEqual(data['format'], image.format) - self.assertEqual(data['type'], image.type) - self.assertEqual('KDE', image.subvariant) + self.assertEqual(data["format"], image.format) + self.assertEqual(data["type"], image.type) + self.assertEqual("KDE", image.subvariant) - self.assertTrue(os.path.isdir(self.topdir + '/compose/Client/amd64/images')) - self.assertTrue(os.path.isdir(self.topdir + '/compose/Client/x86_64/images')) + self.assertTrue(os.path.isdir(self.topdir + "/compose/Client/amd64/images")) + self.assertTrue(os.path.isdir(self.topdir + "/compose/Client/x86_64/images")) - @mock.patch('pungi.phases.image_build.KojiWrapper') - @mock.patch('pungi.phases.image_build.Linker') + @mock.patch("pungi.phases.image_build.KojiWrapper") + @mock.patch("pungi.phases.image_build.Linker") def test_process_handle_fail(self, Linker, KojiWrapper): - compose = DummyCompose(self.topdir, {'koji_profile': 'koji'}) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) pool = mock.Mock() cmd = { "image_conf": { - 'image-build': { - 'install_tree': '/ostree/$arch/Client', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker', 'qcow2'], - 'repo': '/ostree/$arch/Client', - 'variant': compose.variants['Client'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['amd64', 'x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - "can_fail": ['amd64', 'x86_64'], + "image-build": { + "install_tree": "/ostree/$arch/Client", + "kickstart": "fedora-docker-base.ks", + "format": ["docker", "qcow2"], + "repo": "/ostree/$arch/Client", + "variant": compose.variants["Client"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["amd64", "x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + "can_fail": ["amd64", "x86_64"], } }, - "conf_file": 'amd64,x86_64-Client-Fedora-Docker-Base-docker', - "image_dir": '/image_dir/Client/%(arch)s', - "relative_image_dir": 'image_dir/Client/%(arch)s', - "link_type": 'hardlink-or-copy', - 'scratch': False, + "conf_file": "amd64,x86_64-Client-Fedora-Docker-Base-docker", + "image_dir": "/image_dir/Client/%(arch)s", + "relative_image_dir": "image_dir/Client/%(arch)s", + "link_type": "hardlink-or-copy", + "scratch": False, } koji_wrapper = KojiWrapper.return_value koji_wrapper.run_blocking_cmd.return_value = { @@ -901,86 +987,100 @@ class TestCreateImageBuildThread(PungiTestCase): } t = CreateImageBuildThread(pool) - with mock.patch('time.sleep'): + with mock.patch("time.sleep"): t.process((compose, cmd), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Image build (variant Client, arch *, subvariant Client) failed, but going on anyway.'), - mock.call('ImageBuild task failed: 1234. See %s for more details.' - % (os.path.join(self.topdir, - 'logs/amd64-x86_64/imagebuild-Client-Client-docker-qcow2.amd64-x86_64.log'))), - ]) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Image build (variant Client, arch *, subvariant Client) failed, but going on anyway." + ), + mock.call( + "ImageBuild task failed: 1234. See %s for more details." + % ( + os.path.join( + self.topdir, + "logs/amd64-x86_64/imagebuild-Client-Client-docker-qcow2.amd64-x86_64.log", + ) + ) + ), + ] + ) - @mock.patch('pungi.phases.image_build.KojiWrapper') - @mock.patch('pungi.phases.image_build.Linker') + @mock.patch("pungi.phases.image_build.KojiWrapper") + @mock.patch("pungi.phases.image_build.Linker") def test_process_handle_exception(self, Linker, KojiWrapper): - compose = DummyCompose(self.topdir, {'koji_profile': 'koji'}) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) pool = mock.Mock() cmd = { "image_conf": { - 'image-build': { - 'install_tree': '/ostree/$arch/Client', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker', 'qcow2'], - 'repo': '/ostree/$arch/Client', - 'variant': compose.variants['Client'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['amd64', 'x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - 'can_fail': ['amd64', 'x86_64'], + "image-build": { + "install_tree": "/ostree/$arch/Client", + "kickstart": "fedora-docker-base.ks", + "format": ["docker", "qcow2"], + "repo": "/ostree/$arch/Client", + "variant": compose.variants["Client"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["amd64", "x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + "can_fail": ["amd64", "x86_64"], } }, - "conf_file": 'amd64,x86_64-Client-Fedora-Docker-Base-docker', - "image_dir": '/image_dir/Client/%(arch)s', - "relative_image_dir": 'image_dir/Client/%(arch)s', - "link_type": 'hardlink-or-copy', - 'scratch': False, + "conf_file": "amd64,x86_64-Client-Fedora-Docker-Base-docker", + "image_dir": "/image_dir/Client/%(arch)s", + "relative_image_dir": "image_dir/Client/%(arch)s", + "link_type": "hardlink-or-copy", + "scratch": False, } koji_wrapper = KojiWrapper.return_value koji_wrapper.run_blocking_cmd.side_effect = boom t = CreateImageBuildThread(pool) - with mock.patch('time.sleep'): + with mock.patch("time.sleep"): t.process((compose, cmd), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Image build (variant Client, arch *, subvariant Client) failed, but going on anyway.'), - mock.call('BOOM'), - ]) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Image build (variant Client, arch *, subvariant Client) failed, but going on anyway." + ), + mock.call("BOOM"), + ] + ) - @mock.patch('pungi.phases.image_build.KojiWrapper') - @mock.patch('pungi.phases.image_build.Linker') + @mock.patch("pungi.phases.image_build.KojiWrapper") + @mock.patch("pungi.phases.image_build.Linker") def test_process_handle_fail_only_one_optional(self, Linker, KojiWrapper): - compose = DummyCompose(self.topdir, {'koji_profile': 'koji'}) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) pool = mock.Mock() cmd = { "image_conf": { - 'image-build': { - 'install_tree': '/ostree/$arch/Client', - 'kickstart': 'fedora-docker-base.ks', - 'format': ['docker', 'qcow2'], - 'repo': '/ostree/$arch/Client', - 'variant': compose.variants['Client'], - 'target': 'f24', - 'disk_size': 3, - 'name': 'Fedora-Docker-Base', - 'arches': ['amd64', 'x86_64'], - 'version': 'Rawhide', - 'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git', - 'distro': 'Fedora-20', - 'can_fail': ['amd64'], + "image-build": { + "install_tree": "/ostree/$arch/Client", + "kickstart": "fedora-docker-base.ks", + "format": ["docker", "qcow2"], + "repo": "/ostree/$arch/Client", + "variant": compose.variants["Client"], + "target": "f24", + "disk_size": 3, + "name": "Fedora-Docker-Base", + "arches": ["amd64", "x86_64"], + "version": "Rawhide", + "ksurl": "git://git.fedorahosted.org/git/spin-kickstarts.git", + "distro": "Fedora-20", + "can_fail": ["amd64"], } }, - "conf_file": 'amd64,x86_64-Client-Fedora-Docker-Base-docker', - "image_dir": '/image_dir/Client/%(arch)s', - "relative_image_dir": 'image_dir/Client/%(arch)s', - "link_type": 'hardlink-or-copy', - 'scratch': False, + "conf_file": "amd64,x86_64-Client-Fedora-Docker-Base-docker", + "image_dir": "/image_dir/Client/%(arch)s", + "relative_image_dir": "image_dir/Client/%(arch)s", + "link_type": "hardlink-or-copy", + "scratch": False, } koji_wrapper = KojiWrapper.return_value @@ -992,5 +1092,5 @@ class TestCreateImageBuildThread(PungiTestCase): t = CreateImageBuildThread(pool) with self.assertRaises(RuntimeError): - with mock.patch('time.sleep'): + with mock.patch("time.sleep"): t.process((compose, cmd), 1) diff --git a/tests/test_imagechecksumphase.py b/tests/test_imagechecksumphase.py index 51a3624d..2ec81d3d 100644 --- a/tests/test_imagechecksumphase.py +++ b/tests/test_imagechecksumphase.py @@ -16,162 +16,221 @@ from tests.helpers import DummyCompose, PungiTestCase class TestImageChecksumPhase(PungiTestCase): - def test_phase_is_never_skipped(self): compose = DummyCompose(self.topdir, {}) phase = ImageChecksumPhase(compose) self.assertFalse(phase.skip()) def test_config_skip_individual_with_multiple_algorithms(self): - compose = DummyCompose(self.topdir, { - 'media_checksums': ['md5', 'sha1'], - 'media_checksum_one_file': True - }) + compose = DummyCompose( + self.topdir, + {"media_checksums": ["md5", "sha1"], "media_checksum_one_file": True}, + ) phase = ImageChecksumPhase(compose) with self.assertRaises(ValueError) as ctx: phase.validate() - self.assertIn('media_checksum_one_file', str(ctx.exception)) + self.assertIn("media_checksum_one_file", str(ctx.exception)) - @mock.patch('os.path.exists') - @mock.patch('kobo.shortcuts.compute_file_checksums') - @mock.patch('pungi.phases.image_checksum.dump_checksums') + @mock.patch("os.path.exists") + @mock.patch("kobo.shortcuts.compute_file_checksums") + @mock.patch("pungi.phases.image_checksum.dump_checksums") def test_checksum_one_file(self, dump_checksums, cc, exists): - compose = DummyCompose(self.topdir, { - 'media_checksums': ['sha256'], - 'media_checksum_one_file': True, - }) - - phase = ImageChecksumPhase(compose) - - exists.return_value = True - cc.return_value = {'sha256': 'cafebabe'} - - phase.run() - - dump_checksums.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/CHECKSUM', - set([('image.iso', 123, 'sha256', 'cafebabe')])) - cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['sha256']) - compose.image.add_checksum.assert_called_once_with(None, 'sha256', 'cafebabe') - - @mock.patch('os.path.exists') - @mock.patch('kobo.shortcuts.compute_file_checksums') - @mock.patch('pungi.phases.image_checksum.dump_checksums') - def test_checksum_save_individuals(self, dump_checksums, cc, exists): - compose = DummyCompose(self.topdir, { - 'media_checksums': ['md5', 'sha256'], - }) - - phase = ImageChecksumPhase(compose) - - exists.return_value = True - cc.return_value = {'md5': 'cafebabe', 'sha256': 'deadbeef'} - - phase.run() - - dump_checksums.assert_has_calls( - [mock.call(self.topdir + '/compose/Client/i386/iso/image.iso.MD5SUM', - set([('image.iso', 123, 'md5', 'cafebabe')])), - mock.call(self.topdir + '/compose/Client/i386/iso/image.iso.SHA256SUM', - set([('image.iso', 123, 'sha256', 'deadbeef')])), - mock.call(self.topdir + '/compose/Client/i386/iso/MD5SUM', - set([('image.iso', 123, 'md5', 'cafebabe')])), - mock.call(self.topdir + '/compose/Client/i386/iso/SHA256SUM', - set([('image.iso', 123, 'sha256', 'deadbeef')]))], - any_order=True + compose = DummyCompose( + self.topdir, + {"media_checksums": ["sha256"], "media_checksum_one_file": True}, ) - cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['md5', 'sha256']) - compose.image.add_checksum.assert_has_calls([mock.call(None, 'sha256', 'deadbeef'), - mock.call(None, 'md5', 'cafebabe')], - any_order=True) - - @mock.patch('os.path.exists') - @mock.patch('kobo.shortcuts.compute_file_checksums') - @mock.patch('pungi.phases.image_checksum.dump_checksums') - def test_checksum_one_file_custom_name(self, dump_checksums, cc, exists): - compose = DummyCompose(self.topdir, { - 'media_checksums': ['sha256'], - 'media_checksum_one_file': True, - 'media_checksum_base_filename': '%(release_short)s-%(variant)s-%(version)s-%(date)s%(type_suffix)s.%(respin)s_%(label)s-%(dirname)s' - }) - compose.compose_label = 'Alpha-1.0' phase = ImageChecksumPhase(compose) exists.return_value = True - cc.return_value = {'sha256': 'cafebabe'} + cc.return_value = {"sha256": "cafebabe"} phase.run() dump_checksums.assert_called_once_with( - self.topdir + '/compose/Client/i386/iso/test-Client-1.0-20151203.t.0_Alpha-1.0-iso-CHECKSUM', - set([('image.iso', 123, 'sha256', 'cafebabe')])) - cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['sha256']) - compose.image.add_checksum.assert_called_once_with(None, 'sha256', 'cafebabe') + self.topdir + "/compose/Client/i386/iso/CHECKSUM", + set([("image.iso", 123, "sha256", "cafebabe")]), + ) + cc.assert_called_once_with( + self.topdir + "/compose/Client/i386/iso/image.iso", ["sha256"] + ) + compose.image.add_checksum.assert_called_once_with(None, "sha256", "cafebabe") - @mock.patch('os.path.exists') - @mock.patch('kobo.shortcuts.compute_file_checksums') - @mock.patch('pungi.phases.image_checksum.dump_checksums') + @mock.patch("os.path.exists") + @mock.patch("kobo.shortcuts.compute_file_checksums") + @mock.patch("pungi.phases.image_checksum.dump_checksums") + def test_checksum_save_individuals(self, dump_checksums, cc, exists): + compose = DummyCompose(self.topdir, {"media_checksums": ["md5", "sha256"]}) + + phase = ImageChecksumPhase(compose) + + exists.return_value = True + cc.return_value = {"md5": "cafebabe", "sha256": "deadbeef"} + + phase.run() + + dump_checksums.assert_has_calls( + [ + mock.call( + self.topdir + "/compose/Client/i386/iso/image.iso.MD5SUM", + set([("image.iso", 123, "md5", "cafebabe")]), + ), + mock.call( + self.topdir + "/compose/Client/i386/iso/image.iso.SHA256SUM", + set([("image.iso", 123, "sha256", "deadbeef")]), + ), + mock.call( + self.topdir + "/compose/Client/i386/iso/MD5SUM", + set([("image.iso", 123, "md5", "cafebabe")]), + ), + mock.call( + self.topdir + "/compose/Client/i386/iso/SHA256SUM", + set([("image.iso", 123, "sha256", "deadbeef")]), + ), + ], + any_order=True, + ) + cc.assert_called_once_with( + self.topdir + "/compose/Client/i386/iso/image.iso", ["md5", "sha256"] + ) + compose.image.add_checksum.assert_has_calls( + [mock.call(None, "sha256", "deadbeef"), mock.call(None, "md5", "cafebabe")], + any_order=True, + ) + + @mock.patch("os.path.exists") + @mock.patch("kobo.shortcuts.compute_file_checksums") + @mock.patch("pungi.phases.image_checksum.dump_checksums") + def test_checksum_one_file_custom_name(self, dump_checksums, cc, exists): + compose = DummyCompose( + self.topdir, + { + "media_checksums": ["sha256"], + "media_checksum_one_file": True, + "media_checksum_base_filename": "%(release_short)s-%(variant)s-%(version)s-%(date)s%(type_suffix)s.%(respin)s_%(label)s-%(dirname)s", + }, + ) + compose.compose_label = "Alpha-1.0" + + phase = ImageChecksumPhase(compose) + + exists.return_value = True + cc.return_value = {"sha256": "cafebabe"} + + phase.run() + + dump_checksums.assert_called_once_with( + self.topdir + + "/compose/Client/i386/iso/test-Client-1.0-20151203.t.0_Alpha-1.0-iso-CHECKSUM", + set([("image.iso", 123, "sha256", "cafebabe")]), + ) + cc.assert_called_once_with( + self.topdir + "/compose/Client/i386/iso/image.iso", ["sha256"] + ) + compose.image.add_checksum.assert_called_once_with(None, "sha256", "cafebabe") + + @mock.patch("os.path.exists") + @mock.patch("kobo.shortcuts.compute_file_checksums") + @mock.patch("pungi.phases.image_checksum.dump_checksums") def test_checksum_save_individuals_custom_name(self, dump_checksums, cc, exists): - compose = DummyCompose(self.topdir, { - 'media_checksums': ['md5', 'sha256'], - 'media_checksum_base_filename': '%(release_short)s-%(variant)s-%(version)s-%(date)s%(type_suffix)s.%(respin)s' - }) + compose = DummyCompose( + self.topdir, + { + "media_checksums": ["md5", "sha256"], + "media_checksum_base_filename": "%(release_short)s-%(variant)s-%(version)s-%(date)s%(type_suffix)s.%(respin)s", + }, + ) phase = ImageChecksumPhase(compose) exists.return_value = True - cc.return_value = {'md5': 'cafebabe', 'sha256': 'deadbeef'} + cc.return_value = {"md5": "cafebabe", "sha256": "deadbeef"} phase.run() dump_checksums.assert_has_calls( - [mock.call(self.topdir + '/compose/Client/i386/iso/image.iso.MD5SUM', - set([('image.iso', 123, 'md5', 'cafebabe')])), - mock.call(self.topdir + '/compose/Client/i386/iso/image.iso.SHA256SUM', - set([('image.iso', 123, 'sha256', 'deadbeef')])), - mock.call(self.topdir + '/compose/Client/i386/iso/test-Client-1.0-20151203.t.0-MD5SUM', - set([('image.iso', 123, 'md5', 'cafebabe')])), - mock.call(self.topdir + '/compose/Client/i386/iso/test-Client-1.0-20151203.t.0-SHA256SUM', - set([('image.iso', 123, 'sha256', 'deadbeef')]))], - any_order=True + [ + mock.call( + self.topdir + "/compose/Client/i386/iso/image.iso.MD5SUM", + set([("image.iso", 123, "md5", "cafebabe")]), + ), + mock.call( + self.topdir + "/compose/Client/i386/iso/image.iso.SHA256SUM", + set([("image.iso", 123, "sha256", "deadbeef")]), + ), + mock.call( + self.topdir + + "/compose/Client/i386/iso/test-Client-1.0-20151203.t.0-MD5SUM", + set([("image.iso", 123, "md5", "cafebabe")]), + ), + mock.call( + self.topdir + + "/compose/Client/i386/iso/test-Client-1.0-20151203.t.0-SHA256SUM", + set([("image.iso", 123, "sha256", "deadbeef")]), + ), + ], + any_order=True, + ) + cc.assert_called_once_with( + self.topdir + "/compose/Client/i386/iso/image.iso", ["md5", "sha256"] + ) + compose.image.add_checksum.assert_has_calls( + [mock.call(None, "sha256", "deadbeef"), mock.call(None, "md5", "cafebabe")], + any_order=True, ) - cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['md5', 'sha256']) - compose.image.add_checksum.assert_has_calls([mock.call(None, 'sha256', 'deadbeef'), - mock.call(None, 'md5', 'cafebabe')], - any_order=True) - @mock.patch('os.path.exists') - @mock.patch('kobo.shortcuts.compute_file_checksums') - @mock.patch('pungi.phases.image_checksum.dump_checksums') - def test_checksum_save_individuals_custom_name_str_format(self, dump_checksums, cc, exists): - compose = DummyCompose(self.topdir, { - 'media_checksums': ['md5', 'sha256'], - 'media_checksum_base_filename': '{release_short}-{variant}-{version}-{date}{type_suffix}.{respin}' - }) + @mock.patch("os.path.exists") + @mock.patch("kobo.shortcuts.compute_file_checksums") + @mock.patch("pungi.phases.image_checksum.dump_checksums") + def test_checksum_save_individuals_custom_name_str_format( + self, dump_checksums, cc, exists + ): + compose = DummyCompose( + self.topdir, + { + "media_checksums": ["md5", "sha256"], + "media_checksum_base_filename": "{release_short}-{variant}-{version}-{date}{type_suffix}.{respin}", + }, + ) phase = ImageChecksumPhase(compose) exists.return_value = True - cc.return_value = {'md5': 'cafebabe', 'sha256': 'deadbeef'} + cc.return_value = {"md5": "cafebabe", "sha256": "deadbeef"} phase.run() dump_checksums.assert_has_calls( - [mock.call(self.topdir + '/compose/Client/i386/iso/image.iso.MD5SUM', - set([('image.iso', 123, 'md5', 'cafebabe')])), - mock.call(self.topdir + '/compose/Client/i386/iso/image.iso.SHA256SUM', - set([('image.iso', 123, 'sha256', 'deadbeef')])), - mock.call(self.topdir + '/compose/Client/i386/iso/test-Client-1.0-20151203.t.0-MD5SUM', - set([('image.iso', 123, 'md5', 'cafebabe')])), - mock.call(self.topdir + '/compose/Client/i386/iso/test-Client-1.0-20151203.t.0-SHA256SUM', - set([('image.iso', 123, 'sha256', 'deadbeef')]))], - any_order=True + [ + mock.call( + self.topdir + "/compose/Client/i386/iso/image.iso.MD5SUM", + set([("image.iso", 123, "md5", "cafebabe")]), + ), + mock.call( + self.topdir + "/compose/Client/i386/iso/image.iso.SHA256SUM", + set([("image.iso", 123, "sha256", "deadbeef")]), + ), + mock.call( + self.topdir + + "/compose/Client/i386/iso/test-Client-1.0-20151203.t.0-MD5SUM", + set([("image.iso", 123, "md5", "cafebabe")]), + ), + mock.call( + self.topdir + + "/compose/Client/i386/iso/test-Client-1.0-20151203.t.0-SHA256SUM", + set([("image.iso", 123, "sha256", "deadbeef")]), + ), + ], + any_order=True, + ) + cc.assert_called_once_with( + self.topdir + "/compose/Client/i386/iso/image.iso", ["md5", "sha256"] + ) + compose.image.add_checksum.assert_has_calls( + [mock.call(None, "sha256", "deadbeef"), mock.call(None, "md5", "cafebabe")], + any_order=True, ) - cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['md5', 'sha256']) - compose.image.add_checksum.assert_has_calls([mock.call(None, 'sha256', 'deadbeef'), - mock.call(None, 'md5', 'cafebabe')], - any_order=True) class TestDumpChecksums(unittest.TestCase): @@ -182,16 +241,20 @@ class TestDumpChecksums(unittest.TestCase): shutil.rmtree(self.tmp_dir) def test_dump_checksums(self): - dump_checksums(os.path.join(self.tmp_dir, 'CHECKSUM'), - [('file2.iso', 456, 'md5', 'cafebabe'), - ('file1.iso', 123, 'md5', 'abcdef')]) + dump_checksums( + os.path.join(self.tmp_dir, "CHECKSUM"), + [ + ("file2.iso", 456, "md5", "cafebabe"), + ("file1.iso", 123, "md5", "abcdef"), + ], + ) - with open(os.path.join(self.tmp_dir, 'CHECKSUM'), 'r') as f: - data = f.read().rstrip().split('\n') + with open(os.path.join(self.tmp_dir, "CHECKSUM"), "r") as f: + data = f.read().rstrip().split("\n") expected = [ - '# file1.iso: 123 bytes', - 'MD5 (file1.iso) = abcdef', - '# file2.iso: 456 bytes', - 'MD5 (file2.iso) = cafebabe', + "# file1.iso: 123 bytes", + "MD5 (file1.iso) = abcdef", + "# file2.iso: 456 bytes", + "MD5 (file2.iso) = cafebabe", ] self.assertEqual(expected, data) diff --git a/tests/test_initphase.py b/tests/test_initphase.py index da9890b4..e401d597 100644 --- a/tests/test_initphase.py +++ b/tests/test_initphase.py @@ -14,7 +14,13 @@ import sys from pungi.module_util import Modulemd from pungi.phases import init -from tests.helpers import DummyCompose, PungiTestCase, touch, mk_boom, fake_run_in_threads +from tests.helpers import ( + DummyCompose, + PungiTestCase, + touch, + mk_boom, + fake_run_in_threads, +) @mock.patch("pungi.phases.init.run_in_threads", new=fake_run_in_threads) @@ -27,7 +33,6 @@ from tests.helpers import DummyCompose, PungiTestCase, touch, mk_boom, fake_run_ @mock.patch("pungi.phases.init.write_variant_comps") @mock.patch("pungi.phases.init.write_prepopulate_file") class TestInitPhase(PungiTestCase): - def test_run( self, write_prepopulate, @@ -56,23 +61,28 @@ class TestInitPhase(PungiTestCase): six.assertCountEqual( self, create_comps.mock_calls, - [mock.call(compose, "x86_64", None), mock.call(compose, "amd64", None), - mock.call(compose, "x86_64", compose.variants["Server"]), - mock.call(compose, "amd64", compose.variants["Server"]), - mock.call(compose, "amd64", compose.variants["Client"]), - mock.call(compose, "x86_64", compose.variants["Everything"]), - mock.call(compose, "amd64", compose.variants["Everything"]), - mock.call(compose, "x86_64", compose.all_variants["Server-optional"])], + [ + mock.call(compose, "x86_64", None), + mock.call(compose, "amd64", None), + mock.call(compose, "x86_64", compose.variants["Server"]), + mock.call(compose, "amd64", compose.variants["Server"]), + mock.call(compose, "amd64", compose.variants["Client"]), + mock.call(compose, "x86_64", compose.variants["Everything"]), + mock.call(compose, "amd64", compose.variants["Everything"]), + mock.call(compose, "x86_64", compose.all_variants["Server-optional"]), + ], ) six.assertCountEqual( self, write_variant.mock_calls, - [mock.call(compose, "x86_64", compose.variants["Server"]), - mock.call(compose, "amd64", compose.variants["Server"]), - mock.call(compose, "amd64", compose.variants["Client"]), - mock.call(compose, "x86_64", compose.variants["Everything"]), - mock.call(compose, "amd64", compose.variants["Everything"]), - mock.call(compose, "x86_64", compose.all_variants["Server-optional"])], + [ + mock.call(compose, "x86_64", compose.variants["Server"]), + mock.call(compose, "amd64", compose.variants["Server"]), + mock.call(compose, "amd64", compose.variants["Client"]), + mock.call(compose, "x86_64", compose.variants["Everything"]), + mock.call(compose, "amd64", compose.variants["Everything"]), + mock.call(compose, "x86_64", compose.all_variants["Server-optional"]), + ], ) self.assertEqual(write_defaults.call_args_list, []) self.assertEqual(validate_defaults.call_args_list, []) @@ -91,8 +101,8 @@ class TestInitPhase(PungiTestCase): compose = DummyCompose(self.topdir, {}) compose.has_comps = True compose.has_module_defaults = False - compose.variants['Everything'].groups = [] - compose.variants['Everything'].modules = [] + compose.variants["Everything"].groups = [] + compose.variants["Everything"].modules = [] phase = init.InitPhase(compose) phase.run() @@ -109,21 +119,26 @@ class TestInitPhase(PungiTestCase): six.assertCountEqual( self, create_comps.mock_calls, - [mock.call(compose, "x86_64", None), mock.call(compose, "amd64", None), - mock.call(compose, "x86_64", compose.variants["Server"]), - mock.call(compose, "amd64", compose.variants["Server"]), - mock.call(compose, "amd64", compose.variants["Client"]), - mock.call(compose, "x86_64", compose.variants["Everything"]), - mock.call(compose, "amd64", compose.variants["Everything"])], + [ + mock.call(compose, "x86_64", None), + mock.call(compose, "amd64", None), + mock.call(compose, "x86_64", compose.variants["Server"]), + mock.call(compose, "amd64", compose.variants["Server"]), + mock.call(compose, "amd64", compose.variants["Client"]), + mock.call(compose, "x86_64", compose.variants["Everything"]), + mock.call(compose, "amd64", compose.variants["Everything"]), + ], ) six.assertCountEqual( self, write_variant.mock_calls, - [mock.call(compose, "x86_64", compose.variants["Server"]), - mock.call(compose, "amd64", compose.variants["Server"]), - mock.call(compose, "amd64", compose.variants["Client"]), - mock.call(compose, "x86_64", compose.variants["Everything"]), - mock.call(compose, "amd64", compose.variants["Everything"])], + [ + mock.call(compose, "x86_64", compose.variants["Server"]), + mock.call(compose, "amd64", compose.variants["Server"]), + mock.call(compose, "amd64", compose.variants["Client"]), + mock.call(compose, "x86_64", compose.variants["Everything"]), + mock.call(compose, "amd64", compose.variants["Everything"]), + ], ) self.assertEqual(write_defaults.call_args_list, []) self.assertEqual(validate_defaults.call_args_list, []) @@ -185,96 +200,140 @@ class TestInitPhase(PungiTestCase): class TestWriteArchComps(PungiTestCase): - - @mock.patch('pungi.phases.init.run') + @mock.patch("pungi.phases.init.run") def test_run(self, run): compose = DummyCompose(self.topdir, {}) - init.write_arch_comps(compose, 'x86_64') + init.write_arch_comps(compose, "x86_64") - self.assertEqual(run.mock_calls, - [mock.call(['comps_filter', '--arch=x86_64', '--no-cleanup', - '--output=%s/work/x86_64/comps/comps-x86_64.xml' % self.topdir, - self.topdir + '/work/global/comps/comps-global.xml'])]) + self.assertEqual( + run.mock_calls, + [ + mock.call( + [ + "comps_filter", + "--arch=x86_64", + "--no-cleanup", + "--output=%s/work/x86_64/comps/comps-x86_64.xml" % self.topdir, + self.topdir + "/work/global/comps/comps-global.xml", + ] + ) + ], + ) class TestCreateCompsRepo(PungiTestCase): - - @mock.patch('pungi.phases.init.run') + @mock.patch("pungi.phases.init.run") def test_run(self, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - }) + compose = DummyCompose(self.topdir, {"createrepo_checksum": "sha256"}) - init.create_comps_repo(compose, 'x86_64', None) + init.create_comps_repo(compose, "x86_64", None) - self.assertEqual(run.mock_calls, - [mock.call(['createrepo_c', self.topdir + '/work/x86_64/comps_repo', - '--outputdir=%s/work/x86_64/comps_repo' % self.topdir, - '--groupfile=%s/work/x86_64/comps/comps-x86_64.xml' % self.topdir, - '--update', '--no-database', '--checksum=sha256', - '--unique-md-filenames'], - logfile=self.topdir + '/logs/x86_64/comps_repo.x86_64.log', - show_cmd=True)]) + self.assertEqual( + run.mock_calls, + [ + mock.call( + [ + "createrepo_c", + self.topdir + "/work/x86_64/comps_repo", + "--outputdir=%s/work/x86_64/comps_repo" % self.topdir, + "--groupfile=%s/work/x86_64/comps/comps-x86_64.xml" + % self.topdir, + "--update", + "--no-database", + "--checksum=sha256", + "--unique-md-filenames", + ], + logfile=self.topdir + "/logs/x86_64/comps_repo.x86_64.log", + show_cmd=True, + ) + ], + ) - @mock.patch('pungi.phases.init.run') + @mock.patch("pungi.phases.init.run") def test_run_with_variant(self, run): - compose = DummyCompose(self.topdir, { - 'createrepo_checksum': 'sha256', - }) + compose = DummyCompose(self.topdir, {"createrepo_checksum": "sha256"}) - init.create_comps_repo(compose, 'x86_64', compose.variants['Server']) + init.create_comps_repo(compose, "x86_64", compose.variants["Server"]) - self.assertEqual(run.mock_calls, - [mock.call(['createrepo_c', self.topdir + '/work/x86_64/comps_repo_Server', - '--outputdir=%s/work/x86_64/comps_repo_Server' % self.topdir, - '--groupfile=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir, - '--update', '--no-database', '--checksum=sha256', - '--unique-md-filenames'], - logfile=self.topdir + '/logs/x86_64/comps_repo-Server.x86_64.log', - show_cmd=True)]) + self.assertEqual( + run.mock_calls, + [ + mock.call( + [ + "createrepo_c", + self.topdir + "/work/x86_64/comps_repo_Server", + "--outputdir=%s/work/x86_64/comps_repo_Server" % self.topdir, + "--groupfile=%s/work/x86_64/comps/comps-Server.x86_64.xml" + % self.topdir, + "--update", + "--no-database", + "--checksum=sha256", + "--unique-md-filenames", + ], + logfile=self.topdir + "/logs/x86_64/comps_repo-Server.x86_64.log", + show_cmd=True, + ) + ], + ) class TestWriteGlobalComps(PungiTestCase): - - @mock.patch('pungi.phases.init.get_file_from_scm') + @mock.patch("pungi.phases.init.get_file_from_scm") def test_run_local_file(self, get_file): - compose = DummyCompose(self.topdir, {'comps_file': 'some-file.xml'}) + compose = DummyCompose(self.topdir, {"comps_file": "some-file.xml"}) def gen_file(src, dest, compose=None): - self.assertEqual(src, '/home/releng/config/some-file.xml') - touch(os.path.join(dest, 'some-file.xml')) + self.assertEqual(src, "/home/releng/config/some-file.xml") + touch(os.path.join(dest, "some-file.xml")) get_file.side_effect = gen_file init.write_global_comps(compose) - self.assertTrue(os.path.isfile(self.topdir + '/work/global/comps/comps-global.xml')) + self.assertTrue( + os.path.isfile(self.topdir + "/work/global/comps/comps-global.xml") + ) class TestWriteVariantComps(PungiTestCase): - - @mock.patch('pungi.phases.init.run') - @mock.patch('pungi.phases.init.CompsWrapper') + @mock.patch("pungi.phases.init.run") + @mock.patch("pungi.phases.init.CompsWrapper") def test_run(self, CompsWrapper, run): compose = DummyCompose(self.topdir, {}) - variant = compose.variants['Server'] + variant = compose.variants["Server"] comps = CompsWrapper.return_value comps.filter_groups.return_value = [] - init.write_variant_comps(compose, 'x86_64', variant) + init.write_variant_comps(compose, "x86_64", variant) - self.assertEqual(run.mock_calls, - [mock.call(['comps_filter', '--arch=x86_64', '--keep-empty-group=conflicts', - '--keep-empty-group=conflicts-server', - '--variant=Server', - '--output=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir, - self.topdir + '/work/global/comps/comps-global.xml'])]) - self.assertEqual(CompsWrapper.call_args_list, - [mock.call(self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')]) - self.assertEqual(comps.filter_groups.call_args_list, [mock.call(variant.groups)]) - self.assertEqual(comps.filter_environments.mock_calls, - [mock.call(variant.environments)]) + self.assertEqual( + run.mock_calls, + [ + mock.call( + [ + "comps_filter", + "--arch=x86_64", + "--keep-empty-group=conflicts", + "--keep-empty-group=conflicts-server", + "--variant=Server", + "--output=%s/work/x86_64/comps/comps-Server.x86_64.xml" + % self.topdir, + self.topdir + "/work/global/comps/comps-global.xml", + ] + ) + ], + ) + self.assertEqual( + CompsWrapper.call_args_list, + [mock.call(self.topdir + "/work/x86_64/comps/comps-Server.x86_64.xml")], + ) + self.assertEqual( + comps.filter_groups.call_args_list, [mock.call(variant.groups)] + ) + self.assertEqual( + comps.filter_environments.mock_calls, [mock.call(variant.environments)] + ) self.assertEqual(comps.write_comps.mock_calls, [mock.call()]) @mock.patch("pungi.phases.init.get_lookaside_groups") @@ -299,7 +358,8 @@ class TestWriteVariantComps(PungiTestCase): "--keep-empty-group=conflicts", "--keep-empty-group=conflicts-server", "--variant=Server", - "--output=%s/work/x86_64/comps/comps-Server.x86_64.xml" % self.topdir, + "--output=%s/work/x86_64/comps/comps-Server.x86_64.xml" + % self.topdir, self.topdir + "/work/global/comps/comps-global.xml", "--lookaside-group=foo", "--lookaside-group=bar", @@ -319,81 +379,128 @@ class TestWriteVariantComps(PungiTestCase): ) self.assertEqual(comps.write_comps.mock_calls, [mock.call()]) - @mock.patch('pungi.phases.init.run') - @mock.patch('pungi.phases.init.CompsWrapper') + @mock.patch("pungi.phases.init.run") + @mock.patch("pungi.phases.init.CompsWrapper") def test_run_no_filter_without_groups(self, CompsWrapper, run): compose = DummyCompose(self.topdir, {}) - variant = compose.variants['Server'] + variant = compose.variants["Server"] variant.groups = [] comps = CompsWrapper.return_value comps.filter_groups.return_value = [] - init.write_variant_comps(compose, 'x86_64', variant) + init.write_variant_comps(compose, "x86_64", variant) - self.assertEqual(run.mock_calls, - [mock.call(['comps_filter', '--arch=x86_64', '--keep-empty-group=conflicts', - '--keep-empty-group=conflicts-server', - '--variant=Server', - '--output=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir, - self.topdir + '/work/global/comps/comps-global.xml'])]) - self.assertEqual(CompsWrapper.call_args_list, - [mock.call(self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')]) + self.assertEqual( + run.mock_calls, + [ + mock.call( + [ + "comps_filter", + "--arch=x86_64", + "--keep-empty-group=conflicts", + "--keep-empty-group=conflicts-server", + "--variant=Server", + "--output=%s/work/x86_64/comps/comps-Server.x86_64.xml" + % self.topdir, + self.topdir + "/work/global/comps/comps-global.xml", + ] + ) + ], + ) + self.assertEqual( + CompsWrapper.call_args_list, + [mock.call(self.topdir + "/work/x86_64/comps/comps-Server.x86_64.xml")], + ) self.assertEqual(comps.filter_groups.call_args_list, []) - self.assertEqual(comps.filter_environments.mock_calls, - [mock.call(variant.environments)]) + self.assertEqual( + comps.filter_environments.mock_calls, [mock.call(variant.environments)] + ) self.assertEqual(comps.write_comps.mock_calls, [mock.call()]) - @mock.patch('pungi.phases.init.run') - @mock.patch('pungi.phases.init.CompsWrapper') + @mock.patch("pungi.phases.init.run") + @mock.patch("pungi.phases.init.CompsWrapper") def test_run_filter_for_modular(self, CompsWrapper, run): compose = DummyCompose(self.topdir, {}) - variant = compose.variants['Server'] + variant = compose.variants["Server"] variant.groups = [] - variant.modules = ['testmodule:2.0'] + variant.modules = ["testmodule:2.0"] comps = CompsWrapper.return_value comps.filter_groups.return_value = [] - init.write_variant_comps(compose, 'x86_64', variant) + init.write_variant_comps(compose, "x86_64", variant) - self.assertEqual(run.mock_calls, - [mock.call(['comps_filter', '--arch=x86_64', '--keep-empty-group=conflicts', - '--keep-empty-group=conflicts-server', - '--variant=Server', - '--output=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir, - self.topdir + '/work/global/comps/comps-global.xml'])]) - self.assertEqual(CompsWrapper.call_args_list, - [mock.call(self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')]) + self.assertEqual( + run.mock_calls, + [ + mock.call( + [ + "comps_filter", + "--arch=x86_64", + "--keep-empty-group=conflicts", + "--keep-empty-group=conflicts-server", + "--variant=Server", + "--output=%s/work/x86_64/comps/comps-Server.x86_64.xml" + % self.topdir, + self.topdir + "/work/global/comps/comps-global.xml", + ] + ) + ], + ) + self.assertEqual( + CompsWrapper.call_args_list, + [mock.call(self.topdir + "/work/x86_64/comps/comps-Server.x86_64.xml")], + ) self.assertEqual(comps.filter_groups.call_args_list, [mock.call([])]) - self.assertEqual(comps.filter_environments.mock_calls, - [mock.call(variant.environments)]) + self.assertEqual( + comps.filter_environments.mock_calls, [mock.call(variant.environments)] + ) self.assertEqual(comps.write_comps.mock_calls, [mock.call()]) - @mock.patch('pungi.phases.init.run') - @mock.patch('pungi.phases.init.CompsWrapper') + @mock.patch("pungi.phases.init.run") + @mock.patch("pungi.phases.init.CompsWrapper") def test_run_report_unmatched(self, CompsWrapper, run): compose = DummyCompose(self.topdir, {}) - variant = compose.variants['Server'] + variant = compose.variants["Server"] comps = CompsWrapper.return_value - comps.filter_groups.return_value = ['foo', 'bar'] + comps.filter_groups.return_value = ["foo", "bar"] - init.write_variant_comps(compose, 'x86_64', variant) + init.write_variant_comps(compose, "x86_64", variant) - self.assertEqual(run.mock_calls, - [mock.call(['comps_filter', '--arch=x86_64', '--keep-empty-group=conflicts', - '--keep-empty-group=conflicts-server', - '--variant=Server', - '--output=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir, - self.topdir + '/work/global/comps/comps-global.xml'])]) - self.assertEqual(CompsWrapper.call_args_list, - [mock.call(self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')]) - self.assertEqual(comps.filter_groups.call_args_list, [mock.call(variant.groups)]) - self.assertEqual(comps.filter_environments.mock_calls, - [mock.call(variant.environments)]) + self.assertEqual( + run.mock_calls, + [ + mock.call( + [ + "comps_filter", + "--arch=x86_64", + "--keep-empty-group=conflicts", + "--keep-empty-group=conflicts-server", + "--variant=Server", + "--output=%s/work/x86_64/comps/comps-Server.x86_64.xml" + % self.topdir, + self.topdir + "/work/global/comps/comps-global.xml", + ] + ) + ], + ) + self.assertEqual( + CompsWrapper.call_args_list, + [mock.call(self.topdir + "/work/x86_64/comps/comps-Server.x86_64.xml")], + ) + self.assertEqual( + comps.filter_groups.call_args_list, [mock.call(variant.groups)] + ) + self.assertEqual( + comps.filter_environments.mock_calls, [mock.call(variant.environments)] + ) self.assertEqual(comps.write_comps.mock_calls, [mock.call()]) self.assertEqual( compose.log_warning.call_args_list, - [mock.call(init.UNMATCHED_GROUP_MSG % ('Server', 'x86_64', 'foo')), - mock.call(init.UNMATCHED_GROUP_MSG % ('Server', 'x86_64', 'bar'))]) + [ + mock.call(init.UNMATCHED_GROUP_MSG % ("Server", "x86_64", "foo")), + mock.call(init.UNMATCHED_GROUP_MSG % ("Server", "x86_64", "bar")), + ], + ) class TestGetLookasideGroups(PungiTestCase): @@ -426,7 +533,6 @@ class TestGetLookasideGroups(PungiTestCase): @mock.patch("shutil.copytree") @mock.patch("pungi.phases.init.get_dir_from_scm") class TestWriteModuleDefaults(PungiTestCase): - def test_clone_git(self, gdfs, ct): conf = {"scm": "git", "repo": "https://pagure.io/pungi.git", "dir": "."} compose = DummyCompose(self.topdir, {"module_defaults_dir": conf}) @@ -497,7 +603,6 @@ class TestWriteModuleDefaults(PungiTestCase): @unittest.skipUnless(Modulemd, "Skipped test, no module support.") class TestValidateModuleDefaults(PungiTestCase): - def _write_defaults(self, defs): for mod_name, streams in defs.items(): for stream in streams: diff --git a/tests/test_iso_wrapper.py b/tests/test_iso_wrapper.py index e30b3164..cf4ecd06 100644 --- a/tests/test_iso_wrapper.py +++ b/tests/test_iso_wrapper.py @@ -4,6 +4,7 @@ import itertools import mock import os import six + try: import unittest2 as unittest except ImportError: @@ -11,13 +12,13 @@ except ImportError: from pungi.wrappers import iso -CORRECT_OUTPUT = '''dummy.iso: 31ff3e405e26ad01c63b62f6b11d30f6 +CORRECT_OUTPUT = """dummy.iso: 31ff3e405e26ad01c63b62f6b11d30f6 Fragment sums: 6eb92e7bda221d7fe5f19b4d21468c9bf261d84c96d145d96c76444b9cbc Fragment count: 20 Supported ISO: no -''' +""" -INCORRECT_OUTPUT = '''This should never happen: File not found''' +INCORRECT_OUTPUT = """This should never happen: File not found""" # Cached to use in tests that mock os.listdir orig_listdir = os.listdir @@ -35,40 +36,54 @@ def fake_listdir(pattern, result=None, exc=None): raise exc return result return orig_listdir(path) + return worker class TestIsoUtils(unittest.TestCase): - - @mock.patch('pungi.wrappers.iso.run') + @mock.patch("pungi.wrappers.iso.run") def test_get_implanted_md5_correct(self, mock_run): mock_run.return_value = (0, CORRECT_OUTPUT) logger = mock.Mock() - self.assertEqual(iso.get_implanted_md5('dummy.iso', logger=logger), - '31ff3e405e26ad01c63b62f6b11d30f6') - self.assertEqual(mock_run.call_args_list, - [mock.call(['/usr/bin/checkisomd5', '--md5sumonly', 'dummy.iso'], - universal_newlines=True)]) + self.assertEqual( + iso.get_implanted_md5("dummy.iso", logger=logger), + "31ff3e405e26ad01c63b62f6b11d30f6", + ) + self.assertEqual( + mock_run.call_args_list, + [ + mock.call( + ["/usr/bin/checkisomd5", "--md5sumonly", "dummy.iso"], + universal_newlines=True, + ) + ], + ) self.assertEqual(logger.mock_calls, []) - @mock.patch('pungi.wrappers.iso.run') + @mock.patch("pungi.wrappers.iso.run") def test_get_implanted_md5_incorrect(self, mock_run): mock_run.return_value = (0, INCORRECT_OUTPUT) logger = mock.Mock() - self.assertEqual(iso.get_implanted_md5('dummy.iso', logger=logger), None) - self.assertEqual(mock_run.call_args_list, - [mock.call(['/usr/bin/checkisomd5', '--md5sumonly', 'dummy.iso'], - universal_newlines=True)]) + self.assertEqual(iso.get_implanted_md5("dummy.iso", logger=logger), None) + self.assertEqual( + mock_run.call_args_list, + [ + mock.call( + ["/usr/bin/checkisomd5", "--md5sumonly", "dummy.iso"], + universal_newlines=True, + ) + ], + ) self.assertTrue(len(logger.mock_calls) > 0) - @mock.patch('pungi.util.run_unmount_cmd') - @mock.patch('pungi.wrappers.iso.run') + @mock.patch("pungi.util.run_unmount_cmd") + @mock.patch("pungi.wrappers.iso.run") def test_mount_iso(self, mock_run, mock_unmount): # first tuple is return value for command 'which guestmount' # value determines type of the mount/unmount command ('1' - guestmount is not available) # for approach as a root, pair commands mount-umount are used - mock_run.side_effect = [(1, ''), (0, '')] - with iso.mount('dummy') as temp_dir: + mock_run.side_effect = [(1, ""), (0, "")] + with iso.mount("dummy") as temp_dir: self.assertTrue(os.path.isdir(temp_dir)) self.assertEqual(len(mock_run.call_args_list), 2) mount_call_str = str(mock_run.call_args_list[1]) @@ -80,14 +95,14 @@ class TestIsoUtils(unittest.TestCase): @mock.patch("pungi.util.rmtree") @mock.patch("os.listdir", new=fake_listdir("guestfs", ["root"])) - @mock.patch('pungi.util.run_unmount_cmd') - @mock.patch('pungi.wrappers.iso.run') + @mock.patch("pungi.util.run_unmount_cmd") + @mock.patch("pungi.wrappers.iso.run") def test_guestmount(self, mock_run, mock_unmount, mock_rmtree): # first tuple is return value for command 'which guestmount' # value determines type of the mount/unmount command ('0' - guestmount is available) # for approach as a non-root, pair commands guestmount-fusermount are used - mock_run.side_effect = [(0, ''), (0, '')] - with iso.mount('dummy') as temp_dir: + mock_run.side_effect = [(0, ""), (0, "")] + with iso.mount("dummy") as temp_dir: self.assertTrue(os.path.isdir(temp_dir)) self.assertEqual(len(mock_run.call_args_list), 2) mount_call_str = str(mock_run.call_args_list[1]) @@ -99,14 +114,14 @@ class TestIsoUtils(unittest.TestCase): @mock.patch("pungi.util.rmtree") @mock.patch("os.listdir", new=fake_listdir("guestfs", [])) - @mock.patch('pungi.util.run_unmount_cmd') - @mock.patch('pungi.wrappers.iso.run') + @mock.patch("pungi.util.run_unmount_cmd") + @mock.patch("pungi.wrappers.iso.run") def test_guestmount_cleans_up_cache(self, mock_run, mock_unmount, mock_rmtree): # first tuple is return value for command 'which guestmount' # value determines type of the mount/unmount command ('0' - guestmount is available) # for approach as a non-root, pair commands guestmount-fusermount are used - mock_run.side_effect = [(0, ''), (0, '')] - with iso.mount('dummy') as temp_dir: + mock_run.side_effect = [(0, ""), (0, "")] + with iso.mount("dummy") as temp_dir: self.assertTrue(os.path.isdir(temp_dir)) self.assertEqual(len(mock_run.call_args_list), 2) mount_call_str = str(mock_run.call_args_list[1]) @@ -118,14 +133,16 @@ class TestIsoUtils(unittest.TestCase): @mock.patch("pungi.util.rmtree") @mock.patch("os.listdir", new=fake_listdir("guestfs", OSError("No such file"))) - @mock.patch('pungi.util.run_unmount_cmd') - @mock.patch('pungi.wrappers.iso.run') - def test_guestmount_handles_missing_cache(self, mock_run, mock_unmount, mock_rmtree): + @mock.patch("pungi.util.run_unmount_cmd") + @mock.patch("pungi.wrappers.iso.run") + def test_guestmount_handles_missing_cache( + self, mock_run, mock_unmount, mock_rmtree + ): # first tuple is return value for command 'which guestmount' # value determines type of the mount/unmount command ('0' - guestmount is available) # for approach as a non-root, pair commands guestmount-fusermount are used - mock_run.side_effect = [(0, ''), (0, '')] - with iso.mount('dummy') as temp_dir: + mock_run.side_effect = [(0, ""), (0, "")] + with iso.mount("dummy") as temp_dir: self.assertTrue(os.path.isdir(temp_dir)) self.assertEqual(len(mock_run.call_args_list), 2) mount_call_str = str(mock_run.call_args_list[1]) @@ -135,12 +152,12 @@ class TestIsoUtils(unittest.TestCase): self.assertTrue(unmount_call_str.startswith("call(['fusermount'")) self.assertFalse(os.path.isdir(temp_dir)) - @mock.patch('pungi.util.run_unmount_cmd') - @mock.patch('pungi.wrappers.iso.run') + @mock.patch("pungi.util.run_unmount_cmd") + @mock.patch("pungi.wrappers.iso.run") def test_mount_iso_always_unmounts(self, mock_run, mock_unmount): - mock_run.side_effect = [(1, ''), (0, '')] + mock_run.side_effect = [(1, ""), (0, "")] try: - with iso.mount('dummy') as temp_dir: + with iso.mount("dummy") as temp_dir: self.assertTrue(os.path.isdir(temp_dir)) raise RuntimeError() except RuntimeError: @@ -149,13 +166,13 @@ class TestIsoUtils(unittest.TestCase): self.assertEqual(len(mock_unmount.call_args_list), 1) self.assertFalse(os.path.isdir(temp_dir)) - @mock.patch('pungi.util.run_unmount_cmd') - @mock.patch('pungi.wrappers.iso.run') + @mock.patch("pungi.util.run_unmount_cmd") + @mock.patch("pungi.wrappers.iso.run") def test_mount_iso_raises_on_error(self, mock_run, mock_unmount): log = mock.Mock() - mock_run.side_effect = [(1, ''), (1, 'Boom')] + mock_run.side_effect = [(1, ""), (1, "Boom")] with self.assertRaises(RuntimeError): - with iso.mount('dummy', logger=log) as temp_dir: + with iso.mount("dummy", logger=log) as temp_dir: self.assertTrue(os.path.isdir(temp_dir)) self.assertEqual(len(mock_run.call_args_list), 2) self.assertEqual(len(mock_unmount.call_args_list), 0) @@ -166,29 +183,28 @@ class TestCmpGraftPoints(unittest.TestCase): def assertSorted(self, *args): """Tests that all permutations of arguments yield the same sorted results.""" for perm in itertools.permutations(args): - self.assertEqual(sorted(perm, key=iso.graft_point_sort_key), - list(args)) + self.assertEqual(sorted(perm, key=iso.graft_point_sort_key), list(args)) def test_eq(self): - self.assertSorted('pkgs/foo.rpm', 'pkgs/foo.rpm') + self.assertSorted("pkgs/foo.rpm", "pkgs/foo.rpm") def test_rpms_sorted_alphabetically(self): - self.assertSorted('pkgs/bar.rpm', 'pkgs/foo.rpm') + self.assertSorted("pkgs/bar.rpm", "pkgs/foo.rpm") def test_images_sorted_alphabetically(self): - self.assertSorted('aaa.img', 'images/foo', 'isolinux/foo') + self.assertSorted("aaa.img", "images/foo", "isolinux/foo") def test_other_files_sorted_alphabetically(self): - self.assertSorted('bar.txt', 'foo.txt') + self.assertSorted("bar.txt", "foo.txt") def test_rpms_after_images(self): - self.assertSorted('foo.ins', 'bar.rpm') + self.assertSorted("foo.ins", "bar.rpm") def test_other_after_images(self): - self.assertSorted('EFI/anything', 'zzz.txt') + self.assertSorted("EFI/anything", "zzz.txt") def test_rpm_after_other(self): - self.assertSorted('bbb.txt', 'aaa.rpm') + self.assertSorted("bbb.txt", "aaa.rpm") def test_all_kinds(self): - self.assertSorted('etc/file', 'ppc/file', 'c.txt', 'd.txt', 'a.rpm', 'b.rpm') + self.assertSorted("etc/file", "ppc/file", "c.txt", "d.txt", "a.rpm", "b.rpm") diff --git a/tests/test_koji_wrapper.py b/tests/test_koji_wrapper.py index 2ba6b02d..c566e21b 100644 --- a/tests/test_koji_wrapper.py +++ b/tests/test_koji_wrapper.py @@ -2,6 +2,7 @@ import json import mock + try: import unittest2 as unittest except ImportError: @@ -26,32 +27,33 @@ class DumbMock(object): def mock_imagebuild_path(id): if isinstance(id, int): - return '/koji/imagebuild/' + str(id) - return '/koji/imagebuild/' + str(hash(str(id))) + return "/koji/imagebuild/" + str(id) + return "/koji/imagebuild/" + str(hash(str(id))) class KojiWrapperBaseTestCase(unittest.TestCase): def setUp(self): _, self.tmpfile = tempfile.mkstemp() self.koji_profile = mock.Mock() - with mock.patch('pungi.wrappers.kojiwrapper.koji') as koji: + with mock.patch("pungi.wrappers.kojiwrapper.koji") as koji: koji.krb_login = mock.Mock() koji.get_profile_module = mock.Mock( return_value=mock.Mock( config=DumbMock( - server='koji.example.com', - authtype='kerberos', + server="koji.example.com", + authtype="kerberos", krb_rdns=False, - cert=''), + cert="", + ), pathinfo=mock.Mock( - work=mock.Mock(return_value='/koji'), - taskrelpath=mock.Mock(side_effect=lambda id: 'task/' + str(id)), + work=mock.Mock(return_value="/koji"), + taskrelpath=mock.Mock(side_effect=lambda id: "task/" + str(id)), imagebuild=mock.Mock(side_effect=mock_imagebuild_path), - ) + ), ) ) self.koji_profile = koji.get_profile_module.return_value - self.koji = KojiWrapper('custom-koji') + self.koji = KojiWrapper("custom-koji") def tearDown(self): os.remove(self.tmpfile) @@ -59,64 +61,60 @@ class KojiWrapperBaseTestCase(unittest.TestCase): class KojiWrapperTest(KojiWrapperBaseTestCase): def test_krb_login_krb(self): - self.koji.koji_module.config.keytab = 'testkeytab' - self.koji.koji_module.config.principal = 'testprincipal' + self.koji.koji_module.config.keytab = "testkeytab" + self.koji.koji_module.config.principal = "testprincipal" self.assertEqual(self.koji.koji_module.config.krb_rdns, False) self.koji.login() - self.koji.koji_proxy.krb_login.assert_called_with('testprincipal', - 'testkeytab') + self.koji.koji_proxy.krb_login.assert_called_with("testprincipal", "testkeytab") def test_get_image_build_cmd_without_required_data(self): with self.assertRaises(AssertionError): self.koji.get_image_build_cmd( - { - 'image-build': { - 'name': 'test-name', - } - }, - self.tmpfile + {"image-build": {"name": "test-name"}}, self.tmpfile ) def test_get_image_build_cmd_correct(self): cmd = self.koji.get_image_build_cmd( { - 'image-build': { - 'name': 'test-name', - 'version': '1', - 'target': 'test-target', - 'install_tree': '/tmp/test/install_tree', - 'arches': 'x86_64', - 'format': ['docker', 'qcow2'], - 'kickstart': 'test-kickstart', - 'ksurl': 'git://example.com/ks.git', - 'distro': 'test-distro', - 'release': '20160222.0', - 'disk_size': 4, + "image-build": { + "name": "test-name", + "version": "1", + "target": "test-target", + "install_tree": "/tmp/test/install_tree", + "arches": "x86_64", + "format": ["docker", "qcow2"], + "kickstart": "test-kickstart", + "ksurl": "git://example.com/ks.git", + "distro": "test-distro", + "release": "20160222.0", + "disk_size": 4, } }, - self.tmpfile + self.tmpfile, ) - self.assertEqual(cmd[:3], ['koji', '--profile=custom-koji', 'image-build']) + self.assertEqual(cmd[:3], ["koji", "--profile=custom-koji", "image-build"]) six.assertCountEqual(self, cmd[3:], ["--config=" + self.tmpfile, "--wait"]) - with open(self.tmpfile, 'r') as f: - lines = f.read().strip().split('\n') - self.assertEqual(lines[0], '[image-build]') + with open(self.tmpfile, "r") as f: + lines = f.read().strip().split("\n") + self.assertEqual(lines[0], "[image-build]") six.assertCountEqual( self, lines[1:], - ["name = test-name", - "version = 1", - "target = test-target", - "install_tree = /tmp/test/install_tree", - "arches = x86_64", - "format = docker,qcow2", - "kickstart = test-kickstart", - "ksurl = git://example.com/ks.git", - "distro = test-distro", - "release = 20160222.0", - "disk_size = 4"], + [ + "name = test-name", + "version = 1", + "target = test-target", + "install_tree = /tmp/test/install_tree", + "arches = x86_64", + "format = docker,qcow2", + "kickstart = test-kickstart", + "ksurl = git://example.com/ks.git", + "distro = test-distro", + "release = 20160222.0", + "disk_size = 4", + ], ) def test_get_image_paths(self): @@ -128,154 +126,166 @@ class KojiWrapperTest(KojiWrapperBaseTestCase): getTaskChildren_data = { 12387273: [ { - 'arch': 'i386', - 'awaited': False, - 'channel_id': 12, - 'completion_time': '2016-01-03 05:34:08.374262', - 'completion_ts': 1451799248.37426, - 'create_time': '2016-01-03 05:15:20.311599', - 'create_ts': 1451798120.3116, - 'host_id': 158, - 'id': 12387276, - 'label': 'i386', - 'method': 'createImage', - 'owner': 131, - 'parent': 12387273, - 'priority': 19, - 'request': [ - 'Fedora-Cloud-Base', - '23', - '20160103', - 'i386', + "arch": "i386", + "awaited": False, + "channel_id": 12, + "completion_time": "2016-01-03 05:34:08.374262", + "completion_ts": 1451799248.37426, + "create_time": "2016-01-03 05:15:20.311599", + "create_ts": 1451798120.3116, + "host_id": 158, + "id": 12387276, + "label": "i386", + "method": "createImage", + "owner": 131, + "parent": 12387273, + "priority": 19, + "request": [ + "Fedora-Cloud-Base", + "23", + "20160103", + "i386", { - 'build_tag': 299, - 'build_tag_name': 'f23-build', - 'dest_tag': 294, - 'dest_tag_name': 'f23-updates-candidate', - 'id': 144, - 'name': 'f23-candidate' + "build_tag": 299, + "build_tag_name": "f23-build", + "dest_tag": 294, + "dest_tag_name": "f23-updates-candidate", + "id": 144, + "name": "f23-candidate", }, 299, { - 'create_event': 14011966, - 'create_ts': 1451761803.33528, - 'creation_time': '2016-01-02 19:10:03.335283', - 'id': 563977, - 'state': 1 + "create_event": 14011966, + "create_ts": 1451761803.33528, + "creation_time": "2016-01-02 19:10:03.335283", + "id": 563977, + "state": 1, }, - 'http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/i386/os/', + "http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/i386/os/", { - 'disk_size': '3', - 'distro': 'Fedora-20', - 'format': ['qcow2', 'raw-xz'], - 'kickstart': 'work/cli-image/1451798116.800155.wYJWTVHw/fedora-cloud-base-2878aa0.ks', - 'release': '20160103', - 'repo': ['http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/$arch/os/', - 'http://infrastructure.fedoraproject.org/pub/fedora/linux/updates/23/$arch/'], - 'scratch': True - } + "disk_size": "3", + "distro": "Fedora-20", + "format": ["qcow2", "raw-xz"], + "kickstart": "work/cli-image/1451798116.800155.wYJWTVHw/fedora-cloud-base-2878aa0.ks", + "release": "20160103", + "repo": [ + "http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/$arch/os/", + "http://infrastructure.fedoraproject.org/pub/fedora/linux/updates/23/$arch/", + ], + "scratch": True, + }, ], - 'start_time': '2016-01-03 05:15:29.828081', - 'start_ts': 1451798129.82808, - 'state': 2, - 'waiting': None, - 'weight': 2.0 - }, { - 'arch': 'x86_64', - 'awaited': False, - 'channel_id': 12, - 'completion_time': '2016-01-03 05:33:20.066366', - 'completion_ts': 1451799200.06637, - 'create_time': '2016-01-03 05:15:20.754201', - 'create_ts': 1451798120.7542, - 'host_id': 156, - 'id': 12387277, - 'label': 'x86_64', - 'method': 'createImage', - 'owner': 131, - 'parent': 12387273, - 'priority': 19, - 'request': [ - 'Fedora-Cloud-Base', - '23', - '20160103', - 'x86_64', + "start_time": "2016-01-03 05:15:29.828081", + "start_ts": 1451798129.82808, + "state": 2, + "waiting": None, + "weight": 2.0, + }, + { + "arch": "x86_64", + "awaited": False, + "channel_id": 12, + "completion_time": "2016-01-03 05:33:20.066366", + "completion_ts": 1451799200.06637, + "create_time": "2016-01-03 05:15:20.754201", + "create_ts": 1451798120.7542, + "host_id": 156, + "id": 12387277, + "label": "x86_64", + "method": "createImage", + "owner": 131, + "parent": 12387273, + "priority": 19, + "request": [ + "Fedora-Cloud-Base", + "23", + "20160103", + "x86_64", { - 'build_tag': 299, - 'build_tag_name': 'f23-build', - 'dest_tag': 294, - 'dest_tag_name': 'f23-updates-candidate', - 'id': 144, - 'name': 'f23-candidate' + "build_tag": 299, + "build_tag_name": "f23-build", + "dest_tag": 294, + "dest_tag_name": "f23-updates-candidate", + "id": 144, + "name": "f23-candidate", }, 299, { - 'create_event': 14011966, - 'create_ts': 1451761803.33528, - 'creation_time': '2016-01-02 19:10:03.335283', - 'id': 563977, - 'state': 1 + "create_event": 14011966, + "create_ts": 1451761803.33528, + "creation_time": "2016-01-02 19:10:03.335283", + "id": 563977, + "state": 1, }, - 'http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/x86_64/os/', + "http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/x86_64/os/", { - 'disk_size': '3', - 'distro': 'Fedora-20', - 'format': ['qcow2', 'raw-xz'], - 'kickstart': 'work/cli-image/1451798116.800155.wYJWTVHw/fedora-cloud-base-2878aa0.ks', - 'release': '20160103', - 'repo': ['http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/$arch/os/', - 'http://infrastructure.fedoraproject.org/pub/fedora/linux/updates/23/$arch/'], - 'scratch': True - } + "disk_size": "3", + "distro": "Fedora-20", + "format": ["qcow2", "raw-xz"], + "kickstart": "work/cli-image/1451798116.800155.wYJWTVHw/fedora-cloud-base-2878aa0.ks", + "release": "20160103", + "repo": [ + "http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/$arch/os/", + "http://infrastructure.fedoraproject.org/pub/fedora/linux/updates/23/$arch/", + ], + "scratch": True, + }, ], - 'start_time': '2016-01-03 05:15:35.196043', - 'start_ts': 1451798135.19604, - 'state': 2, - 'waiting': None, - 'weight': 2.0 - } + "start_time": "2016-01-03 05:15:35.196043", + "start_ts": 1451798135.19604, + "state": 2, + "waiting": None, + "weight": 2.0, + }, ] } getTaskResult_data = { 12387276: { - 'arch': 'i386', - 'files': ['tdl-i386.xml', - 'fedora-cloud-base-2878aa0.ks', - 'koji-f23-build-12387276-base.ks', - 'libvirt-qcow2-i386.xml', - 'Fedora-Cloud-Base-23-20160103.i386.qcow2', - 'libvirt-raw-xz-i386.xml', - 'Fedora-Cloud-Base-23-20160103.i386.raw.xz'], - 'logs': ['oz-i386.log'], - 'name': 'Fedora-Cloud-Base', - 'release': '20160103', - 'rpmlist': [], - 'task_id': 12387276, - 'version': '23' + "arch": "i386", + "files": [ + "tdl-i386.xml", + "fedora-cloud-base-2878aa0.ks", + "koji-f23-build-12387276-base.ks", + "libvirt-qcow2-i386.xml", + "Fedora-Cloud-Base-23-20160103.i386.qcow2", + "libvirt-raw-xz-i386.xml", + "Fedora-Cloud-Base-23-20160103.i386.raw.xz", + ], + "logs": ["oz-i386.log"], + "name": "Fedora-Cloud-Base", + "release": "20160103", + "rpmlist": [], + "task_id": 12387276, + "version": "23", }, 12387277: { - 'arch': 'x86_64', - 'files': ['tdl-x86_64.xml', - 'fedora-cloud-base-2878aa0.ks', - 'koji-f23-build-12387277-base.ks', - 'libvirt-qcow2-x86_64.xml', - 'Fedora-Cloud-Base-23-20160103.x86_64.qcow2', - 'libvirt-raw-xz-x86_64.xml', - 'Fedora-Cloud-Base-23-20160103.x86_64.raw.xz'], - 'logs': ['oz-x86_64.log'], - 'name': 'Fedora-Cloud-Base', - 'release': '20160103', - 'rpmlist': [], - 'task_id': 12387277, - 'version': '23' - } - + "arch": "x86_64", + "files": [ + "tdl-x86_64.xml", + "fedora-cloud-base-2878aa0.ks", + "koji-f23-build-12387277-base.ks", + "libvirt-qcow2-x86_64.xml", + "Fedora-Cloud-Base-23-20160103.x86_64.qcow2", + "libvirt-raw-xz-x86_64.xml", + "Fedora-Cloud-Base-23-20160103.x86_64.raw.xz", + ], + "logs": ["oz-x86_64.log"], + "name": "Fedora-Cloud-Base", + "release": "20160103", + "rpmlist": [], + "task_id": 12387277, + "version": "23", + }, } self.koji.koji_proxy = mock.Mock( - getTaskChildren=mock.Mock(side_effect=lambda task_id, request: getTaskChildren_data.get(task_id)), - getTaskResult=mock.Mock(side_effect=lambda task_id: getTaskResult_data.get(task_id)) + getTaskChildren=mock.Mock( + side_effect=lambda task_id, request: getTaskChildren_data.get(task_id) + ), + getTaskResult=mock.Mock( + side_effect=lambda task_id: getTaskResult_data.get(task_id) + ), ) result = self.koji.get_image_paths(12387273) six.assertCountEqual(self, result.keys(), ["i386", "x86_64"]) @@ -283,24 +293,28 @@ class KojiWrapperTest(KojiWrapperBaseTestCase): six.assertCountEqual( self, result["i386"], - ["/koji/task/12387276/tdl-i386.xml", - "/koji/task/12387276/fedora-cloud-base-2878aa0.ks", - "/koji/task/12387276/koji-f23-build-12387276-base.ks", - "/koji/task/12387276/libvirt-qcow2-i386.xml", - "/koji/task/12387276/Fedora-Cloud-Base-23-20160103.i386.qcow2", - "/koji/task/12387276/libvirt-raw-xz-i386.xml", - "/koji/task/12387276/Fedora-Cloud-Base-23-20160103.i386.raw.xz"], + [ + "/koji/task/12387276/tdl-i386.xml", + "/koji/task/12387276/fedora-cloud-base-2878aa0.ks", + "/koji/task/12387276/koji-f23-build-12387276-base.ks", + "/koji/task/12387276/libvirt-qcow2-i386.xml", + "/koji/task/12387276/Fedora-Cloud-Base-23-20160103.i386.qcow2", + "/koji/task/12387276/libvirt-raw-xz-i386.xml", + "/koji/task/12387276/Fedora-Cloud-Base-23-20160103.i386.raw.xz", + ], ) six.assertCountEqual( self, result["x86_64"], - ["/koji/task/12387277/tdl-x86_64.xml", - "/koji/task/12387277/fedora-cloud-base-2878aa0.ks", - "/koji/task/12387277/koji-f23-build-12387277-base.ks", - "/koji/task/12387277/libvirt-qcow2-x86_64.xml", - "/koji/task/12387277/Fedora-Cloud-Base-23-20160103.x86_64.qcow2", - "/koji/task/12387277/libvirt-raw-xz-x86_64.xml", - "/koji/task/12387277/Fedora-Cloud-Base-23-20160103.x86_64.raw.xz"], + [ + "/koji/task/12387277/tdl-x86_64.xml", + "/koji/task/12387277/fedora-cloud-base-2878aa0.ks", + "/koji/task/12387277/koji-f23-build-12387277-base.ks", + "/koji/task/12387277/libvirt-qcow2-x86_64.xml", + "/koji/task/12387277/Fedora-Cloud-Base-23-20160103.x86_64.qcow2", + "/koji/task/12387277/libvirt-raw-xz-x86_64.xml", + "/koji/task/12387277/Fedora-Cloud-Base-23-20160103.x86_64.raw.xz", + ], ) def test_get_image_paths_failed_subtask(self): @@ -310,15 +324,19 @@ class KojiWrapperTest(KojiWrapperBaseTestCase): def failed_callback(arch): failed.add(arch) - with open(os.path.join(FIXTURE_DIR, 'task_children_25643870.json')) as f: + with open(os.path.join(FIXTURE_DIR, "task_children_25643870.json")) as f: getTaskChildren_data = json.load(f) - with open(os.path.join(FIXTURE_DIR, 'children_task_results_25643870.json')) as f: + with open( + os.path.join(FIXTURE_DIR, "children_task_results_25643870.json") + ) as f: getTaskResult_data = json.load(f) self.koji.koji_proxy = mock.Mock( getTaskChildren=mock.Mock(return_value=getTaskChildren_data), - getTaskResult=mock.Mock(side_effect=lambda task_id: getTaskResult_data.get(str(task_id))), + getTaskResult=mock.Mock( + side_effect=lambda task_id: getTaskResult_data.get(str(task_id)) + ), getImageBuild=mock.Mock(side_effect=lambda name: {}), ) @@ -332,13 +350,17 @@ class KojiWrapperTest(KojiWrapperBaseTestCase): self.koji.koji_proxy.multiCall.return_value = [[1], [2]] ret = self.koji.multicall_map( - self.koji.koji_proxy, self.koji.koji_proxy.getBuild, ["foo", "bar"], - [{"x":1}, {"x":2}]) + self.koji.koji_proxy, + self.koji.koji_proxy.getBuild, + ["foo", "bar"], + [{"x": 1}, {"x": 2}], + ) six.assertCountEqual( self, self.koji.koji_proxy.getBuild.mock_calls, - [mock.call("foo", x=1), mock.call("bar", x=2)]) + [mock.call("foo", x=1), mock.call("bar", x=2)], + ) self.koji.koji_proxy.multiCall.assert_called_with(strict=True) self.assertEqual(ret, [1, 2]) @@ -346,136 +368,253 @@ class KojiWrapperTest(KojiWrapperBaseTestCase): class LiveMediaTestCase(KojiWrapperBaseTestCase): def test_get_live_media_cmd_minimal(self): opts = { - 'name': 'name', 'version': '1', 'target': 'tgt', 'arch': 'x,y,z', - 'ksfile': 'kickstart', 'install_tree': '/mnt/os', + "name": "name", + "version": "1", + "target": "tgt", + "arch": "x,y,z", + "ksfile": "kickstart", + "install_tree": "/mnt/os", } cmd = self.koji.get_live_media_cmd(opts) - self.assertEqual(cmd, - ['koji', '--profile=custom-koji', 'spin-livemedia', 'name', '1', 'tgt', 'x,y,z', 'kickstart', - '--install-tree=/mnt/os', '--wait']) + self.assertEqual( + cmd, + [ + "koji", + "--profile=custom-koji", + "spin-livemedia", + "name", + "1", + "tgt", + "x,y,z", + "kickstart", + "--install-tree=/mnt/os", + "--wait", + ], + ) def test_get_live_media_cmd_full(self): opts = { - 'name': 'name', 'version': '1', 'target': 'tgt', 'arch': 'x,y,z', - 'ksfile': 'kickstart', 'install_tree': '/mnt/os', 'scratch': True, - 'repo': ['repo-1', 'repo-2'], 'skip_tag': True, - 'ksurl': 'git://example.com/ksurl.git', 'release': '20160222.1', + "name": "name", + "version": "1", + "target": "tgt", + "arch": "x,y,z", + "ksfile": "kickstart", + "install_tree": "/mnt/os", + "scratch": True, + "repo": ["repo-1", "repo-2"], + "skip_tag": True, + "ksurl": "git://example.com/ksurl.git", + "release": "20160222.1", } cmd = self.koji.get_live_media_cmd(opts) - self.assertEqual(cmd[:9], - ['koji', '--profile=custom-koji', 'spin-livemedia', 'name', '1', 'tgt', 'x,y,z', 'kickstart', - '--install-tree=/mnt/os']) + self.assertEqual( + cmd[:9], + [ + "koji", + "--profile=custom-koji", + "spin-livemedia", + "name", + "1", + "tgt", + "x,y,z", + "kickstart", + "--install-tree=/mnt/os", + ], + ) six.assertCountEqual( self, cmd[9:], - ["--repo=repo-1", "--repo=repo-2", "--skip-tag", "--scratch", "--wait", - "--ksurl=git://example.com/ksurl.git", "--release=20160222.1"], + [ + "--repo=repo-1", + "--repo=repo-2", + "--skip-tag", + "--scratch", + "--wait", + "--ksurl=git://example.com/ksurl.git", + "--release=20160222.1", + ], ) class LiveImageKojiWrapperTest(KojiWrapperBaseTestCase): def test_get_create_image_cmd_minimal(self): - cmd = self.koji.get_create_image_cmd('my_name', '1.0', 'f24-candidate', - 'x86_64', '/path/to/ks', ['/repo/1']) - self.assertEqual(cmd[0:3], ['koji', '--profile=custom-koji', 'spin-livecd']) + cmd = self.koji.get_create_image_cmd( + "my_name", "1.0", "f24-candidate", "x86_64", "/path/to/ks", ["/repo/1"] + ) + self.assertEqual(cmd[0:3], ["koji", "--profile=custom-koji", "spin-livecd"]) six.assertCountEqual( self, cmd[3:7], ["--noprogress", "--scratch", "--wait", "--repo=/repo/1"] ) - self.assertEqual(cmd[7:], ['my_name', '1.0', 'f24-candidate', 'x86_64', '/path/to/ks']) + self.assertEqual( + cmd[7:], ["my_name", "1.0", "f24-candidate", "x86_64", "/path/to/ks"] + ) def test_get_create_image_cmd_full(self): - cmd = self.koji.get_create_image_cmd('my_name', '1.0', 'f24-candidate', - 'x86_64', '/path/to/ks', ['/repo/1', '/repo/2'], - release='1', wait=False, archive=True, specfile='foo.spec', - ksurl='https://git.example.com/') - self.assertEqual(cmd[0:3], ['koji', '--profile=custom-koji', 'spin-livecd']) - self.assertEqual(cmd[-5:], ['my_name', '1.0', 'f24-candidate', 'x86_64', '/path/to/ks']) + cmd = self.koji.get_create_image_cmd( + "my_name", + "1.0", + "f24-candidate", + "x86_64", + "/path/to/ks", + ["/repo/1", "/repo/2"], + release="1", + wait=False, + archive=True, + specfile="foo.spec", + ksurl="https://git.example.com/", + ) + self.assertEqual(cmd[0:3], ["koji", "--profile=custom-koji", "spin-livecd"]) + self.assertEqual( + cmd[-5:], ["my_name", "1.0", "f24-candidate", "x86_64", "/path/to/ks"] + ) six.assertCountEqual( self, cmd[3:-5], - ["--noprogress", "--nowait", "--repo=/repo/1", "--repo=/repo/2", - "--release=1", "--specfile=foo.spec", "--ksurl=https://git.example.com/"], + [ + "--noprogress", + "--nowait", + "--repo=/repo/1", + "--repo=/repo/2", + "--release=1", + "--specfile=foo.spec", + "--ksurl=https://git.example.com/", + ], ) def test_spin_livecd_with_format(self): with self.assertRaises(ValueError): - self.koji.get_create_image_cmd('my_name', '1.0', 'f24-candidate', - 'x86_64', '/path/to/ks', [], - image_format='qcow') + self.koji.get_create_image_cmd( + "my_name", + "1.0", + "f24-candidate", + "x86_64", + "/path/to/ks", + [], + image_format="qcow", + ) def test_spin_appliance_with_format(self): - cmd = self.koji.get_create_image_cmd('my_name', '1.0', 'f24-candidate', - 'x86_64', '/path/to/ks', [], - image_type='appliance', - image_format='qcow') - self.assertEqual(cmd[0:3], ['koji', '--profile=custom-koji', 'spin-appliance']) + cmd = self.koji.get_create_image_cmd( + "my_name", + "1.0", + "f24-candidate", + "x86_64", + "/path/to/ks", + [], + image_type="appliance", + image_format="qcow", + ) + self.assertEqual(cmd[0:3], ["koji", "--profile=custom-koji", "spin-appliance"]) six.assertCountEqual( self, cmd[3:7], ["--noprogress", "--scratch", "--wait", "--format=qcow"] ) - self.assertEqual(cmd[7:], ['my_name', '1.0', 'f24-candidate', 'x86_64', '/path/to/ks']) + self.assertEqual( + cmd[7:], ["my_name", "1.0", "f24-candidate", "x86_64", "/path/to/ks"] + ) def test_spin_appliance_with_wrong_format(self): with self.assertRaises(ValueError): - self.koji.get_create_image_cmd('my_name', '1.0', 'f24-candidate', - 'x86_64', '/path/to/ks', [], - image_type='appliance', - image_format='pretty') + self.koji.get_create_image_cmd( + "my_name", + "1.0", + "f24-candidate", + "x86_64", + "/path/to/ks", + [], + image_type="appliance", + image_format="pretty", + ) class RunrootKojiWrapperTest(KojiWrapperBaseTestCase): def test_get_cmd_minimal(self): - cmd = self.koji.get_runroot_cmd('tgt', 's390x', 'date', use_shell=False) + cmd = self.koji.get_runroot_cmd("tgt", "s390x", "date", use_shell=False) self.assertEqual(len(cmd), 9) - self.assertEqual(cmd[:5], ['koji', '--profile=custom-koji', 'runroot', '--nowait', '--task-id']) - self.assertEqual(cmd[-3], 'tgt') - self.assertEqual(cmd[-2], 's390x') - self.assertEqual(cmd[-1], 'rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; date') + self.assertEqual( + cmd[:5], + ["koji", "--profile=custom-koji", "runroot", "--nowait", "--task-id"], + ) + self.assertEqual(cmd[-3], "tgt") + self.assertEqual(cmd[-2], "s390x") + self.assertEqual( + cmd[-1], "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; date" + ) six.assertCountEqual(self, cmd[5:-3], ["--channel-override=runroot-local"]) def test_get_cmd_full(self): - cmd = self.koji.get_runroot_cmd('tgt', 's390x', ['/bin/echo', '&'], - quiet=True, channel='chan', - packages=['lorax', 'some_other_package'], - mounts=['/tmp'], weight=1000) + cmd = self.koji.get_runroot_cmd( + "tgt", + "s390x", + ["/bin/echo", "&"], + quiet=True, + channel="chan", + packages=["lorax", "some_other_package"], + mounts=["/tmp"], + weight=1000, + ) self.assertEqual(len(cmd), 15) - self.assertEqual(cmd[:3], ['koji', '--profile=custom-koji', 'runroot']) - self.assertEqual(cmd[-3], 'tgt') - self.assertEqual(cmd[-2], 's390x') - self.assertEqual(cmd[-1], 'rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo \'&\'') + self.assertEqual(cmd[:3], ["koji", "--profile=custom-koji", "runroot"]) + self.assertEqual(cmd[-3], "tgt") + self.assertEqual(cmd[-2], "s390x") + self.assertEqual( + cmd[-1], + "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&'", + ) six.assertCountEqual( self, cmd[4:-3], - ["--channel-override=chan", "--quiet", "--use-shell", - "--task-id", "--weight=1000", "--package=some_other_package", - "--package=lorax", "--mount=/tmp"], + [ + "--channel-override=chan", + "--quiet", + "--use-shell", + "--task-id", + "--weight=1000", + "--package=some_other_package", + "--package=lorax", + "--mount=/tmp", + ], ) @mock.patch("os.getuid", new=lambda: 1010) def test_with_chown_paths(self): - cmd = self.koji.get_runroot_cmd('tgt', 's390x', ['/bin/echo', '&'], - quiet=True, channel='chan', - packages=['lorax', 'some_other_package'], - mounts=['/tmp'], weight=1000, chown_paths=["/output dir", "/foo"]) + cmd = self.koji.get_runroot_cmd( + "tgt", + "s390x", + ["/bin/echo", "&"], + quiet=True, + channel="chan", + packages=["lorax", "some_other_package"], + mounts=["/tmp"], + weight=1000, + chown_paths=["/output dir", "/foo"], + ) self.assertEqual(len(cmd), 15) - self.assertEqual(cmd[:3], ['koji', '--profile=custom-koji', 'runroot']) - self.assertEqual(cmd[-3], 'tgt') - self.assertEqual(cmd[-2], 's390x') + self.assertEqual(cmd[:3], ["koji", "--profile=custom-koji", "runroot"]) + self.assertEqual(cmd[-3], "tgt") + self.assertEqual(cmd[-2], "s390x") self.assertEqual( cmd[-1], - "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&' && chmod -R a+r '/output dir' /foo && chown -R 1010 '/output dir' /foo" + "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&' && chmod -R a+r '/output dir' /foo && chown -R 1010 '/output dir' /foo", ) six.assertCountEqual( self, cmd[4:-3], - ["--channel-override=chan", "--quiet", "--use-shell", - "--task-id", "--weight=1000", "--package=some_other_package", - "--package=lorax", "--mount=/tmp"], + [ + "--channel-override=chan", + "--quiet", + "--use-shell", + "--task-id", + "--weight=1000", + "--package=some_other_package", + "--package=lorax", + "--mount=/tmp", + ], ) - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_run_runroot_cmd_no_task_id(self, run): - cmd = ['koji', 'runroot'] - output = 'Output ...' + cmd = ["koji", "runroot"] + output = "Output ..." run.return_value = (1, output) with self.assertRaises(RuntimeError) as ctx: @@ -483,216 +622,353 @@ class RunrootKojiWrapperTest(KojiWrapperBaseTestCase): self.assertEqual( run.call_args_list, - [mock.call(cmd, can_fail=True, env=None, logfile=None, show_cmd=True, - universal_newlines=True)] + [ + mock.call( + cmd, + can_fail=True, + env=None, + logfile=None, + show_cmd=True, + universal_newlines=True, + ) + ], ) self.assertEqual( - "Could not find task ID in output. Command '%s' returned '%s'." % (" ".join(cmd), output), - str(ctx.exception) + "Could not find task ID in output. Command '%s' returned '%s'." + % (" ".join(cmd), output), + str(ctx.exception), ) - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_run_runroot_cmd_with_task_id(self, run): - cmd = ['koji', 'runroot', '--task-id'] - run.return_value = (0, '1234\n') + cmd = ["koji", "runroot", "--task-id"] + run.return_value = (0, "1234\n") output = "Output ..." self.koji._wait_for_task = mock.Mock(return_value=(0, output)) result = self.koji.run_runroot_cmd(cmd) - self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': 1234}) + self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234}) self.assertEqual( run.call_args_list, - [mock.call(cmd, can_fail=True, env=None, logfile=None, show_cmd=True, - universal_newlines=True)] + [ + mock.call( + cmd, + can_fail=True, + env=None, + logfile=None, + show_cmd=True, + universal_newlines=True, + ) + ], ) - @mock.patch.dict('os.environ', {'FOO': 'BAR'}, clear=True) - @mock.patch('shutil.rmtree') - @mock.patch('tempfile.mkdtemp') - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch.dict("os.environ", {"FOO": "BAR"}, clear=True) + @mock.patch("shutil.rmtree") + @mock.patch("tempfile.mkdtemp") + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_run_runroot_cmd_with_keytab(self, run, mkdtemp, rmtree): # We mock rmtree to avoid deleing something we did not create. - mkdtemp.return_value = '/tmp/foo' - self.koji.koji_module.config.keytab = 'foo' - cmd = ['koji', 'runroot'] - output = 'Output ...' - run.return_value = (0, '1234\n') + mkdtemp.return_value = "/tmp/foo" + self.koji.koji_module.config.keytab = "foo" + cmd = ["koji", "runroot"] + output = "Output ..." + run.return_value = (0, "1234\n") self.koji._wait_for_task = mock.Mock(return_value=(0, output)) result = self.koji.run_runroot_cmd(cmd) - self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': 1234}) + self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234}) self.assertEqual( run.call_args_list, - [mock.call(cmd, can_fail=True, env={'KRB5CCNAME': 'DIR:/tmp/foo', 'FOO': 'BAR'}, - logfile=None, show_cmd=True, universal_newlines=True)] + [ + mock.call( + cmd, + can_fail=True, + env={"KRB5CCNAME": "DIR:/tmp/foo", "FOO": "BAR"}, + logfile=None, + show_cmd=True, + universal_newlines=True, + ) + ], ) class RunBlockingCmdTest(KojiWrapperBaseTestCase): - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_minimal(self, run): - output = 'Created task: 1234\nHello\n' + output = "Created task: 1234\nHello\n" run.return_value = (0, output) - result = self.koji.run_blocking_cmd('cmd') + result = self.koji.run_blocking_cmd("cmd") - self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': 1234}) + self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234}) six.assertCountEqual( self, run.mock_calls, - [mock.call('cmd', can_fail=True, logfile=None, env=None, universal_newlines=True)], + [ + mock.call( + "cmd", + can_fail=True, + logfile=None, + env=None, + universal_newlines=True, + ) + ], ) - @mock.patch.dict('os.environ', {'FOO': 'BAR'}, clear=True) - @mock.patch('pungi.util.temp_dir') - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch.dict("os.environ", {"FOO": "BAR"}, clear=True) + @mock.patch("pungi.util.temp_dir") + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_with_keytab(self, run, temp_dir): - temp_dir.return_value.__enter__.return_value = '/tmp/foo' - self.koji.koji_module.config.keytab = 'foo' - output = 'Created task: 1234\nHello\n' + temp_dir.return_value.__enter__.return_value = "/tmp/foo" + self.koji.koji_module.config.keytab = "foo" + output = "Created task: 1234\nHello\n" run.return_value = (0, output) - result = self.koji.run_blocking_cmd('cmd') + result = self.koji.run_blocking_cmd("cmd") - self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': 1234}) + self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234}) six.assertCountEqual( self, run.mock_calls, - [mock.call("cmd", can_fail=True, logfile=None, - env={"KRB5CCNAME": "DIR:/tmp/foo", "FOO": "BAR"}, - universal_newlines=True)], + [ + mock.call( + "cmd", + can_fail=True, + logfile=None, + env={"KRB5CCNAME": "DIR:/tmp/foo", "FOO": "BAR"}, + universal_newlines=True, + ) + ], ) - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_with_log(self, run): - output = 'Created task: 1234\nHello\n' + output = "Created task: 1234\nHello\n" run.return_value = (0, output) - result = self.koji.run_blocking_cmd('cmd', log_file='logfile') + result = self.koji.run_blocking_cmd("cmd", log_file="logfile") - self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': 1234}) + self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234}) six.assertCountEqual( self, run.mock_calls, - [mock.call("cmd", can_fail=True, logfile="logfile", env=None, - universal_newlines=True)] + [ + mock.call( + "cmd", + can_fail=True, + logfile="logfile", + env=None, + universal_newlines=True, + ) + ], ) - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_fail_with_task_id(self, run): - output = 'Created task: 1234\nBoom\n' + output = "Created task: 1234\nBoom\n" run.return_value = (1, output) - result = self.koji.run_blocking_cmd('cmd') + result = self.koji.run_blocking_cmd("cmd") - self.assertDictEqual(result, {'retcode': 1, 'output': output, 'task_id': 1234}) + self.assertDictEqual(result, {"retcode": 1, "output": output, "task_id": 1234}) six.assertCountEqual( - self, run.mock_calls, - [mock.call("cmd", can_fail=True, logfile=None, env=None, - universal_newlines=True)], + self, + run.mock_calls, + [ + mock.call( + "cmd", + can_fail=True, + logfile=None, + env=None, + universal_newlines=True, + ) + ], ) - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_fail_without_task_id(self, run): - output = 'Not found\n' + output = "Not found\n" run.return_value = (1, output) with self.assertRaises(RuntimeError) as ctx: - self.koji.run_blocking_cmd('cmd') + self.koji.run_blocking_cmd("cmd") six.assertCountEqual( - self, run.mock_calls, - [mock.call("cmd", can_fail=True, logfile=None, env=None, - universal_newlines=True)], + self, + run.mock_calls, + [ + mock.call( + "cmd", + can_fail=True, + logfile=None, + env=None, + universal_newlines=True, + ) + ], ) - self.assertIn('Could not find task ID', str(ctx.exception)) + self.assertIn("Could not find task ID", str(ctx.exception)) - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_disconnect_and_retry(self, run): - output = 'Created task: 1234\nerror: failed to connect\n' - retry = 'Created task: 1234\nOook\n' + output = "Created task: 1234\nerror: failed to connect\n" + retry = "Created task: 1234\nOook\n" run.side_effect = [(1, output), (0, retry)] - result = self.koji.run_blocking_cmd('cmd') + result = self.koji.run_blocking_cmd("cmd") - self.assertDictEqual(result, {'retcode': 0, 'output': retry, 'task_id': 1234}) - self.assertEqual(run.mock_calls, - [mock.call('cmd', can_fail=True, logfile=None, env=None, - universal_newlines=True), - mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'], - can_fail=True, logfile=None, universal_newlines=True)]) + self.assertDictEqual(result, {"retcode": 0, "output": retry, "task_id": 1234}) + self.assertEqual( + run.mock_calls, + [ + mock.call( + "cmd", + can_fail=True, + logfile=None, + env=None, + universal_newlines=True, + ), + mock.call( + ["koji", "--profile=custom-koji", "watch-task", "1234"], + can_fail=True, + logfile=None, + universal_newlines=True, + ), + ], + ) - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_disconnect_and_retry_but_fail(self, run): - output = 'Created task: 1234\nerror: failed to connect\n' - retry = 'Created task: 1234\nNot working still\n' + output = "Created task: 1234\nerror: failed to connect\n" + retry = "Created task: 1234\nNot working still\n" run.side_effect = [(1, output), (1, retry)] - result = self.koji.run_blocking_cmd('cmd') + result = self.koji.run_blocking_cmd("cmd") - self.assertDictEqual(result, {'retcode': 1, 'output': retry, 'task_id': 1234}) - self.assertEqual(run.mock_calls, - [mock.call('cmd', can_fail=True, logfile=None, env=None, - universal_newlines=True), - mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'], - can_fail=True, logfile=None, universal_newlines=True)]) + self.assertDictEqual(result, {"retcode": 1, "output": retry, "task_id": 1234}) + self.assertEqual( + run.mock_calls, + [ + mock.call( + "cmd", + can_fail=True, + logfile=None, + env=None, + universal_newlines=True, + ), + mock.call( + ["koji", "--profile=custom-koji", "watch-task", "1234"], + can_fail=True, + logfile=None, + universal_newlines=True, + ), + ], + ) - @mock.patch('time.sleep') - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("time.sleep") + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_disconnect_and_retry_multiple_times(self, run, sleep): - output = 'Created task: 1234\nerror: failed to connect\n' - retry = 'Created task: 1234\nOK\n' + output = "Created task: 1234\nerror: failed to connect\n" + retry = "Created task: 1234\nOK\n" run.side_effect = [(1, output), (1, output), (1, output), (0, retry)] - result = self.koji.run_blocking_cmd('cmd') + result = self.koji.run_blocking_cmd("cmd") - self.assertDictEqual(result, {'retcode': 0, 'output': retry, 'task_id': 1234}) - self.assertEqual(run.mock_calls, - [mock.call('cmd', can_fail=True, logfile=None, env=None, - universal_newlines=True), - mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'], - can_fail=True, logfile=None, universal_newlines=True), - mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'], - can_fail=True, logfile=None, universal_newlines=True), - mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'], - can_fail=True, logfile=None, universal_newlines=True)]) - self.assertEqual(sleep.mock_calls, - [mock.call(i * 10) for i in range(1, 3)]) + self.assertDictEqual(result, {"retcode": 0, "output": retry, "task_id": 1234}) + self.assertEqual( + run.mock_calls, + [ + mock.call( + "cmd", + can_fail=True, + logfile=None, + env=None, + universal_newlines=True, + ), + mock.call( + ["koji", "--profile=custom-koji", "watch-task", "1234"], + can_fail=True, + logfile=None, + universal_newlines=True, + ), + mock.call( + ["koji", "--profile=custom-koji", "watch-task", "1234"], + can_fail=True, + logfile=None, + universal_newlines=True, + ), + mock.call( + ["koji", "--profile=custom-koji", "watch-task", "1234"], + can_fail=True, + logfile=None, + universal_newlines=True, + ), + ], + ) + self.assertEqual(sleep.mock_calls, [mock.call(i * 10) for i in range(1, 3)]) - @mock.patch('time.sleep') - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("time.sleep") + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_disconnect_and_never_reconnect(self, run, sleep): - output = 'Created task: 1234\nerror: failed to connect\n' + output = "Created task: 1234\nerror: failed to connect\n" run.side_effect = [(1, output), (1, output), (1, output), (1, output)] with self.assertRaises(RuntimeError) as ctx: - self.koji.run_blocking_cmd('cmd', max_retries=2) + self.koji.run_blocking_cmd("cmd", max_retries=2) - self.assertIn('Failed to wait', str(ctx.exception)) - self.assertEqual(run.mock_calls, - [mock.call('cmd', can_fail=True, logfile=None, env=None, - universal_newlines=True), - mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'], - can_fail=True, logfile=None, universal_newlines=True), - mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'], - can_fail=True, logfile=None, universal_newlines=True)]) + self.assertIn("Failed to wait", str(ctx.exception)) + self.assertEqual( + run.mock_calls, + [ + mock.call( + "cmd", + can_fail=True, + logfile=None, + env=None, + universal_newlines=True, + ), + mock.call( + ["koji", "--profile=custom-koji", "watch-task", "1234"], + can_fail=True, + logfile=None, + universal_newlines=True, + ), + mock.call( + ["koji", "--profile=custom-koji", "watch-task", "1234"], + can_fail=True, + logfile=None, + universal_newlines=True, + ), + ], + ) self.assertEqual(sleep.mock_calls, [mock.call(i * 10) for i in range(1, 2)]) - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_server_offline_and_retry(self, run): - output = 'Created task: 1234\nkoji: ServerOffline:' - retry = 'Created task: 1234\nOook\n' + output = "Created task: 1234\nkoji: ServerOffline:" + retry = "Created task: 1234\nOook\n" run.side_effect = [(1, output), (0, retry)] - result = self.koji.run_blocking_cmd('cmd') - - self.assertDictEqual(result, {'retcode': 0, 'output': retry, 'task_id': 1234}) - self.assertEqual(run.mock_calls, - [mock.call('cmd', can_fail=True, logfile=None, env=None, - universal_newlines=True), - mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'], - can_fail=True, logfile=None, universal_newlines=True)]) + result = self.koji.run_blocking_cmd("cmd") + self.assertDictEqual(result, {"retcode": 0, "output": retry, "task_id": 1234}) + self.assertEqual( + run.mock_calls, + [ + mock.call( + "cmd", + can_fail=True, + logfile=None, + env=None, + universal_newlines=True, + ), + mock.call( + ["koji", "--profile=custom-koji", "watch-task", "1234"], + can_fail=True, + logfile=None, + universal_newlines=True, + ), + ], + ) RPM_QA_QF_OUTPUT = """ @@ -704,111 +980,119 @@ coreutils-8.24-6.fc23.x86_64 """ BUILDROOT_LIST = [ - {'arch': 'x86_64', - 'br_type': 0, - 'cg_id': None, - 'cg_name': None, - 'cg_version': None, - 'container_arch': 'x86_64', - 'container_type': 'chroot', - 'create_event_id': 15862222, - 'create_event_time': '2016-04-28 02:37:00.949772', - 'create_ts': 1461811020.94977, - 'extra': None, - 'host_arch': None, - 'host_id': 99, - 'host_name': 'buildhw-01.phx2.fedoraproject.org', - 'host_os': None, - 'id': 5458481, - 'repo_create_event_id': 15861452, - 'repo_create_event_time': '2016-04-28 00:02:40.639317', - 'repo_id': 599173, - 'repo_state': 1, - 'retire_event_id': 15862276, - 'retire_event_time': '2016-04-28 02:58:07.109387', - 'retire_ts': 1461812287.10939, - 'state': 3, - 'tag_id': 315, - 'tag_name': 'f24-build', - 'task_id': 13831904} + { + "arch": "x86_64", + "br_type": 0, + "cg_id": None, + "cg_name": None, + "cg_version": None, + "container_arch": "x86_64", + "container_type": "chroot", + "create_event_id": 15862222, + "create_event_time": "2016-04-28 02:37:00.949772", + "create_ts": 1461811020.94977, + "extra": None, + "host_arch": None, + "host_id": 99, + "host_name": "buildhw-01.phx2.fedoraproject.org", + "host_os": None, + "id": 5458481, + "repo_create_event_id": 15861452, + "repo_create_event_time": "2016-04-28 00:02:40.639317", + "repo_id": 599173, + "repo_state": 1, + "retire_event_id": 15862276, + "retire_event_time": "2016-04-28 02:58:07.109387", + "retire_ts": 1461812287.10939, + "state": 3, + "tag_id": 315, + "tag_name": "f24-build", + "task_id": 13831904, + } ] RPM_LIST = [ - {'arch': 'noarch', - 'build_id': 756072, - 'buildroot_id': 5398084, - 'buildtime': 1461100903, - 'component_buildroot_id': 5458481, - 'epoch': None, - 'external_repo_id': 0, - 'external_repo_name': 'INTERNAL', - 'extra': None, - 'id': 7614370, - 'is_update': True, - 'metadata_only': False, - 'name': 'python3-kickstart', - 'nvr': 'python3-kickstart-2.25-2.fc24', - 'payloadhash': '403723502d27e43955036d2dcd1b09e0', - 'release': '2.fc24', - 'size': 366038, - 'version': '2.25'}, - {'arch': 'x86_64', - 'build_id': 756276, - 'buildroot_id': 5405310, - 'buildtime': 1461165155, - 'component_buildroot_id': 5458481, - 'epoch': None, - 'external_repo_id': 0, - 'external_repo_name': 'INTERNAL', - 'extra': None, - 'id': 7615629, - 'is_update': False, - 'metadata_only': False, - 'name': 'binutils', - 'nvr': 'binutils-2.26-18.fc24', - 'payloadhash': '8ef08c8a64c52787d3559424e5f51d9d', - 'release': '18.fc24', - 'size': 6172094, - 'version': '2.26'}, - {'arch': 'x86_64', - 'build_id': 756616, - 'buildroot_id': 5412029, - 'buildtime': 1461252071, - 'component_buildroot_id': 5458481, - 'epoch': None, - 'external_repo_id': 0, - 'external_repo_name': 'INTERNAL', - 'extra': None, - 'id': 7619636, - 'is_update': False, - 'metadata_only': False, - 'name': 'kernel-headers', - 'nvr': 'kernel-headers-4.5.2-301.fc24', - 'payloadhash': '11c6d70580c8f0c202c28bc6b0fa98cc', - 'release': '301.fc24', - 'size': 1060138, - 'version': '4.5.2'} + { + "arch": "noarch", + "build_id": 756072, + "buildroot_id": 5398084, + "buildtime": 1461100903, + "component_buildroot_id": 5458481, + "epoch": None, + "external_repo_id": 0, + "external_repo_name": "INTERNAL", + "extra": None, + "id": 7614370, + "is_update": True, + "metadata_only": False, + "name": "python3-kickstart", + "nvr": "python3-kickstart-2.25-2.fc24", + "payloadhash": "403723502d27e43955036d2dcd1b09e0", + "release": "2.fc24", + "size": 366038, + "version": "2.25", + }, + { + "arch": "x86_64", + "build_id": 756276, + "buildroot_id": 5405310, + "buildtime": 1461165155, + "component_buildroot_id": 5458481, + "epoch": None, + "external_repo_id": 0, + "external_repo_name": "INTERNAL", + "extra": None, + "id": 7615629, + "is_update": False, + "metadata_only": False, + "name": "binutils", + "nvr": "binutils-2.26-18.fc24", + "payloadhash": "8ef08c8a64c52787d3559424e5f51d9d", + "release": "18.fc24", + "size": 6172094, + "version": "2.26", + }, + { + "arch": "x86_64", + "build_id": 756616, + "buildroot_id": 5412029, + "buildtime": 1461252071, + "component_buildroot_id": 5458481, + "epoch": None, + "external_repo_id": 0, + "external_repo_name": "INTERNAL", + "extra": None, + "id": 7619636, + "is_update": False, + "metadata_only": False, + "name": "kernel-headers", + "nvr": "kernel-headers-4.5.2-301.fc24", + "payloadhash": "11c6d70580c8f0c202c28bc6b0fa98cc", + "release": "301.fc24", + "size": 1060138, + "version": "4.5.2", + }, ] class TestGetBuildrootRPMs(unittest.TestCase): - - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_get_from_koji(self, KojiWrapper): - compose = mock.Mock(conf={ - 'koji_profile': 'koji', - }) + compose = mock.Mock(conf={"koji_profile": "koji"}) KojiWrapper.return_value.koji_proxy.listBuildroots.return_value = BUILDROOT_LIST KojiWrapper.return_value.koji_proxy.listRPMs.return_value = RPM_LIST rpms = get_buildroot_rpms(compose, 1234) - self.assertEqual(KojiWrapper.call_args_list, - [mock.call('koji')]) - self.assertEqual(KojiWrapper.return_value.mock_calls, - [mock.call.koji_proxy.listBuildroots(taskID=1234), - mock.call.koji_proxy.listRPMs(componentBuildrootID=5458481)]) + self.assertEqual(KojiWrapper.call_args_list, [mock.call("koji")]) + self.assertEqual( + KojiWrapper.return_value.mock_calls, + [ + mock.call.koji_proxy.listBuildroots(taskID=1234), + mock.call.koji_proxy.listRPMs(componentBuildrootID=5458481), + ], + ) six.assertCountEqual( self, @@ -820,7 +1104,7 @@ class TestGetBuildrootRPMs(unittest.TestCase): ], ) - @mock.patch('pungi.wrappers.kojiwrapper.run') + @mock.patch("pungi.wrappers.kojiwrapper.run") def test_get_local(self, mock_run): compose = mock.Mock() diff --git a/tests/test_linker.py b/tests/test_linker.py index 2cfed49d..5d7ca1a4 100644 --- a/tests/test_linker.py +++ b/tests/test_linker.py @@ -67,7 +67,6 @@ class TestLinkerBase(helpers.PungiTestCase): class TestLinkerSymlink(TestLinkerBase): - def test_symlink(self): path_dst = os.path.join(self.topdir, "symlink") @@ -81,7 +80,9 @@ class TestLinkerSymlink(TestLinkerBase): self.linker.symlink(self.path_src, path_dst) # linking existing file with different target must fail - self.assertRaises(OSError, self.linker.symlink, self.path_src, path_dst, relative=False) + self.assertRaises( + OSError, self.linker.symlink, self.path_src, path_dst, relative=False + ) def test_symlink_different_type(self): # try to symlink 'symlink' -> 'another-file' ('symlink' already exists @@ -111,7 +112,6 @@ class TestLinkerSymlink(TestLinkerBase): class TestLinkerHardlink(TestLinkerBase): - def test_hardlink(self): path_dst = os.path.join(self.topdir, "hardlink") @@ -146,7 +146,7 @@ class TestLinkerCopy(TestLinkerBase): def test_copy_to_existing_file_with_different_content(self): path_dst = os.path.join(self.topdir, "b") - helpers.touch(path_dst, 'xxx') + helpers.touch(path_dst, "xxx") self.assertRaises(Exception, self.linker.copy, self.path_src, path_dst) def test_copy_to_directory(self): @@ -260,27 +260,37 @@ class TestLinkerLink(TestLinkerBase): self.assertEqual(len(self.logger.mock_calls), 1) def test_link_file_to_existing_destination(self): - self.assertRaises(OSError, self.linker.link, - self.file1, self.file2, link_type="hardlink") + self.assertRaises( + OSError, self.linker.link, self.file1, self.file2, link_type="hardlink" + ) def test_symlink_file_to_existing_destination(self): - self.assertRaises(OSError, self.linker.link, - self.file1, self.file2, link_type="symlink") + self.assertRaises( + OSError, self.linker.link, self.file1, self.file2, link_type="symlink" + ) def test_copy_file_to_existing_destination(self): - self.assertRaises(OSError, self.linker.link, - self.file1, self.file2, link_type="copy") + self.assertRaises( + OSError, self.linker.link, self.file1, self.file2, link_type="copy" + ) def test_hardlink_or_copy_file_to_existing_destination(self): - self.assertRaises(OSError, self.linker.link, - self.file1, self.file2, link_type="hardlink-or-copy") + self.assertRaises( + OSError, + self.linker.link, + self.file1, + self.file2, + link_type="hardlink-or-copy", + ) def test_link_dir_hardlink(self): self.linker.link(self.src_dir, self.dst_dir, link_type="hardlink") self.assertTrue(os.path.isfile(self.dst_file1)) self.assertTrue(self.same_inode(self.file1, self.dst_file1)) self.assertTrue(self.same_inode(self.file3, self.dst_file3)) - self.assertSameStat(os.path.dirname(self.file3), os.path.dirname(self.dst_file3)) + self.assertSameStat( + os.path.dirname(self.file3), os.path.dirname(self.dst_file3) + ) # always preserve symlinks self.assertEqual(os.readlink(self.dst_symlink1), "../file1") @@ -292,7 +302,9 @@ class TestLinkerLink(TestLinkerBase): self.assertTrue(os.path.isfile(self.dst_file1)) self.assertFalse(self.same_inode(self.file1, self.dst_file1)) self.assertFalse(self.same_inode(self.file3, self.dst_file3)) - self.assertSameStat(os.path.dirname(self.file3), os.path.dirname(self.dst_file3)) + self.assertSameStat( + os.path.dirname(self.file3), os.path.dirname(self.dst_file3) + ) # always preserve symlinks self.assertEqual(os.readlink(self.dst_symlink1), "../file1") @@ -323,7 +335,9 @@ class TestLinkerLink(TestLinkerBase): self.assertTrue(os.path.isfile(self.dst_file1)) self.assertTrue(os.path.islink(self.dst_file1)) self.assertEqual(os.readlink(self.dst_file1), self.file1) - self.assertSameStat(os.path.dirname(self.file3), os.path.dirname(self.dst_file3)) + self.assertSameStat( + os.path.dirname(self.file3), os.path.dirname(self.dst_file3) + ) self.assertTrue(os.path.isdir(os.path.dirname(self.file3))) # always preserve symlinks diff --git a/tests/test_liveimagesphase.py b/tests/test_liveimagesphase.py index 71843835..12252c2f 100644 --- a/tests/test_liveimagesphase.py +++ b/tests/test_liveimagesphase.py @@ -13,21 +13,30 @@ from tests.helpers import DummyCompose, PungiTestCase, boom class TestLiveImagesPhase(PungiTestCase): - - @mock.patch('pungi.phases.live_images.ThreadPool') + @mock.patch("pungi.phases.live_images.ThreadPool") def test_live_image_build(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_images': [ - ('^Client$', { - 'amd64': { - 'kickstart': 'test.ks', - 'repo': ['http://example.com/repo/', 'Everything', 'Server-optional'], - 'release': None, - 'target': 'f27', - } - }) - ], - }) + compose = DummyCompose( + self.topdir, + { + "live_images": [ + ( + "^Client$", + { + "amd64": { + "kickstart": "test.ks", + "repo": [ + "http://example.com/repo/", + "Everything", + "Server-optional", + ], + "release": None, + "target": "f27", + } + }, + ) + ], + }, + ) compose.setup_optional() self.assertValidConfig(compose.conf) @@ -42,51 +51,74 @@ class TestLiveImagesPhase(PungiTestCase): six.assertCountEqual( self, phase.pool.queue_put.mock_calls, - [mock.call((compose, - {"ks_file": "test.ks", - "build_arch": "amd64", - "dest_dir": self.topdir + "/compose/Client/amd64/iso", - "scratch": False, - "repos": [self.topdir + "/compose/Client/amd64/os", - "http://example.com/repo/", - self.topdir + "/compose/Everything/amd64/os", - self.topdir + "/compose/Server-optional/amd64/os"], - "label": "", - "name": None, - "filename": "image-name", - "version": "25", - "specfile": None, - "sign": False, - "type": "live", - "release": "20151203.t.0", - "subvariant": "Client", - "failable_arches": [], - "ksurl": None, - "target": "f27"}, + [ + mock.call( + ( + compose, + { + "ks_file": "test.ks", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/iso", + "scratch": False, + "repos": [ + self.topdir + "/compose/Client/amd64/os", + "http://example.com/repo/", + self.topdir + "/compose/Everything/amd64/os", + self.topdir + "/compose/Server-optional/amd64/os", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": "25", + "specfile": None, + "sign": False, + "type": "live", + "release": "20151203.t.0", + "subvariant": "Client", + "failable_arches": [], + "ksurl": None, + "target": "f27", + }, compose.variants["Client"], - "amd64"))], + "amd64", + ) + ) + ], ) six.assertCountEqual( self, compose.get_image_name.mock_calls, - [mock.call("amd64", compose.variants["Client"], disc_num=None, disc_type="live", - format="%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s")] + [ + mock.call( + "amd64", + compose.variants["Client"], + disc_num=None, + disc_type="live", + format="%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s", + ) + ], ) - @mock.patch('pungi.phases.live_images.ThreadPool') + @mock.patch("pungi.phases.live_images.ThreadPool") def test_live_image_build_single_repo_from(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_images': [ - ('^Client$', { - 'amd64': { - 'kickstart': 'test.ks', - 'repo': ['http://example.com/repo/', 'Everything'], - 'release': None, - 'target': 'f27', - } - }) - ], - }) + compose = DummyCompose( + self.topdir, + { + "live_images": [ + ( + "^Client$", + { + "amd64": { + "kickstart": "test.ks", + "repo": ["http://example.com/repo/", "Everything"], + "release": None, + "target": "f27", + } + }, + ) + ], + }, + ) self.assertValidConfig(compose.conf) @@ -100,45 +132,61 @@ class TestLiveImagesPhase(PungiTestCase): six.assertCountEqual( self, phase.pool.queue_put.mock_calls, - [mock.call((compose, - {'ks_file': 'test.ks', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/iso', - 'scratch': False, - 'repos': [self.topdir + '/compose/Client/amd64/os', - 'http://example.com/repo/', - self.topdir + '/compose/Everything/amd64/os'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': '25', - 'specfile': None, - 'sign': False, - 'type': 'live', - 'release': '20151203.t.0', - 'subvariant': 'Client', - 'failable_arches': [], - 'ksurl': None, - 'target': 'f27'}, - compose.variants['Client'], - 'amd64'))], + [ + mock.call( + ( + compose, + { + "ks_file": "test.ks", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/iso", + "scratch": False, + "repos": [ + self.topdir + "/compose/Client/amd64/os", + "http://example.com/repo/", + self.topdir + "/compose/Everything/amd64/os", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": "25", + "specfile": None, + "sign": False, + "type": "live", + "release": "20151203.t.0", + "subvariant": "Client", + "failable_arches": [], + "ksurl": None, + "target": "f27", + }, + compose.variants["Client"], + "amd64", + ) + ) + ], ) - @mock.patch('pungi.phases.live_images.ThreadPool') + @mock.patch("pungi.phases.live_images.ThreadPool") def test_live_image_build_without_rename(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_images_no_rename': True, - 'live_images': [ - ('^Client$', { - 'amd64': { - 'kickstart': 'test.ks', - 'repo': ['http://example.com/repo/', 'Everything'], - 'release': None, - 'target': 'f27', - } - }) - ], - }) + compose = DummyCompose( + self.topdir, + { + "live_images_no_rename": True, + "live_images": [ + ( + "^Client$", + { + "amd64": { + "kickstart": "test.ks", + "repo": ["http://example.com/repo/", "Everything"], + "release": None, + "target": "f27", + } + }, + ) + ], + }, + ) self.assertValidConfig(compose.conf) @@ -152,47 +200,66 @@ class TestLiveImagesPhase(PungiTestCase): six.assertCountEqual( self, phase.pool.queue_put.mock_calls, - [mock.call((compose, - {'ks_file': 'test.ks', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/iso', - 'scratch': False, - 'repos': [self.topdir + '/compose/Client/amd64/os', - 'http://example.com/repo/', - self.topdir + '/compose/Everything/amd64/os'], - 'label': '', - 'name': None, - 'filename': None, - 'version': '25', - 'specfile': None, - 'sign': False, - 'type': 'live', - 'release': '20151203.t.0', - 'subvariant': 'Client', - 'failable_arches': [], - 'ksurl': None, - 'target': 'f27'}, - compose.variants['Client'], - 'amd64'))], + [ + mock.call( + ( + compose, + { + "ks_file": "test.ks", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/iso", + "scratch": False, + "repos": [ + self.topdir + "/compose/Client/amd64/os", + "http://example.com/repo/", + self.topdir + "/compose/Everything/amd64/os", + ], + "label": "", + "name": None, + "filename": None, + "version": "25", + "specfile": None, + "sign": False, + "type": "live", + "release": "20151203.t.0", + "subvariant": "Client", + "failable_arches": [], + "ksurl": None, + "target": "f27", + }, + compose.variants["Client"], + "amd64", + ) + ) + ], ) - @mock.patch('pungi.phases.live_images.ThreadPool') + @mock.patch("pungi.phases.live_images.ThreadPool") def test_live_image_build_two_images(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_images': [ - ('^Client$', { - 'amd64': [{ - 'kickstart': 'test.ks', - 'repo': ['http://example.com/repo/', 'Everything'], - 'target': 'f27', - }, { - 'kickstart': 'another.ks', - 'repo': ['http://example.com/repo/', 'Everything'], - 'target': 'f27', - }] - }) - ], - }) + compose = DummyCompose( + self.topdir, + { + "live_images": [ + ( + "^Client$", + { + "amd64": [ + { + "kickstart": "test.ks", + "repo": ["http://example.com/repo/", "Everything"], + "target": "f27", + }, + { + "kickstart": "another.ks", + "repo": ["http://example.com/repo/", "Everything"], + "target": "f27", + }, + ] + }, + ) + ], + }, + ) self.assertValidConfig(compose.conf) @@ -206,67 +273,91 @@ class TestLiveImagesPhase(PungiTestCase): six.assertCountEqual( self, phase.pool.queue_put.mock_calls, - [mock.call((compose, - {'ks_file': 'test.ks', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/iso', - 'scratch': False, - 'repos': [self.topdir + '/compose/Client/amd64/os', - 'http://example.com/repo/', - self.topdir + '/compose/Everything/amd64/os'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': '25', - 'specfile': None, - 'sign': False, - 'type': 'live', - 'release': None, - 'subvariant': 'Client', - 'failable_arches': [], - 'target': 'f27', - 'ksurl': None}, - compose.variants['Client'], - 'amd64')), - mock.call((compose, - {'ks_file': 'another.ks', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/iso', - 'scratch': False, - 'repos': [self.topdir + '/compose/Client/amd64/os', - 'http://example.com/repo/', - self.topdir + '/compose/Everything/amd64/os'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': '25', - 'specfile': None, - 'sign': False, - 'type': 'live', - 'release': None, - 'subvariant': 'Client', - 'failable_arches': [], - 'target': 'f27', - 'ksurl': None}, - compose.variants['Client'], - 'amd64'))], + [ + mock.call( + ( + compose, + { + "ks_file": "test.ks", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/iso", + "scratch": False, + "repos": [ + self.topdir + "/compose/Client/amd64/os", + "http://example.com/repo/", + self.topdir + "/compose/Everything/amd64/os", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": "25", + "specfile": None, + "sign": False, + "type": "live", + "release": None, + "subvariant": "Client", + "failable_arches": [], + "target": "f27", + "ksurl": None, + }, + compose.variants["Client"], + "amd64", + ) + ), + mock.call( + ( + compose, + { + "ks_file": "another.ks", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/iso", + "scratch": False, + "repos": [ + self.topdir + "/compose/Client/amd64/os", + "http://example.com/repo/", + self.topdir + "/compose/Everything/amd64/os", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": "25", + "specfile": None, + "sign": False, + "type": "live", + "release": None, + "subvariant": "Client", + "failable_arches": [], + "target": "f27", + "ksurl": None, + }, + compose.variants["Client"], + "amd64", + ) + ), + ], ) - @mock.patch('pungi.phases.live_images.ThreadPool') + @mock.patch("pungi.phases.live_images.ThreadPool") def test_spin_appliance(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_images': [ - ('^Client$', { - 'amd64': { - 'kickstart': 'test.ks', - 'ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE', - 'repo': ['http://example.com/repo/', 'Everything'], - 'type': 'appliance', - 'target': 'f27', - } - }) - ], - }) + compose = DummyCompose( + self.topdir, + { + "live_images": [ + ( + "^Client$", + { + "amd64": { + "kickstart": "test.ks", + "ksurl": "https://git.example.com/kickstarts.git?#CAFEBABE", + "repo": ["http://example.com/repo/", "Everything"], + "type": "appliance", + "target": "f27", + } + }, + ) + ], + }, + ) self.assertValidConfig(compose.conf) @@ -280,47 +371,63 @@ class TestLiveImagesPhase(PungiTestCase): six.assertCountEqual( self, phase.pool.queue_put.mock_calls, - [mock.call((compose, - {'ks_file': 'test.ks', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/images', - 'scratch': False, - 'repos': [self.topdir + '/compose/Client/amd64/os', - 'http://example.com/repo/', - self.topdir + '/compose/Everything/amd64/os'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': '25', - 'specfile': None, - 'sign': False, - 'type': 'appliance', - 'release': None, - 'subvariant': 'Client', - 'failable_arches': [], - 'target': 'f27', - 'ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE'}, - compose.variants['Client'], - 'amd64'))], + [ + mock.call( + ( + compose, + { + "ks_file": "test.ks", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/images", + "scratch": False, + "repos": [ + self.topdir + "/compose/Client/amd64/os", + "http://example.com/repo/", + self.topdir + "/compose/Everything/amd64/os", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": "25", + "specfile": None, + "sign": False, + "type": "appliance", + "release": None, + "subvariant": "Client", + "failable_arches": [], + "target": "f27", + "ksurl": "https://git.example.com/kickstarts.git?#CAFEBABE", + }, + compose.variants["Client"], + "amd64", + ) + ) + ], ) - @mock.patch('pungi.phases.live_images.ThreadPool') + @mock.patch("pungi.phases.live_images.ThreadPool") def test_spin_appliance_phase_global_settings(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_images_ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE', - 'live_images_release': None, - 'live_images_version': 'Rawhide', - 'live_images_target': 'f27', - 'live_images': [ - ('^Client$', { - 'amd64': { - 'kickstart': 'test.ks', - 'repo': ['http://example.com/repo/', 'Everything'], - 'type': 'appliance', - } - }) - ], - }) + compose = DummyCompose( + self.topdir, + { + "live_images_ksurl": "https://git.example.com/kickstarts.git?#CAFEBABE", + "live_images_release": None, + "live_images_version": "Rawhide", + "live_images_target": "f27", + "live_images": [ + ( + "^Client$", + { + "amd64": { + "kickstart": "test.ks", + "repo": ["http://example.com/repo/", "Everything"], + "type": "appliance", + } + }, + ) + ], + }, + ) self.assertValidConfig(compose.conf) @@ -334,99 +441,131 @@ class TestLiveImagesPhase(PungiTestCase): six.assertCountEqual( self, phase.pool.queue_put.mock_calls, - [mock.call((compose, - {'ks_file': 'test.ks', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/images', - 'scratch': False, - 'repos': [self.topdir + '/compose/Client/amd64/os', - 'http://example.com/repo/', - self.topdir + '/compose/Everything/amd64/os'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': 'Rawhide', - 'specfile': None, - 'sign': False, - 'type': 'appliance', - 'release': '20151203.t.0', - 'subvariant': 'Client', - 'failable_arches': [], - 'target': 'f27', - 'ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE'}, - compose.variants['Client'], - 'amd64'))], + [ + mock.call( + ( + compose, + { + "ks_file": "test.ks", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/images", + "scratch": False, + "repos": [ + self.topdir + "/compose/Client/amd64/os", + "http://example.com/repo/", + self.topdir + "/compose/Everything/amd64/os", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": "Rawhide", + "specfile": None, + "sign": False, + "type": "appliance", + "release": "20151203.t.0", + "subvariant": "Client", + "failable_arches": [], + "target": "f27", + "ksurl": "https://git.example.com/kickstarts.git?#CAFEBABE", + }, + compose.variants["Client"], + "amd64", + ) + ) + ], ) - @mock.patch('pungi.phases.live_images.ThreadPool') + @mock.patch("pungi.phases.live_images.ThreadPool") def test_spin_appliance_global_settings(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'global_ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE', - 'global_release': None, - 'global_version': 'Rawhide', - 'global_target': 'f27', - 'live_images': [ - ('^Client$', { - 'amd64': { - 'kickstart': 'test.ks', - 'repo': ['http://example.com/repo/', 'Everything'], - 'type': 'appliance', - } - }) - ], - }) - - self.assertValidConfig(compose.conf) - - phase = LiveImagesPhase(compose) - - phase.run() - - # assert at least one thread was started - self.assertTrue(phase.pool.add.called) - self.maxDiff = None - six.assertCountEqual( - self, - phase.pool.queue_put.mock_calls, - [mock.call((compose, - {'ks_file': 'test.ks', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/images', - 'scratch': False, - 'repos': [self.topdir + '/compose/Client/amd64/os', - 'http://example.com/repo/', - self.topdir + '/compose/Everything/amd64/os'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': 'Rawhide', - 'specfile': None, - 'sign': False, - 'type': 'appliance', - 'release': '20151203.t.0', - 'subvariant': 'Client', - 'failable_arches': [], - 'target': 'f27', - 'ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE'}, - compose.variants['Client'], - 'amd64'))], + compose = DummyCompose( + self.topdir, + { + "global_ksurl": "https://git.example.com/kickstarts.git?#CAFEBABE", + "global_release": None, + "global_version": "Rawhide", + "global_target": "f27", + "live_images": [ + ( + "^Client$", + { + "amd64": { + "kickstart": "test.ks", + "repo": ["http://example.com/repo/", "Everything"], + "type": "appliance", + } + }, + ) + ], + }, ) - @mock.patch('pungi.phases.live_images.ThreadPool') - def test_live_image_build_custom_type(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'disc_types': {'live': 'Live'}, - 'live_images': [ - ('^Client$', { - 'amd64': { - 'kickstart': 'test.ks', - 'repo': ['http://example.com/repo/', 'Everything'], - 'release': None, - 'target': 'f27', - } - }) + self.assertValidConfig(compose.conf) + + phase = LiveImagesPhase(compose) + + phase.run() + + # assert at least one thread was started + self.assertTrue(phase.pool.add.called) + self.maxDiff = None + six.assertCountEqual( + self, + phase.pool.queue_put.mock_calls, + [ + mock.call( + ( + compose, + { + "ks_file": "test.ks", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/images", + "scratch": False, + "repos": [ + self.topdir + "/compose/Client/amd64/os", + "http://example.com/repo/", + self.topdir + "/compose/Everything/amd64/os", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": "Rawhide", + "specfile": None, + "sign": False, + "type": "appliance", + "release": "20151203.t.0", + "subvariant": "Client", + "failable_arches": [], + "target": "f27", + "ksurl": "https://git.example.com/kickstarts.git?#CAFEBABE", + }, + compose.variants["Client"], + "amd64", + ) + ) ], - }) + ) + + @mock.patch("pungi.phases.live_images.ThreadPool") + def test_live_image_build_custom_type(self, ThreadPool): + compose = DummyCompose( + self.topdir, + { + "disc_types": {"live": "Live"}, + "live_images": [ + ( + "^Client$", + { + "amd64": { + "kickstart": "test.ks", + "repo": ["http://example.com/repo/", "Everything"], + "release": None, + "target": "f27", + } + }, + ) + ], + }, + ) self.assertValidConfig(compose.conf) @@ -440,357 +579,478 @@ class TestLiveImagesPhase(PungiTestCase): six.assertCountEqual( self, phase.pool.queue_put.mock_calls, - [mock.call((compose, - {'ks_file': 'test.ks', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/iso', - 'scratch': False, - 'repos': [self.topdir + '/compose/Client/amd64/os', - 'http://example.com/repo/', - self.topdir + '/compose/Everything/amd64/os'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': '25', - 'specfile': None, - 'sign': False, - 'type': 'live', - 'release': '20151203.t.0', - 'subvariant': 'Client', - 'failable_arches': [], - 'target': 'f27', - 'ksurl': None}, - compose.variants['Client'], - 'amd64'))], + [ + mock.call( + ( + compose, + { + "ks_file": "test.ks", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/iso", + "scratch": False, + "repos": [ + self.topdir + "/compose/Client/amd64/os", + "http://example.com/repo/", + self.topdir + "/compose/Everything/amd64/os", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": "25", + "specfile": None, + "sign": False, + "type": "live", + "release": "20151203.t.0", + "subvariant": "Client", + "failable_arches": [], + "target": "f27", + "ksurl": None, + }, + compose.variants["Client"], + "amd64", + ) + ) + ], ) six.assertCountEqual( self, compose.get_image_name.mock_calls, - [mock.call('amd64', compose.variants['Client'], disc_num=None, disc_type='Live', - format='%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s')], + [ + mock.call( + "amd64", + compose.variants["Client"], + disc_num=None, + disc_type="Live", + format="%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s", + ) + ], ) class TestCreateLiveImageThread(PungiTestCase): - - @mock.patch('pungi.phases.live_images.Image') - @mock.patch('shutil.copy2') - @mock.patch('pungi.phases.live_images.run') - @mock.patch('pungi.phases.live_images.KojiWrapper') + @mock.patch("pungi.phases.live_images.Image") + @mock.patch("shutil.copy2") + @mock.patch("pungi.phases.live_images.run") + @mock.patch("pungi.phases.live_images.KojiWrapper") def test_process(self, KojiWrapper, run, copy2, Image): - compose = DummyCompose(self.topdir, {'koji_profile': 'koji'}) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) pool = mock.Mock() cmd = { - 'ks_file': '/path/to/ks_file', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/iso', - 'scratch': False, - 'repos': ['/repo/amd64/Client', - 'http://example.com/repo/', - '/repo/amd64/Everything'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': None, - 'specfile': None, - 'type': 'live', - 'ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE', - 'release': None, - 'subvariant': 'Something', - 'target': 'f27', + "ks_file": "/path/to/ks_file", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/iso", + "scratch": False, + "repos": [ + "/repo/amd64/Client", + "http://example.com/repo/", + "/repo/amd64/Everything", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": None, + "specfile": None, + "type": "live", + "ksurl": "https://git.example.com/kickstarts.git?#CAFEBABE", + "release": None, + "subvariant": "Something", + "target": "f27", } koji_wrapper = KojiWrapper.return_value - koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...' + koji_wrapper.get_create_image_cmd.return_value = "koji spin-livecd ..." koji_wrapper.run_blocking_cmd.return_value = { - 'retcode': 0, - 'output': 'some output', - 'task_id': 123 + "retcode": 0, + "output": "some output", + "task_id": 123, } - koji_wrapper.get_image_path.return_value = ['/path/to/image.iso'] + koji_wrapper.get_image_path.return_value = ["/path/to/image.iso"] t = CreateLiveImageThread(pool) - with mock.patch('pungi.phases.live_images.get_file_size') as get_file_size: + with mock.patch("pungi.phases.live_images.get_file_size") as get_file_size: get_file_size.return_value = 1024 - with mock.patch('pungi.phases.live_images.get_mtime') as get_mtime: + with mock.patch("pungi.phases.live_images.get_mtime") as get_mtime: get_mtime.return_value = 13579 - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Client"], "amd64"), 1) - self.assertEqual(koji_wrapper.run_blocking_cmd.mock_calls, - [mock.call('koji spin-livecd ...', - log_file=self.topdir + '/logs/amd64/liveimage-None-None-None.amd64.log')]) + self.assertEqual( + koji_wrapper.run_blocking_cmd.mock_calls, + [ + mock.call( + "koji spin-livecd ...", + log_file=self.topdir + + "/logs/amd64/liveimage-None-None-None.amd64.log", + ) + ], + ) self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)]) - self.assertEqual(copy2.mock_calls, - [mock.call('/path/to/image.iso', self.topdir + '/compose/Client/amd64/iso/image-name')]) + self.assertEqual( + copy2.mock_calls, + [ + mock.call( + "/path/to/image.iso", + self.topdir + "/compose/Client/amd64/iso/image-name", + ) + ], + ) - write_manifest_cmd = ' && '.join([ - 'cd ' + self.topdir + '/compose/Client/amd64/iso', - 'isoinfo -R -f -i image-name | grep -v \'/TRANS.TBL$\' | sort >> image-name.manifest' - ]) + write_manifest_cmd = " && ".join( + [ + "cd " + self.topdir + "/compose/Client/amd64/iso", + "isoinfo -R -f -i image-name | grep -v '/TRANS.TBL$' | sort >> image-name.manifest", + ] + ) self.assertEqual(run.mock_calls, [mock.call(write_manifest_cmd)]) - self.assertEqual(koji_wrapper.get_create_image_cmd.mock_calls, - [mock.call('test-Something-Live-amd64', '20151203.0.t', 'f27', - 'amd64', '/path/to/ks_file', - ['/repo/amd64/Client', - 'http://example.com/repo/', - '/repo/amd64/Everything'], - image_type='live', - archive=False, - specfile=None, - wait=True, - release=None, - ksurl='https://git.example.com/kickstarts.git?#CAFEBABE')]) - self.assertEqual(Image.return_value.type, 'live') - self.assertEqual(Image.return_value.format, 'iso') - self.assertEqual(Image.return_value.path, 'Client/amd64/iso/image-name') + self.assertEqual( + koji_wrapper.get_create_image_cmd.mock_calls, + [ + mock.call( + "test-Something-Live-amd64", + "20151203.0.t", + "f27", + "amd64", + "/path/to/ks_file", + [ + "/repo/amd64/Client", + "http://example.com/repo/", + "/repo/amd64/Everything", + ], + image_type="live", + archive=False, + specfile=None, + wait=True, + release=None, + ksurl="https://git.example.com/kickstarts.git?#CAFEBABE", + ) + ], + ) + self.assertEqual(Image.return_value.type, "live") + self.assertEqual(Image.return_value.format, "iso") + self.assertEqual(Image.return_value.path, "Client/amd64/iso/image-name") self.assertEqual(Image.return_value.size, 1024) self.assertEqual(Image.return_value.mtime, 13579) - self.assertEqual(Image.return_value.arch, 'amd64') + self.assertEqual(Image.return_value.arch, "amd64") self.assertEqual(Image.return_value.disc_number, 1) self.assertEqual(Image.return_value.disc_count, 1) self.assertTrue(Image.return_value.bootable) - self.assertEqual(compose.im.add.mock_calls, - [mock.call(variant='Client', arch='amd64', image=Image.return_value)]) + self.assertEqual( + compose.im.add.mock_calls, + [mock.call(variant="Client", arch="amd64", image=Image.return_value)], + ) - @mock.patch('pungi.phases.live_images.Image') - @mock.patch('shutil.copy2') - @mock.patch('pungi.phases.live_images.run') - @mock.patch('pungi.phases.live_images.KojiWrapper') + @mock.patch("pungi.phases.live_images.Image") + @mock.patch("shutil.copy2") + @mock.patch("pungi.phases.live_images.run") + @mock.patch("pungi.phases.live_images.KojiWrapper") def test_process_no_rename(self, KojiWrapper, run, copy2, Image): - compose = DummyCompose(self.topdir, {'koji_profile': 'koji'}) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) pool = mock.Mock() cmd = { - 'ks_file': '/path/to/ks_file', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/iso', - 'scratch': False, - 'repos': ['/repo/amd64/Client', - 'http://example.com/repo/', - '/repo/amd64/Everything'], - 'label': '', - 'name': None, - 'filename': None, - 'version': None, - 'specfile': None, - 'type': 'live', - 'ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE', - 'release': None, - 'subvariant': 'Client', - 'target': 'f27', + "ks_file": "/path/to/ks_file", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/iso", + "scratch": False, + "repos": [ + "/repo/amd64/Client", + "http://example.com/repo/", + "/repo/amd64/Everything", + ], + "label": "", + "name": None, + "filename": None, + "version": None, + "specfile": None, + "type": "live", + "ksurl": "https://git.example.com/kickstarts.git?#CAFEBABE", + "release": None, + "subvariant": "Client", + "target": "f27", } koji_wrapper = KojiWrapper.return_value - koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...' + koji_wrapper.get_create_image_cmd.return_value = "koji spin-livecd ..." koji_wrapper.run_blocking_cmd.return_value = { - 'retcode': 0, - 'output': 'some output', - 'task_id': 123 + "retcode": 0, + "output": "some output", + "task_id": 123, } - koji_wrapper.get_image_path.return_value = ['/path/to/image.iso'] + koji_wrapper.get_image_path.return_value = ["/path/to/image.iso"] t = CreateLiveImageThread(pool) - with mock.patch('pungi.phases.live_images.get_file_size') as get_file_size: + with mock.patch("pungi.phases.live_images.get_file_size") as get_file_size: get_file_size.return_value = 1024 - with mock.patch('pungi.phases.live_images.get_mtime') as get_mtime: + with mock.patch("pungi.phases.live_images.get_mtime") as get_mtime: get_mtime.return_value = 13579 - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Client"], "amd64"), 1) - self.assertEqual(koji_wrapper.run_blocking_cmd.mock_calls, - [mock.call('koji spin-livecd ...', - log_file=self.topdir + '/logs/amd64/liveimage-None-None-None.amd64.log')]) + self.assertEqual( + koji_wrapper.run_blocking_cmd.mock_calls, + [ + mock.call( + "koji spin-livecd ...", + log_file=self.topdir + + "/logs/amd64/liveimage-None-None-None.amd64.log", + ) + ], + ) self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)]) - self.assertEqual(copy2.mock_calls, - [mock.call('/path/to/image.iso', self.topdir + '/compose/Client/amd64/iso/image.iso')]) + self.assertEqual( + copy2.mock_calls, + [ + mock.call( + "/path/to/image.iso", + self.topdir + "/compose/Client/amd64/iso/image.iso", + ) + ], + ) - write_manifest_cmd = ' && '.join([ - 'cd ' + self.topdir + '/compose/Client/amd64/iso', - 'isoinfo -R -f -i image.iso | grep -v \'/TRANS.TBL$\' | sort >> image.iso.manifest' - ]) + write_manifest_cmd = " && ".join( + [ + "cd " + self.topdir + "/compose/Client/amd64/iso", + "isoinfo -R -f -i image.iso | grep -v '/TRANS.TBL$' | sort >> image.iso.manifest", + ] + ) self.assertEqual(run.mock_calls, [mock.call(write_manifest_cmd)]) - self.assertEqual(koji_wrapper.get_create_image_cmd.mock_calls, - [mock.call('test-Client-Live-amd64', '20151203.0.t', 'f27', - 'amd64', '/path/to/ks_file', - ['/repo/amd64/Client', - 'http://example.com/repo/', - '/repo/amd64/Everything'], - image_type='live', - archive=False, - specfile=None, - wait=True, - release=None, - ksurl='https://git.example.com/kickstarts.git?#CAFEBABE')]) + self.assertEqual( + koji_wrapper.get_create_image_cmd.mock_calls, + [ + mock.call( + "test-Client-Live-amd64", + "20151203.0.t", + "f27", + "amd64", + "/path/to/ks_file", + [ + "/repo/amd64/Client", + "http://example.com/repo/", + "/repo/amd64/Everything", + ], + image_type="live", + archive=False, + specfile=None, + wait=True, + release=None, + ksurl="https://git.example.com/kickstarts.git?#CAFEBABE", + ) + ], + ) - self.assertEqual(Image.return_value.type, 'live') - self.assertEqual(Image.return_value.format, 'iso') - self.assertEqual(Image.return_value.path, 'Client/amd64/iso/image.iso') + self.assertEqual(Image.return_value.type, "live") + self.assertEqual(Image.return_value.format, "iso") + self.assertEqual(Image.return_value.path, "Client/amd64/iso/image.iso") self.assertEqual(Image.return_value.size, 1024) self.assertEqual(Image.return_value.mtime, 13579) - self.assertEqual(Image.return_value.arch, 'amd64') + self.assertEqual(Image.return_value.arch, "amd64") self.assertEqual(Image.return_value.disc_number, 1) self.assertEqual(Image.return_value.disc_count, 1) self.assertTrue(Image.return_value.bootable) - self.assertEqual(compose.im.add.mock_calls, - [mock.call(variant='Client', arch='amd64', image=Image.return_value)]) + self.assertEqual( + compose.im.add.mock_calls, + [mock.call(variant="Client", arch="amd64", image=Image.return_value)], + ) - @mock.patch('pungi.phases.live_images.Image') - @mock.patch('shutil.copy2') - @mock.patch('pungi.phases.live_images.run') - @mock.patch('pungi.phases.live_images.KojiWrapper') + @mock.patch("pungi.phases.live_images.Image") + @mock.patch("shutil.copy2") + @mock.patch("pungi.phases.live_images.run") + @mock.patch("pungi.phases.live_images.KojiWrapper") def test_process_applicance(self, KojiWrapper, run, copy2, Image): - compose = DummyCompose(self.topdir, {'koji_profile': 'koji'}) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) pool = mock.Mock() cmd = { - 'ks_file': '/path/to/ks_file', - 'build_arch': 'amd64', - 'dest_dir': self.topdir + '/compose/Client/amd64/iso', - 'scratch': False, - 'repos': ['/repo/amd64/Client', - 'http://example.com/repo/', - '/repo/amd64/Everything'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': None, - 'specfile': None, - 'type': 'appliance', - 'ksurl': None, - 'release': None, - 'subvariant': 'Client', - 'target': 'f27', + "ks_file": "/path/to/ks_file", + "build_arch": "amd64", + "dest_dir": self.topdir + "/compose/Client/amd64/iso", + "scratch": False, + "repos": [ + "/repo/amd64/Client", + "http://example.com/repo/", + "/repo/amd64/Everything", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": None, + "specfile": None, + "type": "appliance", + "ksurl": None, + "release": None, + "subvariant": "Client", + "target": "f27", } koji_wrapper = KojiWrapper.return_value - koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...' + koji_wrapper.get_create_image_cmd.return_value = "koji spin-livecd ..." koji_wrapper.run_blocking_cmd.return_value = { - 'retcode': 0, - 'output': 'some output', - 'task_id': 123 + "retcode": 0, + "output": "some output", + "task_id": 123, } - koji_wrapper.get_image_path.return_value = ['/path/to/image-a.b-sda.raw.xz'] + koji_wrapper.get_image_path.return_value = ["/path/to/image-a.b-sda.raw.xz"] t = CreateLiveImageThread(pool) - with mock.patch('pungi.phases.live_images.get_file_size') as get_file_size: + with mock.patch("pungi.phases.live_images.get_file_size") as get_file_size: get_file_size.return_value = 1024 - with mock.patch('pungi.phases.live_images.get_mtime') as get_mtime: + with mock.patch("pungi.phases.live_images.get_mtime") as get_mtime: get_mtime.return_value = 13579 - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Client"], "amd64"), 1) - self.assertEqual(koji_wrapper.run_blocking_cmd.mock_calls, - [mock.call('koji spin-livecd ...', - log_file=self.topdir + '/logs/amd64/liveimage-None-None-None.amd64.log')]) + self.assertEqual( + koji_wrapper.run_blocking_cmd.mock_calls, + [ + mock.call( + "koji spin-livecd ...", + log_file=self.topdir + + "/logs/amd64/liveimage-None-None-None.amd64.log", + ) + ], + ) self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)]) - self.assertEqual(copy2.mock_calls, - [mock.call('/path/to/image-a.b-sda.raw.xz', self.topdir + '/compose/Client/amd64/iso/image-name')]) + self.assertEqual( + copy2.mock_calls, + [ + mock.call( + "/path/to/image-a.b-sda.raw.xz", + self.topdir + "/compose/Client/amd64/iso/image-name", + ) + ], + ) self.assertEqual(run.mock_calls, []) - self.assertEqual(koji_wrapper.get_create_image_cmd.mock_calls, - [mock.call('test-Client-Disk-amd64', '20151203.0.t', 'f27', - 'amd64', '/path/to/ks_file', - ['/repo/amd64/Client', - 'http://example.com/repo/', - '/repo/amd64/Everything'], - image_type='appliance', - archive=False, - specfile=None, - wait=True, - release=None, - ksurl=None)]) + self.assertEqual( + koji_wrapper.get_create_image_cmd.mock_calls, + [ + mock.call( + "test-Client-Disk-amd64", + "20151203.0.t", + "f27", + "amd64", + "/path/to/ks_file", + [ + "/repo/amd64/Client", + "http://example.com/repo/", + "/repo/amd64/Everything", + ], + image_type="appliance", + archive=False, + specfile=None, + wait=True, + release=None, + ksurl=None, + ) + ], + ) - self.assertEqual(Image.return_value.type, 'raw-xz') - self.assertEqual(Image.return_value.format, 'raw.xz') - self.assertEqual(Image.return_value.path, 'Client/amd64/iso/image-name') + self.assertEqual(Image.return_value.type, "raw-xz") + self.assertEqual(Image.return_value.format, "raw.xz") + self.assertEqual(Image.return_value.path, "Client/amd64/iso/image-name") self.assertEqual(Image.return_value.size, 1024) self.assertEqual(Image.return_value.mtime, 13579) - self.assertEqual(Image.return_value.arch, 'amd64') + self.assertEqual(Image.return_value.arch, "amd64") self.assertEqual(Image.return_value.disc_number, 1) self.assertEqual(Image.return_value.disc_count, 1) self.assertTrue(Image.return_value.bootable) - self.assertEqual(compose.im.add.mock_calls, - [mock.call(variant='Client', arch='amd64', image=Image.return_value)]) + self.assertEqual( + compose.im.add.mock_calls, + [mock.call(variant="Client", arch="amd64", image=Image.return_value)], + ) - @mock.patch('shutil.copy2') - @mock.patch('pungi.phases.live_images.run') - @mock.patch('pungi.phases.live_images.KojiWrapper') + @mock.patch("shutil.copy2") + @mock.patch("pungi.phases.live_images.run") + @mock.patch("pungi.phases.live_images.KojiWrapper") def test_process_handles_fail(self, KojiWrapper, run, copy2): - compose = DummyCompose(self.topdir, {'koji_profile': 'koji'}) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) pool = mock.Mock() cmd = { - 'ks_file': '/path/to/ks_file', - 'build_arch': 'amd64', - 'dest_dir': '/top/iso_dir/amd64/Client', - 'scratch': False, - 'repos': ['/repo/amd64/Client', - 'http://example.com/repo/', - '/repo/amd64/Everything'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': None, - 'specfile': None, - 'ksurl': None, - 'subvariant': 'Client', - 'release': 'xyz', - 'type': 'live', - 'failable_arches': ['*'], - 'target': 'f27', + "ks_file": "/path/to/ks_file", + "build_arch": "amd64", + "dest_dir": "/top/iso_dir/amd64/Client", + "scratch": False, + "repos": [ + "/repo/amd64/Client", + "http://example.com/repo/", + "/repo/amd64/Everything", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": None, + "specfile": None, + "ksurl": None, + "subvariant": "Client", + "release": "xyz", + "type": "live", + "failable_arches": ["*"], + "target": "f27", } koji_wrapper = KojiWrapper.return_value - koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...' + koji_wrapper.get_create_image_cmd.return_value = "koji spin-livecd ..." koji_wrapper.run_blocking_cmd.return_value = { - 'retcode': 1, - 'output': 'some output', - 'task_id': 123 + "retcode": 1, + "output": "some output", + "task_id": 123, } t = CreateLiveImageThread(pool) - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Client"], "amd64"), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Live (variant Client, arch amd64, subvariant Client) failed, but going on anyway.'), - mock.call('LiveImage task failed: 123. See %s/logs/amd64/liveimage-None-None-xyz.amd64.log for more details.' - % self.topdir) - ]) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Live (variant Client, arch amd64, subvariant Client) failed, but going on anyway." + ), + mock.call( + "LiveImage task failed: 123. See %s/logs/amd64/liveimage-None-None-xyz.amd64.log for more details." + % self.topdir + ), + ] + ) - @mock.patch('shutil.copy2') - @mock.patch('pungi.phases.live_images.run') - @mock.patch('pungi.phases.live_images.KojiWrapper') + @mock.patch("shutil.copy2") + @mock.patch("pungi.phases.live_images.run") + @mock.patch("pungi.phases.live_images.KojiWrapper") def test_process_handles_exception(self, KojiWrapper, run, copy2): - compose = DummyCompose(self.topdir, {'koji_profile': 'koji'}) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) pool = mock.Mock() cmd = { - 'ks_file': '/path/to/ks_file', - 'build_arch': 'amd64', - 'dest_dir': '/top/iso_dir/amd64/Client', - 'scratch': False, - 'repos': ['/repo/amd64/Client', - 'http://example.com/repo/', - '/repo/amd64/Everything'], - 'label': '', - 'name': None, - 'filename': 'image-name', - 'version': None, - 'specfile': None, - 'ksurl': None, - 'subvariant': 'Client', - 'release': 'xyz', - 'type': 'live', - 'failable_arches': ['*'], - 'target': 'f27', + "ks_file": "/path/to/ks_file", + "build_arch": "amd64", + "dest_dir": "/top/iso_dir/amd64/Client", + "scratch": False, + "repos": [ + "/repo/amd64/Client", + "http://example.com/repo/", + "/repo/amd64/Everything", + ], + "label": "", + "name": None, + "filename": "image-name", + "version": None, + "specfile": None, + "ksurl": None, + "subvariant": "Client", + "release": "xyz", + "type": "live", + "failable_arches": ["*"], + "target": "f27", } koji_wrapper = KojiWrapper.return_value koji_wrapper.get_create_image_cmd.side_effect = boom t = CreateLiveImageThread(pool) - with mock.patch('time.sleep'): - t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1) + with mock.patch("time.sleep"): + t.process((compose, cmd, compose.variants["Client"], "amd64"), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Live (variant Client, arch amd64, subvariant Client) failed, but going on anyway.'), - mock.call('BOOM') - ]) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Live (variant Client, arch amd64, subvariant Client) failed, but going on anyway." + ), + mock.call("BOOM"), + ] + ) diff --git a/tests/test_livemediaphase.py b/tests/test_livemediaphase.py index 444b4956..9cdb4a6e 100644 --- a/tests/test_livemediaphase.py +++ b/tests/test_livemediaphase.py @@ -12,23 +12,25 @@ from tests.helpers import DummyCompose, PungiTestCase, boom class TestLiveMediaPhase(PungiTestCase): - - @mock.patch('pungi.phases.livemedia_phase.ThreadPool') + @mock.patch("pungi.phases.livemedia_phase.ThreadPool") def test_live_media_minimal(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_media': { - '^Server$': [ - { - 'target': 'f24', - 'kickstart': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'name': 'Fedora Server Live', - 'version': 'Rawhide', - } - ] + compose = DummyCompose( + self.topdir, + { + "live_media": { + "^Server$": [ + { + "target": "f24", + "kickstart": "file.ks", + "ksurl": "git://example.com/repo.git", + "name": "Fedora Server Live", + "version": "Rawhide", + } + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) self.assertValidConfig(compose.conf) @@ -36,43 +38,55 @@ class TestLiveMediaPhase(PungiTestCase): phase.run() self.assertTrue(phase.pool.add.called) - self.assertEqual(phase.pool.queue_put.call_args_list, - [mock.call((compose, - compose.variants['Server'], - { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': None, - 'repo': [self.topdir + '/compose/Server/$basearch/os'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'install_tree': self.topdir + '/compose/Server/$basearch/os', - 'version': 'Rawhide', - 'subvariant': 'Server', - 'failable_arches': [], - }))]) + self.assertEqual( + phase.pool.queue_put.call_args_list, + [ + mock.call( + ( + compose, + compose.variants["Server"], + { + "arches": ["amd64", "x86_64"], + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "name": "Fedora Server Live", + "release": None, + "repo": [self.topdir + "/compose/Server/$basearch/os"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "install_tree": self.topdir + + "/compose/Server/$basearch/os", + "version": "Rawhide", + "subvariant": "Server", + "failable_arches": [], + }, + ) + ) + ], + ) - @mock.patch('pungi.phases.livemedia_phase.ThreadPool') + @mock.patch("pungi.phases.livemedia_phase.ThreadPool") def test_expand_failable(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_media': { - '^Server$': [ - { - 'target': 'f24', - 'kickstart': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'name': 'Fedora Server Live', - 'version': 'Rawhide', - 'failable': ['*'], - } - ] + compose = DummyCompose( + self.topdir, + { + "live_media": { + "^Server$": [ + { + "target": "f24", + "kickstart": "file.ks", + "ksurl": "git://example.com/repo.git", + "name": "Fedora Server Live", + "version": "Rawhide", + "failable": ["*"], + } + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) self.assertValidConfig(compose.conf) @@ -80,55 +94,61 @@ class TestLiveMediaPhase(PungiTestCase): phase.run() self.assertTrue(phase.pool.add.called) - self.assertEqual(phase.pool.queue_put.call_args_list, - [mock.call((compose, - compose.variants['Server'], - { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': None, - 'repo': [self.topdir + '/compose/Server/$basearch/os'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'install_tree': self.topdir + '/compose/Server/$basearch/os', - 'version': 'Rawhide', - 'subvariant': 'Server', - 'failable_arches': ['amd64', 'x86_64'], - }))]) + self.assertEqual( + phase.pool.queue_put.call_args_list, + [ + mock.call( + ( + compose, + compose.variants["Server"], + { + "arches": ["amd64", "x86_64"], + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "name": "Fedora Server Live", + "release": None, + "repo": [self.topdir + "/compose/Server/$basearch/os"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "install_tree": self.topdir + + "/compose/Server/$basearch/os", + "version": "Rawhide", + "subvariant": "Server", + "failable_arches": ["amd64", "x86_64"], + }, + ) + ) + ], + ) - @mock.patch('pungi.phases.livemedia_phase.ThreadPool') + @mock.patch("pungi.phases.livemedia_phase.ThreadPool") def test_live_media_with_phase_global_opts(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_media_ksurl': 'git://example.com/repo.git#BEEFCAFE', - 'live_media_target': 'f24', - 'live_media_release': 'RRR', - 'live_media_version': 'Rawhide', - 'live_media': { - '^Server$': [ - { - 'kickstart': 'file.ks', - 'name': 'Fedora Server Live', - }, - { - 'kickstart': 'different.ks', - 'name': 'Fedora Server Live', - }, - { - 'kickstart': 'yet-another.ks', - 'name': 'Fedora Server Live', - 'ksurl': 'git://different.com/repo.git', - 'target': 'f25', - 'release': 'XXX', - 'version': '25', - } - ] + compose = DummyCompose( + self.topdir, + { + "live_media_ksurl": "git://example.com/repo.git#BEEFCAFE", + "live_media_target": "f24", + "live_media_release": "RRR", + "live_media_version": "Rawhide", + "live_media": { + "^Server$": [ + {"kickstart": "file.ks", "name": "Fedora Server Live"}, + {"kickstart": "different.ks", "name": "Fedora Server Live"}, + { + "kickstart": "yet-another.ks", + "name": "Fedora Server Live", + "ksurl": "git://different.com/repo.git", + "target": "f25", + "release": "XXX", + "version": "25", + }, + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) self.assertValidConfig(compose.conf) @@ -136,91 +156,107 @@ class TestLiveMediaPhase(PungiTestCase): phase.run() self.assertTrue(phase.pool.add.called) - self.assertEqual(phase.pool.queue_put.call_args_list, - [mock.call((compose, - compose.variants['Server'], - { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git#BEEFCAFE', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': 'RRR', - 'repo': [self.topdir + '/compose/Server/$basearch/os'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'install_tree': self.topdir + '/compose/Server/$basearch/os', - 'version': 'Rawhide', - 'subvariant': 'Server', - 'failable_arches': [], - })), - mock.call((compose, - compose.variants['Server'], - { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'different.ks', - 'ksurl': 'git://example.com/repo.git#BEEFCAFE', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': 'RRR', - 'repo': [self.topdir + '/compose/Server/$basearch/os'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'install_tree': self.topdir + '/compose/Server/$basearch/os', - 'version': 'Rawhide', - 'subvariant': 'Server', - 'failable_arches': [], - })), - mock.call((compose, - compose.variants['Server'], - { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'yet-another.ks', - 'ksurl': 'git://different.com/repo.git', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': 'XXX', - 'repo': [self.topdir + '/compose/Server/$basearch/os'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f25', - 'install_tree': self.topdir + '/compose/Server/$basearch/os', - 'version': '25', - 'subvariant': 'Server', - 'failable_arches': [], - }))]) + self.assertEqual( + phase.pool.queue_put.call_args_list, + [ + mock.call( + ( + compose, + compose.variants["Server"], + { + "arches": ["amd64", "x86_64"], + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git#BEEFCAFE", + "ksversion": None, + "name": "Fedora Server Live", + "release": "RRR", + "repo": [self.topdir + "/compose/Server/$basearch/os"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "install_tree": self.topdir + + "/compose/Server/$basearch/os", + "version": "Rawhide", + "subvariant": "Server", + "failable_arches": [], + }, + ) + ), + mock.call( + ( + compose, + compose.variants["Server"], + { + "arches": ["amd64", "x86_64"], + "ksfile": "different.ks", + "ksurl": "git://example.com/repo.git#BEEFCAFE", + "ksversion": None, + "name": "Fedora Server Live", + "release": "RRR", + "repo": [self.topdir + "/compose/Server/$basearch/os"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "install_tree": self.topdir + + "/compose/Server/$basearch/os", + "version": "Rawhide", + "subvariant": "Server", + "failable_arches": [], + }, + ) + ), + mock.call( + ( + compose, + compose.variants["Server"], + { + "arches": ["amd64", "x86_64"], + "ksfile": "yet-another.ks", + "ksurl": "git://different.com/repo.git", + "ksversion": None, + "name": "Fedora Server Live", + "release": "XXX", + "repo": [self.topdir + "/compose/Server/$basearch/os"], + "scratch": False, + "skip_tag": None, + "target": "f25", + "install_tree": self.topdir + + "/compose/Server/$basearch/os", + "version": "25", + "subvariant": "Server", + "failable_arches": [], + }, + ) + ), + ], + ) - @mock.patch('pungi.phases.livemedia_phase.ThreadPool') + @mock.patch("pungi.phases.livemedia_phase.ThreadPool") def test_live_media_with_global_opts(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'global_ksurl': 'git://example.com/repo.git#BEEFCAFE', - 'global_target': 'f24', - 'global_release': 'RRR', - 'global_version': 'Rawhide', - 'live_media': { - '^Server$': [ - { - 'kickstart': 'file.ks', - 'name': 'Fedora Server Live', - }, - { - 'kickstart': 'different.ks', - 'name': 'Fedora Server Live', - }, - { - 'kickstart': 'yet-another.ks', - 'name': 'Fedora Server Live', - 'ksurl': 'git://different.com/repo.git', - 'target': 'f25', - 'release': 'XXX', - 'version': '25', - } - ] + compose = DummyCompose( + self.topdir, + { + "global_ksurl": "git://example.com/repo.git#BEEFCAFE", + "global_target": "f24", + "global_release": "RRR", + "global_version": "Rawhide", + "live_media": { + "^Server$": [ + {"kickstart": "file.ks", "name": "Fedora Server Live"}, + {"kickstart": "different.ks", "name": "Fedora Server Live"}, + { + "kickstart": "yet-another.ks", + "name": "Fedora Server Live", + "ksurl": "git://different.com/repo.git", + "target": "f25", + "release": "XXX", + "version": "25", + }, + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) self.assertValidConfig(compose.conf) @@ -228,135 +264,171 @@ class TestLiveMediaPhase(PungiTestCase): phase.run() self.assertTrue(phase.pool.add.called) - self.assertEqual(phase.pool.queue_put.call_args_list, - [mock.call((compose, - compose.variants['Server'], - { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git#BEEFCAFE', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': 'RRR', - 'repo': [self.topdir + '/compose/Server/$basearch/os'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'install_tree': self.topdir + '/compose/Server/$basearch/os', - 'version': 'Rawhide', - 'subvariant': 'Server', - 'failable_arches': [], - })), - mock.call((compose, - compose.variants['Server'], - { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'different.ks', - 'ksurl': 'git://example.com/repo.git#BEEFCAFE', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': 'RRR', - 'repo': [self.topdir + '/compose/Server/$basearch/os'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'install_tree': self.topdir + '/compose/Server/$basearch/os', - 'version': 'Rawhide', - 'subvariant': 'Server', - 'failable_arches': [], - })), - mock.call((compose, - compose.variants['Server'], - { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'yet-another.ks', - 'ksurl': 'git://different.com/repo.git', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': 'XXX', - 'repo': [self.topdir + '/compose/Server/$basearch/os'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f25', - 'install_tree': self.topdir + '/compose/Server/$basearch/os', - 'version': '25', - 'subvariant': 'Server', - 'failable_arches': [], - }))]) + self.assertEqual( + phase.pool.queue_put.call_args_list, + [ + mock.call( + ( + compose, + compose.variants["Server"], + { + "arches": ["amd64", "x86_64"], + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git#BEEFCAFE", + "ksversion": None, + "name": "Fedora Server Live", + "release": "RRR", + "repo": [self.topdir + "/compose/Server/$basearch/os"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "install_tree": self.topdir + + "/compose/Server/$basearch/os", + "version": "Rawhide", + "subvariant": "Server", + "failable_arches": [], + }, + ) + ), + mock.call( + ( + compose, + compose.variants["Server"], + { + "arches": ["amd64", "x86_64"], + "ksfile": "different.ks", + "ksurl": "git://example.com/repo.git#BEEFCAFE", + "ksversion": None, + "name": "Fedora Server Live", + "release": "RRR", + "repo": [self.topdir + "/compose/Server/$basearch/os"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "install_tree": self.topdir + + "/compose/Server/$basearch/os", + "version": "Rawhide", + "subvariant": "Server", + "failable_arches": [], + }, + ) + ), + mock.call( + ( + compose, + compose.variants["Server"], + { + "arches": ["amd64", "x86_64"], + "ksfile": "yet-another.ks", + "ksurl": "git://different.com/repo.git", + "ksversion": None, + "name": "Fedora Server Live", + "release": "XXX", + "repo": [self.topdir + "/compose/Server/$basearch/os"], + "scratch": False, + "skip_tag": None, + "target": "f25", + "install_tree": self.topdir + + "/compose/Server/$basearch/os", + "version": "25", + "subvariant": "Server", + "failable_arches": [], + }, + ) + ), + ], + ) - @mock.patch('pungi.phases.livemedia_phase.ThreadPool') + @mock.patch("pungi.phases.livemedia_phase.ThreadPool") def test_live_media_non_existing_install_tree(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_media': { - '^Server$': [ - { - 'target': 'f24', - 'kickstart': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'name': 'Fedora Server Live', - 'version': 'Rawhide', - 'install_tree_from': 'Missing', - } - ] + compose = DummyCompose( + self.topdir, + { + "live_media": { + "^Server$": [ + { + "target": "f24", + "kickstart": "file.ks", + "ksurl": "git://example.com/repo.git", + "name": "Fedora Server Live", + "version": "Rawhide", + "install_tree_from": "Missing", + } + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) self.assertValidConfig(compose.conf) phase = LiveMediaPhase(compose) - with self.assertRaisesRegexp(RuntimeError, r'no.+Missing.+when building.+Server'): + with self.assertRaisesRegexp( + RuntimeError, r"no.+Missing.+when building.+Server" + ): phase.run() - @mock.patch('pungi.phases.livemedia_phase.ThreadPool') + @mock.patch("pungi.phases.livemedia_phase.ThreadPool") def test_live_media_non_existing_repo(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_media': { - '^Server$': [ - { - 'target': 'f24', - 'kickstart': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'name': 'Fedora Server Live', - 'version': 'Rawhide', - 'repo': 'Missing', - } - ] + compose = DummyCompose( + self.topdir, + { + "live_media": { + "^Server$": [ + { + "target": "f24", + "kickstart": "file.ks", + "ksurl": "git://example.com/repo.git", + "name": "Fedora Server Live", + "version": "Rawhide", + "repo": "Missing", + } + ] + }, + "koji_profile": "koji", }, - 'koji_profile': 'koji', - }) + ) self.assertValidConfig(compose.conf) phase = LiveMediaPhase(compose) - with self.assertRaisesRegexp(RuntimeError, r'There is no variant Missing to get repo from.'): + with self.assertRaisesRegexp( + RuntimeError, r"There is no variant Missing to get repo from." + ): phase.run() - @mock.patch('pungi.phases.livemedia_phase.ThreadPool') + @mock.patch("pungi.phases.livemedia_phase.ThreadPool") def test_live_media_full(self, ThreadPool): - compose = DummyCompose(self.topdir, { - 'live_media': { - '^Server$': [ - { - 'target': 'f24', - 'kickstart': 'file.ks', - 'ksurl': 'git://example.com/repo.git#BEEFCAFE', - 'name': 'Fedora Server Live', - 'scratch': True, - 'skip_tag': True, - 'repo': ['http://example.com/extra_repo', 'Everything', 'Server-optional'], - 'arches': ['x86_64'], - 'ksversion': '24', - 'release': None, - 'install_tree_from': 'Server-optional', - 'subvariant': 'Something', - 'failable': ['*'], - } - ] - } - }) + compose = DummyCompose( + self.topdir, + { + "live_media": { + "^Server$": [ + { + "target": "f24", + "kickstart": "file.ks", + "ksurl": "git://example.com/repo.git#BEEFCAFE", + "name": "Fedora Server Live", + "scratch": True, + "skip_tag": True, + "repo": [ + "http://example.com/extra_repo", + "Everything", + "Server-optional", + ], + "arches": ["x86_64"], + "ksversion": "24", + "release": None, + "install_tree_from": "Server-optional", + "subvariant": "Something", + "failable": ["*"], + } + ] + } + }, + ) compose.setup_optional() self.assertValidConfig(compose.conf) @@ -365,108 +437,131 @@ class TestLiveMediaPhase(PungiTestCase): phase.run() self.assertTrue(phase.pool.add.called) - self.assertEqual(phase.pool.queue_put.call_args_list, - [mock.call((compose, - compose.variants['Server'], - { - 'arches': ['x86_64'], - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git#BEEFCAFE', - 'ksversion': '24', - 'name': 'Fedora Server Live', - 'release': '20151203.t.0', - 'repo': ['http://example.com/extra_repo', - self.topdir + '/compose/Everything/$basearch/os', - self.topdir + '/compose/Server-optional/$basearch/os', - self.topdir + '/compose/Server/$basearch/os'], - 'scratch': True, - 'skip_tag': True, - 'target': 'f24', - 'install_tree': self.topdir + '/compose/Server-optional/$basearch/os', - 'version': '25', - 'subvariant': 'Something', - 'failable_arches': ['x86_64'], - }))]) + self.assertEqual( + phase.pool.queue_put.call_args_list, + [ + mock.call( + ( + compose, + compose.variants["Server"], + { + "arches": ["x86_64"], + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git#BEEFCAFE", + "ksversion": "24", + "name": "Fedora Server Live", + "release": "20151203.t.0", + "repo": [ + "http://example.com/extra_repo", + self.topdir + "/compose/Everything/$basearch/os", + self.topdir + "/compose/Server-optional/$basearch/os", + self.topdir + "/compose/Server/$basearch/os", + ], + "scratch": True, + "skip_tag": True, + "target": "f24", + "install_tree": self.topdir + + "/compose/Server-optional/$basearch/os", + "version": "25", + "subvariant": "Something", + "failable_arches": ["x86_64"], + }, + ) + ) + ], + ) class TestLiveMediaThread(PungiTestCase): - - @mock.patch('pungi.phases.livemedia_phase.get_mtime') - @mock.patch('pungi.phases.livemedia_phase.get_file_size') - @mock.patch('pungi.phases.livemedia_phase.KojiWrapper') - @mock.patch('pungi.phases.livemedia_phase.Linker') + @mock.patch("pungi.phases.livemedia_phase.get_mtime") + @mock.patch("pungi.phases.livemedia_phase.get_file_size") + @mock.patch("pungi.phases.livemedia_phase.KojiWrapper") + @mock.patch("pungi.phases.livemedia_phase.Linker") def test_process(self, Linker, KojiWrapper, get_file_size, get_mtime): - compose = DummyCompose(self.topdir, { - 'koji_profile': 'koji' - }) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) config = { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': None, - 'repo': ['/repo/$basearch/Server'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'version': 'Rawhide', - 'subvariant': 'KDE', - 'failable_arches': [], + "arches": ["amd64", "x86_64"], + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "name": "Fedora Server Live", + "release": None, + "repo": ["/repo/$basearch/Server"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "version": "Rawhide", + "subvariant": "KDE", + "failable_arches": [], } pool = mock.Mock() get_live_media_cmd = KojiWrapper.return_value.get_live_media_cmd - get_live_media_cmd.return_value = 'koji-spin-livemedia' + get_live_media_cmd.return_value = "koji-spin-livemedia" run_blocking_cmd = KojiWrapper.return_value.run_blocking_cmd run_blocking_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': None, + "task_id": 1234, + "retcode": 0, + "output": None, } get_image_paths = KojiWrapper.return_value.get_image_paths get_image_paths.return_value = { - 'x86_64': [ - '/koji/task/1235/tdl-amd64.xml', - '/koji/task/1235/Live-20160103.x86_64.iso', - '/koji/task/1235/Live-20160103.x86_64.tar.xz' + "x86_64": [ + "/koji/task/1235/tdl-amd64.xml", + "/koji/task/1235/Live-20160103.x86_64.iso", + "/koji/task/1235/Live-20160103.x86_64.tar.xz", + ], + "amd64": [ + "/koji/task/1235/tdl-amd64.xml", + "/koji/task/1235/Live-20160103.amd64.iso", + "/koji/task/1235/Live-20160103.amd64.tar.xz", ], - 'amd64': [ - '/koji/task/1235/tdl-amd64.xml', - '/koji/task/1235/Live-20160103.amd64.iso', - '/koji/task/1235/Live-20160103.amd64.tar.xz' - ] } t = LiveMediaThread(pool) get_file_size.return_value = 1024 get_mtime.return_value = 13579 - with mock.patch('time.sleep'): - t.process((compose, compose.variants['Server'], config), 1) + with mock.patch("time.sleep"): + t.process((compose, compose.variants["Server"], config), 1) self.assertEqual( run_blocking_cmd.mock_calls, - [mock.call('koji-spin-livemedia', - log_file=self.topdir + '/logs/amd64-x86_64/livemedia-Server-KDE.amd64-x86_64.log')]) - self.assertEqual(get_live_media_cmd.mock_calls, - [mock.call({'arch': 'amd64,x86_64', - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': None, - 'repo': ['/repo/$basearch/Server'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'version': 'Rawhide', - 'can_fail': []})]) - self.assertEqual(get_image_paths.mock_calls, - [mock.call(1234, callback=mock.ANY)]) - self.assertTrue(os.path.isdir(self.topdir + '/compose/Server/x86_64/iso')) - self.assertTrue(os.path.isdir(self.topdir + '/compose/Server/amd64/iso')) + [ + mock.call( + "koji-spin-livemedia", + log_file=self.topdir + + "/logs/amd64-x86_64/livemedia-Server-KDE.amd64-x86_64.log", + ) + ], + ) + self.assertEqual( + get_live_media_cmd.mock_calls, + [ + mock.call( + { + "arch": "amd64,x86_64", + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "name": "Fedora Server Live", + "release": None, + "repo": ["/repo/$basearch/Server"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "version": "Rawhide", + "can_fail": [], + } + ) + ], + ) + self.assertEqual( + get_image_paths.mock_calls, [mock.call(1234, callback=mock.ANY)] + ) + self.assertTrue(os.path.isdir(self.topdir + "/compose/Server/x86_64/iso")) + self.assertTrue(os.path.isdir(self.topdir + "/compose/Server/amd64/iso")) link = Linker.return_value.link six.assertCountEqual( self, @@ -486,104 +581,120 @@ class TestLiveMediaThread(PungiTestCase): ) image_relative_paths = [ - 'Server/amd64/iso/Live-20160103.amd64.iso', - 'Server/x86_64/iso/Live-20160103.x86_64.iso' + "Server/amd64/iso/Live-20160103.amd64.iso", + "Server/x86_64/iso/Live-20160103.x86_64.iso", ] self.assertEqual(len(compose.im.add.call_args_list), 2) for call in compose.im.add.call_args_list: _, kwargs = call - image = kwargs['image'] - self.assertEqual(kwargs['variant'], 'Server') - self.assertIn(kwargs['arch'], ('amd64', 'x86_64')) - self.assertEqual(kwargs['arch'], image.arch) + image = kwargs["image"] + self.assertEqual(kwargs["variant"], "Server") + self.assertIn(kwargs["arch"], ("amd64", "x86_64")) + self.assertEqual(kwargs["arch"], image.arch) self.assertIn(image.path, image_relative_paths) - self.assertEqual('iso', image.format) - self.assertEqual('live', image.type) - self.assertEqual('KDE', image.subvariant) + self.assertEqual("iso", image.format) + self.assertEqual("live", image.type) + self.assertEqual("KDE", image.subvariant) - @mock.patch('pungi.phases.livemedia_phase.get_mtime') - @mock.patch('pungi.phases.livemedia_phase.get_file_size') - @mock.patch('pungi.phases.livemedia_phase.KojiWrapper') + @mock.patch("pungi.phases.livemedia_phase.get_mtime") + @mock.patch("pungi.phases.livemedia_phase.get_file_size") + @mock.patch("pungi.phases.livemedia_phase.KojiWrapper") def test_handle_koji_fail(self, KojiWrapper, get_file_size, get_mtime): - compose = DummyCompose(self.topdir, { - 'koji_profile': 'koji', - }) + compose = DummyCompose(self.topdir, {"koji_profile": "koji"}) config = { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': None, - 'repo': ['/repo/$basearch/Server'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'version': 'Rawhide', - 'subvariant': 'KDE', - 'failable_arches': ['amd64', 'x86_64'], + "arches": ["amd64", "x86_64"], + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "name": "Fedora Server Live", + "release": None, + "repo": ["/repo/$basearch/Server"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "version": "Rawhide", + "subvariant": "KDE", + "failable_arches": ["amd64", "x86_64"], } pool = mock.Mock() run_blocking_cmd = KojiWrapper.return_value.run_blocking_cmd run_blocking_cmd.return_value = { - 'task_id': 1234, - 'retcode': 1, - 'output': None, + "task_id": 1234, + "retcode": 1, + "output": None, } get_file_size.return_value = 1024 get_mtime.return_value.st_mtime = 13579 t = LiveMediaThread(pool) - with mock.patch('time.sleep'): - t.process((compose, compose.variants['Server'], config), 1) + with mock.patch("time.sleep"): + t.process((compose, compose.variants["Server"], config), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Live media (variant Server, arch *, subvariant KDE) failed, but going on anyway.'), - mock.call('Live media task failed: 1234. See %s for more details.' - % (os.path.join(self.topdir, 'logs/amd64-x86_64/livemedia-Server-KDE.amd64-x86_64.log'))) - ]) - self.assertEqual(KojiWrapper.return_value.get_live_media_cmd.mock_calls, - [mock.call({ - 'arch': 'amd64,x86_64', - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'skip_tag': None, - 'target': 'f24', - 'release': None, - 'version': 'Rawhide', - 'scratch': False, - 'can_fail': ['amd64', 'x86_64'], - 'name': 'Fedora Server Live', - 'repo': ['/repo/$basearch/Server'], - })]) - - @mock.patch('pungi.phases.livemedia_phase.get_mtime') - @mock.patch('pungi.phases.livemedia_phase.get_file_size') - @mock.patch('pungi.phases.livemedia_phase.KojiWrapper') - def test_handle_exception(self, KojiWrapper, get_file_size, get_mtime): - compose = DummyCompose(self.topdir, { - 'koji_profile': 'koji', - 'failable_deliverables': [ - ('^.+$', {'*': ['live-media']}) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Live media (variant Server, arch *, subvariant KDE) failed, but going on anyway." + ), + mock.call( + "Live media task failed: 1234. See %s for more details." + % ( + os.path.join( + self.topdir, + "logs/amd64-x86_64/livemedia-Server-KDE.amd64-x86_64.log", + ) + ) + ), ] - }) + ) + self.assertEqual( + KojiWrapper.return_value.get_live_media_cmd.mock_calls, + [ + mock.call( + { + "arch": "amd64,x86_64", + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "skip_tag": None, + "target": "f24", + "release": None, + "version": "Rawhide", + "scratch": False, + "can_fail": ["amd64", "x86_64"], + "name": "Fedora Server Live", + "repo": ["/repo/$basearch/Server"], + } + ) + ], + ) + + @mock.patch("pungi.phases.livemedia_phase.get_mtime") + @mock.patch("pungi.phases.livemedia_phase.get_file_size") + @mock.patch("pungi.phases.livemedia_phase.KojiWrapper") + def test_handle_exception(self, KojiWrapper, get_file_size, get_mtime): + compose = DummyCompose( + self.topdir, + { + "koji_profile": "koji", + "failable_deliverables": [("^.+$", {"*": ["live-media"]})], + }, + ) config = { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': None, - 'repo': ['/repo/$basearch/Server'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'version': 'Rawhide', - 'subvariant': 'KDE', - 'failable_arches': ['amd64', 'x86_64'], + "arches": ["amd64", "x86_64"], + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "name": "Fedora Server Live", + "release": None, + "repo": ["/repo/$basearch/Server"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "version": "Rawhide", + "subvariant": "KDE", + "failable_arches": ["amd64", "x86_64"], } pool = mock.Mock() @@ -593,53 +704,66 @@ class TestLiveMediaThread(PungiTestCase): get_mtime.return_value.st_mtime = 13579 t = LiveMediaThread(pool) - with mock.patch('time.sleep'): - t.process((compose, compose.variants['Server'], config), 1) + with mock.patch("time.sleep"): + t.process((compose, compose.variants["Server"], config), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Live media (variant Server, arch *, subvariant KDE) failed, but going on anyway.'), - mock.call('BOOM') - ]) - self.assertEqual(KojiWrapper.return_value.get_live_media_cmd.mock_calls, - [mock.call({ - 'arch': 'amd64,x86_64', - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'skip_tag': None, - 'target': 'f24', - 'release': None, - 'version': 'Rawhide', - 'scratch': False, - 'can_fail': ['amd64', 'x86_64'], - 'name': 'Fedora Server Live', - 'repo': ['/repo/$basearch/Server'], - })]) - - @mock.patch('pungi.phases.livemedia_phase.get_mtime') - @mock.patch('pungi.phases.livemedia_phase.get_file_size') - @mock.patch('pungi.phases.livemedia_phase.KojiWrapper') - def test_handle_exception_only_one_arch_optional(self, KojiWrapper, get_file_size, get_mtime): - compose = DummyCompose(self.topdir, { - 'koji_profile': 'koji', - 'failable_deliverables': [ - ('^.+$', {'*': ['live-media']}) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Live media (variant Server, arch *, subvariant KDE) failed, but going on anyway." + ), + mock.call("BOOM"), ] - }) + ) + self.assertEqual( + KojiWrapper.return_value.get_live_media_cmd.mock_calls, + [ + mock.call( + { + "arch": "amd64,x86_64", + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "skip_tag": None, + "target": "f24", + "release": None, + "version": "Rawhide", + "scratch": False, + "can_fail": ["amd64", "x86_64"], + "name": "Fedora Server Live", + "repo": ["/repo/$basearch/Server"], + } + ) + ], + ) + + @mock.patch("pungi.phases.livemedia_phase.get_mtime") + @mock.patch("pungi.phases.livemedia_phase.get_file_size") + @mock.patch("pungi.phases.livemedia_phase.KojiWrapper") + def test_handle_exception_only_one_arch_optional( + self, KojiWrapper, get_file_size, get_mtime + ): + compose = DummyCompose( + self.topdir, + { + "koji_profile": "koji", + "failable_deliverables": [("^.+$", {"*": ["live-media"]})], + }, + ) config = { - 'arches': ['amd64', 'x86_64'], - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'name': 'Fedora Server Live', - 'release': None, - 'repo': ['/repo/$basearch/Server'], - 'scratch': False, - 'skip_tag': None, - 'target': 'f24', - 'version': 'Rawhide', - 'subvariant': 'KDE', - 'failable_arches': ['amd64'], + "arches": ["amd64", "x86_64"], + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "name": "Fedora Server Live", + "release": None, + "repo": ["/repo/$basearch/Server"], + "scratch": False, + "skip_tag": None, + "target": "f24", + "version": "Rawhide", + "subvariant": "KDE", + "failable_arches": ["amd64"], } pool = mock.Mock() @@ -650,21 +774,27 @@ class TestLiveMediaThread(PungiTestCase): t = LiveMediaThread(pool) with self.assertRaises(Exception): - with mock.patch('time.sleep'): - t.process((compose, compose.variants['Server'], config), 1) + with mock.patch("time.sleep"): + t.process((compose, compose.variants["Server"], config), 1) - self.assertEqual(KojiWrapper.return_value.get_live_media_cmd.mock_calls, - [mock.call({ - 'arch': 'amd64,x86_64', - 'ksfile': 'file.ks', - 'ksurl': 'git://example.com/repo.git', - 'ksversion': None, - 'skip_tag': None, - 'target': 'f24', - 'release': None, - 'version': 'Rawhide', - 'scratch': False, - 'can_fail': ['amd64'], - 'name': 'Fedora Server Live', - 'repo': ['/repo/$basearch/Server'], - })]) + self.assertEqual( + KojiWrapper.return_value.get_live_media_cmd.mock_calls, + [ + mock.call( + { + "arch": "amd64,x86_64", + "ksfile": "file.ks", + "ksurl": "git://example.com/repo.git", + "ksversion": None, + "skip_tag": None, + "target": "f24", + "release": None, + "version": "Rawhide", + "scratch": False, + "can_fail": ["amd64"], + "name": "Fedora Server Live", + "repo": ["/repo/$basearch/Server"], + } + ) + ], + ) diff --git a/tests/test_lorax_wrapper.py b/tests/test_lorax_wrapper.py index 7daa77a4..dd8acf5b 100644 --- a/tests/test_lorax_wrapper.py +++ b/tests/test_lorax_wrapper.py @@ -14,56 +14,79 @@ from pungi.wrappers.lorax import LoraxWrapper class LoraxWrapperTest(unittest.TestCase): - def setUp(self): self.lorax = LoraxWrapper() def test_get_command_with_minimal_arguments(self): - cmd = self.lorax.get_lorax_cmd("product", "version", "release", - "/mnt/repo_baseurl", "/mnt/output_dir") + cmd = self.lorax.get_lorax_cmd( + "product", "version", "release", "/mnt/repo_baseurl", "/mnt/output_dir" + ) - self.assertEqual(cmd[0], 'lorax') + self.assertEqual(cmd[0], "lorax") six.assertCountEqual( self, cmd[1:], - ["--product=product", - "--version=version", - "--release=release", - "--source=file:///mnt/repo_baseurl", - "/mnt/output_dir"], + [ + "--product=product", + "--version=version", + "--release=release", + "--source=file:///mnt/repo_baseurl", + "/mnt/output_dir", + ], ) def test_get_command_with_all_arguments(self): - cmd = self.lorax.get_lorax_cmd("product", "version", "release", - "/mnt/repo_baseurl", "/mnt/output_dir", - variant="Server", bugurl="http://example.com/", - nomacboot=True, noupgrade=True, is_final=True, - buildarch='x86_64', volid='VOLUME_ID', - buildinstallpackages=['bash', 'vim'], - add_template=['t1', 't2'], - add_arch_template=['ta1', 'ta2'], - add_template_var=['v1', 'v2'], - add_arch_template_var=['va1', 'va2'], - log_dir="/tmp", - dracut_args=["--foo", "bar"]) + cmd = self.lorax.get_lorax_cmd( + "product", + "version", + "release", + "/mnt/repo_baseurl", + "/mnt/output_dir", + variant="Server", + bugurl="http://example.com/", + nomacboot=True, + noupgrade=True, + is_final=True, + buildarch="x86_64", + volid="VOLUME_ID", + buildinstallpackages=["bash", "vim"], + add_template=["t1", "t2"], + add_arch_template=["ta1", "ta2"], + add_template_var=["v1", "v2"], + add_arch_template_var=["va1", "va2"], + log_dir="/tmp", + dracut_args=["--foo", "bar"], + ) - self.assertEqual(cmd[0], 'lorax') + self.assertEqual(cmd[0], "lorax") six.assertCountEqual( self, cmd[1:], - ["--product=product", "--version=version", - "--release=release", "--variant=Server", - "--source=file:///mnt/repo_baseurl", - "--bugurl=http://example.com/", - "--buildarch=x86_64", "--volid=VOLUME_ID", - "--nomacboot", "--noupgrade", "--isfinal", - "--installpkgs=bash", "--installpkgs=vim", - "--add-template=t1", "--add-template=t2", - "--add-arch-template=ta1", "--add-arch-template=ta2", - "--add-template-var=v1", "--add-template-var=v2", - "--add-arch-template-var=va1", "--add-arch-template-var=va2", - "--logfile=/tmp/lorax.log", - "--dracut-arg=--foo", - "--dracut-arg=bar", - "/mnt/output_dir"], + [ + "--product=product", + "--version=version", + "--release=release", + "--variant=Server", + "--source=file:///mnt/repo_baseurl", + "--bugurl=http://example.com/", + "--buildarch=x86_64", + "--volid=VOLUME_ID", + "--nomacboot", + "--noupgrade", + "--isfinal", + "--installpkgs=bash", + "--installpkgs=vim", + "--add-template=t1", + "--add-template=t2", + "--add-arch-template=ta1", + "--add-arch-template=ta2", + "--add-template-var=v1", + "--add-template-var=v2", + "--add-arch-template-var=va1", + "--add-arch-template-var=va2", + "--logfile=/tmp/lorax.log", + "--dracut-arg=--foo", + "--dracut-arg=bar", + "/mnt/output_dir", + ], ) diff --git a/tests/test_media_split.py b/tests/test_media_split.py index 14813850..3cc3a403 100644 --- a/tests/test_media_split.py +++ b/tests/test_media_split.py @@ -12,26 +12,25 @@ from pungi import media_split class ConvertMediaSizeTestCase(unittest.TestCase): - def test_size_parser_correct_number_as_int(self): self.assertEqual(media_split.convert_media_size(123), 123) def test_size_parser_correct_number_as_str(self): - self.assertEqual(media_split.convert_media_size('123'), 123) + self.assertEqual(media_split.convert_media_size("123"), 123) def test_size_parser_with_unit_b(self): - self.assertEqual(media_split.convert_media_size('123b'), 123) + self.assertEqual(media_split.convert_media_size("123b"), 123) def test_size_parser_with_unit_k(self): - self.assertEqual(media_split.convert_media_size('123k'), 123 * 1024) + self.assertEqual(media_split.convert_media_size("123k"), 123 * 1024) def test_size_parser_with_unit_M(self): - self.assertEqual(media_split.convert_media_size('123M'), - 123 * 1024 * 1024) + self.assertEqual(media_split.convert_media_size("123M"), 123 * 1024 * 1024) def test_size_parser_with_unit_G(self): - self.assertEqual(media_split.convert_media_size('123G'), - 123 * 1024 * 1024 * 1024) + self.assertEqual( + media_split.convert_media_size("123G"), 123 * 1024 * 1024 * 1024 + ) def test_size_parser_with_negative_number(self): with self.assertRaises(ValueError): @@ -39,11 +38,10 @@ class ConvertMediaSizeTestCase(unittest.TestCase): def test_size_parser_with_unknown_unit(self): with self.assertRaises(ValueError): - media_split.convert_media_size('123X') + media_split.convert_media_size("123X") class ConvertFileSizeTestCase(unittest.TestCase): - def test_round_up(self): self.assertEqual(media_split.convert_file_size(123, 2048), 2048) @@ -56,71 +54,78 @@ def bl(s): class MediaSplitterTestCase(unittest.TestCase): - def setUp(self): self.compose = mock.Mock() def test_sum_size(self): ms = media_split.MediaSplitter(bl(100)) - ms.add_file('first', bl(20)) - ms.add_file('second', bl(30)) - ms.add_file('third', 10) + ms.add_file("first", bl(20)) + ms.add_file("second", bl(30)) + ms.add_file("third", 10) self.assertEqual(ms.total_size, bl(50) + 10) self.assertEqual(ms.total_size_in_blocks, bl(51)) def test_add_same_file_twice(self): ms = media_split.MediaSplitter(bl(100)) - ms.add_file('first', bl(20)) - ms.add_file('first', bl(20)) + ms.add_file("first", bl(20)) + ms.add_file("first", bl(20)) self.assertEqual(ms.total_size, bl(20)) def test_add_same_file_twice_with_different_size(self): ms = media_split.MediaSplitter(bl(100)) - ms.add_file('first', bl(20)) + ms.add_file("first", bl(20)) with self.assertRaises(ValueError): - ms.add_file('first', bl(30)) + ms.add_file("first", bl(30)) def test_add_too_big_file(self): ms = media_split.MediaSplitter(bl(100)) with self.assertRaises(ValueError): - ms.add_file('too-big', bl(300)) + ms.add_file("too-big", bl(300)) def test_fit_on_one(self): ms = media_split.MediaSplitter(bl(100), compose=self.compose) - ms.add_file('first', bl(20)) - ms.add_file('second', bl(30)) + ms.add_file("first", bl(20)) + ms.add_file("second", bl(30)) - self.assertEqual(ms.split(), - [{'files': ['first', 'second'], 'size': bl(50)}]) + self.assertEqual(ms.split(), [{"files": ["first", "second"], "size": bl(50)}]) def test_split_on_two_discs(self): ms = media_split.MediaSplitter(bl(100), compose=self.compose) - ms.add_file('first', bl(25)) - ms.add_file('second', bl(40)) - ms.add_file('third', bl(80)) + ms.add_file("first", bl(25)) + ms.add_file("second", bl(40)) + ms.add_file("third", bl(80)) - self.assertEqual(ms.split(), - [{'files': ['first', 'second'], 'size': bl(65)}, - {'files': ['third'], 'size': bl(80)}]) + self.assertEqual( + ms.split(), + [ + {"files": ["first", "second"], "size": bl(65)}, + {"files": ["third"], "size": bl(80)}, + ], + ) def test_split_with_sticky_file(self): ms = media_split.MediaSplitter(bl(100)) - ms.add_file('sticky', bl(15), sticky=True) - ms.add_file('first', bl(25)) - ms.add_file('second', bl(40)) - ms.add_file('third', bl(80)) + ms.add_file("sticky", bl(15), sticky=True) + ms.add_file("first", bl(25)) + ms.add_file("second", bl(40)) + ms.add_file("third", bl(80)) - self.assertEqual(ms.split(), - [{'files': ['sticky', 'first', 'second'], 'size': bl(80)}, - {'files': ['sticky', 'third'], 'size': bl(95)}]) + self.assertEqual( + ms.split(), + [ + {"files": ["sticky", "first", "second"], "size": bl(80)}, + {"files": ["sticky", "third"], "size": bl(95)}, + ], + ) def test_split_unlimited_media(self): ms = media_split.MediaSplitter(None, compose=self.compose) - ms.add_file('first', bl(25)) - ms.add_file('second', bl(40)) - ms.add_file('third', bl(80)) + ms.add_file("first", bl(25)) + ms.add_file("second", bl(40)) + ms.add_file("third", bl(80)) - self.assertEqual(ms.split(), - [{'files': ['first', 'second', 'third'], 'size': bl(145)}]) + self.assertEqual( + ms.split(), [{"files": ["first", "second", "third"], "size": bl(145)}] + ) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index ea90d308..b94fe778 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -11,119 +11,127 @@ from pungi.compose_metadata import discinfo class DiscInfoTestCase(helpers.PungiTestCase): - def setUp(self): super(DiscInfoTestCase, self).setUp() - os.environ['SOURCE_DATE_EPOCH'] = '101010101' - self.path = os.path.join(self.topdir, 'compose/Server/x86_64/os/.discinfo') + os.environ["SOURCE_DATE_EPOCH"] = "101010101" + self.path = os.path.join(self.topdir, "compose/Server/x86_64/os/.discinfo") def test_write_discinfo_variant(self): - compose = helpers.DummyCompose(self.topdir, { - 'release_name': 'Test', - 'release_version': '1.0', - }) + compose = helpers.DummyCompose( + self.topdir, {"release_name": "Test", "release_version": "1.0"} + ) - metadata.write_discinfo(compose, 'x86_64', compose.variants['Server']) + metadata.write_discinfo(compose, "x86_64", compose.variants["Server"]) with open(self.path) as f: - self.assertEqual(f.read().strip().split('\n'), - ['101010101', - 'Test 1.0', - 'x86_64', - 'ALL']) + self.assertEqual( + f.read().strip().split("\n"), ["101010101", "Test 1.0", "x86_64", "ALL"] + ) - self.assertEqual(discinfo.read_discinfo(self.path), - {'timestamp': '101010101', - 'description': 'Test 1.0', - 'disc_numbers': ['ALL'], - 'arch': 'x86_64'}) + self.assertEqual( + discinfo.read_discinfo(self.path), + { + "timestamp": "101010101", + "description": "Test 1.0", + "disc_numbers": ["ALL"], + "arch": "x86_64", + }, + ) def test_write_discinfo_custom_description(self): - compose = helpers.DummyCompose(self.topdir, { - 'release_name': 'Test', - 'release_version': '1.0', - 'release_discinfo_description': 'Fuzzy %(variant_name)s.%(arch)s', - }) - compose.variants['Server'].name = 'Server' + compose = helpers.DummyCompose( + self.topdir, + { + "release_name": "Test", + "release_version": "1.0", + "release_discinfo_description": "Fuzzy %(variant_name)s.%(arch)s", + }, + ) + compose.variants["Server"].name = "Server" - metadata.write_discinfo(compose, 'x86_64', compose.variants['Server']) + metadata.write_discinfo(compose, "x86_64", compose.variants["Server"]) with open(self.path) as f: - self.assertEqual(f.read().strip().split('\n'), - ['101010101', - 'Fuzzy Server.x86_64', - 'x86_64', - 'ALL']) + self.assertEqual( + f.read().strip().split("\n"), + ["101010101", "Fuzzy Server.x86_64", "x86_64", "ALL"], + ) def test_write_discinfo_layered_product(self): - compose = helpers.DummyCompose(self.topdir, { - 'release_name': 'Test', - 'release_version': '1.0', - 'base_product_name': 'Base', - 'base_product_version': 42, - }) + compose = helpers.DummyCompose( + self.topdir, + { + "release_name": "Test", + "release_version": "1.0", + "base_product_name": "Base", + "base_product_version": 42, + }, + ) - metadata.write_discinfo(compose, 'x86_64', compose.variants['Server']) + metadata.write_discinfo(compose, "x86_64", compose.variants["Server"]) with open(self.path) as f: - self.assertEqual(f.read().strip().split('\n'), - ['101010101', - 'Test 1.0 for Base 42', - 'x86_64', - 'ALL']) + self.assertEqual( + f.read().strip().split("\n"), + ["101010101", "Test 1.0 for Base 42", "x86_64", "ALL"], + ) def test_write_discinfo_integrated_layered_product(self): - compose = helpers.DummyCompose(self.topdir, { - 'release_name': 'Test', - 'release_version': '1.0', - }) - compose.variants['ILP'] = mock.Mock(uid='Server', arches=['x86_64'], - type='layered-product', is_empty=False, - release_name='Integrated', - release_version='2.1', - parent=compose.variants['Server']) + compose = helpers.DummyCompose( + self.topdir, {"release_name": "Test", "release_version": "1.0"} + ) + compose.variants["ILP"] = mock.Mock( + uid="Server", + arches=["x86_64"], + type="layered-product", + is_empty=False, + release_name="Integrated", + release_version="2.1", + parent=compose.variants["Server"], + ) - metadata.write_discinfo(compose, 'x86_64', compose.variants['ILP']) + metadata.write_discinfo(compose, "x86_64", compose.variants["ILP"]) with open(self.path) as f: - self.assertEqual(f.read().strip().split('\n'), - ['101010101', - 'Integrated 2.1 for Test 1', - 'x86_64', - 'ALL']) + self.assertEqual( + f.read().strip().split("\n"), + ["101010101", "Integrated 2.1 for Test 1", "x86_64", "ALL"], + ) def test_addons_dont_have_discinfo(self): - compose = helpers.DummyCompose(self.topdir, { - 'release_name': 'Test', - 'release_version': '1.0', - }) - compose.variants['ILP'] = mock.Mock(uid='Server', arches=['x86_64'], - type='addon', is_empty=False, - parent=compose.variants['Server']) + compose = helpers.DummyCompose( + self.topdir, {"release_name": "Test", "release_version": "1.0"} + ) + compose.variants["ILP"] = mock.Mock( + uid="Server", + arches=["x86_64"], + type="addon", + is_empty=False, + parent=compose.variants["Server"], + ) - metadata.write_discinfo(compose, 'x86_64', compose.variants['ILP']) + metadata.write_discinfo(compose, "x86_64", compose.variants["ILP"]) self.assertFalse(os.path.isfile(self.path)) class MediaRepoTestCase(helpers.PungiTestCase): - def setUp(self): super(MediaRepoTestCase, self).setUp() - self.path = os.path.join(self.topdir, 'compose/Server/x86_64/os/media.repo') + self.path = os.path.join(self.topdir, "compose/Server/x86_64/os/media.repo") def test_write_media_repo(self): - compose = helpers.DummyCompose(self.topdir, { - 'release_name': 'Test', - 'release_version': '1.0', - }) + compose = helpers.DummyCompose( + self.topdir, {"release_name": "Test", "release_version": "1.0"} + ) - metadata.write_media_repo(compose, 'x86_64', compose.variants['Server'], - timestamp=123456) + metadata.write_media_repo( + compose, "x86_64", compose.variants["Server"], timestamp=123456 + ) with open(self.path) as f: - lines = f.read().strip().split('\n') - self.assertEqual(lines[0], '[InstallMedia]') + lines = f.read().strip().split("\n") + self.assertEqual(lines[0], "[InstallMedia]") six.assertCountEqual( self, lines[1:], @@ -137,15 +145,18 @@ class MediaRepoTestCase(helpers.PungiTestCase): ) def test_addons_dont_have_media_repo(self): - compose = helpers.DummyCompose(self.topdir, { - 'release_name': 'Test', - 'release_version': '1.0', - }) - compose.variants['ILP'] = mock.Mock(uid='Server', arches=['x86_64'], - type='addon', is_empty=False, - parent=compose.variants['Server']) + compose = helpers.DummyCompose( + self.topdir, {"release_name": "Test", "release_version": "1.0"} + ) + compose.variants["ILP"] = mock.Mock( + uid="Server", + arches=["x86_64"], + type="addon", + is_empty=False, + parent=compose.variants["Server"], + ) - metadata.write_discinfo(compose, 'x86_64', compose.variants['ILP']) + metadata.write_discinfo(compose, "x86_64", compose.variants["ILP"]) self.assertFalse(os.path.isfile(self.path)) @@ -155,7 +166,6 @@ BAR_MD5 = {"md5": "37b51d194a7513e45b56f6524f2d51f2"} class TestPopulateExtraFiles(helpers.PungiTestCase): - def setUp(self): super(TestPopulateExtraFiles, self).setUp() self.variant = mock.Mock(uid="Server") @@ -185,12 +195,8 @@ class TestPopulateExtraFiles(helpers.PungiTestCase): self, self.metadata.mock_calls, [ - mock.call.add( - "Server", "x86_64", "Server/x86_64/os/foo", 3, FOO_MD5 - ), - mock.call.add( - "Server", "x86_64", "Server/x86_64/os/bar", 3, BAR_MD5 - ), + mock.call.add("Server", "x86_64", "Server/x86_64/os/foo", 3, FOO_MD5), + mock.call.add("Server", "x86_64", "Server/x86_64/os/bar", 3, BAR_MD5), mock.call.dump_for_tree( mock.ANY, "Server", "x86_64", "Server/x86_64/os/" ), diff --git a/tests/test_notifier.py b/tests/test_notifier.py index b16de5f2..1ebfaed4 100644 --- a/tests/test_notifier.py +++ b/tests/test_notifier.py @@ -5,6 +5,7 @@ import json import mock import os import sys + try: import unittest2 as unittest except ImportError: @@ -18,124 +19,131 @@ mock_datetime.utcnow.return_value = datetime(2017, 6, 28, 9, 34) mock_datetime.side_effect = lambda *args, **kwargs: datetime(*args, **kwargs) -@mock.patch('pungi.util.makedirs') -@mock.patch('pungi.notifier.datetime', new=mock_datetime) +@mock.patch("pungi.util.makedirs") +@mock.patch("pungi.notifier.datetime", new=mock_datetime) class TestNotifier(unittest.TestCase): - def setUp(self): super(TestNotifier, self).setUp() - self.logfile = '/logs/notifications/notification-2017-06-28_09-34-00.log' + self.logfile = "/logs/notifications/notification-2017-06-28_09-34-00.log" self.compose = mock.Mock( - compose_id='COMPOSE_ID', - compose_date='20171031', + compose_id="COMPOSE_ID", + compose_date="20171031", compose_respin=1, - compose_label='Updates-20171031.1021', - compose_type='production', + compose_label="Updates-20171031.1021", + compose_type="production", log_warning=mock.Mock(), conf={ - 'release_name': 'Layer', - 'release_short': 'L', - 'release_version': '27', - 'release_type': 'updates', - 'release_is_layered': True, - 'base_product_name': 'Base', - 'base_product_short': 'B', - 'base_product_version': '1', - 'base_product_type': 'ga', + "release_name": "Layer", + "release_short": "L", + "release_version": "27", + "release_type": "updates", + "release_is_layered": True, + "base_product_name": "Base", + "base_product_short": "B", + "base_product_version": "1", + "base_product_type": "ga", }, paths=mock.Mock( - compose=mock.Mock( - topdir=mock.Mock(return_value='/a/b') - ), - log=mock.Mock( - topdir=mock.Mock(return_value='/logs') - ) - ) + compose=mock.Mock(topdir=mock.Mock(return_value="/a/b")), + log=mock.Mock(topdir=mock.Mock(return_value="/logs")), + ), ) - self.data = {'foo': 'bar', 'baz': 'quux'} + self.data = {"foo": "bar", "baz": "quux"} def _call(self, script, cmd, **kwargs): data = self.data.copy() - data['compose_id'] = 'COMPOSE_ID' - data['location'] = '/a/b' - data['compose_date'] = '20171031' - data['compose_type'] = 'production' - data['compose_respin'] = 1 - data['compose_label'] = 'Updates-20171031.1021' - data['release_short'] = 'L' - data['release_name'] = 'Layer' - data['release_version'] = '27' - data['release_type'] = 'updates' - data['release_is_layered'] = True - data['base_product_name'] = 'Base' - data['base_product_version'] = '1' - data['base_product_short'] = 'B' - data['base_product_type'] = 'ga' + data["compose_id"] = "COMPOSE_ID" + data["location"] = "/a/b" + data["compose_date"] = "20171031" + data["compose_type"] = "production" + data["compose_respin"] = 1 + data["compose_label"] = "Updates-20171031.1021" + data["release_short"] = "L" + data["release_name"] = "Layer" + data["release_version"] = "27" + data["release_type"] = "updates" + data["release_is_layered"] = True + data["base_product_name"] = "Base" + data["base_product_version"] = "1" + data["base_product_short"] = "B" + data["base_product_type"] = "ga" data.update(kwargs) - return mock.call((script, cmd), - stdin_data=json.dumps(data), - can_fail=True, return_stdout=False, - workdir=self.compose.paths.compose.topdir.return_value, - universal_newlines=True, show_cmd=True, logfile=self.logfile) + return mock.call( + (script, cmd), + stdin_data=json.dumps(data), + can_fail=True, + return_stdout=False, + workdir=self.compose.paths.compose.topdir.return_value, + universal_newlines=True, + show_cmd=True, + logfile=self.logfile, + ) - @mock.patch('pungi.util.translate_path') - @mock.patch('kobo.shortcuts.run') + @mock.patch("pungi.util.translate_path") + @mock.patch("kobo.shortcuts.run") def test_invokes_script(self, run, translate_path, makedirs): run.return_value = (0, None) translate_path.side_effect = lambda compose, x: x - n = PungiNotifier(['run-notify']) + n = PungiNotifier(["run-notify"]) n.compose = self.compose - n.send('cmd', **self.data) + n.send("cmd", **self.data) - makedirs.assert_called_once_with('/logs/notifications') - self.assertEqual(run.call_args_list, [self._call('run-notify', 'cmd')]) + makedirs.assert_called_once_with("/logs/notifications") + self.assertEqual(run.call_args_list, [self._call("run-notify", "cmd")]) - @mock.patch('pungi.util.translate_path') - @mock.patch('kobo.shortcuts.run') + @mock.patch("pungi.util.translate_path") + @mock.patch("kobo.shortcuts.run") def test_invokes_multiple_scripts(self, run, translate_path, makedirs): run.return_value = (0, None) translate_path.side_effect = lambda compose, x: x - n = PungiNotifier(['run-notify', 'ping-user']) + n = PungiNotifier(["run-notify", "ping-user"]) n.compose = self.compose - n.send('cmd', **self.data) + n.send("cmd", **self.data) self.assertEqual( sorted(run.call_args_list), - sorted([self._call('run-notify', 'cmd'), - self._call('ping-user', 'cmd')])) + sorted([self._call("run-notify", "cmd"), self._call("ping-user", "cmd")]), + ) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_translates_path(self, run, makedirs): - self.compose.paths.compose.topdir.return_value = '/root/a/b' - self.compose.conf["translate_paths"] = [("/root/", "http://example.com/compose/")] + self.compose.paths.compose.topdir.return_value = "/root/a/b" + self.compose.conf["translate_paths"] = [ + ("/root/", "http://example.com/compose/") + ] run.return_value = (0, None) - n = PungiNotifier(['run-notify']) + n = PungiNotifier(["run-notify"]) n.compose = self.compose - n.send('cmd', **self.data) + n.send("cmd", **self.data) self.assertEqual( run.call_args_list, - [self._call('run-notify', 'cmd', location='http://example.com/compose/a/b')]) + [ + self._call( + "run-notify", "cmd", location="http://example.com/compose/a/b" + ) + ], + ) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_does_not_run_without_config(self, run, makedirs): n = PungiNotifier(None) - n.send('cmd', foo='bar', baz='quux') + n.send("cmd", foo="bar", baz="quux") self.assertFalse(run.called) - @mock.patch('pungi.util.translate_path') - @mock.patch('kobo.shortcuts.run') + @mock.patch("pungi.util.translate_path") + @mock.patch("kobo.shortcuts.run") def test_logs_warning_on_failure(self, run, translate_path, makedirs): translate_path.side_effect = lambda compose, x: x run.return_value = (1, None) - n = PungiNotifier(['run-notify']) + n = PungiNotifier(["run-notify"]) n.compose = self.compose - n.send('cmd', **self.data) + n.send("cmd", **self.data) - self.assertEqual(run.call_args_list, [self._call('run-notify', 'cmd')]) + self.assertEqual(run.call_args_list, [self._call("run-notify", "cmd")]) self.assertTrue(self.compose.log_warning.called) diff --git a/tests/test_orchestrator.py b/tests/test_orchestrator.py index 02809cca..a92d9fde 100644 --- a/tests/test_orchestrator.py +++ b/tests/test_orchestrator.py @@ -730,9 +730,7 @@ class TestPrepareComposeDir(PungiTestCase): self.assertTrue(os.path.isdir(os.path.join(self.topdir, "logs"))) self.assertTrue(os.path.isdir(os.path.join(self.topdir, "parts"))) self.assertTrue(os.path.isdir(os.path.join(self.topdir, "work/global"))) - self.assertFileContent( - os.path.join(self.topdir, "STATUS"), "STARTED" - ) + self.assertFileContent(os.path.join(self.topdir, "STATUS"), "STARTED") def test_restarting_compose(self, gtd): args = mock.Mock(name="args", spec=["label", "compose_path"]) @@ -914,7 +912,7 @@ class TestSendNotification(BaseTestCase): self.assertEqual(len(notif.mock_calls), 2) self.assertEqual(notif.mock_calls[0], mock.call(["handler"])) _, args, kwargs = notif.mock_calls[1] - self.assertEqual(args, ("status-change", )) + self.assertEqual(args, ("status-change",)) self.assertEqual( kwargs, { diff --git a/tests/test_osbs_phase.py b/tests/test_osbs_phase.py index 6aef4767..43d06430 100644 --- a/tests/test_osbs_phase.py +++ b/tests/test_osbs_phase.py @@ -13,13 +13,10 @@ from pungi.phases import osbs class OSBSPhaseTest(helpers.PungiTestCase): - - @mock.patch('pungi.phases.osbs.ThreadPool') + @mock.patch("pungi.phases.osbs.ThreadPool") def test_run(self, ThreadPool): cfg = helpers.IterableMock() - compose = helpers.DummyCompose(self.topdir, { - 'osbs': {'^Everything$': cfg} - }) + compose = helpers.DummyCompose(self.topdir, {"osbs": {"^Everything$": cfg}}) pool = ThreadPool.return_value @@ -27,10 +24,12 @@ class OSBSPhaseTest(helpers.PungiTestCase): phase.run() self.assertEqual(len(pool.add.call_args_list), 1) - self.assertEqual(pool.queue_put.call_args_list, - [mock.call((compose, compose.variants['Everything'], cfg))]) + self.assertEqual( + pool.queue_put.call_args_list, + [mock.call((compose, compose.variants["Everything"], cfg))], + ) - @mock.patch('pungi.phases.osbs.ThreadPool') + @mock.patch("pungi.phases.osbs.ThreadPool") def test_skip_without_config(self, ThreadPool): compose = helpers.DummyCompose(self.topdir, {}) compose.just_phases = None @@ -38,11 +37,9 @@ class OSBSPhaseTest(helpers.PungiTestCase): phase = osbs.OSBSPhase(compose) self.assertTrue(phase.skip()) - @mock.patch('pungi.phases.osbs.ThreadPool') + @mock.patch("pungi.phases.osbs.ThreadPool") def test_dump_metadata(self, ThreadPool): - compose = helpers.DummyCompose(self.topdir, { - 'osbs': {'^Everything$': {}} - }) + compose = helpers.DummyCompose(self.topdir, {"osbs": {"^Everything$": {}}}) compose.just_phases = None compose.skip_phases = [] compose.notifier = mock.Mock() @@ -52,11 +49,11 @@ class OSBSPhaseTest(helpers.PungiTestCase): phase.pool.metadata = METADATA phase.dump_metadata() - with open(self.topdir + '/compose/metadata/osbs.json') as f: + with open(self.topdir + "/compose/metadata/osbs.json") as f: data = json.load(f) self.assertEqual(data, METADATA) - @mock.patch('pungi.phases.osbs.ThreadPool') + @mock.patch("pungi.phases.osbs.ThreadPool") def test_dump_metadata_after_skip(self, ThreadPool): compose = helpers.DummyCompose(self.topdir, {}) compose.just_phases = None @@ -66,13 +63,11 @@ class OSBSPhaseTest(helpers.PungiTestCase): phase.stop() phase.dump_metadata() - self.assertFalse(os.path.isfile(self.topdir + '/compose/metadata/osbs.json')) + self.assertFalse(os.path.isfile(self.topdir + "/compose/metadata/osbs.json")) @mock.patch("pungi.phases.osbs.ThreadPool") def test_request_push(self, ThreadPool): - compose = helpers.DummyCompose(self.topdir, { - "osbs": {"^Everything$": {}} - }) + compose = helpers.DummyCompose(self.topdir, {"osbs": {"^Everything$": {}}}) compose.just_phases = None compose.skip_phases = [] compose.notifier = mock.Mock() @@ -87,112 +82,124 @@ class OSBSPhaseTest(helpers.PungiTestCase): self.assertEqual(data, phase.pool.registries) self.assertEqual( - compose.notifier.call_args_list, - [], + compose.notifier.call_args_list, [], ) TASK_RESULT = { - 'koji_builds': ['54321'], - 'repositories': [ - 'registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632', - ] + "koji_builds": ["54321"], + "repositories": [ + "registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632", + ], } BUILD_INFO = { - 'completion_time': '2016-06-17 18:25:30', - 'completion_ts': 1466187930.0, - 'creation_event_id': 13227702, - 'creation_time': '2016-06-17 18:25:57.611172', - 'creation_ts': 1466187957.61117, - 'epoch': None, - 'extra': {'container_koji_task_id': '12345', 'image': {}}, - 'id': 54321, - 'name': 'my-name', - 'nvr': 'my-name-1.0-1', - 'owner_id': 3436, - 'owner_name': 'osbs', - 'package_id': 50072, - 'package_name': 'my-name', - 'release': '1', - 'source': 'git://example.com/repo?#BEEFCAFE', - 'start_time': '2016-06-17 18:16:37', - 'start_ts': 1466187397.0, - 'state': 1, - 'task_id': None, - 'version': '1.0', - 'volume_id': 0, - 'volume_name': 'DEFAULT' + "completion_time": "2016-06-17 18:25:30", + "completion_ts": 1466187930.0, + "creation_event_id": 13227702, + "creation_time": "2016-06-17 18:25:57.611172", + "creation_ts": 1466187957.61117, + "epoch": None, + "extra": {"container_koji_task_id": "12345", "image": {}}, + "id": 54321, + "name": "my-name", + "nvr": "my-name-1.0-1", + "owner_id": 3436, + "owner_name": "osbs", + "package_id": 50072, + "package_name": "my-name", + "release": "1", + "source": "git://example.com/repo?#BEEFCAFE", + "start_time": "2016-06-17 18:16:37", + "start_ts": 1466187397.0, + "state": 1, + "task_id": None, + "version": "1.0", + "volume_id": 0, + "volume_name": "DEFAULT", } ARCHIVES = [ - {'build_id': 54321, - 'buildroot_id': 2955357, - 'checksum': 'a2922842dc80873ac782da048c54f6cc', - 'checksum_type': 0, - 'extra': { - 'docker': { - 'id': '408c4cd37a87a807bec65dd13b049a32fe090d2fa1a8e891f65e3e3e683996d7', - 'parent_id': '6c3a84d798dc449313787502060b6d5b4694d7527d64a7c99ba199e3b2df834e', - 'repositories': ['registry.example.com:8888/rcm/buildroot:1.0-1']}, - 'image': {'arch': 'x86_64'}}, - 'filename': 'docker-image-408c4cd37a87a807bec65dd13b049a32fe090d2fa1a8e891f65e3e3e683996d7.x86_64.tar.gz', - 'id': 1436049, - 'metadata_only': False, - 'size': 174038795, - 'type_description': 'Tar file', - 'type_extensions': 'tar tar.gz tar.bz2 tar.xz', - 'type_id': 4, - 'type_name': 'tar'} + { + "build_id": 54321, + "buildroot_id": 2955357, + "checksum": "a2922842dc80873ac782da048c54f6cc", + "checksum_type": 0, + "extra": { + "docker": { + "id": "408c4cd37a87a807bec65dd13b049a32fe090d2fa1a8e891f65e3e3e683996d7", + "parent_id": "6c3a84d798dc449313787502060b6d5b4694d7527d64a7c99ba199e3b2df834e", + "repositories": ["registry.example.com:8888/rcm/buildroot:1.0-1"], + }, + "image": {"arch": "x86_64"}, + }, + "filename": "docker-image-408c4cd37a87a807bec65dd13b049a32fe090d2fa1a8e891f65e3e3e683996d7.x86_64.tar.gz", + "id": 1436049, + "metadata_only": False, + "size": 174038795, + "type_description": "Tar file", + "type_extensions": "tar tar.gz tar.bz2 tar.xz", + "type_id": 4, + "type_name": "tar", + } ] METADATA = { - 'Server': {'x86_64': [{ - 'name': 'my-name', - 'version': '1.0', - 'release': '1', - 'nvr': 'my-name-1.0-1', - 'creation_time': BUILD_INFO['creation_time'], - 'filename': ARCHIVES[0]['filename'], - 'size': ARCHIVES[0]['size'], - 'docker': { - 'id': '408c4cd37a87a807bec65dd13b049a32fe090d2fa1a8e891f65e3e3e683996d7', - 'parent_id': '6c3a84d798dc449313787502060b6d5b4694d7527d64a7c99ba199e3b2df834e', - 'repositories': ['registry.example.com:8888/rcm/buildroot:1.0-1']}, - 'image': {'arch': 'x86_64'}, - 'checksum': ARCHIVES[0]['checksum'], - }]} + "Server": { + "x86_64": [ + { + "name": "my-name", + "version": "1.0", + "release": "1", + "nvr": "my-name-1.0-1", + "creation_time": BUILD_INFO["creation_time"], + "filename": ARCHIVES[0]["filename"], + "size": ARCHIVES[0]["size"], + "docker": { + "id": "408c4cd37a87a807bec65dd13b049a32fe090d2fa1a8e891f65e3e3e683996d7", + "parent_id": "6c3a84d798dc449313787502060b6d5b4694d7527d64a7c99ba199e3b2df834e", + "repositories": ["registry.example.com:8888/rcm/buildroot:1.0-1"], + }, + "image": {"arch": "x86_64"}, + "checksum": ARCHIVES[0]["checksum"], + } + ] + } } SCRATCH_TASK_RESULT = { - 'koji_builds': [], - 'repositories': [ - 'registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632', - ] + "koji_builds": [], + "repositories": [ + "registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632", + ], } SCRATCH_METADATA = { - "Server": {'scratch': [{ - "koji_task": 12345, - "repositories": [ - 'registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632', + "Server": { + "scratch": [ + { + "koji_task": 12345, + "repositories": [ + "registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632", + ], + } ] - }]} + } } class OSBSThreadTest(helpers.PungiTestCase): - def setUp(self): super(OSBSThreadTest, self).setUp() self.pool = mock.Mock(metadata={}, registries={}) self.t = osbs.OSBSThread(self.pool) - self.compose = helpers.DummyCompose(self.topdir, { - 'koji_profile': 'koji', - 'translate_paths': [ - (self.topdir, 'http://root'), - ] - }) + self.compose = helpers.DummyCompose( + self.topdir, + { + "koji_profile": "koji", + "translate_paths": [(self.topdir, "http://root")], + }, + ) def _setupMock(self, KojiWrapper, scratch=False): self.wrapper = KojiWrapper.return_value @@ -203,7 +210,10 @@ class OSBSThreadTest(helpers.PungiTestCase): self.wrapper.koji_proxy.getTaskResult.return_value = TASK_RESULT self.wrapper.koji_proxy.getBuild.return_value = BUILD_INFO self.wrapper.koji_proxy.listArchives.return_value = ARCHIVES - self.wrapper.koji_proxy.getLatestBuilds.return_value = [mock.Mock(), mock.Mock()] + self.wrapper.koji_proxy.getLatestBuilds.return_value = [ + mock.Mock(), + mock.Mock(), + ] self.wrapper.koji_proxy.getNextRelease.return_value = 3 self.wrapper.watch_task.return_value = 0 @@ -211,149 +221,168 @@ class OSBSThreadTest(helpers.PungiTestCase): self.maxDiff = None if scratch: metadata = copy.deepcopy(SCRATCH_METADATA) - metadata['Server']['scratch'][0]['compose_id'] = self.compose.compose_id - metadata['Server']['scratch'][0]['koji_task'] = 12345 + metadata["Server"]["scratch"][0]["compose_id"] = self.compose.compose_id + metadata["Server"]["scratch"][0]["koji_task"] = 12345 else: metadata = copy.deepcopy(METADATA) - metadata['Server']['x86_64'][0]['compose_id'] = self.compose.compose_id - metadata['Server']['x86_64'][0]['koji_task'] = 12345 + metadata["Server"]["x86_64"][0]["compose_id"] = self.compose.compose_id + metadata["Server"]["x86_64"][0]["koji_task"] = 12345 self.assertEqual(self.pool.metadata, metadata) def _assertCorrectCalls(self, opts, setupCalls=None, scratch=False): setupCalls = setupCalls or [] - options = {'yum_repourls': ['http://root/work/global/tmp-Server/compose-rpms-Server-1.repo']} + options = { + "yum_repourls": [ + "http://root/work/global/tmp-Server/compose-rpms-Server-1.repo" + ] + } if scratch: - options['scratch'] = True + options["scratch"] = True options.update(opts) expect_calls = [mock.call.login()] + setupCalls - expect_calls.extend([ - mock.call.koji_proxy.buildContainer( - 'git://example.com/repo?#BEEFCAFE', - 'f24-docker-candidate', - options, - priority=None), - mock.call.watch_task( - 12345, self.topdir + '/logs/global/osbs/Server-1-watch-task.log'), - mock.call.koji_proxy.getTaskResult(12345)]) + expect_calls.extend( + [ + mock.call.koji_proxy.buildContainer( + "git://example.com/repo?#BEEFCAFE", + "f24-docker-candidate", + options, + priority=None, + ), + mock.call.watch_task( + 12345, self.topdir + "/logs/global/osbs/Server-1-watch-task.log" + ), + mock.call.koji_proxy.getTaskResult(12345), + ] + ) if not scratch: - expect_calls.extend([mock.call.koji_proxy.getBuild(54321), - mock.call.koji_proxy.listArchives(54321)]) + expect_calls.extend( + [ + mock.call.koji_proxy.getBuild(54321), + mock.call.koji_proxy.listArchives(54321), + ] + ) self.assertEqual(self.wrapper.mock_calls, expect_calls) def _assertRepoFile(self, variants=None, gpgkey=None): - variants = variants or ['Server'] + variants = variants or ["Server"] for variant in variants: - with open(self.topdir + '/work/global/tmp-%s/compose-rpms-%s-1.repo' % (variant, variant)) as f: - lines = f.read().split('\n') - self.assertIn('baseurl=http://root/compose/%s/$basearch/os' % variant, lines) + with open( + self.topdir + + "/work/global/tmp-%s/compose-rpms-%s-1.repo" % (variant, variant) + ) as f: + lines = f.read().split("\n") + self.assertIn( + "baseurl=http://root/compose/%s/$basearch/os" % variant, lines + ) if gpgkey: - self.assertIn('gpgcheck=1', lines) - self.assertIn('gpgkey=%s' % gpgkey, lines) + self.assertIn("gpgcheck=1", lines) + self.assertIn("gpgkey=%s" % gpgkey, lines) def _assertConfigCorrect(self, cfg): config = copy.deepcopy(self.compose.conf) - config['osbs'] = { - '^Server$': cfg - } + config["osbs"] = {"^Server$": cfg} self.assertEqual(([], []), checks.validate(config, offline=True)) def _assertConfigMissing(self, cfg, key): config = copy.deepcopy(self.compose.conf) - config['osbs'] = { - '^Server$': cfg - } + config["osbs"] = {"^Server$": cfg} errors, warnings = checks.validate(config, offline=True) self.assertIn( - "Failed validation in osbs.^Server$: %r is not valid under any of the given schemas" % cfg, + "Failed validation in osbs.^Server$: %r is not valid under any of the given schemas" + % cfg, errors, ) self.assertIn(" Possible reason: %r is a required property" % key, errors) self.assertEqual([], warnings) - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_minimal_run(self, KojiWrapper): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'f24-docker-candidate', - 'git_branch': 'f24-docker', + "url": "git://example.com/repo?#BEEFCAFE", + "target": "f24-docker-candidate", + "git_branch": "f24-docker", } self._setupMock(KojiWrapper) self._assertConfigCorrect(cfg) - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) - self._assertCorrectCalls({'git_branch': 'f24-docker'}) + self._assertCorrectCalls({"git_branch": "f24-docker"}) self._assertCorrectMetadata() self._assertRepoFile() - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_run_failable(self, KojiWrapper): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'f24-docker-candidate', - 'git_branch': 'f24-docker', - 'failable': ['*'] + "url": "git://example.com/repo?#BEEFCAFE", + "target": "f24-docker-candidate", + "git_branch": "f24-docker", + "failable": ["*"], } self._setupMock(KojiWrapper) self._assertConfigCorrect(cfg) - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) - self._assertCorrectCalls({'git_branch': 'f24-docker'}) + self._assertCorrectCalls({"git_branch": "f24-docker"}) self._assertCorrectMetadata() self._assertRepoFile() - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_run_with_more_args(self, KojiWrapper): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'f24-docker-candidate', - 'git_branch': 'f24-docker', - 'name': 'my-name', - 'version': '1.0', + "url": "git://example.com/repo?#BEEFCAFE", + "target": "f24-docker-candidate", + "git_branch": "f24-docker", + "name": "my-name", + "version": "1.0", } self._setupMock(KojiWrapper) self._assertConfigCorrect(cfg) - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) - self._assertCorrectCalls({'name': 'my-name', 'version': '1.0', 'git_branch': 'f24-docker'}) + self._assertCorrectCalls( + {"name": "my-name", "version": "1.0", "git_branch": "f24-docker"} + ) self._assertCorrectMetadata() self._assertRepoFile() - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_run_with_extra_repos(self, KojiWrapper): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'f24-docker-candidate', - 'git_branch': 'f24-docker', - 'name': 'my-name', - 'version': '1.0', + "url": "git://example.com/repo?#BEEFCAFE", + "target": "f24-docker-candidate", + "git_branch": "f24-docker", + "name": "my-name", + "version": "1.0", "repo": ["Everything", "http://pkgs.example.com/my.repo", "/extra/repo"], } self.compose.conf["translate_paths"].append(("/extra", "http://example.com")) self._setupMock(KojiWrapper) self._assertConfigCorrect(cfg) - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) options = { - 'name': 'my-name', - 'version': '1.0', - 'git_branch': 'f24-docker', - 'yum_repourls': [ - 'http://root/work/global/tmp-Server/compose-rpms-Server-1.repo', - 'http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo', - 'http://pkgs.example.com/my.repo', + "name": "my-name", + "version": "1.0", + "git_branch": "f24-docker", + "yum_repourls": [ + "http://root/work/global/tmp-Server/compose-rpms-Server-1.repo", + "http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo", + "http://pkgs.example.com/my.repo", "http://root/work/global/tmp/compose-rpms-local-1.repo", - ] + ], } self._assertCorrectCalls(options) self._assertCorrectMetadata() - self._assertRepoFile(['Server', 'Everything']) + self._assertRepoFile(["Server", "Everything"]) - with open(os.path.join(self.topdir, "work/global/tmp/compose-rpms-local-1.repo")) as f: + with open( + os.path.join(self.topdir, "work/global/tmp/compose-rpms-local-1.repo") + ) as f: self.assertIn("baseurl=http://example.com/repo\n", f) @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") @@ -380,7 +409,7 @@ class OSBSThreadTest(helpers.PungiTestCase): "http://root/work/global/tmp-Server/compose-rpms-Server-1.repo", "http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo", "http://pkgs.example.com/my.repo", - ] + ], } self._assertCorrectCalls(options) self._assertCorrectMetadata() @@ -411,146 +440,148 @@ class OSBSThreadTest(helpers.PungiTestCase): "http://root/work/global/tmp-Server/compose-rpms-Server-1.repo", "http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo", "http://pkgs.example.com/my.repo", - ] + ], } self._assertCorrectCalls(options) self._assertCorrectMetadata() self._assertRepoFile(["Server", "Everything"]) self.assertEqual(self.t.pool.registries, {"my-name-1.0-1": [{"foo": "bar"}]}) - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_run_with_extra_repos_in_list(self, KojiWrapper): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'f24-docker-candidate', - 'git_branch': 'f24-docker', - 'name': 'my-name', - 'version': '1.0', - 'repo': ['Everything', 'Client', 'http://pkgs.example.com/my.repo'], + "url": "git://example.com/repo?#BEEFCAFE", + "target": "f24-docker-candidate", + "git_branch": "f24-docker", + "name": "my-name", + "version": "1.0", + "repo": ["Everything", "Client", "http://pkgs.example.com/my.repo"], } self._assertConfigCorrect(cfg) self._setupMock(KojiWrapper) - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) options = { - 'name': 'my-name', - 'version': '1.0', - 'git_branch': 'f24-docker', - 'yum_repourls': [ - 'http://root/work/global/tmp-Server/compose-rpms-Server-1.repo', - 'http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo', - 'http://root/work/global/tmp-Client/compose-rpms-Client-1.repo', - 'http://pkgs.example.com/my.repo', - ] + "name": "my-name", + "version": "1.0", + "git_branch": "f24-docker", + "yum_repourls": [ + "http://root/work/global/tmp-Server/compose-rpms-Server-1.repo", + "http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo", + "http://root/work/global/tmp-Client/compose-rpms-Client-1.repo", + "http://pkgs.example.com/my.repo", + ], } self._assertCorrectCalls(options) self._assertCorrectMetadata() - self._assertRepoFile(['Server', 'Everything', 'Client']) + self._assertRepoFile(["Server", "Everything", "Client"]) - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_run_with_gpgkey_enabled(self, KojiWrapper): - gpgkey = 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release' + gpgkey = "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'f24-docker-candidate', - 'git_branch': 'f24-docker', - 'name': 'my-name', - 'version': '1.0', - 'repo': ['Everything', 'Client', 'http://pkgs.example.com/my.repo'], - 'gpgkey': gpgkey, + "url": "git://example.com/repo?#BEEFCAFE", + "target": "f24-docker-candidate", + "git_branch": "f24-docker", + "name": "my-name", + "version": "1.0", + "repo": ["Everything", "Client", "http://pkgs.example.com/my.repo"], + "gpgkey": gpgkey, } self._assertConfigCorrect(cfg) self._setupMock(KojiWrapper) - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) - self._assertRepoFile(['Server', 'Everything', 'Client'], gpgkey=gpgkey) + self._assertRepoFile(["Server", "Everything", "Client"], gpgkey=gpgkey) - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_run_with_extra_repos_missing_variant(self, KojiWrapper): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'f24-docker-candidate', - 'git_branch': 'f24-docker', - 'name': 'my-name', - 'version': '1.0', - 'repo': 'Gold', + "url": "git://example.com/repo?#BEEFCAFE", + "target": "f24-docker-candidate", + "git_branch": "f24-docker", + "name": "my-name", + "version": "1.0", + "repo": "Gold", } self._assertConfigCorrect(cfg) self._setupMock(KojiWrapper) with self.assertRaises(RuntimeError) as ctx: - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) - self.assertIn('no variant Gold', str(ctx.exception)) + self.assertIn("no variant Gold", str(ctx.exception)) def test_run_with_missing_url(self): cfg = { - 'target': 'f24-docker-candidate', - 'git_branch': 'f24-docker', - 'name': 'my-name', + "target": "f24-docker-candidate", + "git_branch": "f24-docker", + "name": "my-name", } - self._assertConfigMissing(cfg, 'url') + self._assertConfigMissing(cfg, "url") def test_run_with_missing_target(self): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'git_branch': 'f24-docker', - 'name': 'my-name', + "url": "git://example.com/repo?#BEEFCAFE", + "git_branch": "f24-docker", + "name": "my-name", } - self._assertConfigMissing(cfg, 'target') + self._assertConfigMissing(cfg, "target") def test_run_with_missing_git_branch(self): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'f24-docker-candidate', + "url": "git://example.com/repo?#BEEFCAFE", + "target": "f24-docker-candidate", } - self._assertConfigMissing(cfg, 'git_branch') + self._assertConfigMissing(cfg, "git_branch") - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_failing_task(self, KojiWrapper): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'fedora-24-docker-candidate', - 'git_branch': 'f24-docker', + "url": "git://example.com/repo?#BEEFCAFE", + "target": "fedora-24-docker-candidate", + "git_branch": "f24-docker", } self._assertConfigCorrect(cfg) self._setupMock(KojiWrapper) self.wrapper.watch_task.return_value = 1 with self.assertRaises(RuntimeError) as ctx: - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) - self.assertRegexpMatches(str(ctx.exception), r"task 12345 failed: see .+ for details") + self.assertRegexpMatches( + str(ctx.exception), r"task 12345 failed: see .+ for details" + ) - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_failing_task_with_failable(self, KojiWrapper): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'fedora-24-docker-candidate', - 'git_branch': 'f24-docker', - 'failable': ['*'] + "url": "git://example.com/repo?#BEEFCAFE", + "target": "fedora-24-docker-candidate", + "git_branch": "f24-docker", + "failable": ["*"], } self._assertConfigCorrect(cfg) self._setupMock(KojiWrapper) self.wrapper.watch_task.return_value = 1 - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) - @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper") def test_scratch_metadata(self, KojiWrapper): cfg = { - 'url': 'git://example.com/repo?#BEEFCAFE', - 'target': 'f24-docker-candidate', - 'git_branch': 'f24-docker', - 'scratch': True, + "url": "git://example.com/repo?#BEEFCAFE", + "target": "f24-docker-candidate", + "git_branch": "f24-docker", + "scratch": True, } self._setupMock(KojiWrapper, scratch=True) self._assertConfigCorrect(cfg) - self.t.process((self.compose, self.compose.variants['Server'], cfg), 1) + self.t.process((self.compose, self.compose.variants["Server"], cfg), 1) - self._assertCorrectCalls({'git_branch': 'f24-docker'}, scratch=True) + self._assertCorrectCalls({"git_branch": "f24-docker"}, scratch=True) self._assertCorrectMetadata(scratch=True) self._assertRepoFile() diff --git a/tests/test_ostree_installer_phase.py b/tests/test_ostree_installer_phase.py index 6542a24a..7f870fe6 100644 --- a/tests/test_ostree_installer_phase.py +++ b/tests/test_ostree_installer_phase.py @@ -12,21 +12,21 @@ from pungi.phases import ostree_installer as ostree from six.moves import shlex_quote -LOG_PATH = 'logs/x86_64/Everything/ostree_installer-1' +LOG_PATH = "logs/x86_64/Everything/ostree_installer-1" class OstreeInstallerPhaseTest(helpers.PungiTestCase): - - @mock.patch('pungi.phases.ostree_installer.ThreadPool') + @mock.patch("pungi.phases.ostree_installer.ThreadPool") def test_run(self, ThreadPool): cfg = helpers.IterableMock() - compose = helpers.DummyCompose(self.topdir, { - 'ostree_installer': [ - ('^Everything$', {'x86_64': cfg}) - ], - 'runroot': True, - "translate_paths": [(self.topdir + "/work", "http://example.com/work")], - }) + compose = helpers.DummyCompose( + self.topdir, + { + "ostree_installer": [("^Everything$", {"x86_64": cfg})], + "runroot": True, + "translate_paths": [(self.topdir + "/work", "http://example.com/work")], + }, + ) pool = ThreadPool.return_value @@ -43,10 +43,12 @@ class OstreeInstallerPhaseTest(helpers.PungiTestCase): "http://example.com/work/$basearch/repo/p2", ], ) - self.assertEqual(pool.queue_put.call_args_list, - [mock.call((compose, compose.variants['Everything'], 'x86_64', cfg))]) + self.assertEqual( + pool.queue_put.call_args_list, + [mock.call((compose, compose.variants["Everything"], "x86_64", cfg))], + ) - @mock.patch('pungi.phases.ostree_installer.ThreadPool') + @mock.patch("pungi.phases.ostree_installer.ThreadPool") def test_skip_without_config(self, ThreadPool): compose = helpers.DummyCompose(self.topdir, {}) compose.just_phases = None @@ -55,11 +57,9 @@ class OstreeInstallerPhaseTest(helpers.PungiTestCase): self.assertTrue(phase.skip()) def test_validate_conflict_with_buildinstall(self): - compose = helpers.DummyCompose(self.topdir, { - 'ostree_installer': [ - ('^Server$', {'x86_64': mock.Mock()}) - ], - }) + compose = helpers.DummyCompose( + self.topdir, {"ostree_installer": [("^Server$", {"x86_64": mock.Mock()})]} + ) skipmock = mock.Mock() skipmock.skip.return_value = False @@ -67,326 +67,399 @@ class OstreeInstallerPhaseTest(helpers.PungiTestCase): with self.assertRaises(ValueError) as ctx: phase.validate() - self.assertEqual(str(ctx.exception), - 'Can not generate ostree installer for Server.x86_64:' - ' it has buildinstall running already and the files' - ' would clash.') + self.assertEqual( + str(ctx.exception), + "Can not generate ostree installer for Server.x86_64:" + " it has buildinstall running already and the files" + " would clash.", + ) def test_validate_buildinstall_skipped(self): - compose = helpers.DummyCompose(self.topdir, { - 'ostree_installer': [ - ('^Server$', {'x86_64': mock.Mock()}) - ], - }) + compose = helpers.DummyCompose( + self.topdir, {"ostree_installer": [("^Server$", {"x86_64": mock.Mock()})]} + ) phase = ostree.OstreeInstallerPhase(compose, mock.Mock(_skipped=True)) phase.validate() def test_validate_overwrite_enabled(self): - compose = helpers.DummyCompose(self.topdir, { - 'ostree_installer_overwrite': True, - 'ostree_installer': [ - ('^Server$', {'x86_64': mock.Mock()}) - ], - }) + compose = helpers.DummyCompose( + self.topdir, + { + "ostree_installer_overwrite": True, + "ostree_installer": [("^Server$", {"x86_64": mock.Mock()})], + }, + ) phase = ostree.OstreeInstallerPhase(compose, mock.Mock(_skipped=False)) phase.validate() class OstreeThreadTest(helpers.PungiTestCase): - def setUp(self): super(OstreeThreadTest, self).setUp() - self.compose = helpers.DummyCompose(self.topdir, { - 'release_name': 'Fedora', - 'release_version': 'Rawhide', - 'koji_profile': 'koji', - 'runroot_tag': 'rrt', - 'image_volid_formats': ['{release_short}-{variant}-{arch}'], - 'translate_paths': [ - (self.topdir + '/work', 'http://example.com/work') - ], - }) + self.compose = helpers.DummyCompose( + self.topdir, + { + "release_name": "Fedora", + "release_version": "Rawhide", + "koji_profile": "koji", + "runroot_tag": "rrt", + "image_volid_formats": ["{release_short}-{variant}-{arch}"], + "translate_paths": [(self.topdir + "/work", "http://example.com/work")], + }, + ) def assertImageAdded(self, compose, ImageCls, iso): image = ImageCls.return_value - self.assertEqual(image.path, 'Everything/x86_64/iso/image-name') + self.assertEqual(image.path, "Everything/x86_64/iso/image-name") self.assertEqual(image.mtime, 13579) self.assertEqual(image.size, 1024) - self.assertEqual(image.arch, 'x86_64') + self.assertEqual(image.arch, "x86_64") self.assertEqual(image.type, "dvd-ostree") self.assertEqual(image.format, "iso") self.assertEqual(image.disc_number, 1) self.assertEqual(image.disc_count, 1) self.assertEqual(image.bootable, True) self.assertEqual(image.implant_md5, iso.get_implanted_md5.return_value) - self.assertEqual(compose.im.add.mock_calls, - [mock.call('Everything', 'x86_64', image)]) + self.assertEqual( + compose.im.add.mock_calls, [mock.call("Everything", "x86_64", image)] + ) - def assertRunrootCall(self, koji, sources, release, isfinal=False, extra=[], - extra_pkgs=[], weight=None): + def assertRunrootCall( + self, + koji, + sources, + release, + isfinal=False, + extra=[], + extra_pkgs=[], + weight=None, + ): lorax_cmd = [ - 'lorax', - '--product=Fedora', - '--version=Rawhide', - '--release=%s' % release, + "lorax", + "--product=Fedora", + "--version=Rawhide", + "--release=%s" % release, ] for s in force_list(sources): - lorax_cmd.append(shlex_quote('--source=%s' % s)) + lorax_cmd.append(shlex_quote("--source=%s" % s)) - lorax_cmd.append('--variant=Everything') - lorax_cmd.append('--nomacboot') + lorax_cmd.append("--variant=Everything") + lorax_cmd.append("--nomacboot") if isfinal: - lorax_cmd.append('--isfinal') + lorax_cmd.append("--isfinal") lorax_cmd.append("--buildarch=x86_64") - lorax_cmd.append('--volid=test-Everything-x86_64') + lorax_cmd.append("--volid=test-Everything-x86_64") if extra: lorax_cmd.extend(extra) - outdir = self.topdir + '/work/x86_64/Everything/ostree_installer' + outdir = self.topdir + "/work/x86_64/Everything/ostree_installer" lorax_cmd.append(outdir) - self.assertEqual(koji.get_runroot_cmd.call_args_list, - [mock.call('rrt', 'x86_64', - 'rm -rf %s && %s' % (outdir, ' '.join(lorax_cmd)), - channel=None, mounts=[self.topdir], - packages=['pungi', 'lorax', 'ostree'] + extra_pkgs, - use_shell=True, weight=weight, - chown_paths=[outdir])]) - self.assertEqual(koji.run_runroot_cmd.call_args_list, - [mock.call(koji.get_runroot_cmd.return_value, - log_file=os.path.join(self.topdir, LOG_PATH, "runroot.log"))]) + self.assertEqual( + koji.get_runroot_cmd.call_args_list, + [ + mock.call( + "rrt", + "x86_64", + "rm -rf %s && %s" % (outdir, " ".join(lorax_cmd)), + channel=None, + mounts=[self.topdir], + packages=["pungi", "lorax", "ostree"] + extra_pkgs, + use_shell=True, + weight=weight, + chown_paths=[outdir], + ) + ], + ) + self.assertEqual( + koji.run_runroot_cmd.call_args_list, + [ + mock.call( + koji.get_runroot_cmd.return_value, + log_file=os.path.join(self.topdir, LOG_PATH, "runroot.log"), + ) + ], + ) def assertIsoLinked(self, link, get_file_size, get_mtime, final_iso_path): - self.assertEqual(link.call_args_list, - [mock.call(self.topdir + '/work/x86_64/Everything/ostree_installer/images/boot.iso', - final_iso_path)]) + self.assertEqual( + link.call_args_list, + [ + mock.call( + self.topdir + + "/work/x86_64/Everything/ostree_installer/images/boot.iso", + final_iso_path, + ) + ], + ) 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, 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(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))]) + 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( + 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('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @mock.patch('os.link') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_run(self, KojiWrapper, link, iso, - get_file_size, get_mtime, ImageCls, copy_all): + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @mock.patch("os.link") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + def test_run( + self, KojiWrapper, link, iso, get_file_size, get_mtime, ImageCls, copy_all + ): self.compose.supported = False pool = mock.Mock() cfg = { - 'repo': 'Everything', # this variant-type repo is deprecated, in result will be replaced with default repo - 'release': '20160321.n.0', + "repo": "Everything", # this variant-type repo is deprecated, in result will be replaced with default repo + "release": "20160321.n.0", } koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': 'Foo bar\n', + "task_id": 1234, + "retcode": 0, + "output": "Foo bar\n", } get_file_size.return_value = 1024 get_mtime.return_value = 13579 - final_iso_path = self.topdir + '/compose/Everything/x86_64/iso/image-name' + final_iso_path = self.topdir + "/compose/Everything/x86_64/iso/image-name" t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) - self.assertRunrootCall(koji, - ["http://example.com/repo/1", - 'http://example.com/work/$basearch/comps_repo_Everything'], - cfg['release'], - extra=['--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)]) + self.assertRunrootCall( + koji, + [ + "http://example.com/repo/1", + "http://example.com/work/$basearch/comps_repo_Everything", + ], + cfg["release"], + 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(copy_all) - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @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, copy_all): + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @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, copy_all + ): pool = mock.Mock() cfg = { - 'repo': 'http://example.com/repo/$arch/', - 'release': '20160321.n.0', + "repo": "http://example.com/repo/$arch/", + "release": "20160321.n.0", } koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': 'Foo bar\n', + "task_id": 1234, + "retcode": 0, + "output": "Foo bar\n", } get_file_size.return_value = 1024 get_mtime.return_value = 13579 - final_iso_path = self.topdir + '/compose/Everything/x86_64/iso/image-name' + final_iso_path = self.topdir + "/compose/Everything/x86_64/iso/image-name" t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) - self.assertRunrootCall(koji, - ('http://example.com/repo/x86_64/', - "http://example.com/repo/1", - 'http://example.com/work/$basearch/comps_repo_Everything'), - cfg['release'], - isfinal=True, - extra=['--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)]) + self.assertRunrootCall( + koji, + ( + "http://example.com/repo/x86_64/", + "http://example.com/repo/1", + "http://example.com/work/$basearch/comps_repo_Everything", + ), + cfg["release"], + isfinal=True, + 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(copy_all) - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @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, copy_all): + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @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, copy_all + ): pool = mock.Mock() cfg = { - 'release': '20160321.n.0', - 'repo': [ - 'Everything', # this variant-type repo is deprecated, in result will be replaced with default repo - 'https://example.com/extra-repo1.repo', - 'https://example.com/extra-repo2.repo', + "release": "20160321.n.0", + "repo": [ + "Everything", # this variant-type repo is deprecated, in result will be replaced with default repo + "https://example.com/extra-repo1.repo", + "https://example.com/extra-repo2.repo", ], } koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': 'Foo bar\n', + "task_id": 1234, + "retcode": 0, + "output": "Foo bar\n", } t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) sources = [ - 'https://example.com/extra-repo1.repo', - 'https://example.com/extra-repo2.repo', + "https://example.com/extra-repo1.repo", + "https://example.com/extra-repo2.repo", "http://example.com/repo/1", - 'http://example.com/work/$basearch/comps_repo_Everything', + "http://example.com/work/$basearch/comps_repo_Everything", ] - self.assertRunrootCall(koji, sources, cfg['release'], isfinal=True, - extra=['--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)]) + self.assertRunrootCall( + koji, + sources, + cfg["release"], + isfinal=True, + extra=["--logfile=%s/%s/lorax.log" % (self.topdir, LOG_PATH)], + ) - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @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, copy_all): + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @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, copy_all + ): pool = mock.Mock() cfg = { - 'release': '20160321.n.0', - 'repo': [ - 'Everything', # this variant-type repo is deprecated, in result will be replaced with default repo - 'Server', # this variant-type repo is deprecated, in result will be replaced with default repo - 'https://example.com/extra-repo1.repo', - 'https://example.com/extra-repo2.repo', + "release": "20160321.n.0", + "repo": [ + "Everything", # this variant-type repo is deprecated, in result will be replaced with default repo + "Server", # this variant-type repo is deprecated, in result will be replaced with default repo + "https://example.com/extra-repo1.repo", + "https://example.com/extra-repo2.repo", ], } koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': 'Foo bar\n', + "task_id": 1234, + "retcode": 0, + "output": "Foo bar\n", } t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) sources = [ - 'https://example.com/extra-repo1.repo', - 'https://example.com/extra-repo2.repo', + "https://example.com/extra-repo1.repo", + "https://example.com/extra-repo2.repo", "http://example.com/repo/1", - 'http://example.com/work/$basearch/comps_repo_Everything', + "http://example.com/work/$basearch/comps_repo_Everything", ] - self.assertRunrootCall(koji, sources, cfg['release'], isfinal=True, - extra=['--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)]) + self.assertRunrootCall( + koji, + sources, + cfg["release"], + isfinal=True, + extra=["--logfile=%s/%s/lorax.log" % (self.topdir, LOG_PATH)], + ) - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @mock.patch('os.link') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @mock.patch("os.link") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run_without_comps( self, KojiWrapper, link, iso, get_file_size, get_mtime, ImageCls, copy_all ): self.compose.has_comps = False pool = mock.Mock() cfg = { - 'release': '20160321.n.0', - 'repo': [], + "release": "20160321.n.0", + "repo": [], } koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': 'Foo bar\n', + "task_id": 1234, + "retcode": 0, + "output": "Foo bar\n", } t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) sources = ["http://example.com/repo/1"] - self.assertRunrootCall(koji, sources, cfg['release'], isfinal=True, - extra=['--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)]) + self.assertRunrootCall( + koji, + sources, + cfg["release"], + isfinal=True, + extra=["--logfile=%s/%s/lorax.log" % (self.topdir, LOG_PATH)], + ) - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.wrappers.iso') - @mock.patch('os.link') - @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, copy_all): + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.wrappers.iso") + @mock.patch("os.link") + @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, copy_all + ): pool = mock.Mock() cfg = { - 'repo': 'Everything', - 'release': '20160321.n.0', - 'add_template': ['some-file.txt'], + "repo": "Everything", + "release": "20160321.n.0", + "add_template": ["some-file.txt"], } koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': 'Foo bar\n', + "task_id": 1234, + "retcode": 0, + "output": "Foo bar\n", } get_file_size.return_value = 1024 get_mtime.return_value = 13579 @@ -394,240 +467,293 @@ class OstreeThreadTest(helpers.PungiTestCase): t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) with self.assertRaises(RuntimeError) as ctx: - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1 + ) - self.assertIn('template_repo', str(ctx.exception)) + self.assertIn("template_repo", str(ctx.exception)) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @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, copy_all, - get_dir_from_scm): + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @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, + copy_all, + get_dir_from_scm, + ): pool = mock.Mock() cfg = { - 'repo': 'Everything', # this variant-type repo is deprecated, in result will be replaced with default repo - 'release': '20160321.n.0', - 'add_template': ['some_file.txt'], - 'add_arch_template': ['other_file.txt'], - 'template_repo': 'git://example.com/templates.git', - 'template_branch': 'f24', - 'extra_runroot_pkgs': ['templatedep'], + "repo": "Everything", # this variant-type repo is deprecated, in result will be replaced with default repo + "release": "20160321.n.0", + "add_template": ["some_file.txt"], + "add_arch_template": ["other_file.txt"], + "template_repo": "git://example.com/templates.git", + "template_branch": "f24", + "extra_runroot_pkgs": ["templatedep"], } koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': 'Foo bar\n', + "task_id": 1234, + "retcode": 0, + "output": "Foo bar\n", } get_file_size.return_value = 1024 get_mtime.return_value = 13579 - final_iso_path = self.topdir + '/compose/Everything/x86_64/iso/image-name' - templ_dir = self.topdir + '/work/x86_64/Everything/lorax_templates' + final_iso_path = self.topdir + "/compose/Everything/x86_64/iso/image-name" + templ_dir = self.topdir + "/work/x86_64/Everything/lorax_templates" t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) - self.assertEqual(get_dir_from_scm.call_args_list, - [mock.call({'scm': 'git', 'repo': 'git://example.com/templates.git', - 'branch': 'f24', 'dir': '.'}, - templ_dir, compose=self.compose)]) - self.assertRunrootCall(koji, - ["http://example.com/repo/1", - 'http://example.com/work/$basearch/comps_repo_Everything'], - cfg['release'], - isfinal=True, - extra=['--add-template=%s/some_file.txt' % templ_dir, - '--add-arch-template=%s/other_file.txt' % templ_dir, - '--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)], - extra_pkgs=['templatedep']) + self.assertEqual( + get_dir_from_scm.call_args_list, + [ + mock.call( + { + "scm": "git", + "repo": "git://example.com/templates.git", + "branch": "f24", + "dir": ".", + }, + templ_dir, + compose=self.compose, + ) + ], + ) + self.assertRunrootCall( + koji, + [ + "http://example.com/repo/1", + "http://example.com/work/$basearch/comps_repo_Everything", + ], + cfg["release"], + isfinal=True, + extra=[ + "--add-template=%s/some_file.txt" % templ_dir, + "--add-arch-template=%s/other_file.txt" % templ_dir, + "--logfile=%s/%s/lorax.log" % (self.topdir, LOG_PATH), + ], + extra_pkgs=["templatedep"], + ) self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path) self.assertImageAdded(self.compose, ImageCls, iso) self.assertAllCopied(copy_all) - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @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, copy_all): + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @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, copy_all + ): pool = mock.Mock() cfg = { - 'repo': 'Everything', # this variant-type repo is deprecated, in result will be replaced with default repo - 'release': '!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN', + "repo": "Everything", # this variant-type repo is deprecated, in result will be replaced with default repo + "release": "!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN", "installpkgs": ["fedora-productimg-atomic"], - "add_template": ["/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl"], + "add_template": [ + "/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl" + ], "add_template_var": [ "ostree_osname=fedora-atomic", "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", ], - "add_arch_template": ["/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl"], + "add_arch_template": [ + "/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl" + ], "add_arch_template_var": [ "ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/", "ostree_osname=fedora-atomic", "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", ], } - self.compose.conf['runroot_weights'] = {'ostree_installer': 123} + self.compose.conf["runroot_weights"] = {"ostree_installer": 123} koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': 'Foo bar\n', + "task_id": 1234, + "retcode": 0, + "output": "Foo bar\n", } get_file_size.return_value = 1024 get_mtime.return_value = 13579 - final_iso_path = self.topdir + '/compose/Everything/x86_64/iso/image-name' + final_iso_path = self.topdir + "/compose/Everything/x86_64/iso/image-name" t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) self.assertRunrootCall( koji, - ["http://example.com/repo/1", - 'http://example.com/work/$basearch/comps_repo_Everything'], - '20151203.t.0', + [ + "http://example.com/repo/1", + "http://example.com/work/$basearch/comps_repo_Everything", + ], + "20151203.t.0", isfinal=True, - extra=['--installpkgs=fedora-productimg-atomic', - '--add-template=/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl', - '--add-arch-template=/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl', - '--add-template-var=ostree_osname=fedora-atomic', - '--add-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host', - '--add-arch-template-var=ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/', - '--add-arch-template-var=ostree_osname=fedora-atomic', - '--add-arch-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host', - '--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)], + extra=[ + "--installpkgs=fedora-productimg-atomic", + "--add-template=/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl", + "--add-arch-template=/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl", + "--add-template-var=ostree_osname=fedora-atomic", + "--add-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", + "--add-arch-template-var=ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/", + "--add-arch-template-var=ostree_osname=fedora-atomic", + "--add-arch-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", + "--logfile=%s/%s/lorax.log" % (self.topdir, LOG_PATH), + ], weight=123, ) self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path) self.assertImageAdded(self.compose, ImageCls, iso) self.assertAllCopied(copy_all) - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @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, copy_all): + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @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, copy_all + ): pool = mock.Mock() cfg = { - 'repo': 'Everything', # this variant-type repo is deprecated, in result will be replaced with default repo - 'release': None, + "repo": "Everything", # this variant-type repo is deprecated, in result will be replaced with default repo + "release": None, "installpkgs": ["fedora-productimg-atomic"], - "add_template": ["/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl"], + "add_template": [ + "/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl" + ], "add_template_var": [ "ostree_osname=fedora-atomic", "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", ], - "add_arch_template": ["/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl"], + "add_arch_template": [ + "/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl" + ], "add_arch_template_var": [ "ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/", "ostree_osname=fedora-atomic", "ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", ], } - self.compose.conf['runroot_weights'] = {'ostree_installer': 123} + self.compose.conf["runroot_weights"] = {"ostree_installer": 123} koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'task_id': 1234, - 'retcode': 0, - 'output': 'Foo bar\n', + "task_id": 1234, + "retcode": 0, + "output": "Foo bar\n", } get_file_size.return_value = 1024 get_mtime.return_value = 13579 - final_iso_path = self.topdir + '/compose/Everything/x86_64/iso/image-name' + final_iso_path = self.topdir + "/compose/Everything/x86_64/iso/image-name" t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) self.assertRunrootCall( koji, - ["http://example.com/repo/1", - 'http://example.com/work/$basearch/comps_repo_Everything'], - '20151203.t.0', + [ + "http://example.com/repo/1", + "http://example.com/work/$basearch/comps_repo_Everything", + ], + "20151203.t.0", isfinal=True, - extra=['--installpkgs=fedora-productimg-atomic', - '--add-template=/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl', - '--add-arch-template=/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl', - '--add-template-var=ostree_osname=fedora-atomic', - '--add-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host', - '--add-arch-template-var=ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/', - '--add-arch-template-var=ostree_osname=fedora-atomic', - '--add-arch-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host', - '--logfile=%s/%s/lorax.log' % (self.topdir, LOG_PATH)], + extra=[ + "--installpkgs=fedora-productimg-atomic", + "--add-template=/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl", + "--add-arch-template=/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl", + "--add-template-var=ostree_osname=fedora-atomic", + "--add-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", + "--add-arch-template-var=ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/", + "--add-arch-template-var=ostree_osname=fedora-atomic", + "--add-arch-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host", + "--logfile=%s/%s/lorax.log" % (self.topdir, LOG_PATH), + ], weight=123, ) self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path) self.assertImageAdded(self.compose, ImageCls, iso) self.assertAllCopied(copy_all) - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @mock.patch('os.link') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_fail_crash(self, KojiWrapper, link, iso, get_file_size, - get_mtime, ImageCls, copy_all): + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @mock.patch("os.link") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + def test_fail_crash( + self, KojiWrapper, link, iso, get_file_size, get_mtime, ImageCls, copy_all + ): pool = mock.Mock() - cfg = { - 'repo': 'Everything', - 'release': None, - 'failable': ['x86_64'] - } + cfg = {"repo": "Everything", "release": None, "failable": ["x86_64"]} koji = KojiWrapper.return_value koji.run_runroot_cmd.side_effect = helpers.boom t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway.'), - mock.call('BOOM') - ]) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway." + ), + mock.call("BOOM"), + ] + ) - @mock.patch('pungi.util.copy_all') - @mock.patch('productmd.images.Image') - @mock.patch('pungi.util.get_mtime') - @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.phases.ostree_installer.iso') - @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, copy_all): + @mock.patch("pungi.util.copy_all") + @mock.patch("productmd.images.Image") + @mock.patch("pungi.util.get_mtime") + @mock.patch("pungi.util.get_file_size") + @mock.patch("pungi.phases.ostree_installer.iso") + @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, copy_all + ): pool = mock.Mock() cfg = { - 'repo': 'Everything', - 'release': None, - 'failable': ['*'], + "repo": "Everything", + "release": None, + "failable": ["*"], } koji = KojiWrapper.return_value koji.run_runroot_cmd.return_value = { - 'output': 'Failed', - 'task_id': 1234, - 'retcode': 1, + "output": "Failed", + "task_id": 1234, + "retcode": 1, } t = ostree.OstreeInstallerThread(pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) - pool._logger.error.assert_has_calls([ - mock.call('[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway.'), - mock.call('Runroot task failed: 1234. See %s/%s/runroot.log for more details.' - % (self.topdir, LOG_PATH)) - ]) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) + pool._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway." + ), + mock.call( + "Runroot task failed: 1234. See %s/%s/runroot.log for more details." + % (self.topdir, LOG_PATH) + ), + ] + ) diff --git a/tests/test_ostree_phase.py b/tests/test_ostree_phase.py index 692ab88e..3ec8dde1 100644 --- a/tests/test_ostree_phase.py +++ b/tests/test_ostree_phase.py @@ -12,19 +12,17 @@ from pungi.phases import ostree class OSTreePhaseTest(helpers.PungiTestCase): - - @mock.patch('pungi.phases.ostree.ThreadPool') + @mock.patch("pungi.phases.ostree.ThreadPool") def test_run(self, ThreadPool): cfg = helpers.IterableMock() - compose = helpers.DummyCompose(self.topdir, { - 'ostree': [ - ('^Everything$', {'x86_64': cfg}) - ], - 'runroot': True, - "translate_paths": [ - (self.topdir, "http://example.com") - ], - }) + compose = helpers.DummyCompose( + self.topdir, + { + "ostree": [("^Everything$", {"x86_64": cfg})], + "runroot": True, + "translate_paths": [(self.topdir, "http://example.com")], + }, + ) pool = ThreadPool.return_value @@ -39,10 +37,12 @@ class OSTreePhaseTest(helpers.PungiTestCase): "http://example.com/work/$basearch/repo/p2", ], ) - self.assertEqual(pool.queue_put.call_args_list, - [mock.call((compose, compose.variants['Everything'], 'x86_64', cfg))]) + self.assertEqual( + pool.queue_put.call_args_list, + [mock.call((compose, compose.variants["Everything"], "x86_64", cfg))], + ) - @mock.patch('pungi.phases.ostree.ThreadPool') + @mock.patch("pungi.phases.ostree.ThreadPool") def test_skip_without_config(self, ThreadPool): compose = helpers.DummyCompose(self.topdir, {}) compose.just_phases = None @@ -50,14 +50,10 @@ class OSTreePhaseTest(helpers.PungiTestCase): phase = ostree.OSTreePhase(compose) self.assertTrue(phase.skip()) - @mock.patch('pungi.phases.ostree.ThreadPool') + @mock.patch("pungi.phases.ostree.ThreadPool") def test_run_with_simple_config(self, ThreadPool): cfg = helpers.IterableMock(get=lambda x, y: None) - compose = helpers.DummyCompose(self.topdir, { - 'ostree': { - '^Everything$': cfg - } - }) + compose = helpers.DummyCompose(self.topdir, {"ostree": {"^Everything$": cfg}}) pool = ThreadPool.return_value @@ -65,18 +61,18 @@ class OSTreePhaseTest(helpers.PungiTestCase): phase.run() self.assertEqual(len(pool.add.call_args_list), 2) - self.assertEqual(pool.queue_put.call_args_list, - [mock.call((compose, compose.variants['Everything'], 'x86_64', cfg)), - mock.call((compose, compose.variants['Everything'], 'amd64', cfg))]) + self.assertEqual( + pool.queue_put.call_args_list, + [ + mock.call((compose, compose.variants["Everything"], "x86_64", cfg)), + mock.call((compose, compose.variants["Everything"], "amd64", cfg)), + ], + ) - @mock.patch('pungi.phases.ostree.ThreadPool') + @mock.patch("pungi.phases.ostree.ThreadPool") def test_run_with_simple_config_limit_arches(self, ThreadPool): - cfg = helpers.IterableMock(get=lambda x, y: ['x86_64']) - compose = helpers.DummyCompose(self.topdir, { - 'ostree': { - '^Everything$': cfg - } - }) + cfg = helpers.IterableMock(get=lambda x, y: ["x86_64"]) + compose = helpers.DummyCompose(self.topdir, {"ostree": {"^Everything$": cfg}}) pool = ThreadPool.return_value @@ -84,18 +80,18 @@ class OSTreePhaseTest(helpers.PungiTestCase): phase.run() self.assertEqual(len(pool.add.call_args_list), 1) - self.assertEqual(pool.queue_put.call_args_list, - [mock.call((compose, compose.variants['Everything'], 'x86_64', cfg))]) + self.assertEqual( + pool.queue_put.call_args_list, + [mock.call((compose, compose.variants["Everything"], "x86_64", cfg))], + ) - @mock.patch('pungi.phases.ostree.ThreadPool') + @mock.patch("pungi.phases.ostree.ThreadPool") def test_run_with_simple_config_limit_arches_two_blocks(self, ThreadPool): - cfg1 = helpers.IterableMock(get=lambda x, y: ['x86_64']) - cfg2 = helpers.IterableMock(get=lambda x, y: ['s390x']) - compose = helpers.DummyCompose(self.topdir, { - 'ostree': { - '^Everything$': [cfg1, cfg2], - } - }) + cfg1 = helpers.IterableMock(get=lambda x, y: ["x86_64"]) + cfg2 = helpers.IterableMock(get=lambda x, y: ["s390x"]) + compose = helpers.DummyCompose( + self.topdir, {"ostree": {"^Everything$": [cfg1, cfg2]}} + ) pool = ThreadPool.return_value @@ -103,219 +99,319 @@ class OSTreePhaseTest(helpers.PungiTestCase): phase.run() self.assertEqual(len(pool.add.call_args_list), 2) - self.assertEqual(pool.queue_put.call_args_list, - [mock.call((compose, compose.variants['Everything'], 'x86_64', cfg1)), - mock.call((compose, compose.variants['Everything'], 's390x', cfg2))]) + self.assertEqual( + pool.queue_put.call_args_list, + [ + mock.call((compose, compose.variants["Everything"], "x86_64", cfg1)), + mock.call((compose, compose.variants["Everything"], "s390x", cfg2)), + ], + ) class OSTreeThreadTest(helpers.PungiTestCase): - def setUp(self): super(OSTreeThreadTest, self).setUp() - self.repo = os.path.join(self.topdir, 'place/for/atomic') - os.makedirs(os.path.join(self.repo, 'refs', 'heads')) + self.repo = os.path.join(self.topdir, "place/for/atomic") + os.makedirs(os.path.join(self.repo, "refs", "heads")) self.cfg = { - 'repo': 'Everything', - 'config_url': 'https://git.fedorahosted.org/git/fedora-atomic.git', - 'config_branch': 'f24', - 'treefile': 'fedora-atomic-docker-host.json', - 'ostree_repo': self.repo, + "repo": "Everything", + "config_url": "https://git.fedorahosted.org/git/fedora-atomic.git", + "config_branch": "f24", + "treefile": "fedora-atomic-docker-host.json", + "ostree_repo": self.repo, } - self.compose = helpers.DummyCompose(self.topdir, { - 'koji_profile': 'koji', - 'runroot_tag': 'rrt', - 'translate_paths': [ - (self.topdir, 'http://example.com') - ], - }) + self.compose = helpers.DummyCompose( + self.topdir, + { + "koji_profile": "koji", + "runroot_tag": "rrt", + "translate_paths": [(self.topdir, "http://example.com")], + }, + ) self.pool = mock.Mock() def _dummy_config_repo(self, scm_dict, target, compose=None): os.makedirs(target) - helpers.touch(os.path.join(target, 'fedora-atomic-docker-host.json'), - json.dumps({'ref': 'fedora-atomic/25/x86_64', - 'repos': ['fedora-rawhide', 'fedora-24', 'fedora-23']})) - helpers.touch(os.path.join(target, 'fedora-rawhide.repo'), - '[fedora-rawhide]\nmirrorlist=mirror-mirror-on-the-wall') - helpers.touch(os.path.join(target, 'fedora-24.repo'), - '[fedora-24]\nmetalink=who-is-the-fairest-of-them-all') - helpers.touch(os.path.join(target, 'fedora-23.repo'), - '[fedora-23]\nbaseurl=why-not-zoidberg?') + helpers.touch( + os.path.join(target, "fedora-atomic-docker-host.json"), + json.dumps( + { + "ref": "fedora-atomic/25/x86_64", + "repos": ["fedora-rawhide", "fedora-24", "fedora-23"], + } + ), + ) + helpers.touch( + os.path.join(target, "fedora-rawhide.repo"), + "[fedora-rawhide]\nmirrorlist=mirror-mirror-on-the-wall", + ) + helpers.touch( + os.path.join(target, "fedora-24.repo"), + "[fedora-24]\nmetalink=who-is-the-fairest-of-them-all", + ) + helpers.touch( + os.path.join(target, "fedora-23.repo"), + "[fedora-23]\nbaseurl=why-not-zoidberg?", + ) def _mock_runroot(self, retcode, writefiles=None): """Pretend to run a task in runroot, creating a log file with given line Also allows for writing other files of requested""" + def fake_runroot(self, log_file, **kwargs): if writefiles: logdir = os.path.dirname(log_file) for filename in writefiles: - helpers.touch(os.path.join(logdir, filename), - '\n'.join(writefiles[filename])) + helpers.touch( + os.path.join(logdir, filename), "\n".join(writefiles[filename]) + ) helpers.touch(os.path.join(logdir, filename + ".stamp")) - return {'task_id': 1234, 'retcode': retcode, 'output': 'Foo bar\n'} + return {"task_id": 1234, "retcode": retcode, "output": "Foo bar\n"} + return fake_runroot - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_extra_config_content(self, KojiWrapper, get_dir_from_scm): get_dir_from_scm.side_effect = self._dummy_config_repo - self.compose.conf['runroot_weights'] = {'ostree': 123} + self.compose.conf["runroot_weights"] = {"ostree": 123} koji = KojiWrapper.return_value koji.run_runroot_cmd.side_effect = self._mock_runroot(0) t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - extra_config_file = os.path.join(self.topdir, 'work/ostree-1/extra_config.json') + extra_config_file = os.path.join(self.topdir, "work/ostree-1/extra_config.json") self.assertFalse(os.path.isfile(extra_config_file)) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) self.assertTrue(os.path.isfile(extra_config_file)) - with open(extra_config_file, 'r') as f: + with open(extra_config_file, "r") as f: extraconf_content = json.load(f) proper_extraconf_content = { "repo": [ - {"name": "http:__example.com_repo_1", - "baseurl": "http://example.com/repo/1"}, - {"name": "http:__example.com_work__basearch_comps_repo_Everything", - "baseurl": "http://example.com/work/$basearch/comps_repo_Everything"} + { + "name": "http:__example.com_repo_1", + "baseurl": "http://example.com/repo/1", + }, + { + "name": "http:__example.com_work__basearch_comps_repo_Everything", + "baseurl": "http://example.com/work/$basearch/comps_repo_Everything", + }, ] } self.assertEqual(proper_extraconf_content, extraconf_content) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run(self, KojiWrapper, get_dir_from_scm): get_dir_from_scm.side_effect = self._dummy_config_repo - self.compose.conf['runroot_weights'] = {'ostree': 123} + self.compose.conf["runroot_weights"] = {"ostree": 123} koji = KojiWrapper.return_value koji.run_runroot_cmd.side_effect = self._mock_runroot(0) t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) - self.assertEqual(get_dir_from_scm.call_args_list, - [mock.call({'scm': 'git', 'repo': 'https://git.fedorahosted.org/git/fedora-atomic.git', - 'branch': 'f24', 'dir': '.'}, - self.topdir + '/work/ostree-1/config_repo', compose=self.compose)]) - self.assertEqual(koji.get_runroot_cmd.call_args_list, - [mock.call('rrt', 'x86_64', - ['pungi-make-ostree', - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s/logs/x86_64/Everything/ostree-1' % self.topdir, - '--treefile=%s/fedora-atomic-docker-host.json' % ( - self.topdir + '/work/ostree-1/config_repo'), - '--extra-config=%s/extra_config.json' % (self.topdir + '/work/ostree-1')], - channel=None, mounts=[self.topdir, self.repo], - packages=['pungi', 'ostree', 'rpm-ostree'], - use_shell=True, new_chroot=True, weight=123)]) - self.assertEqual(koji.run_runroot_cmd.call_args_list, - [mock.call(koji.get_runroot_cmd.return_value, - log_file=self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log')]) + self.assertEqual( + get_dir_from_scm.call_args_list, + [ + mock.call( + { + "scm": "git", + "repo": "https://git.fedorahosted.org/git/fedora-atomic.git", + "branch": "f24", + "dir": ".", + }, + self.topdir + "/work/ostree-1/config_repo", + compose=self.compose, + ) + ], + ) + self.assertEqual( + koji.get_runroot_cmd.call_args_list, + [ + mock.call( + "rrt", + "x86_64", + [ + "pungi-make-ostree", + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s/logs/x86_64/Everything/ostree-1" % self.topdir, + "--treefile=%s/fedora-atomic-docker-host.json" + % (self.topdir + "/work/ostree-1/config_repo"), + "--extra-config=%s/extra_config.json" + % (self.topdir + "/work/ostree-1"), + ], + channel=None, + mounts=[self.topdir, self.repo], + packages=["pungi", "ostree", "rpm-ostree"], + use_shell=True, + new_chroot=True, + weight=123, + ) + ], + ) + self.assertEqual( + koji.run_runroot_cmd.call_args_list, + [ + mock.call( + koji.get_runroot_cmd.return_value, + log_file=self.topdir + + "/logs/x86_64/Everything/ostree-1/runroot.log", + ) + ], + ) - self.assertTrue(os.path.isfile(os.path.join(self.topdir, 'work/ostree-1/extra_config.json'))) + self.assertTrue( + os.path.isfile(os.path.join(self.topdir, "work/ostree-1/extra_config.json")) + ) self.assertTrue(os.path.isdir(self.repo)) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run_fail(self, KojiWrapper, get_dir_from_scm): get_dir_from_scm.side_effect = self._dummy_config_repo - self.cfg['failable'] = ['*'] + self.cfg["failable"] = ["*"] koji = KojiWrapper.return_value koji.run_runroot_cmd.side_effect = self._mock_runroot(1) t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) - self.compose._logger.error.assert_has_calls([ - mock.call('[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway.'), - mock.call('Runroot task failed: 1234. See %s for more details.' - % (self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log')) - ]) + self.compose._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway." + ), + mock.call( + "Runroot task failed: 1234. See %s for more details." + % (self.topdir + "/logs/x86_64/Everything/ostree-1/runroot.log") + ), + ] + ) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run_handle_exception(self, KojiWrapper, get_dir_from_scm): get_dir_from_scm.side_effect = self._dummy_config_repo - self.cfg['failable'] = ['*'] + self.cfg["failable"] = ["*"] koji = KojiWrapper.return_value koji.run_runroot_cmd.side_effect = helpers.boom t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) - self.compose._logger.error.assert_has_calls([ - mock.call('[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway.'), - mock.call('BOOM') - ]) + self.compose._logger.error.assert_has_calls( + [ + mock.call( + "[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway." + ), + mock.call("BOOM"), + ] + ) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run_send_message(self, KojiWrapper, get_dir_from_scm): get_dir_from_scm.side_effect = self._dummy_config_repo self.compose.notifier = mock.Mock() - self.compose.conf['translate_paths'] = [(self.topdir, 'http://example.com/')] + self.compose.conf["translate_paths"] = [(self.topdir, "http://example.com/")] koji = KojiWrapper.return_value koji.run_runroot_cmd.side_effect = self._mock_runroot( 0, - {'commitid.log': 'fca3465861a', - 'create-ostree-repo.log': - ['Doing work', 'fedora-atomic/25/x86_64 -> fca3465861a']}) + { + "commitid.log": "fca3465861a", + "create-ostree-repo.log": [ + "Doing work", + "fedora-atomic/25/x86_64 -> fca3465861a", + ], + }, + ) t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) - self.assertEqual(self.compose.notifier.send.mock_calls, - [mock.call('ostree', - variant='Everything', - arch='x86_64', - ref='fedora-atomic/25/x86_64', - commitid='fca3465861a', - repo_path='http://example.com/place/for/atomic', - local_repo_path=self.repo)]) + self.assertEqual( + self.compose.notifier.send.mock_calls, + [ + mock.call( + "ostree", + variant="Everything", + arch="x86_64", + ref="fedora-atomic/25/x86_64", + commitid="fca3465861a", + repo_path="http://example.com/place/for/atomic", + local_repo_path=self.repo, + ) + ], + ) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run_send_message_custom_ref(self, KojiWrapper, get_dir_from_scm): get_dir_from_scm.side_effect = self._dummy_config_repo self.cfg["ostree_ref"] = "my/${basearch}" self.compose.notifier = mock.Mock() - self.compose.conf['translate_paths'] = [(self.topdir, 'http://example.com/')] + self.compose.conf["translate_paths"] = [(self.topdir, "http://example.com/")] koji = KojiWrapper.return_value koji.run_runroot_cmd.side_effect = self._mock_runroot( 0, - {'commitid.log': 'fca3465861a', - 'create-ostree-repo.log': - ['Doing work', 'fedora-atomic/25/x86_64 -> fca3465861a']}) + { + "commitid.log": "fca3465861a", + "create-ostree-repo.log": [ + "Doing work", + "fedora-atomic/25/x86_64 -> fca3465861a", + ], + }, + ) t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) - self.assertEqual(self.compose.notifier.send.mock_calls, - [mock.call('ostree', - variant='Everything', - arch='x86_64', - ref='my/x86_64', - commitid='fca3465861a', - repo_path='http://example.com/place/for/atomic', - local_repo_path=self.repo)]) + self.assertEqual( + self.compose.notifier.send.mock_calls, + [ + mock.call( + "ostree", + variant="Everything", + arch="x86_64", + ref="my/x86_64", + commitid="fca3465861a", + repo_path="http://example.com/place/for/atomic", + local_repo_path=self.repo, + ) + ], + ) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run_send_message_without_commit_id(self, KojiWrapper, get_dir_from_scm): get_dir_from_scm.side_effect = self._dummy_config_repo @@ -323,23 +419,31 @@ class OSTreeThreadTest(helpers.PungiTestCase): koji = KojiWrapper.return_value koji.run_runroot_cmd.side_effect = self._mock_runroot( - 0, - {'create-ostree-repo.log': ['Doing work', 'Weird output']}) + 0, {"create-ostree-repo.log": ["Doing work", "Weird output"]} + ) t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) - self.assertEqual(self.compose.notifier.send.mock_calls, - [mock.call('ostree', - variant='Everything', - arch='x86_64', - ref='fedora-atomic/25/x86_64', - commitid=None, - repo_path='http://example.com/place/for/atomic', - local_repo_path=self.repo)]) + self.assertEqual( + self.compose.notifier.send.mock_calls, + [ + mock.call( + "ostree", + variant="Everything", + arch="x86_64", + ref="fedora-atomic/25/x86_64", + commitid=None, + repo_path="http://example.com/place/for/atomic", + local_repo_path=self.repo, + ) + ], + ) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run_send_no_message_on_failure(self, KojiWrapper, get_dir_from_scm): get_dir_from_scm.side_effect = self._dummy_config_repo @@ -349,15 +453,18 @@ class OSTreeThreadTest(helpers.PungiTestCase): koji.run_runroot_cmd.side_effect = self._mock_runroot(1) t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - self.assertRaises(RuntimeError, t.process, - (self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), - 1) + self.assertRaises( + RuntimeError, + t.process, + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), + 1, + ) self.assertEqual(self.compose.notifier.send.mock_calls, []) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run_with_update_summary(self, KojiWrapper, get_dir_from_scm): - self.cfg['update_summary'] = True + self.cfg["update_summary"] = True get_dir_from_scm.side_effect = self._dummy_config_repo @@ -366,33 +473,66 @@ class OSTreeThreadTest(helpers.PungiTestCase): t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) - self.assertEqual(get_dir_from_scm.call_args_list, - [mock.call({'scm': 'git', 'repo': 'https://git.fedorahosted.org/git/fedora-atomic.git', - 'branch': 'f24', 'dir': '.'}, - self.topdir + '/work/ostree-1/config_repo', compose=self.compose)]) - self.assertEqual(koji.get_runroot_cmd.call_args_list, - [mock.call('rrt', 'x86_64', - ['pungi-make-ostree', - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s/logs/x86_64/Everything/ostree-1' % self.topdir, - '--treefile=%s/fedora-atomic-docker-host.json' % ( - self.topdir + '/work/ostree-1/config_repo'), - '--extra-config=%s/work/ostree-1/extra_config.json' % self.topdir, - '--update-summary'], - channel=None, mounts=[self.topdir, self.repo], - packages=['pungi', 'ostree', 'rpm-ostree'], - use_shell=True, new_chroot=True, weight=None)]) - self.assertEqual(koji.run_runroot_cmd.call_args_list, - [mock.call(koji.get_runroot_cmd.return_value, - log_file=self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log')]) + self.assertEqual( + get_dir_from_scm.call_args_list, + [ + mock.call( + { + "scm": "git", + "repo": "https://git.fedorahosted.org/git/fedora-atomic.git", + "branch": "f24", + "dir": ".", + }, + self.topdir + "/work/ostree-1/config_repo", + compose=self.compose, + ) + ], + ) + self.assertEqual( + koji.get_runroot_cmd.call_args_list, + [ + mock.call( + "rrt", + "x86_64", + [ + "pungi-make-ostree", + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s/logs/x86_64/Everything/ostree-1" % self.topdir, + "--treefile=%s/fedora-atomic-docker-host.json" + % (self.topdir + "/work/ostree-1/config_repo"), + "--extra-config=%s/work/ostree-1/extra_config.json" + % self.topdir, + "--update-summary", + ], + channel=None, + mounts=[self.topdir, self.repo], + packages=["pungi", "ostree", "rpm-ostree"], + use_shell=True, + new_chroot=True, + weight=None, + ) + ], + ) + self.assertEqual( + koji.run_runroot_cmd.call_args_list, + [ + mock.call( + koji.get_runroot_cmd.return_value, + log_file=self.topdir + + "/logs/x86_64/Everything/ostree-1/runroot.log", + ) + ], + ) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run_with_versioning_metadata(self, KojiWrapper, get_dir_from_scm): - self.cfg['version'] = '24' + self.cfg["version"] = "24" get_dir_from_scm.side_effect = self._dummy_config_repo @@ -401,33 +541,68 @@ class OSTreeThreadTest(helpers.PungiTestCase): t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) - self.assertEqual(get_dir_from_scm.call_args_list, - [mock.call({'scm': 'git', 'repo': 'https://git.fedorahosted.org/git/fedora-atomic.git', - 'branch': 'f24', 'dir': '.'}, - self.topdir + '/work/ostree-1/config_repo', compose=self.compose)]) - self.assertEqual(koji.get_runroot_cmd.call_args_list, - [mock.call('rrt', 'x86_64', - ['pungi-make-ostree', - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s/logs/x86_64/Everything/ostree-1' % self.topdir, - '--treefile=%s/fedora-atomic-docker-host.json' % ( - self.topdir + '/work/ostree-1/config_repo'), - '--version=24', - '--extra-config=%s/work/ostree-1/extra_config.json' % self.topdir], - channel=None, mounts=[self.topdir, self.repo], - packages=['pungi', 'ostree', 'rpm-ostree'], - use_shell=True, new_chroot=True, weight=None)]) - self.assertEqual(koji.run_runroot_cmd.call_args_list, - [mock.call(koji.get_runroot_cmd.return_value, - log_file=self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log')]) + self.assertEqual( + get_dir_from_scm.call_args_list, + [ + mock.call( + { + "scm": "git", + "repo": "https://git.fedorahosted.org/git/fedora-atomic.git", + "branch": "f24", + "dir": ".", + }, + self.topdir + "/work/ostree-1/config_repo", + compose=self.compose, + ) + ], + ) + self.assertEqual( + koji.get_runroot_cmd.call_args_list, + [ + mock.call( + "rrt", + "x86_64", + [ + "pungi-make-ostree", + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s/logs/x86_64/Everything/ostree-1" % self.topdir, + "--treefile=%s/fedora-atomic-docker-host.json" + % (self.topdir + "/work/ostree-1/config_repo"), + "--version=24", + "--extra-config=%s/work/ostree-1/extra_config.json" + % self.topdir, + ], + channel=None, + mounts=[self.topdir, self.repo], + packages=["pungi", "ostree", "rpm-ostree"], + use_shell=True, + new_chroot=True, + weight=None, + ) + ], + ) + self.assertEqual( + koji.run_runroot_cmd.call_args_list, + [ + mock.call( + koji.get_runroot_cmd.return_value, + log_file=self.topdir + + "/logs/x86_64/Everything/ostree-1/runroot.log", + ) + ], + ) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_run_with_generated_versioning_metadata(self, KojiWrapper, get_dir_from_scm): - self.cfg['version'] = '!OSTREE_VERSION_FROM_LABEL_DATE_TYPE_RESPIN' + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") + def test_run_with_generated_versioning_metadata( + self, KojiWrapper, get_dir_from_scm + ): + self.cfg["version"] = "!OSTREE_VERSION_FROM_LABEL_DATE_TYPE_RESPIN" get_dir_from_scm.side_effect = self._dummy_config_repo @@ -436,31 +611,64 @@ class OSTreeThreadTest(helpers.PungiTestCase): t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + t.process( + (self.compose, self.compose.variants["Everything"], "x86_64", self.cfg), 1 + ) - self.assertEqual(get_dir_from_scm.call_args_list, - [mock.call({'scm': 'git', 'repo': 'https://git.fedorahosted.org/git/fedora-atomic.git', - 'branch': 'f24', 'dir': '.'}, - self.topdir + '/work/ostree-1/config_repo', compose=self.compose)]) - self.assertEqual(koji.get_runroot_cmd.call_args_list, - [mock.call('rrt', 'x86_64', - ['pungi-make-ostree', - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s/logs/x86_64/Everything/ostree-1' % self.topdir, - '--treefile=%s/fedora-atomic-docker-host.json' % ( - self.topdir + '/work/ostree-1/config_repo'), - '--version=25.20151203.t.0', - '--extra-config=%s/work/ostree-1/extra_config.json' % self.topdir], - channel=None, mounts=[self.topdir, self.repo], - packages=['pungi', 'ostree', 'rpm-ostree'], - use_shell=True, new_chroot=True, weight=None)]) - self.assertEqual(koji.run_runroot_cmd.call_args_list, - [mock.call(koji.get_runroot_cmd.return_value, - log_file=self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log')]) + self.assertEqual( + get_dir_from_scm.call_args_list, + [ + mock.call( + { + "scm": "git", + "repo": "https://git.fedorahosted.org/git/fedora-atomic.git", + "branch": "f24", + "dir": ".", + }, + self.topdir + "/work/ostree-1/config_repo", + compose=self.compose, + ) + ], + ) + self.assertEqual( + koji.get_runroot_cmd.call_args_list, + [ + mock.call( + "rrt", + "x86_64", + [ + "pungi-make-ostree", + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s/logs/x86_64/Everything/ostree-1" % self.topdir, + "--treefile=%s/fedora-atomic-docker-host.json" + % (self.topdir + "/work/ostree-1/config_repo"), + "--version=25.20151203.t.0", + "--extra-config=%s/work/ostree-1/extra_config.json" + % self.topdir, + ], + channel=None, + mounts=[self.topdir, self.repo], + packages=["pungi", "ostree", "rpm-ostree"], + use_shell=True, + new_chroot=True, + weight=None, + ) + ], + ) + self.assertEqual( + koji.run_runroot_cmd.call_args_list, + [ + mock.call( + koji.get_runroot_cmd.return_value, + log_file=self.topdir + + "/logs/x86_64/Everything/ostree-1/runroot.log", + ) + ], + ) - @mock.patch('pungi.wrappers.scm.get_dir_from_scm') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.wrappers.scm.get_dir_from_scm") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_write_extra_config_file(self, KojiWrapper, get_dir_from_scm): get_dir_from_scm.side_effect = self._dummy_config_repo @@ -468,38 +676,44 @@ class OSTreeThreadTest(helpers.PungiTestCase): koji.run_runroot_cmd.side_effect = self._mock_runroot(0) cfg = { - 'repo': [ # Variant type repos will not be included into extra_config. This part of the config is deprecated - 'Everything', # do not include + "repo": [ # Variant type repos will not be included into extra_config. This part of the config is deprecated + "Everything", # do not include { - 'name': 'repo_a', - 'baseurl': 'http://url/to/repo/a', - 'exclude': 'systemd-container' + "name": "repo_a", + "baseurl": "http://url/to/repo/a", + "exclude": "systemd-container", }, { # do not include - 'name': 'Server', - 'baseurl': 'Server', - 'exclude': 'systemd-container' - } + "name": "Server", + "baseurl": "Server", + "exclude": "systemd-container", + }, ], - 'keep_original_sources': True, - 'config_url': 'https://git.fedorahosted.org/git/fedora-atomic.git', - 'config_branch': 'f24', - 'treefile': 'fedora-atomic-docker-host.json', - 'ostree_repo': self.repo + "keep_original_sources": True, + "config_url": "https://git.fedorahosted.org/git/fedora-atomic.git", + "config_branch": "f24", + "treefile": "fedora-atomic-docker-host.json", + "ostree_repo": self.repo, } t = ostree.OSTreeThread(self.pool, ["http://example.com/repo/1"]) - t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) + t.process((self.compose, self.compose.variants["Everything"], "x86_64", cfg), 1) - extra_config_file = os.path.join(self.topdir, 'work/ostree-1/extra_config.json') + extra_config_file = os.path.join(self.topdir, "work/ostree-1/extra_config.json") self.assertTrue(os.path.isfile(extra_config_file)) - with open(extra_config_file, 'r') as extra_config_fd: + with open(extra_config_file, "r") as extra_config_fd: extra_config = json.load(extra_config_fd) - self.assertTrue(extra_config.get('keep_original_sources', False)) + self.assertTrue(extra_config.get("keep_original_sources", False)) # should equal to number of valid repositories in cfg['repo'] + default repository + comps repository - self.assertEqual(len(extra_config.get('repo', [])), 3) - self.assertEqual(extra_config.get('repo').pop()['baseurl'], - 'http://example.com/work/$basearch/comps_repo_Everything') - self.assertEqual(extra_config.get("repo").pop()["baseurl"], "http://example.com/repo/1") - self.assertEqual(extra_config.get('repo').pop()['baseurl'], 'http://url/to/repo/a') + self.assertEqual(len(extra_config.get("repo", [])), 3) + self.assertEqual( + extra_config.get("repo").pop()["baseurl"], + "http://example.com/work/$basearch/comps_repo_Everything", + ) + self.assertEqual( + extra_config.get("repo").pop()["baseurl"], "http://example.com/repo/1" + ) + self.assertEqual( + extra_config.get("repo").pop()["baseurl"], "http://url/to/repo/a" + ) diff --git a/tests/test_ostree_script.py b/tests/test_ostree_script.py index cf1dfe06..9bdaae1b 100644 --- a/tests/test_ostree_script.py +++ b/tests/test_ostree_script.py @@ -14,24 +14,41 @@ from pungi import ostree class OstreeTreeScriptTest(helpers.PungiTestCase): - def setUp(self): super(OstreeTreeScriptTest, self).setUp() self.repo = os.path.join(self.topdir, "atomic") def _make_dummy_config_dir(self, path): - helpers.touch(os.path.join(path, 'fedora-atomic-docker-host.json'), - json.dumps({'ref': 'fedora-atomic/25/x86_64', - 'repos': ['fedora-rawhide', 'fedora-24', 'fedora-23']})) - helpers.touch(os.path.join(path, 'fedora-atomic-docker-host.yaml'), - yaml.dump({'ref': 'fedora-atomic/25/x86_64', - 'repos': ['fedora-rawhide', 'fedora-24', 'fedora-23']})) - helpers.touch(os.path.join(path, 'fedora-rawhide.repo'), - '[fedora-rawhide]\nmirrorlist=mirror-mirror-on-the-wall') - helpers.touch(os.path.join(path, 'fedora-24.repo'), - '[fedora-24]\nmetalink=who-is-the-fairest-of-them-all') - helpers.touch(os.path.join(path, 'fedora-23.repo'), - '[fedora-23]\nbaseurl=why-not-zoidberg?') + helpers.touch( + os.path.join(path, "fedora-atomic-docker-host.json"), + json.dumps( + { + "ref": "fedora-atomic/25/x86_64", + "repos": ["fedora-rawhide", "fedora-24", "fedora-23"], + } + ), + ) + helpers.touch( + os.path.join(path, "fedora-atomic-docker-host.yaml"), + yaml.dump( + { + "ref": "fedora-atomic/25/x86_64", + "repos": ["fedora-rawhide", "fedora-24", "fedora-23"], + } + ), + ) + helpers.touch( + os.path.join(path, "fedora-rawhide.repo"), + "[fedora-rawhide]\nmirrorlist=mirror-mirror-on-the-wall", + ) + helpers.touch( + os.path.join(path, "fedora-24.repo"), + "[fedora-24]\nmetalink=who-is-the-fairest-of-them-all", + ) + helpers.touch( + os.path.join(path, "fedora-23.repo"), + "[fedora-23]\nbaseurl=why-not-zoidberg?", + ) def assertCorrectCall(self, mock_run, extra_calls=[], extra_args=[]): six.assertCountEqual( @@ -44,65 +61,76 @@ class OstreeTreeScriptTest(helpers.PungiTestCase): "compose", "tree", "--repo=%s" % self.repo, - "--write-commitid-to=%s" % (self.topdir + "/logs/Atomic/commitid.log"), - "--touch-if-changed=%s.stamp" % (self.topdir + "/logs/Atomic/commitid.log"), - ] + extra_args + [ - self.topdir + "/fedora-atomic-docker-host.json" - ], + "--write-commitid-to=%s" + % (self.topdir + "/logs/Atomic/commitid.log"), + "--touch-if-changed=%s.stamp" + % (self.topdir + "/logs/Atomic/commitid.log"), + ] + + extra_args + + [self.topdir + "/fedora-atomic-docker-host.json"], logfile=self.topdir + "/logs/Atomic/create-ostree-repo.log", show_cmd=True, stdout=True, universal_newlines=True, ) - ] + extra_calls + ] + + extra_calls, ) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_full_run(self, run): - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s/fedora-atomic-docker-host.json' % self.topdir, - ]) + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s/fedora-atomic-docker-host.json" % self.topdir, + ] + ) self.assertCorrectCall(run) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_run_on_existing_empty_dir(self, run): os.mkdir(self.repo) - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s/fedora-atomic-docker-host.json' % self.topdir, - ]) + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s/fedora-atomic-docker-host.json" % self.topdir, + ] + ) self.assertCorrectCall(run) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_run_on_initialized_repo(self, run): - helpers.touch(os.path.join(self.repo, 'initialized')) + helpers.touch(os.path.join(self.repo, "initialized")) - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s/fedora-atomic-docker-host.json' % self.topdir, - ]) + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s/fedora-atomic-docker-host.json" % self.topdir, + ] + ) self.assertCorrectCall(run) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_update_summary(self, run): - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s/fedora-atomic-docker-host.json' % self.topdir, - '--update-summary', - ]) + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s/fedora-atomic-docker-host.json" % self.topdir, + "--update-summary", + ] + ) self.assertCorrectCall( run, @@ -114,133 +142,137 @@ class OstreeTreeScriptTest(helpers.PungiTestCase): stdout=True, universal_newlines=True, ) + ], + ) + + @mock.patch("kobo.shortcuts.run") + def test_versioning_metadata(self, run): + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s/fedora-atomic-docker-host.json" % self.topdir, + "--version=24", ] ) - @mock.patch('kobo.shortcuts.run') - def test_versioning_metadata(self, run): - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s/fedora-atomic-docker-host.json' % self.topdir, - '--version=24', - ]) - self.assertCorrectCall(run, extra_args=["--add-metadata-string=version=24"]) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_ostree_ref(self, run): self._make_dummy_config_dir(self.topdir) - treefile = os.path.join(self.topdir, 'fedora-atomic-docker-host.json') + treefile = os.path.join(self.topdir, "fedora-atomic-docker-host.json") - with open(treefile, 'r') as f: + with open(treefile, "r") as f: treefile_content = json.load(f) - original_repos = treefile_content['repos'] - original_ref = treefile_content['ref'] - replacing_ref = original_ref + '-changed' + original_repos = treefile_content["repos"] + original_ref = treefile_content["ref"] + replacing_ref = original_ref + "-changed" - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s' % treefile, - '--ostree-ref=%s' % replacing_ref, - ]) + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s" % treefile, + "--ostree-ref=%s" % replacing_ref, + ] + ) - with open(treefile, 'r') as f: + with open(treefile, "r") as f: treefile_content = json.load(f) - new_repos = treefile_content['repos'] - new_ref = treefile_content['ref'] + new_repos = treefile_content["repos"] + new_ref = treefile_content["ref"] # ref value in treefile should be overrided with new ref self.assertEqual(replacing_ref, new_ref) # repos should stay unchanged self.assertEqual(original_repos, new_repos) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_run_with_yaml_file(self, run): self._make_dummy_config_dir(self.topdir) - treefile = os.path.join(self.topdir, 'fedora-atomic-docker-host.yaml') + treefile = os.path.join(self.topdir, "fedora-atomic-docker-host.yaml") - with open(treefile, 'r') as f: + with open(treefile, "r") as f: # Read initial content from YAML file treefile_content = yaml.safe_load(f) - original_repos = treefile_content['repos'] - original_ref = treefile_content['ref'] - replacing_ref = original_ref + '-changed' + original_repos = treefile_content["repos"] + original_ref = treefile_content["ref"] + replacing_ref = original_ref + "-changed" - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s' % treefile, - '--ostree-ref=%s' % replacing_ref, - ]) + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s" % treefile, + "--ostree-ref=%s" % replacing_ref, + ] + ) - with open(treefile.replace(".yaml", ".json"), 'r') as f: + with open(treefile.replace(".yaml", ".json"), "r") as f: # There is now a tweaked JSON file treefile_content = json.load(f) - new_repos = treefile_content['repos'] - new_ref = treefile_content['ref'] + new_repos = treefile_content["repos"] + new_ref = treefile_content["ref"] # ref value in treefile should be overrided with new ref self.assertEqual(replacing_ref, new_ref) # repos should stay unchanged self.assertEqual(original_repos, new_repos) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_force_new_commit(self, run): - helpers.touch(os.path.join(self.repo, 'initialized')) + helpers.touch(os.path.join(self.repo, "initialized")) - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s/fedora-atomic-docker-host.json' % self.topdir, - '--force-new-commit', - ]) + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s/fedora-atomic-docker-host.json" % self.topdir, + "--force-new-commit", + ] + ) self.assertCorrectCall(run, extra_args=["--force-nocache"]) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_extra_config_with_extra_repos(self, run): - configdir = os.path.join(self.topdir, 'config') + configdir = os.path.join(self.topdir, "config") self._make_dummy_config_dir(configdir) - treefile = os.path.join(configdir, 'fedora-atomic-docker-host.json') + treefile = os.path.join(configdir, "fedora-atomic-docker-host.json") - extra_config_file = os.path.join(self.topdir, 'extra_config.json') + extra_config_file = os.path.join(self.topdir, "extra_config.json") extra_config = { "repo": [ - { - "name": "server", - "baseurl": "http://www.example.com/Server/repo", - }, + {"name": "server", "baseurl": "http://www.example.com/Server/repo"}, { "name": "optional", "baseurl": "http://example.com/repo/x86_64/optional", "exclude": "systemd-container", - "gpgcheck": False + "gpgcheck": False, }, - { - "name": "extra", - "baseurl": "http://example.com/repo/x86_64/extra", - } + {"name": "extra", "baseurl": "http://example.com/repo/x86_64/extra"}, ] } helpers.touch(extra_config_file, json.dumps(extra_config)) - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s' % treefile, - '--extra-config=%s' % extra_config_file, - ]) + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s" % treefile, + "--extra-config=%s" % extra_config_file, + ] + ) pungi_repo = os.path.join(configdir, "pungi.repo") self.assertTrue(os.path.isfile(pungi_repo)) - with open(pungi_repo, 'r') as f: + with open(pungi_repo, "r") as f: content = f.read().strip() result_template = ( "[repo-0]", @@ -257,57 +289,59 @@ class OstreeTreeScriptTest(helpers.PungiTestCase): "baseurl=http://www.example.com/Server/repo", "gpgcheck=0", ) - result = '\n'.join(result_template).strip() + result = "\n".join(result_template).strip() self.assertEqual(content, result) - treeconf = json.load(open(treefile, 'r')) - repos = treeconf['repos'] + treeconf = json.load(open(treefile, "r")) + repos = treeconf["repos"] self.assertEqual(len(repos), 3) for name in ("repo-0", "repo-1", "repo-2"): self.assertIn(name, repos) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_extra_config_with_keep_original_sources(self, run): - configdir = os.path.join(self.topdir, 'config') + configdir = os.path.join(self.topdir, "config") self._make_dummy_config_dir(configdir) - treefile = os.path.join(configdir, 'fedora-atomic-docker-host.json') + treefile = os.path.join(configdir, "fedora-atomic-docker-host.json") - extra_config_file = os.path.join(self.topdir, 'extra_config.json') + extra_config_file = os.path.join(self.topdir, "extra_config.json") extra_config = { "repo": [ - { - "name": "server", - "baseurl": "http://www.example.com/Server/repo", - }, + {"name": "server", "baseurl": "http://www.example.com/Server/repo"}, { "name": "optional", "baseurl": "http://example.com/repo/x86_64/optional", "exclude": "systemd-container", - "gpgcheck": False + "gpgcheck": False, }, - { - "name": "extra", - "baseurl": "http://example.com/repo/x86_64/extra", - } + {"name": "extra", "baseurl": "http://example.com/repo/x86_64/extra"}, ], - "keep_original_sources": True + "keep_original_sources": True, } helpers.touch(extra_config_file, json.dumps(extra_config)) - ostree.main([ - 'tree', - '--repo=%s' % self.repo, - '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), - '--treefile=%s' % treefile, - '--extra-config=%s' % extra_config_file, - ]) + ostree.main( + [ + "tree", + "--repo=%s" % self.repo, + "--log-dir=%s" % os.path.join(self.topdir, "logs", "Atomic"), + "--treefile=%s" % treefile, + "--extra-config=%s" % extra_config_file, + ] + ) - treeconf = json.load(open(treefile, 'r')) - repos = treeconf['repos'] + treeconf = json.load(open(treefile, "r")) + repos = treeconf["repos"] self.assertEqual(len(repos), 6) - for name in ['fedora-rawhide', 'fedora-24', 'fedora-23', - 'repo-0', 'repo-1', 'repo-2']: + for name in [ + "fedora-rawhide", + "fedora-24", + "fedora-23", + "repo-0", + "repo-1", + "repo-2", + ]: self.assertIn(name, repos) @@ -317,30 +351,32 @@ class OstreeInstallerScriptTest(helpers.PungiTestCase): self.product = "dummyproduct" self.version = "1.0" self.release = "20160101.t.0" - self.output = os.path.join(self.topdir, 'output') - self.logdir = os.path.join(self.topdir, 'logs') - self.volid = '%s-%s' % (self.product, self.version) - self.variant = 'dummy' + self.output = os.path.join(self.topdir, "output") + self.logdir = os.path.join(self.topdir, "logs") + self.volid = "%s-%s" % (self.product, self.version) + self.variant = "dummy" self.rootfs_size = None - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_run_with_args(self, run): - args = ['installer', - '--product=%s' % self.product, - '--version=%s' % self.version, - '--release=%s' % self.release, - '--output=%s' % self.output, - '--variant=%s' % self.variant, - '--rootfs-size=%s' % self.rootfs_size, - '--nomacboot', - '--isfinal'] - args.append('--source=%s' % 'http://www.example.com/dummy/repo') - args.append('--installpkgs=dummy-foo') - args.append('--installpkgs=dummy-bar') - args.append('--add-template=/path/to/lorax.tmpl') - args.append('--add-template-var=ostree_osname=dummy') - args.append('--add-arch-template=/path/to/lorax-embed.tmpl') - args.append('--add-arch-template-var=ostree_repo=http://www.example.com/ostree') + args = [ + "installer", + "--product=%s" % self.product, + "--version=%s" % self.version, + "--release=%s" % self.release, + "--output=%s" % self.output, + "--variant=%s" % self.variant, + "--rootfs-size=%s" % self.rootfs_size, + "--nomacboot", + "--isfinal", + ] + args.append("--source=%s" % "http://www.example.com/dummy/repo") + args.append("--installpkgs=dummy-foo") + args.append("--installpkgs=dummy-bar") + args.append("--add-template=/path/to/lorax.tmpl") + args.append("--add-template-var=ostree_osname=dummy") + args.append("--add-arch-template=/path/to/lorax-embed.tmpl") + args.append("--add-arch-template-var=ostree_repo=http://www.example.com/ostree") ostree.main(args) self.maxDiff = None six.assertCountEqual( @@ -370,29 +406,41 @@ class OstreeInstallerScriptTest(helpers.PungiTestCase): ], ) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_run_with_extra_config_file(self, run): - extra_config_file = os.path.join(self.topdir, 'extra_config.json') - helpers.touch(extra_config_file, - json.dumps({'repo': 'http://www.example.com/another/repo', - 'installpkgs': ['dummy-foo', 'dummy-bar'], - 'add_template': ['/path/to/lorax.tmpl'], - 'add_template_var': ['ostree_osname=dummy-atomic', - 'ostree_ref=dummy/x86_64/docker'], - 'add_arch_template': ['/path/to/lorax-embed.tmpl'], - 'add_arch_template_var': ['ostree_osname=dummy-atomic', - 'ostree_repo=http://www.example.com/ostree']})) - args = ['installer', - '--product=%s' % self.product, - '--version=%s' % self.version, - '--release=%s' % self.release, - '--output=%s' % self.output, - '--variant=%s' % self.variant, - '--rootfs-size=%s' % self.rootfs_size, - '--nomacboot', - '--isfinal'] - args.append('--source=%s' % 'http://www.example.com/dummy/repo') - args.append('--extra-config=%s' % extra_config_file) + extra_config_file = os.path.join(self.topdir, "extra_config.json") + helpers.touch( + extra_config_file, + json.dumps( + { + "repo": "http://www.example.com/another/repo", + "installpkgs": ["dummy-foo", "dummy-bar"], + "add_template": ["/path/to/lorax.tmpl"], + "add_template_var": [ + "ostree_osname=dummy-atomic", + "ostree_ref=dummy/x86_64/docker", + ], + "add_arch_template": ["/path/to/lorax-embed.tmpl"], + "add_arch_template_var": [ + "ostree_osname=dummy-atomic", + "ostree_repo=http://www.example.com/ostree", + ], + } + ), + ) + args = [ + "installer", + "--product=%s" % self.product, + "--version=%s" % self.version, + "--release=%s" % self.release, + "--output=%s" % self.output, + "--variant=%s" % self.variant, + "--rootfs-size=%s" % self.rootfs_size, + "--nomacboot", + "--isfinal", + ] + args.append("--source=%s" % "http://www.example.com/dummy/repo") + args.append("--extra-config=%s" % extra_config_file) ostree.main(args) self.maxDiff = None six.assertCountEqual( diff --git a/tests/test_patch_iso.py b/tests/test_patch_iso.py index 0f7713de..ff266ca6 100644 --- a/tests/test_patch_iso.py +++ b/tests/test_patch_iso.py @@ -3,6 +3,7 @@ import mock import os import sys + try: import unittest2 as unittest except ImportError: @@ -17,39 +18,39 @@ class TestUnifiedIsos(unittest.TestCase): class TestGetLoraxDir(unittest.TestCase): - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_success(self, mock_run): - mock_run.return_value = (0, 'hello') - self.assertEqual(patch_iso.get_lorax_dir(None), 'hello') + mock_run.return_value = (0, "hello") + self.assertEqual(patch_iso.get_lorax_dir(None), "hello") self.assertEqual(1, len(mock_run.call_args_list)) - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_crash(self, mock_run): mock_run.side_effect = boom - self.assertEqual(patch_iso.get_lorax_dir('hello'), 'hello') + self.assertEqual(patch_iso.get_lorax_dir("hello"), "hello") self.assertEqual(1, len(mock_run.call_args_list)) class TestSh(unittest.TestCase): - @mock.patch('kobo.shortcuts.run') + @mock.patch("kobo.shortcuts.run") def test_cmd(self, mock_run): - mock_run.return_value = (0, 'ok') + mock_run.return_value = (0, "ok") log = mock.Mock() - patch_iso.sh(log, ['ls'], foo='bar') - self.assertEqual(mock_run.call_args_list, - [mock.call(['ls'], foo='bar', universal_newlines=True)]) - self.assertEqual(log.info.call_args_list, - [mock.call('Running: %s', 'ls')]) - self.assertEqual(log.debug.call_args_list, - [mock.call('%s', 'ok')]) + patch_iso.sh(log, ["ls"], foo="bar") + self.assertEqual( + mock_run.call_args_list, + [mock.call(["ls"], foo="bar", universal_newlines=True)], + ) + self.assertEqual(log.info.call_args_list, [mock.call("Running: %s", "ls")]) + self.assertEqual(log.debug.call_args_list, [mock.call("%s", "ok")]) class TestAsBool(unittest.TestCase): def test_true(self): - self.assertTrue(patch_iso.as_bool('true')) + self.assertTrue(patch_iso.as_bool("true")) def test_false(self): - self.assertFalse(patch_iso.as_bool('false')) + self.assertFalse(patch_iso.as_bool("false")) def test_anything_else(self): obj = mock.Mock() @@ -61,171 +62,206 @@ class EqualsAny(object): return True def __repr__(self): - return u'ANYTHING' + return u"ANYTHING" ANYTHING = EqualsAny() class TestPatchingIso(unittest.TestCase): - - @mock.patch('pungi_utils.patch_iso.util.copy_all') - @mock.patch('pungi_utils.patch_iso.iso') - @mock.patch('pungi_utils.patch_iso.sh') + @mock.patch("pungi_utils.patch_iso.util.copy_all") + @mock.patch("pungi_utils.patch_iso.iso") + @mock.patch("pungi_utils.patch_iso.sh") def test_whole(self, sh, iso, copy_all): - iso.mount.return_value.__enter__.return_value = 'mounted-iso-dir' + iso.mount.return_value.__enter__.return_value = "mounted-iso-dir" def _create_files(src, dest): - touch(os.path.join(dest, 'dir', 'file.txt'), 'Hello') + touch(os.path.join(dest, "dir", "file.txt"), "Hello") copy_all.side_effect = _create_files - log = mock.Mock(name='logger') + log = mock.Mock(name="logger") opts = mock.Mock( - target='test.iso', - source='source.iso', + target="test.iso", + source="source.iso", force_arch=None, - volume_id='FOOBAR', - dirs=[] - ) - patch_iso.run(log, opts) - - self.assertEqual(iso.get_mkisofs_cmd.call_args_list, - [mock.call(os.path.abspath(opts.target), None, - boot_args=None, - exclude=['./lost+found'], - graft_points=ANYTHING, - input_charset=None, - volid='FOOBAR')]) - self.assertEqual(iso.mount.call_args_list, - [mock.call('source.iso')]) - self.assertEqual(copy_all.mock_calls, - [mock.call('mounted-iso-dir', ANYTHING)]) - self.assertEqual( - sh.call_args_list, - [mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING), - mock.call(log, iso.get_implantisomd5_cmd.return_value)]) - - @mock.patch('pungi_utils.patch_iso.util.copy_all') - @mock.patch('pungi_utils.patch_iso.iso') - @mock.patch('pungi_utils.patch_iso.sh') - def test_detect_arch_discinfo(self, sh, iso, copy_all): - iso.mount.return_value.__enter__.return_value = 'mounted-iso-dir' - - def _create_files(src, dest): - touch(os.path.join(dest, 'dir', 'file.txt'), 'Hello') - touch(os.path.join(dest, '.discinfo'), - '1487578537.111417\nDummy Product 1.0\nppc64\n1') - - copy_all.side_effect = _create_files - - log = mock.Mock(name='logger') - opts = mock.Mock( - target='test.iso', - source='source.iso', - force_arch=None, - volume_id=None, - dirs=[] - ) - patch_iso.run(log, opts) - - self.assertEqual(iso.mount.call_args_list, - [mock.call('source.iso')]) - self.assertEqual(iso.get_mkisofs_cmd.call_args_list, - [mock.call(os.path.abspath(opts.target), None, - boot_args=iso.get_boot_options.return_value, - exclude=['./lost+found'], - graft_points=ANYTHING, - input_charset=None, - volid=iso.get_volume_id.return_value)]) - self.assertEqual(copy_all.mock_calls, - [mock.call('mounted-iso-dir', ANYTHING)]) - self.assertEqual( - sh.call_args_list, - [mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING), - mock.call(log, iso.get_implantisomd5_cmd.return_value)]) - - @mock.patch('pungi_utils.patch_iso.util.copy_all') - @mock.patch('pungi_utils.patch_iso.iso') - @mock.patch('pungi_utils.patch_iso.sh') - def test_run_isohybrid(self, sh, iso, copy_all): - iso.mount.return_value.__enter__.return_value = 'mounted-iso-dir' - - def _create_files(src, dest): - touch(os.path.join(dest, 'dir', 'file.txt'), 'Hello') - copy_fixture( - 'DP-1.0-20161013.t.4/compose/Server/x86_64/os/.treeinfo', - os.path.join(dest, '.treeinfo') - ) - - copy_all.side_effect = _create_files - - log = mock.Mock(name='logger') - opts = mock.Mock( - target='test.iso', - source='source.iso', - force_arch=None, - volume_id=None, - dirs=[] - ) - patch_iso.run(log, opts) - - self.assertEqual(iso.mount.call_args_list, - [mock.call('source.iso')]) - self.assertEqual(iso.get_mkisofs_cmd.call_args_list, - [mock.call(os.path.abspath(opts.target), None, - boot_args=iso.get_boot_options.return_value, - exclude=['./lost+found'], - graft_points=ANYTHING, - input_charset='utf-8', - volid=iso.get_volume_id.return_value)]) - self.assertEqual(copy_all.mock_calls, - [mock.call('mounted-iso-dir', ANYTHING)]) - self.assertEqual( - sh.call_args_list, - [mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING), - mock.call(log, iso.get_isohybrid_cmd.return_value), - mock.call(log, iso.get_implantisomd5_cmd.return_value)]) - - @mock.patch('pungi_utils.patch_iso.tweak_configs') - @mock.patch('pungi_utils.patch_iso.util.copy_all') - @mock.patch('pungi_utils.patch_iso.iso') - @mock.patch('pungi_utils.patch_iso.sh') - def test_add_ks_cfg(self, sh, iso, copy_all, tweak_configs): - iso.mount.return_value.__enter__.return_value = 'mounted-iso-dir' - iso.get_graft_points.return_value = { - 'ks.cfg': 'path/to/ks.cfg', - } - - def _create_files(src, dest): - touch(os.path.join(dest, 'dir', 'file.txt'), 'Hello') - - copy_all.side_effect = _create_files - - log = mock.Mock(name='logger') - opts = mock.Mock( - target='test.iso', - source='source.iso', - force_arch='s390', - volume_id='foobar', + volume_id="FOOBAR", dirs=[], ) patch_iso.run(log, opts) - self.assertEqual(iso.mount.call_args_list, - [mock.call('source.iso')]) - self.assertEqual(iso.get_mkisofs_cmd.call_args_list, - [mock.call(os.path.abspath(opts.target), None, - boot_args=iso.get_boot_options.return_value, - exclude=['./lost+found'], - graft_points=ANYTHING, - input_charset='utf-8', - volid='foobar')]) - self.assertEqual(tweak_configs.call_args_list, - [mock.call(ANYTHING, 'foobar', 'path/to/ks.cfg', logger=log)]) - self.assertEqual(copy_all.mock_calls, - [mock.call('mounted-iso-dir', ANYTHING)]) + self.assertEqual( + iso.get_mkisofs_cmd.call_args_list, + [ + mock.call( + os.path.abspath(opts.target), + None, + boot_args=None, + exclude=["./lost+found"], + graft_points=ANYTHING, + input_charset=None, + volid="FOOBAR", + ) + ], + ) + self.assertEqual(iso.mount.call_args_list, [mock.call("source.iso")]) + self.assertEqual(copy_all.mock_calls, [mock.call("mounted-iso-dir", ANYTHING)]) self.assertEqual( sh.call_args_list, - [mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING), - mock.call(log, iso.get_implantisomd5_cmd.return_value)]) + [ + mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING), + mock.call(log, iso.get_implantisomd5_cmd.return_value), + ], + ) + + @mock.patch("pungi_utils.patch_iso.util.copy_all") + @mock.patch("pungi_utils.patch_iso.iso") + @mock.patch("pungi_utils.patch_iso.sh") + def test_detect_arch_discinfo(self, sh, iso, copy_all): + iso.mount.return_value.__enter__.return_value = "mounted-iso-dir" + + def _create_files(src, dest): + touch(os.path.join(dest, "dir", "file.txt"), "Hello") + touch( + os.path.join(dest, ".discinfo"), + "1487578537.111417\nDummy Product 1.0\nppc64\n1", + ) + + copy_all.side_effect = _create_files + + log = mock.Mock(name="logger") + opts = mock.Mock( + target="test.iso", + source="source.iso", + force_arch=None, + volume_id=None, + dirs=[], + ) + patch_iso.run(log, opts) + + self.assertEqual(iso.mount.call_args_list, [mock.call("source.iso")]) + self.assertEqual( + iso.get_mkisofs_cmd.call_args_list, + [ + mock.call( + os.path.abspath(opts.target), + None, + boot_args=iso.get_boot_options.return_value, + exclude=["./lost+found"], + graft_points=ANYTHING, + input_charset=None, + volid=iso.get_volume_id.return_value, + ) + ], + ) + self.assertEqual(copy_all.mock_calls, [mock.call("mounted-iso-dir", ANYTHING)]) + self.assertEqual( + sh.call_args_list, + [ + mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING), + mock.call(log, iso.get_implantisomd5_cmd.return_value), + ], + ) + + @mock.patch("pungi_utils.patch_iso.util.copy_all") + @mock.patch("pungi_utils.patch_iso.iso") + @mock.patch("pungi_utils.patch_iso.sh") + def test_run_isohybrid(self, sh, iso, copy_all): + iso.mount.return_value.__enter__.return_value = "mounted-iso-dir" + + def _create_files(src, dest): + touch(os.path.join(dest, "dir", "file.txt"), "Hello") + copy_fixture( + "DP-1.0-20161013.t.4/compose/Server/x86_64/os/.treeinfo", + os.path.join(dest, ".treeinfo"), + ) + + copy_all.side_effect = _create_files + + log = mock.Mock(name="logger") + opts = mock.Mock( + target="test.iso", + source="source.iso", + force_arch=None, + volume_id=None, + dirs=[], + ) + patch_iso.run(log, opts) + + self.assertEqual(iso.mount.call_args_list, [mock.call("source.iso")]) + self.assertEqual( + iso.get_mkisofs_cmd.call_args_list, + [ + mock.call( + os.path.abspath(opts.target), + None, + boot_args=iso.get_boot_options.return_value, + exclude=["./lost+found"], + graft_points=ANYTHING, + input_charset="utf-8", + volid=iso.get_volume_id.return_value, + ) + ], + ) + self.assertEqual(copy_all.mock_calls, [mock.call("mounted-iso-dir", ANYTHING)]) + self.assertEqual( + sh.call_args_list, + [ + mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING), + mock.call(log, iso.get_isohybrid_cmd.return_value), + mock.call(log, iso.get_implantisomd5_cmd.return_value), + ], + ) + + @mock.patch("pungi_utils.patch_iso.tweak_configs") + @mock.patch("pungi_utils.patch_iso.util.copy_all") + @mock.patch("pungi_utils.patch_iso.iso") + @mock.patch("pungi_utils.patch_iso.sh") + def test_add_ks_cfg(self, sh, iso, copy_all, tweak_configs): + iso.mount.return_value.__enter__.return_value = "mounted-iso-dir" + iso.get_graft_points.return_value = { + "ks.cfg": "path/to/ks.cfg", + } + + def _create_files(src, dest): + touch(os.path.join(dest, "dir", "file.txt"), "Hello") + + copy_all.side_effect = _create_files + + log = mock.Mock(name="logger") + opts = mock.Mock( + target="test.iso", + source="source.iso", + force_arch="s390", + volume_id="foobar", + dirs=[], + ) + patch_iso.run(log, opts) + + self.assertEqual(iso.mount.call_args_list, [mock.call("source.iso")]) + self.assertEqual( + iso.get_mkisofs_cmd.call_args_list, + [ + mock.call( + os.path.abspath(opts.target), + None, + boot_args=iso.get_boot_options.return_value, + exclude=["./lost+found"], + graft_points=ANYTHING, + input_charset="utf-8", + volid="foobar", + ) + ], + ) + self.assertEqual( + tweak_configs.call_args_list, + [mock.call(ANYTHING, "foobar", "path/to/ks.cfg", logger=log)], + ) + self.assertEqual(copy_all.mock_calls, [mock.call("mounted-iso-dir", ANYTHING)]) + self.assertEqual( + sh.call_args_list, + [ + mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING), + mock.call(log, iso.get_implantisomd5_cmd.return_value), + ], + ) diff --git a/tests/test_pathmatch.py b/tests/test_pathmatch.py index b9e91981..e8129f50 100644 --- a/tests/test_pathmatch.py +++ b/tests/test_pathmatch.py @@ -32,7 +32,6 @@ class TestHeadTailSplit(unittest.TestCase): class TestPathMatch(unittest.TestCase): - def setUp(self): self.pm = PathMatch() @@ -56,7 +55,9 @@ class TestPathMatch(unittest.TestCase): self.pm["/*/*"] = "/star/star1" self.assertEqual(list(self.pm._patterns.keys()), ["*"]) self.assertEqual(list(self.pm._patterns["*"]._final_patterns.keys()), ["*"]) - self.assertEqual(self.pm._patterns["*"]._final_patterns["*"]._values, ["/star/star1"]) + self.assertEqual( + self.pm._patterns["*"]._final_patterns["*"]._values, ["/star/star1"] + ) self.assertEqual(sorted(self.pm["/lib/asd"]), ["/star/star1"]) self.pm["/*"] = "/star2" diff --git a/tests/test_phase_base.py b/tests/test_phase_base.py index 21558c75..1db7fe79 100644 --- a/tests/test_phase_base.py +++ b/tests/test_phase_base.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import mock + try: import unittest2 as unittest except ImportError: @@ -78,7 +79,7 @@ class TestWeaver(unittest.TestCase): weaver_phase.start() weaver_phase.stop() - self.assertEqual('BOOM', str(ctx.exception)) + self.assertEqual("BOOM", str(ctx.exception)) self.assertFinalized(self.p1) self.assertInterrupted(self.p2) self.assertMissed(self.p3) @@ -92,7 +93,7 @@ class TestWeaver(unittest.TestCase): weaver_phase.start() weaver_phase.stop() - self.assertEqual('BOOM', str(ctx.exception)) + self.assertEqual("BOOM", str(ctx.exception)) self.assertFinalized(self.p1) self.assertInterrupted(self.p2) self.assertFinalized(self.p3) @@ -107,7 +108,7 @@ class TestWeaver(unittest.TestCase): weaver_phase.start() weaver_phase.stop() - self.assertEqual('BOOM', str(ctx.exception)) + self.assertEqual("BOOM", str(ctx.exception)) self.assertFinalized(self.p1) self.assertInterrupted(self.p2) self.assertMissed(self.p3) @@ -125,7 +126,7 @@ class TestWeaver(unittest.TestCase): weaver_phase.start() weaver_phase.stop() - self.assertEqual('BOOM', str(ctx.exception)) + self.assertEqual("BOOM", str(ctx.exception)) self.assertFinalized(self.p1) self.assertInterrupted(self.p2) self.assertMissed(self.p3) diff --git a/tests/test_pkgset_pkgsets.py b/tests/test_pkgset_pkgsets.py index 6eb3381d..94118331 100644 --- a/tests/test_pkgset_pkgsets.py +++ b/tests/test_pkgset_pkgsets.py @@ -4,6 +4,7 @@ import mock import os import six import sys + try: import unittest2 as unittest except ImportError: @@ -25,24 +26,24 @@ class MockPathInfo(object): return self.topdir def get_filename(self, rpm_info): - return '{name}@{version}@{release}@{arch}'.format(**rpm_info) + return "{name}@{version}@{release}@{arch}".format(**rpm_info) def signed(self, rpm_info, sigkey): - return os.path.join('signed', sigkey, self.get_filename(rpm_info)) + return os.path.join("signed", sigkey, self.get_filename(rpm_info)) def rpm(self, rpm_info): - return os.path.join('rpms', self.get_filename(rpm_info)) + return os.path.join("rpms", self.get_filename(rpm_info)) class MockFile(object): def __init__(self, path): - if path.startswith('/tmp'): + if path.startswith("/tmp"): # Drop /tmp/something/ from path - path = path.split('/', 3)[-1] + path = path.split("/", 3)[-1] self.file_path = path self.file_name = os.path.basename(path) - self.name, self.version, self.release, self.arch = self.file_name.split('@') - self.sourcerpm = '{0.name}-{0.version}-{0.release}.{0.arch}'.format(self) + self.name, self.version, self.release, self.arch = self.file_name.split("@") + self.sourcerpm = "{0.name}-{0.version}-{0.release}.{0.arch}".format(self) self.exclusivearch = [] self.excludearch = [] @@ -78,6 +79,7 @@ class MockFileCache(dict): """Mock for kobo.pkgset.FileCache. It gets data from filename and does not touch filesystem. """ + def __init__(self, _wrapper): super(MockFileCache, self).__init__() self.file_cache = self @@ -93,6 +95,7 @@ class FakePool(object): It implements the same interface, but uses only the last added worker to process all tasks sequentially. """ + def __init__(self, package_set, logger=None): self.queue = [] self.worker = None @@ -128,13 +131,12 @@ class PkgsetCompareMixin(object): self.assertEqual({}, actual) -@mock.patch('pungi.phases.pkgset.pkgsets.ReaderPool', new=FakePool) -@mock.patch('kobo.pkgset.FileCache', new=MockFileCache) +@mock.patch("pungi.phases.pkgset.pkgsets.ReaderPool", new=FakePool) +@mock.patch("kobo.pkgset.FileCache", new=MockFileCache) class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase): - def setUp(self): super(TestKojiPkgset, self).setUp() - with open(os.path.join(helpers.FIXTURE_DIR, 'tagged-rpms.json')) as f: + with open(os.path.join(helpers.FIXTURE_DIR, "tagged-rpms.json")) as f: self.tagged_rpms = json.load(f) self.path_info = MockPathInfo(self.topdir) @@ -152,163 +154,208 @@ class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase): self.assertIn(k, actual) v2 = actual.pop(k) six.assertCountEqual(self, v1, v2) - self.assertEqual({}, actual, msg='Some architectures were missing') + self.assertEqual({}, actual, msg="Some architectures were missing") def test_all_arches(self): - self._touch_files([ - 'rpms/pungi@4.1.3@3.fc25@noarch', - 'rpms/pungi@4.1.3@3.fc25@src', - 'rpms/bash@4.3.42@4.fc24@i686', - 'rpms/bash@4.3.42@4.fc24@x86_64', - 'rpms/bash@4.3.42@4.fc24@src', - 'rpms/bash-debuginfo@4.3.42@4.fc24@i686', - 'rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - ]) + self._touch_files( + [ + "rpms/pungi@4.1.3@3.fc25@noarch", + "rpms/pungi@4.1.3@3.fc25@src", + "rpms/bash@4.3.42@4.fc24@i686", + "rpms/bash@4.3.42@4.fc24@x86_64", + "rpms/bash@4.3.42@4.fc24@src", + "rpms/bash-debuginfo@4.3.42@4.fc24@i686", + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + ] + ) pkgset = pkgsets.KojiPackageSet("pkgset", self.koji_wrapper, [None]) - result = pkgset.populate('f25') + result = pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)], + ) - self.assertPkgsetEqual(result, - {'src': ['rpms/pungi@4.1.3@3.fc25@src', - 'rpms/bash@4.3.42@4.fc24@src'], - 'noarch': ['rpms/pungi@4.1.3@3.fc25@noarch'], - 'i686': ['rpms/bash@4.3.42@4.fc24@i686', - 'rpms/bash-debuginfo@4.3.42@4.fc24@i686'], - 'x86_64': ['rpms/bash@4.3.42@4.fc24@x86_64', - 'rpms/bash-debuginfo@4.3.42@4.fc24@x86_64']}) + self.assertPkgsetEqual( + result, + { + "src": ["rpms/pungi@4.1.3@3.fc25@src", "rpms/bash@4.3.42@4.fc24@src"], + "noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"], + "i686": [ + "rpms/bash@4.3.42@4.fc24@i686", + "rpms/bash-debuginfo@4.3.42@4.fc24@i686", + ], + "x86_64": [ + "rpms/bash@4.3.42@4.fc24@x86_64", + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + ], + }, + ) def test_only_one_arch(self): - self._touch_files([ - 'rpms/bash@4.3.42@4.fc24@x86_64', - 'rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - ]) - - pkgset = pkgsets.KojiPackageSet( - "pkgset", self.koji_wrapper, [None], arches=['x86_64'] + self._touch_files( + [ + "rpms/bash@4.3.42@4.fc24@x86_64", + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + ] ) - result = pkgset.populate('f25') + pkgset = pkgsets.KojiPackageSet( + "pkgset", self.koji_wrapper, [None], arches=["x86_64"] + ) + + result = pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)], + ) - self.assertPkgsetEqual(result, - {'x86_64': ['rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - 'rpms/bash@4.3.42@4.fc24@x86_64']}) + self.assertPkgsetEqual( + result, + { + "x86_64": [ + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + "rpms/bash@4.3.42@4.fc24@x86_64", + ] + }, + ) def test_find_signed_with_preference(self): - self._touch_files([ - 'signed/cafebabe/bash@4.3.42@4.fc24@x86_64', - 'signed/deadbeef/bash@4.3.42@4.fc24@x86_64', - 'signed/deadbeef/bash-debuginfo@4.3.42@4.fc24@x86_64', - ]) - - pkgset = pkgsets.KojiPackageSet( - "pkgset", self.koji_wrapper, ['cafebabe', 'deadbeef'], arches=['x86_64'] + self._touch_files( + [ + "signed/cafebabe/bash@4.3.42@4.fc24@x86_64", + "signed/deadbeef/bash@4.3.42@4.fc24@x86_64", + "signed/deadbeef/bash-debuginfo@4.3.42@4.fc24@x86_64", + ] ) - result = pkgset.populate('f25') + pkgset = pkgsets.KojiPackageSet( + "pkgset", self.koji_wrapper, ["cafebabe", "deadbeef"], arches=["x86_64"] + ) + + result = pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)], + ) - self.assertPkgsetEqual(result, - {'x86_64': ['signed/cafebabe/bash@4.3.42@4.fc24@x86_64', - 'signed/deadbeef/bash-debuginfo@4.3.42@4.fc24@x86_64']}) + self.assertPkgsetEqual( + result, + { + "x86_64": [ + "signed/cafebabe/bash@4.3.42@4.fc24@x86_64", + "signed/deadbeef/bash-debuginfo@4.3.42@4.fc24@x86_64", + ] + }, + ) def test_find_signed_fallback_unsigned(self): - self._touch_files([ - 'signed/cafebabe/bash@4.3.42@4.fc24@x86_64', - 'rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - ]) - - pkgset = pkgsets.KojiPackageSet( - "pkgset", self.koji_wrapper, ['cafebabe', None], arches=['x86_64'] + self._touch_files( + [ + "signed/cafebabe/bash@4.3.42@4.fc24@x86_64", + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + ] ) - result = pkgset.populate('f25') + pkgset = pkgsets.KojiPackageSet( + "pkgset", self.koji_wrapper, ["cafebabe", None], arches=["x86_64"] + ) + + result = pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)], + ) - self.assertPkgsetEqual(result, - {'x86_64': ['rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - 'signed/cafebabe/bash@4.3.42@4.fc24@x86_64']}) + self.assertPkgsetEqual( + result, + { + "x86_64": [ + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + "signed/cafebabe/bash@4.3.42@4.fc24@x86_64", + ] + }, + ) def test_can_not_find_signed_package(self): pkgset = pkgsets.KojiPackageSet( - "pkgset", self.koji_wrapper, ['cafebabe'], arches=['x86_64'] + "pkgset", self.koji_wrapper, ["cafebabe"], arches=["x86_64"] ) with self.assertRaises(RuntimeError) as ctx: - pkgset.populate('f25') + pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)], + ) figure = re.compile( - r'^RPM\(s\) not found for sigs: .+Check log for details.+bash-4\.3\.42-4\.fc24.+bash-debuginfo-4\.3\.42-4\.fc24$', - re.DOTALL) + r"^RPM\(s\) not found for sigs: .+Check log for details.+bash-4\.3\.42-4\.fc24.+bash-debuginfo-4\.3\.42-4\.fc24$", + re.DOTALL, + ) self.assertRegexpMatches(str(ctx.exception), figure) def test_can_not_find_signed_package_allow_invalid_sigkeys(self): pkgset = pkgsets.KojiPackageSet( "pkgset", self.koji_wrapper, - ['cafebabe'], - arches=['x86_64'], + ["cafebabe"], + arches=["x86_64"], allow_invalid_sigkeys=True, ) - pkgset.populate('f25') + pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)], + ) with self.assertRaises(RuntimeError) as ctx: pkgset.raise_invalid_sigkeys_exception(pkgset.invalid_sigkey_rpms) figure = re.compile( - r'^RPM\(s\) not found for sigs: .+Check log for details.+bash-4\.3\.42-4\.fc24.+bash-debuginfo-4\.3\.42-4\.fc24$', - re.DOTALL) + r"^RPM\(s\) not found for sigs: .+Check log for details.+bash-4\.3\.42-4\.fc24.+bash-debuginfo-4\.3\.42-4\.fc24$", + re.DOTALL, + ) self.assertRegexpMatches(str(ctx.exception), figure) def test_can_not_find_any_package(self): pkgset = pkgsets.KojiPackageSet( - "pkgset", self.koji_wrapper, ['cafebabe', None], arches=['x86_64'] + "pkgset", self.koji_wrapper, ["cafebabe", None], arches=["x86_64"] ) with self.assertRaises(RuntimeError) as ctx: - pkgset.populate('f25') + pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)], + ) self.assertRegexpMatches( str(ctx.exception), - r'^RPM\(s\) not found for sigs: .+Check log for details.+') + r"^RPM\(s\) not found for sigs: .+Check log for details.+", + ) def test_packages_attribute(self): - self._touch_files([ - 'rpms/pungi@4.1.3@3.fc25@noarch', - 'rpms/pungi@4.1.3@3.fc25@src', - 'rpms/bash@4.3.42@4.fc24@i686', - 'rpms/bash@4.3.42@4.fc24@x86_64', - 'rpms/bash@4.3.42@4.fc24@src', - 'rpms/bash-debuginfo@4.3.42@4.fc24@i686', - 'rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - ]) + self._touch_files( + [ + "rpms/pungi@4.1.3@3.fc25@noarch", + "rpms/pungi@4.1.3@3.fc25@src", + "rpms/bash@4.3.42@4.fc24@i686", + "rpms/bash@4.3.42@4.fc24@x86_64", + "rpms/bash@4.3.42@4.fc24@src", + "rpms/bash-debuginfo@4.3.42@4.fc24@i686", + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + ] + ) pkgset = pkgsets.KojiPackageSet( "pkgset", @@ -318,56 +365,75 @@ class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase): populate_only_packages=True, ) - result = pkgset.populate('f25') + result = pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)], + ) - self.assertPkgsetEqual(result, - {'src': ['rpms/bash@4.3.42@4.fc24@src'], - 'i686': ['rpms/bash@4.3.42@4.fc24@i686'], - 'x86_64': ['rpms/bash@4.3.42@4.fc24@x86_64']}) + self.assertPkgsetEqual( + result, + { + "src": ["rpms/bash@4.3.42@4.fc24@src"], + "i686": ["rpms/bash@4.3.42@4.fc24@i686"], + "x86_64": ["rpms/bash@4.3.42@4.fc24@x86_64"], + }, + ) def test_get_latest_rpms_cache(self): - self._touch_files([ - 'rpms/bash@4.3.42@4.fc24@x86_64', - 'rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - ]) + self._touch_files( + [ + "rpms/bash@4.3.42@4.fc24@x86_64", + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + ] + ) cache_region = make_region().configure("dogpile.cache.memory") pkgset = pkgsets.KojiPackageSet( "pkgset", self.koji_wrapper, [None], - arches=['x86_64'], + arches=["x86_64"], cache_region=cache_region, ) # Try calling the populate twice, but expect just single listTaggedRPMs # call - that means the caching worked. for i in range(2): - result = pkgset.populate('f25') + result = pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [ + mock.call.listTaggedRPMS( + "f25", event=None, inherit=True, latest=True + ) + ], + ) self.assertPkgsetEqual( result, - {'x86_64': ['rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - 'rpms/bash@4.3.42@4.fc24@x86_64']}) + { + "x86_64": [ + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + "rpms/bash@4.3.42@4.fc24@x86_64", + ] + }, + ) def test_get_latest_rpms_cache_different_id(self): - self._touch_files([ - 'rpms/bash@4.3.42@4.fc24@x86_64', - 'rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - ]) + self._touch_files( + [ + "rpms/bash@4.3.42@4.fc24@x86_64", + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + ] + ) cache_region = make_region().configure("dogpile.cache.memory") pkgset = pkgsets.KojiPackageSet( "pkgset", self.koji_wrapper, [None], - arches=['x86_64'], + arches=["x86_64"], cache_region=cache_region, ) @@ -376,185 +442,215 @@ class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase): expected_calls = [] for i in range(2): expected_calls.append( - mock.call.listTaggedRPMS('f25', event=i, inherit=True, latest=True)) - result = pkgset.populate('f25', event={"id": i}) - self.assertEqual( - self.koji_wrapper.koji_proxy.mock_calls, - expected_calls) + mock.call.listTaggedRPMS("f25", event=i, inherit=True, latest=True) + ) + result = pkgset.populate("f25", event={"id": i}) + self.assertEqual(self.koji_wrapper.koji_proxy.mock_calls, expected_calls) self.assertPkgsetEqual( result, - {'x86_64': ['rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - 'rpms/bash@4.3.42@4.fc24@x86_64']}) + { + "x86_64": [ + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + "rpms/bash@4.3.42@4.fc24@x86_64", + ] + }, + ) def test_extra_builds_attribute(self): - self._touch_files([ - 'rpms/pungi@4.1.3@3.fc25@noarch', - 'rpms/pungi@4.1.3@3.fc25@src', - 'rpms/bash@4.3.42@4.fc24@i686', - 'rpms/bash@4.3.42@4.fc24@x86_64', - 'rpms/bash@4.3.42@4.fc24@src', - 'rpms/bash-debuginfo@4.3.42@4.fc24@i686', - 'rpms/bash-debuginfo@4.3.42@4.fc24@x86_64', - ]) + self._touch_files( + [ + "rpms/pungi@4.1.3@3.fc25@noarch", + "rpms/pungi@4.1.3@3.fc25@src", + "rpms/bash@4.3.42@4.fc24@i686", + "rpms/bash@4.3.42@4.fc24@x86_64", + "rpms/bash@4.3.42@4.fc24@src", + "rpms/bash-debuginfo@4.3.42@4.fc24@i686", + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + ] + ) # Return "pungi" RPMs and builds using "get_latest_rpms" which gets # them from Koji multiCall. - extra_rpms = [rpm for rpm in self.tagged_rpms[0] - if rpm["name"] == "pungi"] - extra_builds = [build for build in self.tagged_rpms[1] - if build["package_name"] == "pungi"] + extra_rpms = [rpm for rpm in self.tagged_rpms[0] if rpm["name"] == "pungi"] + extra_builds = [ + build for build in self.tagged_rpms[1] if build["package_name"] == "pungi" + ] self.koji_wrapper.retrying_multicall_map.side_effect = [ - extra_builds, [extra_rpms]] + extra_builds, + [extra_rpms], + ] # Do not return "pungi" RPMs and builds using the listTaggedRPMs, so # we can be sure "pungi" gets into compose using the `extra_builds`. self.koji_wrapper.koji_proxy.listTaggedRPMS.return_value = [ [rpm for rpm in self.tagged_rpms[0] if rpm["name"] != "pungi"], - [b for b in self.tagged_rpms[1] if b["package_name"] != "pungi"]] + [b for b in self.tagged_rpms[1] if b["package_name"] != "pungi"], + ] pkgset = pkgsets.KojiPackageSet( "pkgset", self.koji_wrapper, [None], extra_builds=["pungi-4.1.3-3.fc25"] ) - result = pkgset.populate('f25') + result = pkgset.populate("f25") self.assertEqual( self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.listTaggedRPMS('f25', event=None, inherit=True, latest=True)]) + [mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)], + ) - self.assertPkgsetEqual(result, - {'src': ['rpms/pungi@4.1.3@3.fc25@src', - 'rpms/bash@4.3.42@4.fc24@src'], - 'noarch': ['rpms/pungi@4.1.3@3.fc25@noarch'], - 'i686': ['rpms/bash@4.3.42@4.fc24@i686', - 'rpms/bash-debuginfo@4.3.42@4.fc24@i686'], - 'x86_64': ['rpms/bash@4.3.42@4.fc24@x86_64', - 'rpms/bash-debuginfo@4.3.42@4.fc24@x86_64']}) + self.assertPkgsetEqual( + result, + { + "src": ["rpms/pungi@4.1.3@3.fc25@src", "rpms/bash@4.3.42@4.fc24@src"], + "noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"], + "i686": [ + "rpms/bash@4.3.42@4.fc24@i686", + "rpms/bash-debuginfo@4.3.42@4.fc24@i686", + ], + "x86_64": [ + "rpms/bash@4.3.42@4.fc24@x86_64", + "rpms/bash-debuginfo@4.3.42@4.fc24@x86_64", + ], + }, + ) -@mock.patch('kobo.pkgset.FileCache', new=MockFileCache) +@mock.patch("kobo.pkgset.FileCache", new=MockFileCache) class TestMergePackageSets(PkgsetCompareMixin, unittest.TestCase): def test_merge_in_another_arch(self): first = pkgsets.PackageSetBase("first", [None]) second = pkgsets.PackageSetBase("second", [None]) - for name in ['rpms/pungi@4.1.3@3.fc25@noarch', 'rpms/pungi@4.1.3@3.fc25@src']: + for name in ["rpms/pungi@4.1.3@3.fc25@noarch", "rpms/pungi@4.1.3@3.fc25@src"]: pkg = first.file_cache.add(name) first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - for name in ['rpms/bash@4.3.42@4.fc24@i686']: + for name in ["rpms/bash@4.3.42@4.fc24@i686"]: pkg = second.file_cache.add(name) second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - first.merge(second, 'i386', ['i686']) + first.merge(second, "i386", ["i686"]) - self.assertPkgsetEqual(first.rpms_by_arch, - {'src': ['rpms/pungi@4.1.3@3.fc25@src'], - 'noarch': ['rpms/pungi@4.1.3@3.fc25@noarch'], - 'i686': ['rpms/bash@4.3.42@4.fc24@i686']}) + self.assertPkgsetEqual( + first.rpms_by_arch, + { + "src": ["rpms/pungi@4.1.3@3.fc25@src"], + "noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"], + "i686": ["rpms/bash@4.3.42@4.fc24@i686"], + }, + ) def test_merge_includes_noarch_with_different_exclude_arch(self): first = pkgsets.PackageSetBase("first", [None]) second = pkgsets.PackageSetBase("second", [None]) - pkg = first.file_cache.add('rpms/bash@4.3.42@4.fc24@i686') + pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686") first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - pkg = second.file_cache.add('rpms/pungi@4.1.3@3.fc25@noarch') - pkg.excludearch = ['x86_64'] + pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch") + pkg.excludearch = ["x86_64"] second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - first.merge(second, 'i386', ['i686', 'noarch']) + first.merge(second, "i386", ["i686", "noarch"]) - self.assertPkgsetEqual(first.rpms_by_arch, - {'i686': ['rpms/bash@4.3.42@4.fc24@i686'], - 'noarch': ['rpms/pungi@4.1.3@3.fc25@noarch']}) + self.assertPkgsetEqual( + first.rpms_by_arch, + { + "i686": ["rpms/bash@4.3.42@4.fc24@i686"], + "noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"], + }, + ) def test_merge_excludes_noarch_exclude_arch(self): first = pkgsets.PackageSetBase("first", [None]) second = pkgsets.PackageSetBase("second", [None]) - pkg = first.file_cache.add('rpms/bash@4.3.42@4.fc24@i686') + pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686") first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - pkg = second.file_cache.add('rpms/pungi@4.1.3@3.fc25@noarch') - pkg.excludearch = ['i686'] + pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch") + pkg.excludearch = ["i686"] second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - first.merge(second, 'i386', ['i686', 'noarch']) + first.merge(second, "i386", ["i686", "noarch"]) - self.assertPkgsetEqual(first.rpms_by_arch, - {'i686': ['rpms/bash@4.3.42@4.fc24@i686'], - 'noarch': []}) + self.assertPkgsetEqual( + first.rpms_by_arch, {"i686": ["rpms/bash@4.3.42@4.fc24@i686"], "noarch": []} + ) def test_merge_excludes_noarch_exclusive_arch(self): first = pkgsets.PackageSetBase("first", [None]) second = pkgsets.PackageSetBase("second", [None]) - pkg = first.file_cache.add('rpms/bash@4.3.42@4.fc24@i686') + pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686") first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - pkg = second.file_cache.add('rpms/pungi@4.1.3@3.fc25@noarch') - pkg.exclusivearch = ['x86_64'] + pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch") + pkg.exclusivearch = ["x86_64"] second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - first.merge(second, 'i386', ['i686', 'noarch']) + first.merge(second, "i386", ["i686", "noarch"]) - self.assertPkgsetEqual(first.rpms_by_arch, - {'i686': ['rpms/bash@4.3.42@4.fc24@i686'], - 'noarch': []}) + self.assertPkgsetEqual( + first.rpms_by_arch, {"i686": ["rpms/bash@4.3.42@4.fc24@i686"], "noarch": []} + ) def test_merge_includes_noarch_with_same_exclusive_arch(self): first = pkgsets.PackageSetBase("first", [None]) second = pkgsets.PackageSetBase("second", [None]) - pkg = first.file_cache.add('rpms/bash@4.3.42@4.fc24@i686') + pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686") first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - pkg = second.file_cache.add('rpms/pungi@4.1.3@3.fc25@noarch') - pkg.exclusivearch = ['i686'] + pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch") + pkg.exclusivearch = ["i686"] second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - first.merge(second, 'i386', ['i686', 'noarch']) + first.merge(second, "i386", ["i686", "noarch"]) - self.assertPkgsetEqual(first.rpms_by_arch, - {'i686': ['rpms/bash@4.3.42@4.fc24@i686'], - 'noarch': ['rpms/pungi@4.1.3@3.fc25@noarch']}) + self.assertPkgsetEqual( + first.rpms_by_arch, + { + "i686": ["rpms/bash@4.3.42@4.fc24@i686"], + "noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"], + }, + ) def test_merge_skips_package_in_cache(self): first = pkgsets.PackageSetBase("first", [None]) second = pkgsets.PackageSetBase("second", [None]) - pkg = first.file_cache.add('rpms/bash@4.3.42@4.fc24@i686') + pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686") first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - pkg = second.file_cache.add('rpms/bash@4.3.42@4.fc24@i686') + pkg = second.file_cache.add("rpms/bash@4.3.42@4.fc24@i686") second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - first.merge(second, 'i386', ['i686']) + first.merge(second, "i386", ["i686"]) - self.assertPkgsetEqual(first.rpms_by_arch, - {'i686': ['rpms/bash@4.3.42@4.fc24@i686']}) + self.assertPkgsetEqual( + first.rpms_by_arch, {"i686": ["rpms/bash@4.3.42@4.fc24@i686"]} + ) def test_merge_skips_src_without_binary(self): first = pkgsets.PackageSetBase("first", [None]) second = pkgsets.PackageSetBase("second", [None]) - pkg = first.file_cache.add('rpms/bash@4.3.42@4.fc24@i686') + pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686") first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - pkg = second.file_cache.add('rpms/pungi@4.1.3@3.fc25@src') + pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@src") second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - first.merge(second, 'i386', ['i686', 'src']) + first.merge(second, "i386", ["i686", "src"]) - self.assertPkgsetEqual(first.rpms_by_arch, - {'i686': ['rpms/bash@4.3.42@4.fc24@i686'], - 'src': [], - 'nosrc': []}) + self.assertPkgsetEqual( + first.rpms_by_arch, + {"i686": ["rpms/bash@4.3.42@4.fc24@i686"], "src": [], "nosrc": []}, + ) -@mock.patch('kobo.pkgset.FileCache', new=MockFileCache) +@mock.patch("kobo.pkgset.FileCache", new=MockFileCache) class TestSaveFileList(unittest.TestCase): def setUp(self): fd, self.tmpfile = tempfile.mkstemp() @@ -565,30 +661,37 @@ class TestSaveFileList(unittest.TestCase): def test_save_arches_alphabetically(self): pkgset = pkgsets.PackageSetBase("pkgset", [None]) - for name in ['rpms/pungi@4.1.3@3.fc25@x86_64', - 'rpms/pungi@4.1.3@3.fc25@src', - 'rpms/pungi@4.1.3@3.fc25@ppc64']: + for name in [ + "rpms/pungi@4.1.3@3.fc25@x86_64", + "rpms/pungi@4.1.3@3.fc25@src", + "rpms/pungi@4.1.3@3.fc25@ppc64", + ]: pkg = pkgset.file_cache.add(name) pkgset.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) pkgset.save_file_list(self.tmpfile) with open(self.tmpfile) as f: - rpms = f.read().strip().split('\n') - self.assertEqual(rpms, ['rpms/pungi@4.1.3@3.fc25@ppc64', - 'rpms/pungi@4.1.3@3.fc25@src', - 'rpms/pungi@4.1.3@3.fc25@x86_64']) + rpms = f.read().strip().split("\n") + self.assertEqual( + rpms, + [ + "rpms/pungi@4.1.3@3.fc25@ppc64", + "rpms/pungi@4.1.3@3.fc25@src", + "rpms/pungi@4.1.3@3.fc25@x86_64", + ], + ) def test_save_strip_prefix(self): pkgset = pkgsets.PackageSetBase("pkgset", [None]) - for name in ['rpms/pungi@4.1.3@3.fc25@noarch', 'rpms/pungi@4.1.3@3.fc25@src']: + for name in ["rpms/pungi@4.1.3@3.fc25@noarch", "rpms/pungi@4.1.3@3.fc25@src"]: pkg = pkgset.file_cache.add(name) pkgset.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) - pkgset.save_file_list(self.tmpfile, remove_path_prefix='rpms/') + pkgset.save_file_list(self.tmpfile, remove_path_prefix="rpms/") with open(self.tmpfile) as f: - rpms = f.read().strip().split('\n') + rpms = f.read().strip().split("\n") six.assertCountEqual( self, rpms, ["pungi@4.1.3@3.fc25@noarch", "pungi@4.1.3@3.fc25@src"] ) diff --git a/tests/test_pkgset_source_koji.py b/tests/test_pkgset_source_koji.py index b6570c9e..bb6ae1cf 100644 --- a/tests/test_pkgset_source_koji.py +++ b/tests/test_pkgset_source_koji.py @@ -6,6 +6,7 @@ import os import re import six import sys + try: import unittest2 as unittest except ImportError: @@ -15,29 +16,26 @@ from pungi.phases.pkgset.sources import source_koji from tests import helpers from pungi.module_util import Modulemd -EVENT_INFO = {'id': 15681980, 'ts': 1460956382.81936} +EVENT_INFO = {"id": 15681980, "ts": 1460956382.81936} TAG_INFO = { "maven_support": False, "locked": False, "name": "f25", - "extra": { - "mock.package_manager": "dnf" - }, + "extra": {"mock.package_manager": "dnf"}, "perm": None, "id": 335, "arches": None, "maven_include_all": None, - "perm_id": None + "perm_id": None, } class TestGetKojiEvent(helpers.PungiTestCase): - def setUp(self): super(TestGetKojiEvent, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) - self.event_file = self.topdir + '/work/global/koji-event' + self.event_file = self.topdir + "/work/global/koji-event" def test_use_preconfigured_event(self): koji_wrapper = mock.Mock() @@ -49,9 +47,8 @@ class TestGetKojiEvent(helpers.PungiTestCase): self.assertEqual(event, EVENT_INFO) six.assertCountEqual( - self, - koji_wrapper.mock_calls, - [mock.call.koji_proxy.getEvent(123456)]) + self, koji_wrapper.mock_calls, [mock.call.koji_proxy.getEvent(123456)] + ) with open(self.event_file) as f: self.assertEqual(json.load(f), EVENT_INFO) @@ -65,9 +62,8 @@ class TestGetKojiEvent(helpers.PungiTestCase): self.assertEqual(event, EVENT_INFO) six.assertCountEqual( - self, - koji_wrapper.mock_calls, - [mock.call.koji_proxy.getLastEvent()]) + self, koji_wrapper.mock_calls, [mock.call.koji_proxy.getLastEvent()] + ) with open(self.event_file) as f: self.assertEqual(json.load(f), EVENT_INFO) @@ -75,16 +71,19 @@ class TestGetKojiEvent(helpers.PungiTestCase): class TestPopulateGlobalPkgset(helpers.PungiTestCase): def setUp(self): super(TestPopulateGlobalPkgset, self).setUp() - self.compose = helpers.DummyCompose(self.topdir, { - 'pkgset_koji_tag': 'f25', - 'sigkeys': ["foo", "bar"], - }) + self.compose = helpers.DummyCompose( + self.topdir, {"pkgset_koji_tag": "f25", "sigkeys": ["foo", "bar"]} + ) self.koji_wrapper = mock.Mock() - self.pkgset_path = os.path.join(self.topdir, 'work', 'global', 'pkgset_global.pickle') - self.koji_module_path = os.path.join(self.topdir, 'work', 'global', 'koji-module-Server.yaml') + self.pkgset_path = os.path.join( + self.topdir, "work", "global", "pkgset_global.pickle" + ) + self.koji_module_path = os.path.join( + self.topdir, "work", "global", "koji-module-Server.yaml" + ) @mock.patch("pungi.phases.pkgset.sources.source_koji.MaterializedPackageSet.create") - @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet') + @mock.patch("pungi.phases.pkgset.pkgsets.KojiPackageSet") def test_populate(self, KojiPackageSet, materialize): materialize.side_effect = self.mock_materialize @@ -106,14 +105,12 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): return pkgset @mock.patch("pungi.phases.pkgset.sources.source_koji.MaterializedPackageSet.create") - @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet') - def test_populate_with_multiple_koji_tags( - self, KojiPackageSet, materialize - ): - self.compose = helpers.DummyCompose(self.topdir, { - 'pkgset_koji_tag': ['f25', 'f25-extra'], - 'sigkeys': ["foo", "bar"], - }) + @mock.patch("pungi.phases.pkgset.pkgsets.KojiPackageSet") + def test_populate_with_multiple_koji_tags(self, KojiPackageSet, materialize): + self.compose = helpers.DummyCompose( + self.topdir, + {"pkgset_koji_tag": ["f25", "f25-extra"], "sigkeys": ["foo", "bar"]}, + ) materialize.side_effect = self.mock_materialize @@ -123,7 +120,9 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): self.assertEqual(len(pkgsets), 2) init_calls = KojiPackageSet.call_args_list - six.assertCountEqual(self, [call[0][0] for call in init_calls], ["f25", "f25-extra"]) + six.assertCountEqual( + self, [call[0][0] for call in init_calls], ["f25", "f25-extra"] + ) six.assertCountEqual( self, [call[0][1] for call in init_calls], [self.koji_wrapper] * 2 ) @@ -143,22 +142,24 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): ) @mock.patch("pungi.phases.pkgset.sources.source_koji.MaterializedPackageSet.create") - @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet.populate') - @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet.save_file_list') + @mock.patch("pungi.phases.pkgset.pkgsets.KojiPackageSet.populate") + @mock.patch("pungi.phases.pkgset.pkgsets.KojiPackageSet.save_file_list") def test_populate_packages_to_gather(self, save_file_list, popuplate, materialize): - self.compose = helpers.DummyCompose(self.topdir, { - 'gather_method': 'nodeps', - 'pkgset_koji_tag': 'f25', - 'sigkeys': ["foo", "bar"], - 'additional_packages': [ - ('.*', {'*': ['pkg', 'foo.x86_64']}), - ] - }) + self.compose = helpers.DummyCompose( + self.topdir, + { + "gather_method": "nodeps", + "pkgset_koji_tag": "f25", + "sigkeys": ["foo", "bar"], + "additional_packages": [(".*", {"*": ["pkg", "foo.x86_64"]})], + }, + ) materialize.side_effect = self.mock_materialize pkgsets = source_koji.populate_global_pkgset( - self.compose, self.koji_wrapper, '/prefix', 123456) + self.compose, self.koji_wrapper, "/prefix", 123456 + ) self.assertEqual(len(pkgsets), 1) six.assertCountEqual(self, pkgsets[0].packages, ["pkg", "foo"]) @@ -166,57 +167,55 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): class TestGetPackageSetFromKoji(helpers.PungiTestCase): def setUp(self): super(TestGetPackageSetFromKoji, self).setUp() - self.compose = helpers.DummyCompose(self.topdir, { - 'pkgset_koji_tag': 'f25', - }) + self.compose = helpers.DummyCompose(self.topdir, {"pkgset_koji_tag": "f25"}) self.compose.koji_event = None self.koji_wrapper = mock.Mock() self.koji_wrapper.koji_proxy.getLastEvent.return_value = EVENT_INFO self.koji_wrapper.koji_proxy.getTag.return_value = TAG_INFO - @mock.patch('pungi.phases.pkgset.sources.source_koji.populate_global_pkgset') + @mock.patch("pungi.phases.pkgset.sources.source_koji.populate_global_pkgset") def test_get_package_sets(self, pgp): pkgsets = source_koji.get_pkgset_from_koji( self.compose, self.koji_wrapper, "/prefix" ) six.assertCountEqual( - self, - self.koji_wrapper.koji_proxy.mock_calls, - [mock.call.getLastEvent()] + self, self.koji_wrapper.koji_proxy.mock_calls, [mock.call.getLastEvent()] ) self.assertEqual(pkgsets, pgp.return_value) self.assertEqual( pgp.call_args_list, - [mock.call(self.compose, self.koji_wrapper, '/prefix', EVENT_INFO)], + [mock.call(self.compose, self.koji_wrapper, "/prefix", EVENT_INFO)], ) def test_get_koji_modules(self): - mock_build_ids = [{'id': 1065873, 'name': 'testmodule2-master_dash-20180406051653.96c371af'}] + mock_build_ids = [ + {"id": 1065873, "name": "testmodule2-master_dash-20180406051653.96c371af"} + ] mock_extra = { - 'typeinfo': { - 'module': { - 'content_koji_tag': 'module-b62270b82443edde', - 'modulemd_str': mock.Mock(), - 'name': 'testmodule2', - 'stream': 'master', - 'version': '20180406051653', - 'context': '96c371af', + "typeinfo": { + "module": { + "content_koji_tag": "module-b62270b82443edde", + "modulemd_str": mock.Mock(), + "name": "testmodule2", + "stream": "master", + "version": "20180406051653", + "context": "96c371af", } } } mock_build_md = [ { - 'id': 1065873, - 'epoch': None, - 'extra': mock_extra, - 'name': 'testmodule2', - 'nvr': 'testmodule2-master_dash-20180406051653.2e6f5e0a', - 'release': '20180406051653.2e6f5e0a', - 'state': 1, - 'version': 'master_dash', - 'completion_ts': 1433473124.0, + "id": 1065873, + "epoch": None, + "extra": mock_extra, + "name": "testmodule2", + "nvr": "testmodule2-master_dash-20180406051653.2e6f5e0a", + "release": "20180406051653.2e6f5e0a", + "state": 1, + "version": "master_dash", + "completion_ts": 1433473124.0, } ] @@ -239,9 +238,12 @@ class TestGetPackageSetFromKoji(helpers.PungiTestCase): self.assertIn("tag", module) expected_query = "testmodule2-master_dash-20180406051653.96c371af" - self.koji_wrapper.koji_proxy.search.assert_called_once_with(expected_query, "build", - "glob") - self.koji_wrapper.koji_proxy.getBuild.assert_called_once_with(mock_build_ids[0]["id"]) + self.koji_wrapper.koji_proxy.search.assert_called_once_with( + expected_query, "build", "glob" + ) + self.koji_wrapper.koji_proxy.getBuild.assert_called_once_with( + mock_build_ids[0]["id"] + ) def test_get_koji_modules_filter_by_event(self): mock_build_ids = [ @@ -251,7 +253,8 @@ class TestGetPackageSetFromKoji(helpers.PungiTestCase): "typeinfo": { "module": { "content_koji_tag": "module-b62270b82443edde", - "modulemd_str": mock.Mock()} + "modulemd_str": mock.Mock(), + } } } mock_build_md = [ @@ -282,64 +285,66 @@ class TestGetPackageSetFromKoji(helpers.PungiTestCase): self.koji_wrapper.koji_proxy.search.assert_called_once_with( "testmodule2-master_dash-*", "build", "glob" ) - self.koji_wrapper.koji_proxy.getBuild.assert_called_once_with(mock_build_ids[0]["id"]) + self.koji_wrapper.koji_proxy.getBuild.assert_called_once_with( + mock_build_ids[0]["id"] + ) self.koji_wrapper.koji_proxy.listArchives.assert_not_called() self.koji_wrapper.koji_proxy.listRPMs.assert_not_called() def test_get_koji_modules_no_version(self): mock_build_ids = [ - {'id': 1065873, 'name': 'testmodule2-master-20180406051653.2e6f5e0a'}, - {'id': 1065874, 'name': 'testmodule2-master-20180406051653.96c371af'} + {"id": 1065873, "name": "testmodule2-master-20180406051653.2e6f5e0a"}, + {"id": 1065874, "name": "testmodule2-master-20180406051653.96c371af"}, ] mock_extra = [ { - 'typeinfo': { - 'module': { - 'content_koji_tag': 'module-b62270b82443edde', - 'modulemd_str': mock.Mock(), - 'name': 'testmodule2', - 'stream': 'master', - 'version': '20180406051653', - 'context': '2e6f5e0a', + "typeinfo": { + "module": { + "content_koji_tag": "module-b62270b82443edde", + "modulemd_str": mock.Mock(), + "name": "testmodule2", + "stream": "master", + "version": "20180406051653", + "context": "2e6f5e0a", } } }, { - 'typeinfo': { - 'module': { - 'content_koji_tag': 'module-52e40b9cdd3c0f7d', - 'modulemd_str': mock.Mock(), - 'name': 'testmodule2', - 'stream': 'master', - 'version': '20180406051653', - 'context': '96c371af', + "typeinfo": { + "module": { + "content_koji_tag": "module-52e40b9cdd3c0f7d", + "modulemd_str": mock.Mock(), + "name": "testmodule2", + "stream": "master", + "version": "20180406051653", + "context": "96c371af", } } - } + }, ] mock_build_md = [ { - 'id': 1065873, - 'epoch': None, - 'extra': mock_extra[0], - 'name': 'testmodule2', - 'nvr': 'testmodule2-master-20180406051653.2e6f5e0a', - 'release': '20180406051653.2e6f5e0a', - 'state': 1, - 'version': 'master', - 'completion_ts': 1433473124.0, + "id": 1065873, + "epoch": None, + "extra": mock_extra[0], + "name": "testmodule2", + "nvr": "testmodule2-master-20180406051653.2e6f5e0a", + "release": "20180406051653.2e6f5e0a", + "state": 1, + "version": "master", + "completion_ts": 1433473124.0, }, { - 'id': 1065874, - 'epoch': None, - 'extra': mock_extra[1], - 'name': 'testmodule2', - 'nvr': 'testmodule2-master-20180406051653.96c371af', - 'release': '20180406051653.96c371af', - 'state': 1, - 'version': 'master', - 'completion_ts': 1433473124.0, - } + "id": 1065874, + "epoch": None, + "extra": mock_extra[1], + "name": "testmodule2", + "nvr": "testmodule2-master-20180406051653.96c371af", + "release": "20180406051653.96c371af", + "state": 1, + "version": "master", + "completion_ts": 1433473124.0, + }, ] self.koji_wrapper.koji_proxy.search.return_value = mock_build_ids @@ -362,10 +367,14 @@ class TestGetPackageSetFromKoji(helpers.PungiTestCase): self.assertIn("module_context", module) expected_query = "testmodule2-master-*" - self.koji_wrapper.koji_proxy.search.assert_called_once_with(expected_query, "build", - "glob") + self.koji_wrapper.koji_proxy.search.assert_called_once_with( + expected_query, "build", "glob" + ) - expected_calls = [mock.call(mock_build_ids[0]["id"]), mock.call(mock_build_ids[1]["id"])] + expected_calls = [ + mock.call(mock_build_ids[0]["id"]), + mock.call(mock_build_ids[1]["id"]), + ] self.koji_wrapper.koji_proxy.getBuild.mock_calls == expected_calls def test_get_koji_modules_ignore_deleted(self): @@ -416,31 +425,29 @@ class TestGetPackageSetFromKoji(helpers.PungiTestCase): self.koji_wrapper.koji_proxy.search.assert_called_once_with( "testmodule2-master_dash-*", "build", "glob" ) - self.koji_wrapper.koji_proxy.getBuild.assert_called_once_with(mock_build_ids[0]["id"]) + self.koji_wrapper.koji_proxy.getBuild.assert_called_once_with( + mock_build_ids[0]["id"] + ) self.koji_wrapper.koji_proxy.listArchives.assert_not_called() self.koji_wrapper.koji_proxy.listRPMs.assert_not_called() class TestSourceKoji(helpers.PungiTestCase): - - @mock.patch('pungi.phases.pkgset.sources.source_koji.get_pkgset_from_koji') - @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + @mock.patch("pungi.phases.pkgset.sources.source_koji.get_pkgset_from_koji") + @mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper") def test_run(self, KojiWrapper, gpfk): - compose = helpers.DummyCompose(self.topdir, { - 'koji_profile': 'koji' - }) - KojiWrapper.return_value.koji_module.config.topdir = '/prefix' + compose = helpers.DummyCompose(self.topdir, {"koji_profile": "koji"}) + KojiWrapper.return_value.koji_module.config.topdir = "/prefix" phase = source_koji.PkgsetSourceKoji(compose) pkgsets, path_prefix = phase() self.assertEqual(pkgsets, gpfk.return_value) - self.assertEqual(path_prefix, '/prefix/') - self.assertEqual(KojiWrapper.mock_calls, [mock.call('koji')]) + self.assertEqual(path_prefix, "/prefix/") + self.assertEqual(KojiWrapper.mock_calls, [mock.call("koji")]) class TestCorrectNVR(helpers.PungiTestCase): - def setUp(self): super(TestCorrectNVR, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) @@ -467,36 +474,39 @@ class TestCorrectNVR(helpers.PungiTestCase): def test_new_nv(self): module_info = source_koji.variant_dict_from_str(self.compose, self.new_nv) - expected = { - 'name': 'base-runtime', - 'stream': 'f26'} + expected = {"name": "base-runtime", "stream": "f26"} self.assertEqual(module_info, expected) def test_new_nvr(self): module_info = source_koji.variant_dict_from_str(self.compose, self.new_nvr) expected = { - 'name': 'base-runtime', - 'stream': 'f26', - 'version': '20170502134116'} + "name": "base-runtime", + "stream": "f26", + "version": "20170502134116", + } self.assertEqual(module_info, expected) def test_new_nvrc(self): module_info = source_koji.variant_dict_from_str(self.compose, self.new_nvrc) expected = { - 'name': 'base-runtime', - 'stream': 'f26', - 'version': '20170502134116', - 'context': '0123abcd'} + "name": "base-runtime", + "stream": "f26", + "version": "20170502134116", + "context": "0123abcd", + } self.assertEqual(module_info, expected) def test_new_garbage_value(self): - self.assertRaises(ValueError, source_koji.variant_dict_from_str, - self.compose, 'foo:bar:baz:quux:qaar') + self.assertRaises( + ValueError, + source_koji.variant_dict_from_str, + self.compose, + "foo:bar:baz:quux:qaar", + ) class TestFilterInherited(unittest.TestCase): - def test_empty_module_list(self): event = {"id": 123456} koji_proxy = mock.Mock() @@ -504,7 +514,8 @@ class TestFilterInherited(unittest.TestCase): top_tag = "top-tag" koji_proxy.getFullInheritance.return_value = [ - {"name": "middle-tag"}, {"name": "bottom-tag"} + {"name": "middle-tag"}, + {"name": "bottom-tag"}, ] result = source_koji.filter_inherited(koji_proxy, event, module_builds, top_tag) @@ -521,7 +532,8 @@ class TestFilterInherited(unittest.TestCase): top_tag = "top-tag" koji_proxy.getFullInheritance.return_value = [ - {"name": "middle-tag"}, {"name": "bottom-tag"} + {"name": "middle-tag"}, + {"name": "bottom-tag"}, ] module_builds = [ {"name": "foo", "version": "1", "release": "1", "tag_name": "top-tag"}, @@ -547,7 +559,8 @@ class TestFilterInherited(unittest.TestCase): top_tag = "top-tag" koji_proxy.getFullInheritance.return_value = [ - {"name": "middle-tag"}, {"name": "bottom-tag"} + {"name": "middle-tag"}, + {"name": "bottom-tag"}, ] module_builds = [ {"name": "foo", "version": "1", "release": "2", "tag_name": "bottom-tag"}, @@ -671,7 +684,6 @@ class MockModule(object): @mock.patch("pungi.module_util.Modulemd.ModuleStream.read_file", new=MockModule) @unittest.skipIf(Modulemd is None, "Skipping tests, no module support") class TestAddModuleToVariant(helpers.PungiTestCase): - def setUp(self): super(TestAddModuleToVariant, self).setUp() self.koji = mock.Mock() @@ -695,9 +707,7 @@ class TestAddModuleToVariant(helpers.PungiTestCase): } def test_adding_module(self): - variant = mock.Mock( - arches=["armhfp", "x86_64"], arch_mmds={}, modules=[] - ) + variant = mock.Mock(arches=["armhfp", "x86_64"], arch_mmds={}, modules=[]) source_koji._add_module_to_variant(self.koji, variant, self.buildinfo) @@ -705,10 +715,14 @@ class TestAddModuleToVariant(helpers.PungiTestCase): variant.arch_mmds, { "armhfp": { - "module:master:20190318:abcdef": MockModule("/koji/modulemd.armv7hl.txt"), + "module:master:20190318:abcdef": MockModule( + "/koji/modulemd.armv7hl.txt" + ), }, "x86_64": { - "module:master:20190318:abcdef": MockModule("/koji/modulemd.x86_64.txt"), + "module:master:20190318:abcdef": MockModule( + "/koji/modulemd.x86_64.txt" + ), }, }, ) @@ -729,10 +743,14 @@ class TestAddModuleToVariant(helpers.PungiTestCase): variant.arch_mmds, { "armhfp": { - "module:master:20190318:abcdef": MockModule("/koji/modulemd.armv7hl.txt"), + "module:master:20190318:abcdef": MockModule( + "/koji/modulemd.armv7hl.txt" + ), }, "x86_64": { - "module:master:20190318:abcdef": MockModule("/koji/modulemd.x86_64.txt"), + "module:master:20190318:abcdef": MockModule( + "/koji/modulemd.x86_64.txt" + ), "m1:latest:20190101:cafe": MockModule("/koji/m1.x86_64.txt"), }, }, @@ -742,9 +760,7 @@ class TestAddModuleToVariant(helpers.PungiTestCase): ) def test_adding_module_with_add_module(self): - variant = mock.Mock( - arches=["armhfp", "x86_64"], arch_mmds={}, modules=[] - ) + variant = mock.Mock(arches=["armhfp", "x86_64"], arch_mmds={}, modules=[]) source_koji._add_module_to_variant( self.koji, variant, self.buildinfo, add_to_variant_modules=True @@ -754,10 +770,14 @@ class TestAddModuleToVariant(helpers.PungiTestCase): variant.arch_mmds, { "armhfp": { - "module:master:20190318:abcdef": MockModule("/koji/modulemd.armv7hl.txt"), + "module:master:20190318:abcdef": MockModule( + "/koji/modulemd.armv7hl.txt" + ), }, "x86_64": { - "module:master:20190318:abcdef": MockModule("/koji/modulemd.x86_64.txt"), + "module:master:20190318:abcdef": MockModule( + "/koji/modulemd.x86_64.txt" + ), }, }, ) @@ -782,10 +802,14 @@ class TestAddModuleToVariant(helpers.PungiTestCase): variant.arch_mmds, { "armhfp": { - "module:master:20190318:abcdef": MockModule("/koji/modulemd.armv7hl.txt"), + "module:master:20190318:abcdef": MockModule( + "/koji/modulemd.armv7hl.txt" + ), }, "x86_64": { - "module:master:20190318:abcdef": MockModule("/koji/modulemd.x86_64.txt"), + "module:master:20190318:abcdef": MockModule( + "/koji/modulemd.x86_64.txt" + ), "m1:latest:20190101:cafe": MockModule("/koji/m1.x86_64.txt"), }, }, diff --git a/tests/test_repoclosure_wrapper.py b/tests/test_repoclosure_wrapper.py index 7e4060ad..61207ae3 100755 --- a/tests/test_repoclosure_wrapper.py +++ b/tests/test_repoclosure_wrapper.py @@ -11,95 +11,101 @@ from . import helpers class RepoclosureWrapperTestCase(helpers.BaseTestCase): def test_minimal_command(self): - self.assertEqual(rc.get_repoclosure_cmd(), - ['/usr/bin/repoclosure', '--tempcache']) + self.assertEqual( + rc.get_repoclosure_cmd(), ["/usr/bin/repoclosure", "--tempcache"] + ) def test_minimal_dnf_command(self): - self.assertEqual(rc.get_repoclosure_cmd(backend='dnf'), - ['dnf', 'repoclosure']) + self.assertEqual(rc.get_repoclosure_cmd(backend="dnf"), ["dnf", "repoclosure"]) def test_unknown_backend(self): with self.assertRaises(RuntimeError) as ctx: - rc.get_repoclosure_cmd(backend='rpm') + rc.get_repoclosure_cmd(backend="rpm") - self.assertEqual(str(ctx.exception), 'Unknown repoclosure backend: rpm') + self.assertEqual(str(ctx.exception), "Unknown repoclosure backend: rpm") def test_multiple_arches(self): - self.assertEqual(rc.get_repoclosure_cmd(arch=['x86_64', 'ppc64']), - ['/usr/bin/repoclosure', '--tempcache', '--arch=x86_64', '--arch=ppc64']) + self.assertEqual( + rc.get_repoclosure_cmd(arch=["x86_64", "ppc64"]), + ["/usr/bin/repoclosure", "--tempcache", "--arch=x86_64", "--arch=ppc64"], + ) def test_full_command(self): - repos = {'my-repo': '/mnt/koji/repo'} - lookaside = {'fedora': 'http://kojipkgs.fp.o/repo'} + repos = {"my-repo": "/mnt/koji/repo"} + lookaside = {"fedora": "http://kojipkgs.fp.o/repo"} - cmd = rc.get_repoclosure_cmd(arch='x86_64', repos=repos, lookaside=lookaside) - self.assertEqual(cmd[0], '/usr/bin/repoclosure') + cmd = rc.get_repoclosure_cmd(arch="x86_64", repos=repos, lookaside=lookaside) + self.assertEqual(cmd[0], "/usr/bin/repoclosure") six.assertCountEqual( self, cmd[1:], [ - '--tempcache', - '--arch=x86_64', - '--repofrompath=my-repo,file:///mnt/koji/repo', - '--repofrompath=fedora,http://kojipkgs.fp.o/repo', - '--repoid=my-repo', - '--lookaside=fedora', - ] + "--tempcache", + "--arch=x86_64", + "--repofrompath=my-repo,file:///mnt/koji/repo", + "--repofrompath=fedora,http://kojipkgs.fp.o/repo", + "--repoid=my-repo", + "--lookaside=fedora", + ], ) def test_full_dnf_command(self): - repos = {'my-repo': '/mnt/koji/repo'} - lookaside = {'fedora': 'http://kojipkgs.fp.o/repo'} + repos = {"my-repo": "/mnt/koji/repo"} + lookaside = {"fedora": "http://kojipkgs.fp.o/repo"} - cmd = rc.get_repoclosure_cmd(backend='dnf', arch='x86_64', - repos=repos, lookaside=lookaside) - self.assertEqual(cmd[:2], ['dnf', 'repoclosure']) + cmd = rc.get_repoclosure_cmd( + backend="dnf", arch="x86_64", repos=repos, lookaside=lookaside + ) + self.assertEqual(cmd[:2], ["dnf", "repoclosure"]) six.assertCountEqual( self, cmd[2:], - ['--arch=x86_64', - '--repofrompath=my-repo,file:///mnt/koji/repo', - '--repofrompath=fedora,http://kojipkgs.fp.o/repo', - '--repo=my-repo', - '--check=my-repo', - '--repo=fedora']) + [ + "--arch=x86_64", + "--repofrompath=my-repo,file:///mnt/koji/repo", + "--repofrompath=fedora,http://kojipkgs.fp.o/repo", + "--repo=my-repo", + "--check=my-repo", + "--repo=fedora", + ], + ) def test_expand_repo(self): repos = { - 'local': '/mnt/koji/repo', - 'remote': 'http://kojipkgs.fp.o/repo', + "local": "/mnt/koji/repo", + "remote": "http://kojipkgs.fp.o/repo", } cmd = rc.get_repoclosure_cmd(repos=repos) - self.assertEqual(cmd[0], '/usr/bin/repoclosure') + self.assertEqual(cmd[0], "/usr/bin/repoclosure") six.assertCountEqual( self, cmd[1:], [ - '--tempcache', - '--repofrompath=local,file:///mnt/koji/repo', - '--repofrompath=remote,http://kojipkgs.fp.o/repo', - '--repoid=local', - '--repoid=remote', - ] + "--tempcache", + "--repofrompath=local,file:///mnt/koji/repo", + "--repofrompath=remote,http://kojipkgs.fp.o/repo", + "--repoid=local", + "--repoid=remote", + ], ) def test_expand_lookaside(self): repos = { - 'local': '/mnt/koji/repo', - 'remote': 'http://kojipkgs.fp.o/repo', + "local": "/mnt/koji/repo", + "remote": "http://kojipkgs.fp.o/repo", } cmd = rc.get_repoclosure_cmd(lookaside=repos) - self.assertEqual(cmd[0], '/usr/bin/repoclosure') + self.assertEqual(cmd[0], "/usr/bin/repoclosure") six.assertCountEqual( self, cmd[1:], [ - '--tempcache', - '--repofrompath=local,file:///mnt/koji/repo', - '--repofrompath=remote,http://kojipkgs.fp.o/repo', - '--lookaside=local', - '--lookaside=remote', - ] + "--tempcache", + "--repofrompath=local,file:///mnt/koji/repo", + "--repofrompath=remote,http://kojipkgs.fp.o/repo", + "--lookaside=local", + "--lookaside=remote", + ], ) @@ -118,7 +124,7 @@ class FusExtractorTestCase(helpers.PungiTestCase): def test_error(self): helpers.touch( self.input1, - "fus-DEBUG: Installing bar\nProblem 1/1\n - nothing provides foo\n" + "fus-DEBUG: Installing bar\nProblem 1/1\n - nothing provides foo\n", ) with self.assertRaises(RuntimeError) as ctx: rc.extract_from_fus_logs([self.input1], self.output) @@ -130,11 +136,11 @@ class FusExtractorTestCase(helpers.PungiTestCase): def test_errors_in_multiple_files(self): helpers.touch( self.input1, - "fus-DEBUG: Installing bar\nProblem 1/1\n - nothing provides foo\n" + "fus-DEBUG: Installing bar\nProblem 1/1\n - nothing provides foo\n", ) helpers.touch( self.input2, - "fus-DEBUG: Installing baz\nProblem 1/1\n - nothing provides quux\n" + "fus-DEBUG: Installing baz\nProblem 1/1\n - nothing provides quux\n", ) with self.assertRaises(RuntimeError) as ctx: rc.extract_from_fus_logs([self.input1, self.input2], self.output) diff --git a/tests/test_runroot.py b/tests/test_runroot.py index ab8942ba..aa23783c 100644 --- a/tests/test_runroot.py +++ b/tests/test_runroot.py @@ -11,15 +11,16 @@ from tests import helpers class TestRunrootOpenSSH(helpers.PungiTestCase): def setUp(self): super(TestRunrootOpenSSH, self).setUp() - self.compose = helpers.DummyCompose(self.topdir, { - "runroot": True, - "runroot_method": "openssh", - "runroot_ssh_user": "root", - "runroot_ssh_hostnames": { - "x86_64": "localhost" + self.compose = helpers.DummyCompose( + self.topdir, + { + "runroot": True, + "runroot_method": "openssh", + "runroot_ssh_user": "root", + "runroot_ssh_hostnames": {"x86_64": "localhost"}, + "runroot_tag": "f28-build", }, - "runroot_tag": "f28-build", - }) + ) self.runroot = Runroot(self.compose) @@ -52,7 +53,7 @@ class TestRunrootOpenSSH(helpers.PungiTestCase): """ logfile = ("/foo/runroot." + suffix + ".log") if suffix else "/foo/runroot.log" return mock.call( - ['ssh', '-oBatchMode=yes', '-n', '-l', 'root', 'localhost', cmd], + ["ssh", "-oBatchMode=yes", "-n", "-l", "root", "localhost", cmd], logfile=logfile, show_cmd=True, ) @@ -61,12 +62,15 @@ class TestRunrootOpenSSH(helpers.PungiTestCase): def test_run(self, run): run.return_value = (0, "dummy output\n") self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64") - run.assert_has_calls([ - self._ssh_call('df -h'), - self._ssh_call( - "rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", suffix="rpms" - ), - ]) + run.assert_has_calls( + [ + self._ssh_call("df -h"), + self._ssh_call( + "rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", + suffix="rpms", + ), + ] + ) @mock.patch("pungi.runroot.run") def test_get_buildroot_rpms(self, run): @@ -75,92 +79,123 @@ class TestRunrootOpenSSH(helpers.PungiTestCase): self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64") rpms = self.runroot.get_buildroot_rpms() - self.assertEqual( - set(rpms), set(["foo-1-1.fc29.noarch", "bar-1-1.fc29.noarch"])) + self.assertEqual(set(rpms), set(["foo-1-1.fc29.noarch", "bar-1-1.fc29.noarch"])) @mock.patch("pungi.runroot.run") def test_run_templates(self, run): - self.compose.conf["runroot_ssh_init_template"] = "/usr/sbin/init_runroot {runroot_tag}" - self.compose.conf["runroot_ssh_install_packages_template"] = \ - "install {runroot_key} {packages}" + self.compose.conf[ + "runroot_ssh_init_template" + ] = "/usr/sbin/init_runroot {runroot_tag}" + self.compose.conf[ + "runroot_ssh_install_packages_template" + ] = "install {runroot_key} {packages}" self.compose.conf["runroot_ssh_run_template"] = "run {runroot_key} {command}" run.return_value = (0, "key\n") - self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64", - packages=["lorax", "automake"]) - run.assert_has_calls([ - self._ssh_call('/usr/sbin/init_runroot f28-build', suffix="init"), - self._ssh_call('install key lorax automake', suffix="install_packages"), - self._ssh_call('run key df -h'), - self._ssh_call( - "run key rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", - suffix="rpms", - ), - ]) + self.runroot.run( + "df -h", + log_file="/foo/runroot.log", + arch="x86_64", + packages=["lorax", "automake"], + ) + run.assert_has_calls( + [ + self._ssh_call("/usr/sbin/init_runroot f28-build", suffix="init"), + self._ssh_call("install key lorax automake", suffix="install_packages"), + self._ssh_call("run key df -h"), + self._ssh_call( + "run key rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", + suffix="rpms", + ), + ] + ) @mock.patch("pungi.runroot.run") def test_run_templates_no_init(self, run): - self.compose.conf["runroot_ssh_install_packages_template"] = \ - "install {packages}" + self.compose.conf[ + "runroot_ssh_install_packages_template" + ] = "install {packages}" self.compose.conf["runroot_ssh_run_template"] = "run {command}" run.return_value = (0, "key\n") - self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64", - packages=["lorax", "automake"]) - run.assert_has_calls([ - self._ssh_call('install lorax automake', suffix="install_packages"), - self._ssh_call('run df -h'), - self._ssh_call( - "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", - suffix="rpms", - ), - ]) + self.runroot.run( + "df -h", + log_file="/foo/runroot.log", + arch="x86_64", + packages=["lorax", "automake"], + ) + run.assert_has_calls( + [ + self._ssh_call("install lorax automake", suffix="install_packages"), + self._ssh_call("run df -h"), + self._ssh_call( + "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", + suffix="rpms", + ), + ] + ) @mock.patch("pungi.runroot.run") def test_run_templates_no_packages(self, run): - self.compose.conf["runroot_ssh_install_packages_template"] = \ - "install {packages}" + self.compose.conf[ + "runroot_ssh_install_packages_template" + ] = "install {packages}" self.compose.conf["runroot_ssh_run_template"] = "run {command}" run.return_value = (0, "key\n") self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64") - run.assert_has_calls([ - self._ssh_call('run df -h'), - self._ssh_call( - "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", - suffix="rpms", - ), - ]) + run.assert_has_calls( + [ + self._ssh_call("run df -h"), + self._ssh_call( + "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", + suffix="rpms", + ), + ] + ) @mock.patch("pungi.runroot.run") def test_run_templates_no_install_packages(self, run): self.compose.conf["runroot_ssh_run_template"] = "run {command}" run.return_value = (0, "key\n") - self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64", - packages=["lorax", "automake"]) - run.assert_has_calls([ - self._ssh_call('run df -h'), - self._ssh_call( - "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", - suffix="rpms", - ), - ]) + self.runroot.run( + "df -h", + log_file="/foo/runroot.log", + arch="x86_64", + packages=["lorax", "automake"], + ) + run.assert_has_calls( + [ + self._ssh_call("run df -h"), + self._ssh_call( + "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", + suffix="rpms", + ), + ] + ) @mock.patch("pungi.runroot.run") def test_run_templates_output_dir(self, run): self.compose.conf["runroot_ssh_run_template"] = "run {command}" run.return_value = (0, "key\n") - self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64", - packages=["lorax", "automake"], - chown_paths=["/mnt/foo/compose", "/mnt/foo/x"]) - run.assert_has_calls([ - self._ssh_call( - "run df -h && chmod -R a+r /mnt/foo/compose /mnt/foo/x && " - "chown -R %d /mnt/foo/compose /mnt/foo/x" % os.getuid()), - self._ssh_call( - "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", - suffix="rpms", - ), - ]) + self.runroot.run( + "df -h", + log_file="/foo/runroot.log", + arch="x86_64", + packages=["lorax", "automake"], + chown_paths=["/mnt/foo/compose", "/mnt/foo/x"], + ) + run.assert_has_calls( + [ + self._ssh_call( + "run df -h && chmod -R a+r /mnt/foo/compose /mnt/foo/x && " + "chown -R %d /mnt/foo/compose /mnt/foo/x" % os.getuid() + ), + self._ssh_call( + "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", + suffix="rpms", + ), + ] + ) diff --git a/tests/test_scm.py b/tests/test_scm.py index cd872530..1238b04d 100644 --- a/tests/test_scm.py +++ b/tests/test_scm.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import mock + try: import unittest2 as unittest except ImportError: @@ -53,52 +54,58 @@ class FileSCMTestCase(SCMBaseTest): """ super(FileSCMTestCase, self).setUp() self.srcdir = tempfile.mkdtemp() - touch(os.path.join(self.srcdir, 'in_root')) - touch(os.path.join(self.srcdir, 'subdir', 'first')) - touch(os.path.join(self.srcdir, 'subdir', 'second')) + touch(os.path.join(self.srcdir, "in_root")) + touch(os.path.join(self.srcdir, "subdir", "first")) + touch(os.path.join(self.srcdir, "subdir", "second")) def tearDown(self): super(FileSCMTestCase, self).tearDown() shutil.rmtree(self.srcdir) def test_get_file_by_name(self): - file = os.path.join(self.srcdir, 'in_root') + file = os.path.join(self.srcdir, "in_root") retval = scm.get_file_from_scm(file, self.destdir) - self.assertStructure(retval, ['in_root']) + self.assertStructure(retval, ["in_root"]) def test_get_file_by_dict(self): - retval = scm.get_file_from_scm({ - 'scm': 'file', 'repo': None, 'file': os.path.join(self.srcdir, 'subdir', 'first')}, - self.destdir) - self.assertStructure(retval, ['first']) + retval = scm.get_file_from_scm( + { + "scm": "file", + "repo": None, + "file": os.path.join(self.srcdir, "subdir", "first"), + }, + self.destdir, + ) + self.assertStructure(retval, ["first"]) def test_get_dir_by_name(self): - retval = scm.get_dir_from_scm(os.path.join(self.srcdir, 'subdir'), self.destdir) - self.assertStructure(retval, ['first', 'second']) + retval = scm.get_dir_from_scm(os.path.join(self.srcdir, "subdir"), self.destdir) + self.assertStructure(retval, ["first", "second"]) def test_get_dir_by_dict(self): retval = scm.get_dir_from_scm( - {'scm': 'file', 'repo': None, 'dir': os.path.join(self.srcdir, 'subdir')}, - self.destdir) - self.assertStructure(retval, ['first', 'second']) + {"scm": "file", "repo": None, "dir": os.path.join(self.srcdir, "subdir")}, + self.destdir, + ) + self.assertStructure(retval, ["first", "second"]) def test_get_missing_file(self): with self.assertRaises(RuntimeError) as ctx: - scm.get_file_from_scm({'scm': 'file', - 'repo': None, - 'file': 'this-is-really-not-here.txt'}, - self.destdir) + scm.get_file_from_scm( + {"scm": "file", "repo": None, "file": "this-is-really-not-here.txt"}, + self.destdir, + ) - self.assertIn('No files matched', str(ctx.exception)) + self.assertIn("No files matched", str(ctx.exception)) def test_get_missing_dir(self): with self.assertRaises(RuntimeError) as ctx: - scm.get_dir_from_scm({'scm': 'file', - 'repo': None, - 'dir': 'this-is-really-not-here'}, - self.destdir) + scm.get_dir_from_scm( + {"scm": "file", "repo": None, "dir": "this-is-really-not-here"}, + self.destdir, + ) - self.assertIn('No directories matched', str(ctx.exception)) + self.assertIn("No directories matched", str(ctx.exception)) class GitSCMTestCase(SCMBaseTest): @@ -110,26 +117,30 @@ class GitSCMTestCase(SCMBaseTest): ["git", "init"], ["git", "fetch", "--depth=1", url, branch], ["git", "checkout", "FETCH_HEAD"], - ] + command, + ] + + command, ) - @mock.patch('pungi.wrappers.scm.run') + @mock.patch("pungi.wrappers.scm.run") def test_get_file(self, run): - def process(cmd, workdir=None, **kwargs): - touch(os.path.join(workdir, 'some_file.txt')) - touch(os.path.join(workdir, 'other_file.txt')) + touch(os.path.join(workdir, "some_file.txt")) + touch(os.path.join(workdir, "other_file.txt")) run.side_effect = process - retval = scm.get_file_from_scm({'scm': 'git', - 'repo': 'git://example.com/git/repo.git', - 'file': 'some_file.txt'}, - self.destdir) - self.assertStructure(retval, ['some_file.txt']) + retval = scm.get_file_from_scm( + { + "scm": "git", + "repo": "git://example.com/git/repo.git", + "file": "some_file.txt", + }, + self.destdir, + ) + self.assertStructure(retval, ["some_file.txt"]) self.assertCalls(run, "git://example.com/git/repo.git", "master") - @mock.patch('pungi.wrappers.scm.run') + @mock.patch("pungi.wrappers.scm.run") def test_get_file_fetch_fails(self, run): url = "git://example.com/git/repo.git" @@ -138,15 +149,15 @@ class GitSCMTestCase(SCMBaseTest): exc = RuntimeError() exc.output = "" raise exc - touch(os.path.join(workdir, 'some_file.txt')) - touch(os.path.join(workdir, 'other_file.txt')) + touch(os.path.join(workdir, "some_file.txt")) + touch(os.path.join(workdir, "other_file.txt")) run.side_effect = process retval = scm.get_file_from_scm( {"scm": "git", "repo": url, "file": "some_file.txt"}, self.destdir ) - self.assertStructure(retval, ['some_file.txt']) + self.assertStructure(retval, ["some_file.txt"]) self.assertEqual( [call[0][0] for call in run.call_args_list], [ @@ -158,77 +169,85 @@ class GitSCMTestCase(SCMBaseTest): ], ) - @mock.patch('pungi.wrappers.scm.run') + @mock.patch("pungi.wrappers.scm.run") def test_get_file_generated_by_command(self, run): - def process(cmd, workdir=None, **kwargs): if cmd[0] == "git": - touch(os.path.join(workdir, 'some_file.txt')) - return 0, '' + touch(os.path.join(workdir, "some_file.txt")) + return 0, "" run.side_effect = process - retval = scm.get_file_from_scm({'scm': 'git', - 'repo': 'git://example.com/git/repo.git', - 'file': 'some_file.txt', - 'command': 'make'}, - self.destdir) - self.assertStructure(retval, ['some_file.txt']) + retval = scm.get_file_from_scm( + { + "scm": "git", + "repo": "git://example.com/git/repo.git", + "file": "some_file.txt", + "command": "make", + }, + self.destdir, + ) + self.assertStructure(retval, ["some_file.txt"]) self.assertCalls(run, "git://example.com/git/repo.git", "master", "make") - @mock.patch('pungi.wrappers.scm.run') + @mock.patch("pungi.wrappers.scm.run") def test_get_file_and_fail_to_generate(self, run): - def process(cmd, workdir=None, **kwargs): if cmd[0] == "git": - touch(os.path.join(workdir, 'some_file.txt')) + touch(os.path.join(workdir, "some_file.txt")) return 0, "output" return 1, "output" run.side_effect = process with self.assertRaises(RuntimeError) as ctx: - scm.get_file_from_scm({'scm': 'git', - 'repo': 'git://example.com/git/repo.git', - 'file': 'some_file.txt', - 'command': 'make'}, - self.destdir) + scm.get_file_from_scm( + { + "scm": "git", + "repo": "git://example.com/git/repo.git", + "file": "some_file.txt", + "command": "make", + }, + self.destdir, + ) self.assertEqual(str(ctx.exception), "'make' failed with exit code 1") - @mock.patch('pungi.wrappers.scm.run') + @mock.patch("pungi.wrappers.scm.run") def test_get_dir(self, run): - def process(cmd, workdir=None, **kwargs): - touch(os.path.join(workdir, "subdir", 'first')) - touch(os.path.join(workdir, "subdir", 'second')) + touch(os.path.join(workdir, "subdir", "first")) + touch(os.path.join(workdir, "subdir", "second")) run.side_effect = process - retval = scm.get_dir_from_scm({'scm': 'git', - 'repo': 'git://example.com/git/repo.git', - 'dir': 'subdir'}, - self.destdir) - self.assertStructure(retval, ['first', 'second']) + retval = scm.get_dir_from_scm( + {"scm": "git", "repo": "git://example.com/git/repo.git", "dir": "subdir"}, + self.destdir, + ) + self.assertStructure(retval, ["first", "second"]) self.assertCalls(run, "git://example.com/git/repo.git", "master") - @mock.patch('pungi.wrappers.scm.run') + @mock.patch("pungi.wrappers.scm.run") def test_get_dir_and_generate(self, run): - def process(cmd, workdir=None, **kwargs): if cmd[0] == "git": - touch(os.path.join(workdir, 'subdir', 'first')) - touch(os.path.join(workdir, 'subdir', 'second')) - return 0, '' + touch(os.path.join(workdir, "subdir", "first")) + touch(os.path.join(workdir, "subdir", "second")) + return 0, "" run.side_effect = process - retval = scm.get_dir_from_scm({'scm': 'git', - 'repo': 'git://example.com/git/repo.git', - 'dir': 'subdir', - 'command': 'make'}, - self.destdir) - self.assertStructure(retval, ['first', 'second']) + retval = scm.get_dir_from_scm( + { + "scm": "git", + "repo": "git://example.com/git/repo.git", + "dir": "subdir", + "command": "make", + }, + self.destdir, + ) + self.assertStructure(retval, ["first", "second"]) self.assertCalls(run, "git://example.com/git/repo.git", "master", "make") @@ -237,8 +256,11 @@ class RpmSCMTestCase(SCMBaseTest): super(RpmSCMTestCase, self).setUp() self.tmpdir = tempfile.mkdtemp() self.exploded = set() - self.rpms = [self.tmpdir + '/whatever.rpm', self.tmpdir + '/another.rpm'] - self.numbered = [self.tmpdir + x for x in ['/one1.rpm', '/one2.rpm', '/two1.rpm', '/two2.rpm']] + self.rpms = [self.tmpdir + "/whatever.rpm", self.tmpdir + "/another.rpm"] + self.numbered = [ + self.tmpdir + x + for x in ["/one1.rpm", "/one2.rpm", "/two1.rpm", "/two2.rpm"] + ] for rpm in self.rpms + self.numbered: touch(rpm) @@ -248,155 +270,180 @@ class RpmSCMTestCase(SCMBaseTest): def _explode_rpm(self, path, dest): self.exploded.add(path) - touch(os.path.join(dest, 'some-file.txt')) - touch(os.path.join(dest, 'subdir', 'foo.txt')) - touch(os.path.join(dest, 'subdir', 'bar.txt')) + touch(os.path.join(dest, "some-file.txt")) + touch(os.path.join(dest, "subdir", "foo.txt")) + touch(os.path.join(dest, "subdir", "bar.txt")) def _explode_multiple(self, path, dest): self.exploded.add(path) cnt = len(self.exploded) - touch(os.path.join(dest, 'some-file-%d.txt' % cnt)) - touch(os.path.join(dest, 'subdir-%d' % cnt, 'foo-%d.txt' % cnt)) - touch(os.path.join(dest, 'common', 'foo-%d.txt' % cnt)) + touch(os.path.join(dest, "some-file-%d.txt" % cnt)) + touch(os.path.join(dest, "subdir-%d" % cnt, "foo-%d.txt" % cnt)) + touch(os.path.join(dest, "common", "foo-%d.txt" % cnt)) - @mock.patch('pungi.wrappers.scm.explode_rpm_package') + @mock.patch("pungi.wrappers.scm.explode_rpm_package") def test_get_file(self, explode): explode.side_effect = self._explode_rpm retval = scm.get_file_from_scm( - {'scm': 'rpm', 'repo': self.rpms[0], 'file': 'some-file.txt'}, - self.destdir) + {"scm": "rpm", "repo": self.rpms[0], "file": "some-file.txt"}, self.destdir + ) - self.assertStructure(retval, ['some-file.txt']) + self.assertStructure(retval, ["some-file.txt"]) self.assertEqual(self.exploded, set([self.rpms[0]])) - @mock.patch('pungi.wrappers.scm.explode_rpm_package') + @mock.patch("pungi.wrappers.scm.explode_rpm_package") def test_get_more_files(self, explode): explode.side_effect = self._explode_rpm retval = scm.get_file_from_scm( - {'scm': 'rpm', 'repo': self.rpms[0], - 'file': ['some-file.txt', 'subdir/foo.txt']}, - self.destdir) + { + "scm": "rpm", + "repo": self.rpms[0], + "file": ["some-file.txt", "subdir/foo.txt"], + }, + self.destdir, + ) - self.assertStructure(retval, ['some-file.txt', 'foo.txt']) + self.assertStructure(retval, ["some-file.txt", "foo.txt"]) self.assertEqual(self.exploded, set([self.rpms[0]])) - @mock.patch('pungi.wrappers.scm.explode_rpm_package') + @mock.patch("pungi.wrappers.scm.explode_rpm_package") def test_get_whole_dir(self, explode): explode.side_effect = self._explode_rpm retval = scm.get_dir_from_scm( - {'scm': 'rpm', 'repo': self.rpms[0], 'dir': 'subdir'}, - self.destdir) + {"scm": "rpm", "repo": self.rpms[0], "dir": "subdir"}, self.destdir + ) - self.assertStructure(retval, ['subdir/foo.txt', 'subdir/bar.txt']) + self.assertStructure(retval, ["subdir/foo.txt", "subdir/bar.txt"]) self.assertEqual(self.exploded, set([self.rpms[0]])) - @mock.patch('pungi.wrappers.scm.explode_rpm_package') + @mock.patch("pungi.wrappers.scm.explode_rpm_package") def test_get_dir_contents(self, explode): explode.side_effect = self._explode_rpm retval = scm.get_dir_from_scm( - {'scm': 'rpm', 'repo': self.rpms[0], 'dir': 'subdir/'}, - self.destdir) + {"scm": "rpm", "repo": self.rpms[0], "dir": "subdir/"}, self.destdir + ) - self.assertStructure(retval, ['foo.txt', 'bar.txt']) + self.assertStructure(retval, ["foo.txt", "bar.txt"]) self.assertEqual(self.exploded, set([self.rpms[0]])) - @mock.patch('pungi.wrappers.scm.explode_rpm_package') + @mock.patch("pungi.wrappers.scm.explode_rpm_package") def test_get_files_from_two_rpms(self, explode): explode.side_effect = self._explode_multiple retval = scm.get_file_from_scm( - {'scm': 'rpm', 'repo': self.rpms, - 'file': ['some-file-1.txt', 'some-file-2.txt']}, - self.destdir) + { + "scm": "rpm", + "repo": self.rpms, + "file": ["some-file-1.txt", "some-file-2.txt"], + }, + self.destdir, + ) - self.assertStructure(retval, ['some-file-1.txt', 'some-file-2.txt']) + self.assertStructure(retval, ["some-file-1.txt", "some-file-2.txt"]) six.assertCountEqual(self, self.exploded, self.rpms) - @mock.patch('pungi.wrappers.scm.explode_rpm_package') + @mock.patch("pungi.wrappers.scm.explode_rpm_package") def test_get_files_from_glob_rpms(self, explode): explode.side_effect = self._explode_multiple retval = scm.get_file_from_scm( - {'scm': 'rpm', 'file': 'some-file-*.txt', - 'repo': [self.tmpdir + '/one*.rpm', self.tmpdir + '/two*.rpm']}, - self.destdir) + { + "scm": "rpm", + "file": "some-file-*.txt", + "repo": [self.tmpdir + "/one*.rpm", self.tmpdir + "/two*.rpm"], + }, + self.destdir, + ) - self.assertStructure(retval, - ['some-file-1.txt', 'some-file-2.txt', 'some-file-3.txt', 'some-file-4.txt']) + self.assertStructure( + retval, + [ + "some-file-1.txt", + "some-file-2.txt", + "some-file-3.txt", + "some-file-4.txt", + ], + ) six.assertCountEqual(self, self.exploded, self.numbered) - @mock.patch('pungi.wrappers.scm.explode_rpm_package') + @mock.patch("pungi.wrappers.scm.explode_rpm_package") def test_get_dir_from_two_rpms(self, explode): explode.side_effect = self._explode_multiple - retval = scm.get_dir_from_scm({'scm': 'rpm', - 'repo': self.rpms, - 'dir': 'common'}, - self.destdir) + retval = scm.get_dir_from_scm( + {"scm": "rpm", "repo": self.rpms, "dir": "common"}, self.destdir + ) - self.assertStructure(retval, ['common/foo-1.txt', 'common/foo-2.txt']) + self.assertStructure(retval, ["common/foo-1.txt", "common/foo-2.txt"]) six.assertCountEqual(self, self.exploded, self.rpms) - @mock.patch('pungi.wrappers.scm.explode_rpm_package') + @mock.patch("pungi.wrappers.scm.explode_rpm_package") def test_get_dir_from_glob_rpms(self, explode): explode.side_effect = self._explode_multiple retval = scm.get_dir_from_scm( - {'scm': 'rpm', 'dir': 'common/', - 'repo': [self.tmpdir + '/one*.rpm', self.tmpdir + '/two*.rpm']}, - self.destdir) + { + "scm": "rpm", + "dir": "common/", + "repo": [self.tmpdir + "/one*.rpm", self.tmpdir + "/two*.rpm"], + }, + self.destdir, + ) - self.assertStructure(retval, - ['foo-1.txt', 'foo-2.txt', 'foo-3.txt', 'foo-4.txt']) + self.assertStructure( + retval, ["foo-1.txt", "foo-2.txt", "foo-3.txt", "foo-4.txt"] + ) six.assertCountEqual(self, self.exploded, self.numbered) class CvsSCMTestCase(SCMBaseTest): - @mock.patch('pungi.wrappers.scm.run') + @mock.patch("pungi.wrappers.scm.run") def test_get_file(self, run): commands = [] def process(cmd, workdir=None, **kwargs): fname = cmd[-1] touch(os.path.join(workdir, fname)) - commands.append(' '.join(cmd)) + commands.append(" ".join(cmd)) run.side_effect = process - retval = scm.get_file_from_scm({'scm': 'cvs', - 'repo': 'http://example.com/cvs', - 'file': 'some_file.txt'}, - self.destdir) - self.assertStructure(retval, ['some_file.txt']) + retval = scm.get_file_from_scm( + {"scm": "cvs", "repo": "http://example.com/cvs", "file": "some_file.txt"}, + self.destdir, + ) + self.assertStructure(retval, ["some_file.txt"]) self.assertEqual( commands, - ['/usr/bin/cvs -q -d http://example.com/cvs export -r HEAD some_file.txt']) + ["/usr/bin/cvs -q -d http://example.com/cvs export -r HEAD some_file.txt"], + ) - @mock.patch('pungi.wrappers.scm.run') + @mock.patch("pungi.wrappers.scm.run") def test_get_dir(self, run): commands = [] def process(cmd, workdir=None, **kwargs): fname = cmd[-1] - touch(os.path.join(workdir, fname, 'first')) - touch(os.path.join(workdir, fname, 'second')) - commands.append(' '.join(cmd)) + touch(os.path.join(workdir, fname, "first")) + touch(os.path.join(workdir, fname, "second")) + commands.append(" ".join(cmd)) run.side_effect = process - retval = scm.get_dir_from_scm({'scm': 'cvs', - 'repo': 'http://example.com/cvs', - 'dir': 'subdir'}, - self.destdir) - self.assertStructure(retval, ['first', 'second']) + retval = scm.get_dir_from_scm( + {"scm": "cvs", "repo": "http://example.com/cvs", "dir": "subdir"}, + self.destdir, + ) + self.assertStructure(retval, ["first", "second"]) self.assertEqual( commands, - ['/usr/bin/cvs -q -d http://example.com/cvs export -r HEAD subdir']) + ["/usr/bin/cvs -q -d http://example.com/cvs export -r HEAD subdir"], + ) @mock.patch("pungi.wrappers.scm.urlretrieve") diff --git a/tests/test_test_phase.py b/tests/test_test_phase.py index e3a304a1..90738c04 100644 --- a/tests/test_test_phase.py +++ b/tests/test_test_phase.py @@ -16,27 +16,36 @@ from tests.helpers import DummyCompose, PungiTestCase, touch, mk_boom try: import dnf + HAS_DNF = True except ImportError: HAS_DNF = False try: import yum + HAS_YUM = True except ImportError: HAS_YUM = False -PAD = b'\0' * 100 -UNBOOTABLE_ISO = (b'\0' * 0x8001) + b'CD001' + PAD -ISO_WITH_MBR = (b'\0' * 0x1fe) + b'\x55\xAA' + (b'\0' * 0x7e01) + b'CD001' + PAD -ISO_WITH_GPT = (b'\0' * 0x200) + b'EFI PART' + (b'\0' * 0x7df9) + b'CD001' + PAD -ISO_WITH_MBR_AND_GPT = (b'\0' * 0x1fe) + b'\x55\xAAEFI PART' + (b'\0' * 0x7df9) + b'CD001' + PAD -ISO_WITH_TORITO = (b'\0' * 0x8001) + b'CD001' + (b'\0' * 0x7fa) + b'\0CD001\1EL TORITO SPECIFICATION' + PAD +PAD = b"\0" * 100 +UNBOOTABLE_ISO = (b"\0" * 0x8001) + b"CD001" + PAD +ISO_WITH_MBR = (b"\0" * 0x1FE) + b"\x55\xAA" + (b"\0" * 0x7E01) + b"CD001" + PAD +ISO_WITH_GPT = (b"\0" * 0x200) + b"EFI PART" + (b"\0" * 0x7DF9) + b"CD001" + PAD +ISO_WITH_MBR_AND_GPT = ( + (b"\0" * 0x1FE) + b"\x55\xAAEFI PART" + (b"\0" * 0x7DF9) + b"CD001" + PAD +) +ISO_WITH_TORITO = ( + (b"\0" * 0x8001) + + b"CD001" + + (b"\0" * 0x7FA) + + b"\0CD001\1EL TORITO SPECIFICATION" + + PAD +) class TestCheckImageSanity(PungiTestCase): - def test_missing_file_reports_error(self): compose = DummyCompose(self.topdir, {}) @@ -45,141 +54,154 @@ class TestCheckImageSanity(PungiTestCase): def test_missing_file_doesnt_report_if_failable(self): compose = DummyCompose(self.topdir, {}) - compose.image.deliverable = 'iso' + compose.image.deliverable = "iso" compose.image.can_fail = True try: test_phase.check_image_sanity(compose) except Exception: - self.fail('Failable deliverable must not raise') + self.fail("Failable deliverable must not raise") def test_correct_iso_does_not_raise(self): compose = DummyCompose(self.topdir, {}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = False - touch(os.path.join(self.topdir, 'compose', compose.image.path), UNBOOTABLE_ISO) + touch(os.path.join(self.topdir, "compose", compose.image.path), UNBOOTABLE_ISO) try: test_phase.check_image_sanity(compose) except Exception: - self.fail('Correct unbootable image must not raise') + self.fail("Correct unbootable image must not raise") def test_incorrect_iso_raises(self): compose = DummyCompose(self.topdir, {}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = False - touch(os.path.join(self.topdir, 'compose', compose.image.path), 'Hey there') + touch(os.path.join(self.topdir, "compose", compose.image.path), "Hey there") with self.assertRaises(RuntimeError) as ctx: test_phase.check_image_sanity(compose) - self.assertIn('does not look like an ISO file', str(ctx.exception)) + self.assertIn("does not look like an ISO file", str(ctx.exception)) def test_bootable_iso_without_mbr_or_gpt_raises_on_x86_64(self): compose = DummyCompose(self.topdir, {}) - compose.image.arch = 'x86_64' - compose.image.format = 'iso' + compose.image.arch = "x86_64" + compose.image.format = "iso" compose.image.bootable = True - touch(os.path.join(self.topdir, 'compose', compose.image.path), UNBOOTABLE_ISO) + touch(os.path.join(self.topdir, "compose", compose.image.path), UNBOOTABLE_ISO) with self.assertRaises(RuntimeError) as ctx: test_phase.check_image_sanity(compose) - self.assertIn('is supposed to be bootable, but does not have MBR nor GPT', - str(ctx.exception)) + self.assertIn( + "is supposed to be bootable, but does not have MBR nor GPT", + str(ctx.exception), + ) def test_bootable_iso_without_mbr_or_gpt_doesnt_raise_on_arm(self): compose = DummyCompose(self.topdir, {}) - compose.image.arch = 'armhfp' - compose.image.format = 'iso' + compose.image.arch = "armhfp" + compose.image.format = "iso" compose.image.bootable = True - touch(os.path.join(self.topdir, 'compose', compose.image.path), UNBOOTABLE_ISO) + touch(os.path.join(self.topdir, "compose", compose.image.path), UNBOOTABLE_ISO) try: test_phase.check_image_sanity(compose) except Exception: - self.fail('Failable deliverable must not raise') + self.fail("Failable deliverable must not raise") def test_failable_bootable_iso_without_mbr_gpt_doesnt_raise(self): compose = DummyCompose(self.topdir, {}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = True - compose.image.deliverable = 'iso' + compose.image.deliverable = "iso" compose.image.can_fail = True - touch(os.path.join(self.topdir, 'compose', compose.image.path), UNBOOTABLE_ISO) + touch(os.path.join(self.topdir, "compose", compose.image.path), UNBOOTABLE_ISO) try: test_phase.check_image_sanity(compose) except Exception: - self.fail('Failable deliverable must not raise') + self.fail("Failable deliverable must not raise") def test_bootable_iso_with_mbr_does_not_raise(self): compose = DummyCompose(self.topdir, {}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = True - touch(os.path.join(self.topdir, 'compose', compose.image.path), ISO_WITH_MBR) + touch(os.path.join(self.topdir, "compose", compose.image.path), ISO_WITH_MBR) try: test_phase.check_image_sanity(compose) except Exception: - self.fail('Bootable image with MBR must not raise') + self.fail("Bootable image with MBR must not raise") def test_bootable_iso_with_gpt_does_not_raise(self): compose = DummyCompose(self.topdir, {}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = True - touch(os.path.join(self.topdir, 'compose', compose.image.path), ISO_WITH_GPT) + touch(os.path.join(self.topdir, "compose", compose.image.path), ISO_WITH_GPT) try: test_phase.check_image_sanity(compose) except Exception: - self.fail('Bootable image with GPT must not raise') + self.fail("Bootable image with GPT must not raise") def test_bootable_iso_with_mbr_and_gpt_does_not_raise(self): compose = DummyCompose(self.topdir, {}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = True - touch(os.path.join(self.topdir, 'compose', compose.image.path), ISO_WITH_MBR_AND_GPT) + touch( + os.path.join(self.topdir, "compose", compose.image.path), + ISO_WITH_MBR_AND_GPT, + ) try: test_phase.check_image_sanity(compose) except Exception: - self.fail('Bootable image with MBR and GPT must not raise') + self.fail("Bootable image with MBR and GPT must not raise") def test_bootable_iso_with_el_torito_does_not_raise(self): compose = DummyCompose(self.topdir, {}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = True - touch(os.path.join(self.topdir, 'compose', compose.image.path), ISO_WITH_TORITO) + touch(os.path.join(self.topdir, "compose", compose.image.path), ISO_WITH_TORITO) try: test_phase.check_image_sanity(compose) except Exception: - self.fail('Bootable image with El Torito must not raise') + self.fail("Bootable image with El Torito must not raise") def test_checks_with_optional_variant(self): compose = DummyCompose(self.topdir, {}) - compose.variants['Server'].variants = { - 'optional': mock.Mock(uid='Server-optional', arches=['x86_64'], - type='optional', is_empty=False) + compose.variants["Server"].variants = { + "optional": mock.Mock( + uid="Server-optional", + arches=["x86_64"], + type="optional", + is_empty=False, + ) } - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = True - touch(os.path.join(self.topdir, 'compose', compose.image.path), ISO_WITH_MBR_AND_GPT) + touch( + os.path.join(self.topdir, "compose", compose.image.path), + ISO_WITH_MBR_AND_GPT, + ) - image = mock.Mock(path="Server/i386/optional/iso/image.iso", - format='iso', bootable=False) - compose.im.images['Server-optional'] = {'i386': [image]} + image = mock.Mock( + path="Server/i386/optional/iso/image.iso", format="iso", bootable=False + ) + compose.im.images["Server-optional"] = {"i386": [image]} try: test_phase.check_image_sanity(compose) except Exception: - self.fail('Checking optional variant must not raise') + self.fail("Checking optional variant must not raise") @mock.patch("pungi.phases.test.check_sanity", new=mock.Mock()) def test_too_big_iso(self): compose = DummyCompose(self.topdir, {"createiso_max_size": [(".*", {"*": 10})]}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = False compose.image.size = 20 @@ -200,7 +222,7 @@ class TestCheckImageSanity(PungiTestCase): "createiso_max_size_is_strict": [(".*", {"*": True})], }, ) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = False compose.image.size = 20 @@ -221,7 +243,7 @@ class TestCheckImageSanity(PungiTestCase): "createiso_max_size_is_strict": [(".*", {"*": False})], }, ) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = False compose.image.size = 20 @@ -236,7 +258,7 @@ class TestCheckImageSanity(PungiTestCase): @mock.patch("pungi.phases.test.check_sanity", new=mock.Mock()) def test_too_big_unified(self): compose = DummyCompose(self.topdir, {}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = False compose.image.size = 20 compose.image.unified = True @@ -253,10 +275,9 @@ class TestCheckImageSanity(PungiTestCase): @mock.patch("pungi.phases.test.check_sanity", new=mock.Mock()) def test_too_big_unified_strict(self): compose = DummyCompose( - self.topdir, - {"createiso_max_size_is_strict": [(".*", {"*": True})]}, + self.topdir, {"createiso_max_size_is_strict": [(".*", {"*": True})]}, ) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = False compose.image.size = 20 compose.image.unified = True @@ -273,7 +294,7 @@ class TestCheckImageSanity(PungiTestCase): @mock.patch("pungi.phases.test.check_sanity", new=mock.Mock()) def test_fits_in_limit(self): compose = DummyCompose(self.topdir, {"createiso_max_size": [(".*", {"*": 20})]}) - compose.image.format = 'iso' + compose.image.format = "iso" compose.image.bootable = False compose.image.size = 5 @@ -284,7 +305,7 @@ class TestCheckImageSanity(PungiTestCase): @mock.patch("pungi.phases.test.check_sanity", new=mock.Mock()) def test_non_iso(self): compose = DummyCompose(self.topdir, {"createiso_max_size": [(".*", {"*": 10})]}) - compose.image.format = 'qcow2' + compose.image.format = "qcow2" compose.image.bootable = False compose.image.size = 20 @@ -294,32 +315,32 @@ class TestCheckImageSanity(PungiTestCase): class TestRepoclosure(PungiTestCase): - def setUp(self): super(TestRepoclosure, self).setUp() self.maxDiff = None def _get_repo(self, compose_id, variant, arch, path=None): - path = path or arch + '/os' + path = path or arch + "/os" return { - '%s-repoclosure-%s.%s' % (compose_id, variant, arch): self.topdir + '/compose/%s/%s' % (variant, path) + "%s-repoclosure-%s.%s" % (compose_id, variant, arch): self.topdir + + "/compose/%s/%s" % (variant, path) } - @mock.patch('pungi.wrappers.repoclosure.get_repoclosure_cmd') - @mock.patch('pungi.phases.test.run') + @mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd") + @mock.patch("pungi.phases.test.run") def test_repoclosure_skip_if_disabled(self, mock_run, mock_grc): - compose = DummyCompose(self.topdir, { - 'repoclosure_strictness': [('^.*$', {'*': 'off'})] - }) + compose = DummyCompose( + self.topdir, {"repoclosure_strictness": [("^.*$", {"*": "off"})]} + ) test_phase.run_repoclosure(compose) self.assertEqual(mock_grc.call_args_list, []) - @unittest.skipUnless(HAS_YUM, 'YUM is not available') - @mock.patch('pungi.wrappers.repoclosure.get_repoclosure_cmd') - @mock.patch('pungi.phases.test.run') + @unittest.skipUnless(HAS_YUM, "YUM is not available") + @mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd") + @mock.patch("pungi.phases.test.run") def test_repoclosure_default_backend(self, mock_run, mock_grc): - with mock.patch('six.PY2', new=True): + with mock.patch("six.PY2", new=True): compose = DummyCompose(self.topdir, {}) test_phase.run_repoclosure(compose) @@ -327,37 +348,83 @@ class TestRepoclosure(PungiTestCase): six.assertCountEqual( self, mock_grc.call_args_list, - [mock.call(backend='yum', arch=['amd64', 'x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Everything', 'amd64')), - mock.call(backend='yum', arch=['amd64', 'x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Client', 'amd64')), - mock.call(backend='yum', arch=['amd64', 'x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Server', 'amd64')), - mock.call(backend='yum', arch=['x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Server', 'x86_64')), - mock.call(backend='yum', arch=['x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Everything', 'x86_64'))]) + [ + mock.call( + backend="yum", + arch=["amd64", "x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Everything", "amd64"), + ), + mock.call( + backend="yum", + arch=["amd64", "x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Client", "amd64"), + ), + mock.call( + backend="yum", + arch=["amd64", "x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Server", "amd64"), + ), + mock.call( + backend="yum", + arch=["x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Server", "x86_64"), + ), + mock.call( + backend="yum", + arch=["x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Everything", "x86_64"), + ), + ], + ) - @unittest.skipUnless(HAS_DNF, 'DNF is not available') - @mock.patch('pungi.wrappers.repoclosure.get_repoclosure_cmd') - @mock.patch('pungi.phases.test.run') + @unittest.skipUnless(HAS_DNF, "DNF is not available") + @mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd") + @mock.patch("pungi.phases.test.run") def test_repoclosure_dnf_backend(self, mock_run, mock_grc): - compose = DummyCompose(self.topdir, {'repoclosure_backend': 'dnf'}) + compose = DummyCompose(self.topdir, {"repoclosure_backend": "dnf"}) test_phase.run_repoclosure(compose) six.assertCountEqual( self, mock_grc.call_args_list, - [mock.call(backend='dnf', arch=['amd64', 'x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Everything', 'amd64')), - mock.call(backend='dnf', arch=['amd64', 'x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Client', 'amd64')), - mock.call(backend='dnf', arch=['amd64', 'x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Server', 'amd64')), - mock.call(backend='dnf', arch=['x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Server', 'x86_64')), - mock.call(backend='dnf', arch=['x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Everything', 'x86_64'))]) + [ + mock.call( + backend="dnf", + arch=["amd64", "x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Everything", "amd64"), + ), + mock.call( + backend="dnf", + arch=["amd64", "x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Client", "amd64"), + ), + mock.call( + backend="dnf", + arch=["amd64", "x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Server", "amd64"), + ), + mock.call( + backend="dnf", + arch=["x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Server", "x86_64"), + ), + mock.call( + backend="dnf", + arch=["x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Everything", "x86_64"), + ), + ], + ) @mock.patch("glob.glob") @mock.patch("pungi.wrappers.repoclosure.extract_from_fus_logs") @@ -385,53 +452,71 @@ class TestRepoclosure(PungiTestCase): mock.call([f], _log("amd64", "Server")), mock.call([f], _log("x86_64", "Server")), mock.call([f], _log("x86_64", "Everything")), - ] + ], ) - @mock.patch('pungi.wrappers.repoclosure.get_repoclosure_cmd') - @mock.patch('pungi.phases.test.run') + @mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd") + @mock.patch("pungi.phases.test.run") def test_repoclosure_report_error(self, mock_run, mock_grc): - compose = DummyCompose(self.topdir, { - 'repoclosure_strictness': [('^.*$', {'*': 'fatal'})] - }) + compose = DummyCompose( + self.topdir, {"repoclosure_strictness": [("^.*$", {"*": "fatal"})]} + ) mock_run.side_effect = mk_boom(cls=RuntimeError) with self.assertRaises(RuntimeError): test_phase.run_repoclosure(compose) - @unittest.skipUnless(HAS_DNF, 'DNF is not available') - @mock.patch('pungi.wrappers.repoclosure.get_repoclosure_cmd') - @mock.patch('pungi.phases.test.run') - def test_repoclosure_overwrite_options_creates_correct_commands(self, mock_run, mock_grc): - compose = DummyCompose(self.topdir, { - 'repoclosure_backend': 'dnf', - 'repoclosure_strictness': [ - ('^.*$', {'*': 'off'}), - ('^Server$', {'*': 'fatal'}), - ] - }) + @unittest.skipUnless(HAS_DNF, "DNF is not available") + @mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd") + @mock.patch("pungi.phases.test.run") + def test_repoclosure_overwrite_options_creates_correct_commands( + self, mock_run, mock_grc + ): + compose = DummyCompose( + self.topdir, + { + "repoclosure_backend": "dnf", + "repoclosure_strictness": [ + ("^.*$", {"*": "off"}), + ("^Server$", {"*": "fatal"}), + ], + }, + ) test_phase.run_repoclosure(compose) six.assertCountEqual( self, mock_grc.call_args_list, - [mock.call(backend='dnf', arch=['amd64', 'x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Server', 'amd64')), - mock.call(backend='dnf', arch=['x86_64', 'noarch'], lookaside={}, - repos=self._get_repo(compose.compose_id, 'Server', 'x86_64')), - ]) + [ + mock.call( + backend="dnf", + arch=["amd64", "x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Server", "amd64"), + ), + mock.call( + backend="dnf", + arch=["x86_64", "noarch"], + lookaside={}, + repos=self._get_repo(compose.compose_id, "Server", "x86_64"), + ), + ], + ) - @mock.patch('pungi.phases.test._delete_repoclosure_cache_dirs') - @mock.patch('pungi.wrappers.repoclosure.get_repoclosure_cmd') - @mock.patch('pungi.phases.test.run') + @mock.patch("pungi.phases.test._delete_repoclosure_cache_dirs") + @mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd") + @mock.patch("pungi.phases.test.run") def test_repoclosure_uses_correct_behaviour(self, mock_run, mock_grc, mock_del): - compose = DummyCompose(self.topdir, { - 'repoclosure_backend': 'dnf', - 'repoclosure_strictness': [ - ('^.*$', {'*': 'off'}), - ('^Server$', {'*': 'fatal'}), - ] - }) + compose = DummyCompose( + self.topdir, + { + "repoclosure_backend": "dnf", + "repoclosure_strictness": [ + ("^.*$", {"*": "off"}), + ("^Server$", {"*": "fatal"}), + ], + }, + ) mock_run.side_effect = mk_boom(cls=RuntimeError) with self.assertRaises(RuntimeError): diff --git a/tests/test_unified_isos.py b/tests/test_unified_isos.py index 3c502328..30b510ed 100755 --- a/tests/test_unified_isos.py +++ b/tests/test_unified_isos.py @@ -11,137 +11,177 @@ from tests.helpers import PungiTestCase, FIXTURE_DIR, touch, mk_boom from pungi_utils import unified_isos -COMPOSE_ID = 'DP-1.0-20161013.t.4' +COMPOSE_ID = "DP-1.0-20161013.t.4" class TestUnifiedIsos(PungiTestCase): def setUp(self): super(TestUnifiedIsos, self).setUp() - shutil.copytree(os.path.join(FIXTURE_DIR, COMPOSE_ID), - os.path.join(self.topdir, COMPOSE_ID)) + shutil.copytree( + os.path.join(FIXTURE_DIR, COMPOSE_ID), os.path.join(self.topdir, COMPOSE_ID) + ) def test_can_init(self): - compose_path = os.path.join(self.topdir, COMPOSE_ID, 'compose') + compose_path = os.path.join(self.topdir, COMPOSE_ID, "compose") isos = unified_isos.UnifiedISO(compose_path) self.assertEqual(isos.compose_path, compose_path) self.assertRegexpMatches( - isos.temp_dir, '^%s/' % os.path.join(self.topdir, COMPOSE_ID, 'work')) + isos.temp_dir, "^%s/" % os.path.join(self.topdir, COMPOSE_ID, "work") + ) def test_can_find_compose_subdir(self): isos = unified_isos.UnifiedISO(os.path.join(self.topdir, COMPOSE_ID)) - self.assertEqual(isos.compose_path, os.path.join(self.topdir, COMPOSE_ID, 'compose')) - self.assertRegexpMatches(isos.temp_dir, - '^%s/' % os.path.join(self.topdir, COMPOSE_ID, 'work')) + self.assertEqual( + isos.compose_path, os.path.join(self.topdir, COMPOSE_ID, "compose") + ) + self.assertRegexpMatches( + isos.temp_dir, "^%s/" % os.path.join(self.topdir, COMPOSE_ID, "work") + ) - @mock.patch('os.rename') + @mock.patch("os.rename") def test_dump_manifest(self, rename): - compose_path = os.path.join(self.topdir, COMPOSE_ID, 'compose') + compose_path = os.path.join(self.topdir, COMPOSE_ID, "compose") isos = unified_isos.UnifiedISO(compose_path) isos.compose._images = mock.Mock() isos.dump_manifest() - self.assertEqual(isos.compose._images.mock_calls, - [mock.call.dump(compose_path + '/metadata/images.json.tmp')]) - self.assertEqual(rename.call_args_list, - [mock.call(compose_path + '/metadata/images.json.tmp', - compose_path + '/metadata/images.json')]) + self.assertEqual( + isos.compose._images.mock_calls, + [mock.call.dump(compose_path + "/metadata/images.json.tmp")], + ) + self.assertEqual( + rename.call_args_list, + [ + mock.call( + compose_path + "/metadata/images.json.tmp", + compose_path + "/metadata/images.json", + ) + ], + ) - @mock.patch('os.rename') + @mock.patch("os.rename") def test_dump_manifest_fails(self, rename): - compose_path = os.path.join(self.topdir, COMPOSE_ID, 'compose') + compose_path = os.path.join(self.topdir, COMPOSE_ID, "compose") isos = unified_isos.UnifiedISO(compose_path) isos.compose._images = mock.Mock() isos.compose._images.dump.side_effect = mk_boom() with self.assertRaises(Exception): isos.dump_manifest() - self.assertEqual(isos.compose._images.mock_calls, - [mock.call.dump(compose_path + '/metadata/images.json.tmp')]) + self.assertEqual( + isos.compose._images.mock_calls, + [mock.call.dump(compose_path + "/metadata/images.json.tmp")], + ) self.assertEqual(rename.call_args_list, []) class TestCreate(PungiTestCase): def setUp(self): super(TestCreate, self).setUp() - shutil.copytree(os.path.join(FIXTURE_DIR, COMPOSE_ID), - os.path.join(self.topdir, COMPOSE_ID)) - compose_path = os.path.join(self.topdir, COMPOSE_ID, 'compose') + shutil.copytree( + os.path.join(FIXTURE_DIR, COMPOSE_ID), os.path.join(self.topdir, COMPOSE_ID) + ) + compose_path = os.path.join(self.topdir, COMPOSE_ID, "compose") self.isos = unified_isos.UnifiedISO(compose_path) def test_create_method(self): - methods = ('link_to_temp', 'createrepo', 'discinfo', 'createiso', - 'update_checksums', 'dump_manifest') + methods = ( + "link_to_temp", + "createrepo", + "discinfo", + "createiso", + "update_checksums", + "dump_manifest", + ) for attr in methods: setattr(self.isos, attr, mock.Mock()) - with mock.patch('shutil.rmtree') as rmtree: + with mock.patch("shutil.rmtree") as rmtree: self.isos.create() for attr in methods: self.assertEqual(len(getattr(self.isos, attr).call_args_list), 1) - self.assertEqual(rmtree.call_args_list, - [mock.call(self.isos.temp_dir)]) + self.assertEqual(rmtree.call_args_list, [mock.call(self.isos.temp_dir)]) def get_comps_mapping(path): def _comps(variant, arch): - return os.path.join(path, variant, arch, 'os', 'repodata', - 'comps-%s.%s.xml' % (variant, arch)) + return os.path.join( + path, variant, arch, "os", "repodata", "comps-%s.%s.xml" % (variant, arch) + ) + return { - 'i386': {'Client': _comps('Client', 'i386')}, - 's390x': {'Server': _comps('Server', 's390x')}, - 'x86_64': {'Client': _comps('Client', 'x86_64'), - 'Server': _comps('Server', 'x86_64')} + "i386": {"Client": _comps("Client", "i386")}, + "s390x": {"Server": _comps("Server", "s390x")}, + "x86_64": { + "Client": _comps("Client", "x86_64"), + "Server": _comps("Server", "x86_64"), + }, } def get_productid_mapping(path): def _productid(variant, arch): - return os.path.join(path, variant, arch, 'os', 'repodata', 'productid') + return os.path.join(path, variant, arch, "os", "repodata", "productid") + return { - 'i386': {'Client': _productid('Client', 'i386')}, - 's390x': {'Server': _productid('Server', 's390x')}, - 'x86_64': {'Client': _productid('Client', 'x86_64'), - 'Server': _productid('Server', 'x86_64')} + "i386": {"Client": _productid("Client", "i386")}, + "s390x": {"Server": _productid("Server", "s390x")}, + "x86_64": { + "Client": _productid("Client", "x86_64"), + "Server": _productid("Server", "x86_64"), + }, } def get_repos_mapping(path): def _repo(variant, arch): - return os.path.join(path, 'trees', arch, variant) + return os.path.join(path, "trees", arch, variant) def _debug(variant, arch): - return os.path.join(path, 'trees', 'debug-' + arch, variant) + return os.path.join(path, "trees", "debug-" + arch, variant) + return { - 'i386': {'Client': _repo('Client', 'i386')}, - 'debug-i386': {'Client': _debug('Client', 'i386')}, - 's390x': {'Server': _repo('Server', 's390x')}, - 'debug-s390x': {'Server': _debug('Server', 's390x')}, - 'src': {'Client': _repo('Client', 'src'), - 'Server': _repo('Server', 'src')}, - 'x86_64': {'Client': _repo('Client', 'x86_64'), - 'Server': _repo('Server', 'x86_64')}, - 'debug-x86_64': {'Client': _debug('Client', 'x86_64'), - 'Server': _debug('Server', 'x86_64')} + "i386": {"Client": _repo("Client", "i386")}, + "debug-i386": {"Client": _debug("Client", "i386")}, + "s390x": {"Server": _repo("Server", "s390x")}, + "debug-s390x": {"Server": _debug("Server", "s390x")}, + "src": {"Client": _repo("Client", "src"), "Server": _repo("Server", "src")}, + "x86_64": { + "Client": _repo("Client", "x86_64"), + "Server": _repo("Server", "x86_64"), + }, + "debug-x86_64": { + "Client": _debug("Client", "x86_64"), + "Server": _debug("Server", "x86_64"), + }, } class TestLinkToTemp(PungiTestCase): def setUp(self): super(TestLinkToTemp, 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') + 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() def _linkCall(self, variant, arch, file): - debuginfo = 'debuginfo' in file - srcdir = 'tree' if arch == 'src' else 'debug/tree' if debuginfo else 'os' - destdir = 'debug-' + arch if debuginfo else arch - return mock.call(os.path.join(self.compose_path, variant, - arch if arch != 'src' else 'source', - srcdir, - 'Packages', file[0].lower(), file), - os.path.join(self.isos.temp_dir, 'trees', destdir, variant, file)) + debuginfo = "debuginfo" in file + srcdir = "tree" if arch == "src" else "debug/tree" if debuginfo else "os" + destdir = "debug-" + arch if debuginfo else arch + return mock.call( + os.path.join( + self.compose_path, + variant, + arch if arch != "src" else "source", + srcdir, + "Packages", + file[0].lower(), + file, + ), + os.path.join(self.isos.temp_dir, "trees", destdir, variant, file), + ) def test_link_to_temp(self): self.isos.link_to_temp() @@ -149,35 +189,55 @@ class TestLinkToTemp(PungiTestCase): six.assertCountEqual( self, self.isos.treeinfo.keys(), - ["i386", "s390x", "src", "x86_64", "debug-i386", "debug-s390x", "debug-x86_64"], + [ + "i386", + "s390x", + "src", + "x86_64", + "debug-i386", + "debug-s390x", + "debug-x86_64", + ], ) - self.assertEqual(self.isos.comps, - get_comps_mapping(self.compose_path)) - self.assertEqual(self.isos.productid, - get_productid_mapping(self.compose_path)) - self.assertEqual(self.isos.repos, - get_repos_mapping(self.isos.temp_dir)) + self.assertEqual(self.isos.comps, get_comps_mapping(self.compose_path)) + self.assertEqual(self.isos.productid, get_productid_mapping(self.compose_path)) + self.assertEqual(self.isos.repos, get_repos_mapping(self.isos.temp_dir)) six.assertCountEqual( self, self.isos.linker.link.call_args_list, - [self._linkCall('Server', 's390x', 'dummy-filesystem-4.2.37-6.s390x.rpm'), - self._linkCall('Server', 's390x', 'dummy-elinks-debuginfo-2.6-2.s390x.rpm'), - self._linkCall('Server', 'x86_64', 'dummy-filesystem-4.2.37-6.x86_64.rpm'), - self._linkCall('Server', 'x86_64', 'dummy-elinks-debuginfo-2.6-2.x86_64.rpm'), - self._linkCall('Server', 'src', 'dummy-filesystem-4.2.37-6.src.rpm'), - self._linkCall('Server', 'src', 'dummy-filesystem-4.2.37-6.src.rpm'), - self._linkCall('Client', 'i386', 'dummy-bash-4.2.37-6.i686.rpm'), - self._linkCall('Client', 'i386', 'dummy-bash-debuginfo-4.2.37-6.i686.rpm'), - self._linkCall('Client', 'x86_64', 'dummy-bash-4.2.37-6.x86_64.rpm'), - self._linkCall('Client', 'x86_64', 'dummy-bash-debuginfo-4.2.37-6.x86_64.rpm'), - self._linkCall('Client', 'src', 'dummy-bash-4.2.37-6.src.rpm'), - self._linkCall('Client', 'src', 'dummy-bash-4.2.37-6.src.rpm')]) + [ + self._linkCall( + "Server", "s390x", "dummy-filesystem-4.2.37-6.s390x.rpm" + ), + self._linkCall( + "Server", "s390x", "dummy-elinks-debuginfo-2.6-2.s390x.rpm" + ), + self._linkCall( + "Server", "x86_64", "dummy-filesystem-4.2.37-6.x86_64.rpm" + ), + self._linkCall( + "Server", "x86_64", "dummy-elinks-debuginfo-2.6-2.x86_64.rpm" + ), + self._linkCall("Server", "src", "dummy-filesystem-4.2.37-6.src.rpm"), + self._linkCall("Server", "src", "dummy-filesystem-4.2.37-6.src.rpm"), + self._linkCall("Client", "i386", "dummy-bash-4.2.37-6.i686.rpm"), + self._linkCall( + "Client", "i386", "dummy-bash-debuginfo-4.2.37-6.i686.rpm" + ), + self._linkCall("Client", "x86_64", "dummy-bash-4.2.37-6.x86_64.rpm"), + self._linkCall( + "Client", "x86_64", "dummy-bash-debuginfo-4.2.37-6.x86_64.rpm" + ), + self._linkCall("Client", "src", "dummy-bash-4.2.37-6.src.rpm"), + self._linkCall("Client", "src", "dummy-bash-4.2.37-6.src.rpm"), + ], + ) def test_link_to_temp_without_treefile(self): - os.remove(os.path.join(self.compose_path, 'Client', 'i386', 'os', '.treeinfo')) + os.remove(os.path.join(self.compose_path, "Client", "i386", "os", ".treeinfo")) - with mock.patch('sys.stderr'): + with mock.patch("sys.stderr"): self.isos.link_to_temp() six.assertCountEqual( @@ -186,14 +246,14 @@ class TestLinkToTemp(PungiTestCase): ["s390x", "src", "x86_64", "debug-s390x", "debug-x86_64"], ) comps = get_comps_mapping(self.compose_path) - comps.pop('i386') + comps.pop("i386") self.assertEqual(self.isos.comps, comps) productid = get_productid_mapping(self.compose_path) - productid.pop('i386') + productid.pop("i386") self.assertEqual(self.isos.productid, productid) repos = get_repos_mapping(self.isos.temp_dir) - repos.pop('i386') - repos.pop('debug-i386') + repos.pop("i386") + repos.pop("debug-i386") self.assertEqual(self.isos.repos, repos) self.maxDiff = None @@ -201,58 +261,96 @@ class TestLinkToTemp(PungiTestCase): six.assertCountEqual( self, self.isos.linker.link.call_args_list, - [self._linkCall('Server', 's390x', 'dummy-filesystem-4.2.37-6.s390x.rpm'), - self._linkCall('Server', 's390x', 'dummy-elinks-debuginfo-2.6-2.s390x.rpm'), - self._linkCall('Server', 'x86_64', 'dummy-filesystem-4.2.37-6.x86_64.rpm'), - self._linkCall('Server', 'x86_64', 'dummy-elinks-debuginfo-2.6-2.x86_64.rpm'), - self._linkCall('Server', 'src', 'dummy-filesystem-4.2.37-6.src.rpm'), - self._linkCall('Server', 'src', 'dummy-filesystem-4.2.37-6.src.rpm'), - self._linkCall('Client', 'x86_64', 'dummy-bash-4.2.37-6.x86_64.rpm'), - self._linkCall('Client', 'x86_64', 'dummy-bash-debuginfo-4.2.37-6.x86_64.rpm'), - self._linkCall('Client', 'src', 'dummy-bash-4.2.37-6.src.rpm')]) + [ + self._linkCall( + "Server", "s390x", "dummy-filesystem-4.2.37-6.s390x.rpm" + ), + self._linkCall( + "Server", "s390x", "dummy-elinks-debuginfo-2.6-2.s390x.rpm" + ), + self._linkCall( + "Server", "x86_64", "dummy-filesystem-4.2.37-6.x86_64.rpm" + ), + self._linkCall( + "Server", "x86_64", "dummy-elinks-debuginfo-2.6-2.x86_64.rpm" + ), + self._linkCall("Server", "src", "dummy-filesystem-4.2.37-6.src.rpm"), + self._linkCall("Server", "src", "dummy-filesystem-4.2.37-6.src.rpm"), + self._linkCall("Client", "x86_64", "dummy-bash-4.2.37-6.x86_64.rpm"), + self._linkCall( + "Client", "x86_64", "dummy-bash-debuginfo-4.2.37-6.x86_64.rpm" + ), + self._linkCall("Client", "src", "dummy-bash-4.2.37-6.src.rpm"), + ], + ) def test_link_to_temp_extra_file(self): - gpl_file = touch(os.path.join(self.compose_path, 'Server', 'x86_64', 'os', 'GPL')) + gpl_file = touch( + os.path.join(self.compose_path, "Server", "x86_64", "os", "GPL") + ) self.isos.link_to_temp() six.assertCountEqual( self, self.isos.treeinfo.keys(), - ["i386", "s390x", "src", "x86_64", "debug-i386", "debug-s390x", "debug-x86_64"], + [ + "i386", + "s390x", + "src", + "x86_64", + "debug-i386", + "debug-s390x", + "debug-x86_64", + ], ) - self.assertEqual(self.isos.comps, - get_comps_mapping(self.compose_path)) - self.assertEqual(self.isos.productid, - get_productid_mapping(self.compose_path)) - self.assertEqual(self.isos.repos, - get_repos_mapping(self.isos.temp_dir)) + self.assertEqual(self.isos.comps, get_comps_mapping(self.compose_path)) + self.assertEqual(self.isos.productid, get_productid_mapping(self.compose_path)) + self.assertEqual(self.isos.repos, get_repos_mapping(self.isos.temp_dir)) six.assertCountEqual( self, self.isos.linker.link.call_args_list, - [self._linkCall('Server', 's390x', 'dummy-filesystem-4.2.37-6.s390x.rpm'), - self._linkCall('Server', 's390x', 'dummy-elinks-debuginfo-2.6-2.s390x.rpm'), - self._linkCall('Server', 'x86_64', 'dummy-filesystem-4.2.37-6.x86_64.rpm'), - self._linkCall('Server', 'x86_64', 'dummy-elinks-debuginfo-2.6-2.x86_64.rpm'), - self._linkCall('Server', 'src', 'dummy-filesystem-4.2.37-6.src.rpm'), - self._linkCall('Server', 'src', 'dummy-filesystem-4.2.37-6.src.rpm'), - self._linkCall('Client', 'i386', 'dummy-bash-4.2.37-6.i686.rpm'), - self._linkCall('Client', 'i386', 'dummy-bash-debuginfo-4.2.37-6.i686.rpm'), - self._linkCall('Client', 'x86_64', 'dummy-bash-4.2.37-6.x86_64.rpm'), - self._linkCall('Client', 'x86_64', 'dummy-bash-debuginfo-4.2.37-6.x86_64.rpm'), - self._linkCall('Client', 'src', 'dummy-bash-4.2.37-6.src.rpm'), - self._linkCall('Client', 'src', 'dummy-bash-4.2.37-6.src.rpm'), - mock.call(os.path.join(gpl_file), - os.path.join(self.isos.temp_dir, 'trees', 'x86_64', 'GPL'))]) + [ + self._linkCall( + "Server", "s390x", "dummy-filesystem-4.2.37-6.s390x.rpm" + ), + self._linkCall( + "Server", "s390x", "dummy-elinks-debuginfo-2.6-2.s390x.rpm" + ), + self._linkCall( + "Server", "x86_64", "dummy-filesystem-4.2.37-6.x86_64.rpm" + ), + self._linkCall( + "Server", "x86_64", "dummy-elinks-debuginfo-2.6-2.x86_64.rpm" + ), + self._linkCall("Server", "src", "dummy-filesystem-4.2.37-6.src.rpm"), + self._linkCall("Server", "src", "dummy-filesystem-4.2.37-6.src.rpm"), + self._linkCall("Client", "i386", "dummy-bash-4.2.37-6.i686.rpm"), + self._linkCall( + "Client", "i386", "dummy-bash-debuginfo-4.2.37-6.i686.rpm" + ), + self._linkCall("Client", "x86_64", "dummy-bash-4.2.37-6.x86_64.rpm"), + self._linkCall( + "Client", "x86_64", "dummy-bash-debuginfo-4.2.37-6.x86_64.rpm" + ), + self._linkCall("Client", "src", "dummy-bash-4.2.37-6.src.rpm"), + self._linkCall("Client", "src", "dummy-bash-4.2.37-6.src.rpm"), + mock.call( + os.path.join(gpl_file), + os.path.join(self.isos.temp_dir, "trees", "x86_64", "GPL"), + ), + ], + ) class TestCreaterepo(PungiTestCase): def setUp(self): super(TestCreaterepo, 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') + 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() # TODO mock treeinfo and use mappings for other data @@ -262,15 +360,15 @@ class TestCreaterepo(PungiTestCase): def mock_cr(self, path, groupfile, update): self.assertTrue(update) - touch(os.path.join(path, 'repodata', 'repomd.xml')) - return ('/'.join(path.split('/')[-2:]), groupfile) + touch(os.path.join(path, "repodata", "repomd.xml")) + return ("/".join(path.split("/")[-2:]), groupfile) def mock_mr(self, path, pid, compress_type): - self.assertEqual(compress_type, 'gz') - return ('/'.join(path.split('/')[-3:-1]), pid) + self.assertEqual(compress_type, "gz") + return ("/".join(path.split("/")[-3:-1]), pid) - @mock.patch('pungi.wrappers.createrepo.CreaterepoWrapper') - @mock.patch('pungi_utils.unified_isos.run') + @mock.patch("pungi.wrappers.createrepo.CreaterepoWrapper") + @mock.patch("pungi_utils.unified_isos.run") def test_createrepo(self, run, cr): cr.return_value.get_createrepo_cmd.side_effect = self.mock_cr self.isos.createrepo() @@ -278,16 +376,24 @@ class TestCreaterepo(PungiTestCase): six.assertCountEqual( self, run.call_args_list, - [mock.call(('src/Client', None), show_cmd=True), - mock.call(('src/Server', None), show_cmd=True), - mock.call(('i386/Client', self.comps['i386']['Client']), show_cmd=True), - mock.call(('s390x/Server', self.comps['s390x']['Server']), show_cmd=True), - mock.call(('x86_64/Client', self.comps['x86_64']['Client']), show_cmd=True), - mock.call(('x86_64/Server', self.comps['x86_64']['Server']), show_cmd=True), - mock.call(('debug-i386/Client', None), show_cmd=True), - mock.call(('debug-s390x/Server', None), show_cmd=True), - mock.call(('debug-x86_64/Client', None), show_cmd=True), - mock.call(('debug-x86_64/Server', None), show_cmd=True)] + [ + mock.call(("src/Client", None), show_cmd=True), + mock.call(("src/Server", None), show_cmd=True), + mock.call(("i386/Client", self.comps["i386"]["Client"]), show_cmd=True), + mock.call( + ("s390x/Server", self.comps["s390x"]["Server"]), show_cmd=True + ), + mock.call( + ("x86_64/Client", self.comps["x86_64"]["Client"]), show_cmd=True + ), + mock.call( + ("x86_64/Server", self.comps["x86_64"]["Server"]), show_cmd=True + ), + mock.call(("debug-i386/Client", None), show_cmd=True), + mock.call(("debug-s390x/Server", None), show_cmd=True), + mock.call(("debug-x86_64/Client", None), show_cmd=True), + mock.call(("debug-x86_64/Server", None), show_cmd=True), + ], ) checksums = {} @@ -296,22 +402,27 @@ class TestCreaterepo(PungiTestCase): for arch in self.isos.treeinfo.keys(): parser = SafeConfigParser() parser.optionxform = str - parser.read(os.path.join(self.isos.temp_dir, 'trees', arch, '.treeinfo')) - checksums[arch] = [k for k, v in parser.items('checksums')] + parser.read(os.path.join(self.isos.temp_dir, "trees", arch, ".treeinfo")) + checksums[arch] = [k for k, v in parser.items("checksums")] self.assertEqual( checksums, - {'i386': ['Client/repodata/repomd.xml'], - 'debug-i386': ['Client/repodata/repomd.xml'], - 's390x': ['Server/repodata/repomd.xml'], - 'debug-s390x': ['Server/repodata/repomd.xml'], - 'src': ['Client/repodata/repomd.xml', 'Server/repodata/repomd.xml'], - 'x86_64': ['Client/repodata/repomd.xml', 'Server/repodata/repomd.xml'], - 'debug-x86_64': ['Client/repodata/repomd.xml', 'Server/repodata/repomd.xml']} + { + "i386": ["Client/repodata/repomd.xml"], + "debug-i386": ["Client/repodata/repomd.xml"], + "s390x": ["Server/repodata/repomd.xml"], + "debug-s390x": ["Server/repodata/repomd.xml"], + "src": ["Client/repodata/repomd.xml", "Server/repodata/repomd.xml"], + "x86_64": ["Client/repodata/repomd.xml", "Server/repodata/repomd.xml"], + "debug-x86_64": [ + "Client/repodata/repomd.xml", + "Server/repodata/repomd.xml", + ], + }, ) - @mock.patch('pungi.wrappers.createrepo.CreaterepoWrapper') - @mock.patch('pungi_utils.unified_isos.run') + @mock.patch("pungi.wrappers.createrepo.CreaterepoWrapper") + @mock.patch("pungi_utils.unified_isos.run") def test_createrepo_with_productid(self, run, cr): for x in self.isos.productid.values(): for f in x.values(): @@ -323,24 +434,56 @@ class TestCreaterepo(PungiTestCase): six.assertCountEqual( self, run.call_args_list, - [mock.call(('src/Client', None), show_cmd=True), - mock.call(('src/Server', None), show_cmd=True), - mock.call(('i386/Client', self.comps['i386']['Client']), show_cmd=True), - mock.call(('debug-i386/Client', None), show_cmd=True), - mock.call(('s390x/Server', self.comps['s390x']['Server']), show_cmd=True), - mock.call(('debug-s390x/Server', None), show_cmd=True), - mock.call(('x86_64/Client', self.comps['x86_64']['Client']), show_cmd=True), - mock.call(('debug-x86_64/Client', None), show_cmd=True), - mock.call(('x86_64/Server', self.comps['x86_64']['Server']), show_cmd=True), - mock.call(('debug-x86_64/Server', None), show_cmd=True), - mock.call(('x86_64/Server', os.path.join(self.isos.temp_dir, - 'trees/x86_64/Server/repodata/productid'))), - mock.call(('x86_64/Client', os.path.join(self.isos.temp_dir, - 'trees/x86_64/Client/repodata/productid'))), - mock.call(('s390x/Server', os.path.join(self.isos.temp_dir, - 'trees/s390x/Server/repodata/productid'))), - mock.call(('i386/Client', os.path.join(self.isos.temp_dir, - 'trees/i386/Client/repodata/productid')))] + [ + mock.call(("src/Client", None), show_cmd=True), + mock.call(("src/Server", None), show_cmd=True), + mock.call(("i386/Client", self.comps["i386"]["Client"]), show_cmd=True), + mock.call(("debug-i386/Client", None), show_cmd=True), + mock.call( + ("s390x/Server", self.comps["s390x"]["Server"]), show_cmd=True + ), + mock.call(("debug-s390x/Server", None), show_cmd=True), + mock.call( + ("x86_64/Client", self.comps["x86_64"]["Client"]), show_cmd=True + ), + mock.call(("debug-x86_64/Client", None), show_cmd=True), + mock.call( + ("x86_64/Server", self.comps["x86_64"]["Server"]), show_cmd=True + ), + mock.call(("debug-x86_64/Server", None), show_cmd=True), + mock.call( + ( + "x86_64/Server", + os.path.join( + self.isos.temp_dir, "trees/x86_64/Server/repodata/productid" + ), + ) + ), + mock.call( + ( + "x86_64/Client", + os.path.join( + self.isos.temp_dir, "trees/x86_64/Client/repodata/productid" + ), + ) + ), + mock.call( + ( + "s390x/Server", + os.path.join( + self.isos.temp_dir, "trees/s390x/Server/repodata/productid" + ), + ) + ), + mock.call( + ( + "i386/Client", + os.path.join( + self.isos.temp_dir, "trees/i386/Client/repodata/productid" + ), + ) + ), + ], ) checksums = {} @@ -349,69 +492,105 @@ class TestCreaterepo(PungiTestCase): for arch in self.isos.treeinfo.keys(): parser = SafeConfigParser() parser.optionxform = str - parser.read(os.path.join(self.isos.temp_dir, 'trees', arch, '.treeinfo')) - checksums[arch] = [k for k, v in parser.items('checksums')] + parser.read(os.path.join(self.isos.temp_dir, "trees", arch, ".treeinfo")) + checksums[arch] = [k for k, v in parser.items("checksums")] self.assertEqual( checksums, - {'i386': ['Client/repodata/repomd.xml'], - 'debug-i386': ['Client/repodata/repomd.xml'], - 's390x': ['Server/repodata/repomd.xml'], - 'debug-s390x': ['Server/repodata/repomd.xml'], - 'src': ['Client/repodata/repomd.xml', 'Server/repodata/repomd.xml'], - 'x86_64': ['Client/repodata/repomd.xml', 'Server/repodata/repomd.xml'], - 'debug-x86_64': ['Client/repodata/repomd.xml', 'Server/repodata/repomd.xml']} + { + "i386": ["Client/repodata/repomd.xml"], + "debug-i386": ["Client/repodata/repomd.xml"], + "s390x": ["Server/repodata/repomd.xml"], + "debug-s390x": ["Server/repodata/repomd.xml"], + "src": ["Client/repodata/repomd.xml", "Server/repodata/repomd.xml"], + "x86_64": ["Client/repodata/repomd.xml", "Server/repodata/repomd.xml"], + "debug-x86_64": [ + "Client/repodata/repomd.xml", + "Server/repodata/repomd.xml", + ], + }, ) class TestDiscinfo(PungiTestCase): def setUp(self): super(TestDiscinfo, 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') + 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() # TODO mock treeinfo and use mappings for other data self.isos.link_to_temp() self.maxDiff = None - @mock.patch('pungi_utils.unified_isos.create_discinfo') + @mock.patch("pungi_utils.unified_isos.create_discinfo") def test_discinfo(self, create_discinfo): self.isos.discinfo() six.assertCountEqual( self, create_discinfo.call_args_list, - [mock.call(os.path.join(self.isos.temp_dir, 'trees', 'i386', '.discinfo'), - 'Dummy Product 1.0', 'i386'), - mock.call(os.path.join(self.isos.temp_dir, 'trees', 'debug-i386', '.discinfo'), - 'Dummy Product 1.0', 'i386'), - mock.call(os.path.join(self.isos.temp_dir, 'trees', 's390x', '.discinfo'), - 'Dummy Product 1.0', 's390x'), - mock.call(os.path.join(self.isos.temp_dir, 'trees', 'debug-s390x', '.discinfo'), - 'Dummy Product 1.0', 's390x'), - mock.call(os.path.join(self.isos.temp_dir, 'trees', 'src', '.discinfo'), - 'Dummy Product 1.0', 'src'), - mock.call(os.path.join(self.isos.temp_dir, 'trees', 'x86_64', '.discinfo'), - 'Dummy Product 1.0', 'x86_64'), - mock.call(os.path.join(self.isos.temp_dir, 'trees', 'debug-x86_64', '.discinfo'), - 'Dummy Product 1.0', 'x86_64')] + [ + mock.call( + os.path.join(self.isos.temp_dir, "trees", "i386", ".discinfo"), + "Dummy Product 1.0", + "i386", + ), + mock.call( + os.path.join( + self.isos.temp_dir, "trees", "debug-i386", ".discinfo" + ), + "Dummy Product 1.0", + "i386", + ), + mock.call( + os.path.join(self.isos.temp_dir, "trees", "s390x", ".discinfo"), + "Dummy Product 1.0", + "s390x", + ), + mock.call( + os.path.join( + self.isos.temp_dir, "trees", "debug-s390x", ".discinfo" + ), + "Dummy Product 1.0", + "s390x", + ), + mock.call( + os.path.join(self.isos.temp_dir, "trees", "src", ".discinfo"), + "Dummy Product 1.0", + "src", + ), + mock.call( + os.path.join(self.isos.temp_dir, "trees", "x86_64", ".discinfo"), + "Dummy Product 1.0", + "x86_64", + ), + mock.call( + os.path.join( + self.isos.temp_dir, "trees", "debug-x86_64", ".discinfo" + ), + "Dummy Product 1.0", + "x86_64", + ), + ], ) CHECKSUMS = { - 'MD5': 'cbc3a5767b22babfe3578a2b82d83fcb', - 'SHA1': 'afaf8621bfbc22781edfc81b774a2b2f66fdc8b0', - 'SHA256': '84c1c8611b287209e1e76d657e7e69e6192ad72dd2531e0fb7a43b95070fabb1', + "MD5": "cbc3a5767b22babfe3578a2b82d83fcb", + "SHA1": "afaf8621bfbc22781edfc81b774a2b2f66fdc8b0", + "SHA256": "84c1c8611b287209e1e76d657e7e69e6192ad72dd2531e0fb7a43b95070fabb1", } class TestCreateiso(PungiTestCase): def setUp(self): super(TestCreateiso, 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') + 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() # TODO mock treeinfo and use mappings for other data @@ -421,91 +600,130 @@ class TestCreateiso(PungiTestCase): 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) + 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') + touch(path, "ISO FILE\n") + self.mkisofs_cmd = self.mkisofs_cmd or mock.Mock(name="mkisofs cmd") return self.mkisofs_cmd def _iso(self, variant, arch, name): - return os.path.join(self.compose_path, variant, arch, 'iso', name) + return os.path.join(self.compose_path, variant, arch, "iso", name) def assertResults(self, iso, run, arches): self.assertEqual( run.mock_calls, - [mock.call(self.mkisofs_cmd), - mock.call(iso.get_implantisomd5_cmd.return_value), - mock.call(iso.get_manifest_cmd.return_value)] * len(arches) + [ + mock.call(self.mkisofs_cmd), + mock.call(iso.get_implantisomd5_cmd.return_value), + mock.call(iso.get_manifest_cmd.return_value), + ] + * len(arches), ) images = self.isos.compose.images - for v in ('Client', 'Server'): + for v in ("Client", "Server"): for a in arches: - for image in images[v]['x86_64']: - arch = iso_arch = 'source' if image.arch == 'src' else image.arch - if a.startswith('debug-'): - iso_arch += '-debuginfo' - a = a.split('-', 1)[1] - path = '{0}/{1}/iso/DP-1.0-20161013.t.4-{1}-dvd.iso'.format(v, arch, iso_arch) + for image in images[v]["x86_64"]: + arch = iso_arch = "source" if image.arch == "src" else image.arch + if a.startswith("debug-"): + iso_arch += "-debuginfo" + a = a.split("-", 1)[1] + path = "{0}/{1}/iso/DP-1.0-20161013.t.4-{1}-dvd.iso".format( + v, arch, iso_arch + ) if image.unified and image.arch == a and image.path == path: break else: - self.fail('Image for %s.%s missing' % (v, a)) + 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')), + 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')), - ]) + 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" + ), + ), + ] + ) six.assertCountEqual(self, self.isos.linker.link.call_args_list, expected) - @mock.patch('pungi_utils.unified_isos.iso') - @mock.patch('pungi_utils.unified_isos.run') + @mock.patch("pungi_utils.unified_isos.iso") + @mock.patch("pungi_utils.unified_isos.run") def test_createiso(self, run, iso): iso.get_mkisofs_cmd.side_effect = self.mock_gmc - iso.get_implanted_md5.return_value = 'beefcafebabedeadbeefcafebabedead' - iso.get_volume_id.return_value = 'VOLID' + iso.get_implanted_md5.return_value = "beefcafebabedeadbeefcafebabedead" + iso.get_volume_id.return_value = "VOLID" - self.isos.treeinfo = {'x86_64': self.isos.treeinfo['x86_64'], - 'src': self.isos.treeinfo['src']} + self.isos.treeinfo = { + "x86_64": self.isos.treeinfo["x86_64"], + "src": self.isos.treeinfo["src"], + } self.isos.createiso() - self.assertResults(iso, run, ['src', 'x86_64']) + self.assertResults(iso, run, ["src", "x86_64"]) - @mock.patch('pungi_utils.unified_isos.iso') - @mock.patch('pungi_utils.unified_isos.run') + @mock.patch("pungi_utils.unified_isos.iso") + @mock.patch("pungi_utils.unified_isos.run") def test_createiso_debuginfo(self, run, iso): iso.get_mkisofs_cmd.side_effect = self.mock_gmc - iso.get_implanted_md5.return_value = 'beefcafebabedeadbeefcafebabedead' - iso.get_volume_id.return_value = 'VOLID' + iso.get_implanted_md5.return_value = "beefcafebabedeadbeefcafebabedead" + iso.get_volume_id.return_value = "VOLID" - self.isos.treeinfo = {'x86_64': self.isos.treeinfo['x86_64'], - 'debug-x86_64': self.isos.treeinfo['x86_64'], - 'src': self.isos.treeinfo['src']} + self.isos.treeinfo = { + "x86_64": self.isos.treeinfo["x86_64"], + "debug-x86_64": self.isos.treeinfo["x86_64"], + "src": self.isos.treeinfo["src"], + } self.isos.createiso() - self.assertResults(iso, run, ['src', 'x86_64', 'debug-x86_64']) + self.assertResults(iso, run, ["src", "x86_64", "debug-x86_64"]) class MockImage(mock.Mock): @@ -516,45 +734,67 @@ class MockImage(mock.Mock): class TestUpdateChecksums(PungiTestCase): def setUp(self): super(TestUpdateChecksums, 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') + 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.maxDiff = None def _isodir(self, variant, arch): - return os.path.join(self.compose_path, variant, arch, 'iso') + return os.path.join(self.compose_path, variant, arch, "iso") - def _call(self, variant, arch, source=False, basename='', one_file=False): - archdir = arch if not source else 'source' + def _call(self, variant, arch, source=False, basename="", one_file=False): + archdir = arch if not source else "source" isodir = self._isodir(variant, archdir) - filename = 'DP-1.0-20161013.t.4-%s-%s-dvd1.iso' % (variant, archdir) - return mock.call(variant, arch, isodir, - [MockImage(path=os.path.join(variant, archdir, 'iso', filename))], - ['md5', 'sha1', 'sha256'], basename, one_file) + filename = "DP-1.0-20161013.t.4-%s-%s-dvd1.iso" % (variant, archdir) + return mock.call( + variant, + arch, + isodir, + [MockImage(path=os.path.join(variant, archdir, "iso", filename))], + ["md5", "sha1", "sha256"], + basename, + one_file, + ) - @mock.patch('pungi_utils.unified_isos.make_checksums') + @mock.patch("pungi_utils.unified_isos.make_checksums") def test_update_checksums(self, mmc): self.isos.update_checksums() six.assertCountEqual( self, mmc.call_args_list, - [mock.call(self.compose_path, self.isos.compose.images, - unified_isos.DEFAULT_CHECKSUMS, False, - self.isos._get_base_filename)]) + [ + mock.call( + self.compose_path, + self.isos.compose.images, + unified_isos.DEFAULT_CHECKSUMS, + False, + self.isos._get_base_filename, + ) + ], + ) - @mock.patch('pungi_utils.unified_isos.make_checksums') + @mock.patch("pungi_utils.unified_isos.make_checksums") def test_update_checksums_one_file(self, mmc): - self.isos.conf['media_checksum_one_file'] = True + self.isos.conf["media_checksum_one_file"] = True self.isos.update_checksums() six.assertCountEqual( self, mmc.call_args_list, - [mock.call(self.compose_path, self.isos.compose.images, - unified_isos.DEFAULT_CHECKSUMS, True, - self.isos._get_base_filename)]) + [ + mock.call( + self.compose_path, + self.isos.compose.images, + unified_isos.DEFAULT_CHECKSUMS, + True, + self.isos._get_base_filename, + ) + ], + ) def test_get_base_filename(self): - self.isos.conf['media_checksum_base_filename'] = '{variant}-{arch}' - self.assertEqual(self.isos._get_base_filename('Client', 'x86_64'), - 'Client-x86_64-') + self.isos.conf["media_checksum_base_filename"] = "{variant}-{arch}" + self.assertEqual( + self.isos._get_base_filename("Client", "x86_64"), "Client-x86_64-" + ) diff --git a/tests/test_util.py b/tests/test_util.py index d60edd20..00cbf931 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -4,6 +4,7 @@ import argparse import mock import os import sys + try: import unittest2 as unittest except ImportError: @@ -20,35 +21,41 @@ from tests.helpers import touch, PungiTestCase, mk_boom class TestGitRefResolver(unittest.TestCase): - - @mock.patch('pungi.util.run') + @mock.patch("pungi.util.run") def test_successful_resolve(self, run): - run.return_value = (0, 'CAFEBABE\tHEAD\n') + run.return_value = (0, "CAFEBABE\tHEAD\n") - url = util.resolve_git_url('https://git.example.com/repo.git?somedir#HEAD') + url = util.resolve_git_url("https://git.example.com/repo.git?somedir#HEAD") - self.assertEqual(url, 'https://git.example.com/repo.git?somedir#CAFEBABE') - run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD'], - universal_newlines=True) + self.assertEqual(url, "https://git.example.com/repo.git?somedir#CAFEBABE") + run.assert_called_once_with( + ["git", "ls-remote", "https://git.example.com/repo.git", "HEAD"], + universal_newlines=True, + ) - @mock.patch('pungi.util.run') + @mock.patch("pungi.util.run") def test_successful_resolve_branch(self, run): - run.return_value = (0, 'CAFEBABE\trefs/heads/f24\n') + run.return_value = (0, "CAFEBABE\trefs/heads/f24\n") - url = util.resolve_git_url('https://git.example.com/repo.git?somedir#origin/f24') + url = util.resolve_git_url( + "https://git.example.com/repo.git?somedir#origin/f24" + ) - self.assertEqual(url, 'https://git.example.com/repo.git?somedir#CAFEBABE') - run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'refs/heads/f24'], - universal_newlines=True) + self.assertEqual(url, "https://git.example.com/repo.git?somedir#CAFEBABE") + run.assert_called_once_with( + ["git", "ls-remote", "https://git.example.com/repo.git", "refs/heads/f24"], + universal_newlines=True, + ) def test_resolve_ref_with_commit_id(self): ref = util.resolve_git_ref("https://git.example.com/repo.git", "a" * 40) self.assertEqual(ref, "a" * 40) - @mock.patch('pungi.util.run') + @mock.patch("pungi.util.run") def test_resolve_ref_multiple_matches(self, run): run.return_value = ( - 0, "CAFEBABE\trefs/heads/master\nBABECAFE\trefs/remotes/origin/master" + 0, + "CAFEBABE\trefs/heads/master\nBABECAFE\trefs/remotes/origin/master", ) ref = util.resolve_git_ref("https://git.example.com/repo.git", "master") @@ -59,11 +66,9 @@ class TestGitRefResolver(unittest.TestCase): universal_newlines=True, ) - @mock.patch('pungi.util.run') + @mock.patch("pungi.util.run") def test_resolve_ref_with_remote_head(self, run): - run.return_value = ( - 0, "CAFEBABE\tHEAD\nBABECAFE\trefs/remotes/origin/HEAD" - ) + run.return_value = (0, "CAFEBABE\tHEAD\nBABECAFE\trefs/remotes/origin/HEAD") ref = util.resolve_git_ref("https://git.example.com/repo.git", "HEAD") @@ -73,74 +78,95 @@ class TestGitRefResolver(unittest.TestCase): universal_newlines=True, ) - @mock.patch('pungi.util.run') + @mock.patch("pungi.util.run") def test_resolve_missing_spec(self, run): - url = util.resolve_git_url('https://git.example.com/repo.git') + url = util.resolve_git_url("https://git.example.com/repo.git") - self.assertEqual(url, 'https://git.example.com/repo.git') + self.assertEqual(url, "https://git.example.com/repo.git") self.assertEqual(run.mock_calls, []) - @mock.patch('pungi.util.run') + @mock.patch("pungi.util.run") def test_resolve_non_head_spec(self, run): - url = util.resolve_git_url('https://git.example.com/repo.git#some-tag') + url = util.resolve_git_url("https://git.example.com/repo.git#some-tag") - self.assertEqual(url, 'https://git.example.com/repo.git#some-tag') + self.assertEqual(url, "https://git.example.com/repo.git#some-tag") self.assertEqual(run.mock_calls, []) - @mock.patch('pungi.util.run') + @mock.patch("pungi.util.run") def test_resolve_ambiguous(self, run): - run.return_value = (0, 'CAFEBABE\tF11\nDEADBEEF\tF10\n') + run.return_value = (0, "CAFEBABE\tF11\nDEADBEEF\tF10\n") with self.assertRaises(RuntimeError): - util.resolve_git_url('https://git.example.com/repo.git?somedir#HEAD') - - run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD'], - universal_newlines=True) - - @mock.patch('pungi.util.run') - def test_resolve_keep_empty_query_string(self, run): - run.return_value = (0, 'CAFEBABE\tHEAD\n') - - url = util.resolve_git_url('https://git.example.com/repo.git?#HEAD') - - run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD'], - universal_newlines=True) - self.assertEqual(url, 'https://git.example.com/repo.git?#CAFEBABE') - - @mock.patch('pungi.util.run') - def test_resolve_strip_git_plus_prefix(self, run): - run.return_value = (0, 'CAFEBABE\tHEAD\n') - - url = util.resolve_git_url('git+https://git.example.com/repo.git#HEAD') - - run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD'], - universal_newlines=True) - self.assertEqual(url, 'git+https://git.example.com/repo.git#CAFEBABE') - - @mock.patch('pungi.util.run') - def test_resolve_no_branch_in_remote(self, run): - run.return_value = (0, '') - - with self.assertRaises(RuntimeError) as ctx: - util.resolve_git_url('https://git.example.com/repo.git?somedir#origin/my-branch') + util.resolve_git_url("https://git.example.com/repo.git?somedir#HEAD") run.assert_called_once_with( - ['git', 'ls-remote', 'https://git.example.com/repo.git', 'refs/heads/my-branch'], - universal_newlines=True) - self.assertIn('ref does not exist in remote repo', str(ctx.exception)) + ["git", "ls-remote", "https://git.example.com/repo.git", "HEAD"], + universal_newlines=True, + ) - @mock.patch('time.sleep') - @mock.patch('pungi.util.run') + @mock.patch("pungi.util.run") + def test_resolve_keep_empty_query_string(self, run): + run.return_value = (0, "CAFEBABE\tHEAD\n") + + url = util.resolve_git_url("https://git.example.com/repo.git?#HEAD") + + run.assert_called_once_with( + ["git", "ls-remote", "https://git.example.com/repo.git", "HEAD"], + universal_newlines=True, + ) + self.assertEqual(url, "https://git.example.com/repo.git?#CAFEBABE") + + @mock.patch("pungi.util.run") + def test_resolve_strip_git_plus_prefix(self, run): + run.return_value = (0, "CAFEBABE\tHEAD\n") + + url = util.resolve_git_url("git+https://git.example.com/repo.git#HEAD") + + run.assert_called_once_with( + ["git", "ls-remote", "https://git.example.com/repo.git", "HEAD"], + universal_newlines=True, + ) + self.assertEqual(url, "git+https://git.example.com/repo.git#CAFEBABE") + + @mock.patch("pungi.util.run") + def test_resolve_no_branch_in_remote(self, run): + run.return_value = (0, "") + + with self.assertRaises(RuntimeError) as ctx: + util.resolve_git_url( + "https://git.example.com/repo.git?somedir#origin/my-branch" + ) + + run.assert_called_once_with( + [ + "git", + "ls-remote", + "https://git.example.com/repo.git", + "refs/heads/my-branch", + ], + universal_newlines=True, + ) + self.assertIn("ref does not exist in remote repo", str(ctx.exception)) + + @mock.patch("time.sleep") + @mock.patch("pungi.util.run") def test_retry(self, run, sleep): - run.side_effect = [RuntimeError('Boom'), (0, 'CAFEBABE\tHEAD\n')] + run.side_effect = [RuntimeError("Boom"), (0, "CAFEBABE\tHEAD\n")] - url = util.resolve_git_url('https://git.example.com/repo.git?somedir#HEAD') + url = util.resolve_git_url("https://git.example.com/repo.git?somedir#HEAD") - self.assertEqual(url, 'https://git.example.com/repo.git?somedir#CAFEBABE') + self.assertEqual(url, "https://git.example.com/repo.git?somedir#CAFEBABE") self.assertEqual(sleep.call_args_list, [mock.call(30)]) - self.assertEqual(run.call_args_list, - [mock.call(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD'], - universal_newlines=True)] * 2) + self.assertEqual( + run.call_args_list, + [ + mock.call( + ["git", "ls-remote", "https://git.example.com/repo.git", "HEAD"], + universal_newlines=True, + ) + ] + * 2, + ) @mock.patch("pungi.util.resolve_git_ref") @mock.patch("pungi.util.resolve_git_url") @@ -158,8 +184,7 @@ class TestGitRefResolver(unittest.TestCase): def test_resolver_offline_branch(self, mock_resolve_url, mock_resolve_ref): resolver = util.GitUrlResolver(offline=True) self.assertEqual( - resolver("http://example.com/repo.git", "master"), - "master", + resolver("http://example.com/repo.git", "master"), "master", ) self.assertEqual(mock_resolve_url.call_args_list, []) self.assertEqual(mock_resolve_ref.call_args_list, []) @@ -207,48 +232,32 @@ class TestGitRefResolver(unittest.TestCase): class TestGetVariantData(unittest.TestCase): def test_get_simple(self): - conf = { - 'foo': { - '^Client$': 1 - } - } - result = util.get_variant_data(conf, 'foo', mock.Mock(uid='Client')) + conf = {"foo": {"^Client$": 1}} + result = util.get_variant_data(conf, "foo", mock.Mock(uid="Client")) self.assertEqual(result, [1]) def test_get_make_list(self): - conf = { - 'foo': { - '^Client$': [1, 2], - '^.*$': 3, - } - } - result = util.get_variant_data(conf, 'foo', mock.Mock(uid='Client')) + conf = {"foo": {"^Client$": [1, 2], "^.*$": 3}} + result = util.get_variant_data(conf, "foo", mock.Mock(uid="Client")) six.assertCountEqual(self, result, [1, 2, 3]) def test_not_matching_arch(self): - conf = { - 'foo': { - '^Client$': [1, 2], - } - } - result = util.get_variant_data(conf, 'foo', mock.Mock(uid='Server')) + conf = {"foo": {"^Client$": [1, 2]}} + result = util.get_variant_data(conf, "foo", mock.Mock(uid="Server")) self.assertEqual(result, []) def test_handle_missing_config(self): - result = util.get_variant_data({}, 'foo', mock.Mock(uid='Client')) + result = util.get_variant_data({}, "foo", mock.Mock(uid="Client")) self.assertEqual(result, []) def test_get_save_pattern(self): - conf = { - 'foo': { - '^Client$': 1, - '^NotClient$': 2, - } - } + conf = {"foo": {"^Client$": 1, "^NotClient$": 2}} patterns = set() - result = util.get_variant_data(conf, 'foo', mock.Mock(uid='Client'), keys=patterns) + result = util.get_variant_data( + conf, "foo", mock.Mock(uid="Client"), keys=patterns + ) self.assertEqual(result, [1]) - self.assertEqual(patterns, set(['^Client$'])) + self.assertEqual(patterns, set(["^Client$"])) class TestVolumeIdGenerator(unittest.TestCase): @@ -258,119 +267,137 @@ class TestVolumeIdGenerator(unittest.TestCase): def tearDown(self): shutil.rmtree(self.tmp_dir) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_volid(self, ci): all_keys = [ - (['arch', 'compose_id', 'date', 'disc_type'], 'x86_64-compose_id-20160107-'), - (['label', 'label_major_version', 'release_short', 'respin'], 'RC-1.0-1-rel_short2-2'), - (['type', 'type_suffix', 'variant', 'version'], 'nightly-.n-Server-6.0') + ( + ["arch", "compose_id", "date", "disc_type"], + "x86_64-compose_id-20160107-", + ), + ( + ["label", "label_major_version", "release_short", "respin"], + "RC-1.0-1-rel_short2-2", + ), + (["type", "type_suffix", "variant", "version"], "nightly-.n-Server-6.0"), ] for keys, expected in all_keys: - format = '-'.join(['%(' + k + ')s' for k in keys]) + format = "-".join(["%(" + k + ")s" for k in keys]) conf = { - 'release_short': 'rel_short2', - 'release_version': '6.0', - 'image_volid_formats': [format], - 'image_volid_layered_product_formats': [], - 'volume_id_substitutions': {}, - 'restricted_volid': False, + "release_short": "rel_short2", + "release_version": "6.0", + "image_volid_formats": [format], + "image_volid_layered_product_formats": [], + "volume_id_substitutions": {}, + "restricted_volid": False, } - variant = mock.Mock(uid='Server', type='variant') + variant = mock.Mock(uid="Server", type="variant") ci.return_value.compose.respin = 2 - ci.return_value.compose.id = 'compose_id' - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' - ci.return_value.compose.label = 'RC-1.0' - ci.return_value.compose.label_major_version = '1' + ci.return_value.compose.id = "compose_id" + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" + ci.return_value.compose.label = "RC-1.0" + ci.return_value.compose.label_major_version = "1" - ci.return_value.release.version = '3.0' - ci.return_value.release.short = 'rel_short' + ci.return_value.release.version = "3.0" + ci.return_value.release.short = "rel_short" c = compose.Compose(conf, self.tmp_dir) - volid = util.get_volid(c, 'x86_64', variant, disc_type=False) + volid = util.get_volid(c, "x86_64", variant, disc_type=False) self.assertEqual(volid, expected) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_restricted_volid(self, ci): all_keys = [ - (['arch', 'compose_id', 'date', 'disc_type'], 'x86_64-compose_id-20160107-'), - (['label', 'label_major_version', 'release_short', 'respin'], 'RC-1-0-1-rel_short2-2'), - (['type', 'type_suffix', 'variant', 'version'], 'nightly--n-Server-6-0') + ( + ["arch", "compose_id", "date", "disc_type"], + "x86_64-compose_id-20160107-", + ), + ( + ["label", "label_major_version", "release_short", "respin"], + "RC-1-0-1-rel_short2-2", + ), + (["type", "type_suffix", "variant", "version"], "nightly--n-Server-6-0"), ] for keys, expected in all_keys: - format = '-'.join(['%(' + k + ')s' for k in keys]) + format = "-".join(["%(" + k + ")s" for k in keys]) conf = { - 'release_short': 'rel_short2', - 'release_version': '6.0', - 'image_volid_formats': [format], - 'image_volid_layered_product_formats': [], - 'volume_id_substitutions': {}, - 'restricted_volid': True, + "release_short": "rel_short2", + "release_version": "6.0", + "image_volid_formats": [format], + "image_volid_layered_product_formats": [], + "volume_id_substitutions": {}, + "restricted_volid": True, } - variant = mock.Mock(uid='Server', type='variant') + variant = mock.Mock(uid="Server", type="variant") ci.return_value.compose.respin = 2 - ci.return_value.compose.id = 'compose_id' - ci.return_value.compose.date = '20160107' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' - ci.return_value.compose.label = 'RC-1.0' - ci.return_value.compose.label_major_version = '1' + ci.return_value.compose.id = "compose_id" + ci.return_value.compose.date = "20160107" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" + ci.return_value.compose.label = "RC-1.0" + ci.return_value.compose.label_major_version = "1" - ci.return_value.release.version = '3.0' - ci.return_value.release.short = 'rel_short' + ci.return_value.release.version = "3.0" + ci.return_value.release.short = "rel_short" c = compose.Compose(conf, self.tmp_dir) - volid = util.get_volid(c, 'x86_64', variant, disc_type=False) + volid = util.get_volid(c, "x86_64", variant, disc_type=False) self.assertEqual(volid, expected) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_get_volid_too_long(self, ci): conf = { - 'release_short': 'rel_short2', - 'release_version': '6.0', - 'image_volid_formats': [ - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', # 34 chars - 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', # 33 chars + "release_short": "rel_short2", + "release_version": "6.0", + "image_volid_formats": [ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", # 34 chars + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", # 33 chars ], - 'image_volid_layered_product_formats': [], - 'volume_id_substitutions': {}, + "image_volid_layered_product_formats": [], + "volume_id_substitutions": {}, } - variant = mock.Mock(uid='Server', type='variant') + variant = mock.Mock(uid="Server", type="variant") c = compose.Compose(conf, self.tmp_dir) with self.assertRaises(ValueError) as ctx: - util.get_volid(c, 'x86_64', variant, disc_type=False) + util.get_volid(c, "x86_64", variant, disc_type=False) - self.assertIn('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', str(ctx.exception)) - self.assertIn('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', str(ctx.exception)) + self.assertIn("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", str(ctx.exception)) + self.assertIn("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", str(ctx.exception)) - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def test_apply_substitutions(self, ci): all_keys = [ - ('Fedora-WorkstationOstree-ostree-x86_64-rawhide', 'Fedora-WS-ostree-x86_64-rawhide'), - ('Fedora-WorkstationOstree-ostree-x86_64-Rawhide', 'Fedora-WS-ostree-x86_64-rawh'), - ('x86_64-compose_id-20160107', 'x86_64-compose_id-20160107'), - ('x86_64-compose_id-20160107-Alpha', 'x86_64-compose_id-20160107-A'), + ( + "Fedora-WorkstationOstree-ostree-x86_64-rawhide", + "Fedora-WS-ostree-x86_64-rawhide", + ), + ( + "Fedora-WorkstationOstree-ostree-x86_64-Rawhide", + "Fedora-WS-ostree-x86_64-rawh", + ), + ("x86_64-compose_id-20160107", "x86_64-compose_id-20160107"), + ("x86_64-compose_id-20160107-Alpha", "x86_64-compose_id-20160107-A"), # These test the case where one substitution is a subset # of the other, but sorts alphabetically ahead of it, to # make sure we're correctly sorting by length - ('Fedora-zzzaaaaaazzz-Rawhide', 'Fedora-zzz-rawh'), - ('Fedora-aaaaaa-Rawhide', 'Fedora-aaa-rawh'), + ("Fedora-zzzaaaaaazzz-Rawhide", "Fedora-zzz-rawh"), + ("Fedora-aaaaaa-Rawhide", "Fedora-aaa-rawh"), ] for volid, expected in all_keys: conf = { - 'volume_id_substitutions': { - 'Rawhide': 'rawh', - 'WorkstationOstree': 'WS', - 'Workstation': 'WS', - 'Alpha': 'A', - 'zzzaaaaaazzz': 'zzz', - 'aaaaaa': 'aaa', + "volume_id_substitutions": { + "Rawhide": "rawh", + "WorkstationOstree": "WS", + "Workstation": "WS", + "Alpha": "A", + "zzzaaaaaazzz": "zzz", + "aaaaaa": "aaa", } } c = compose.Compose(conf, self.tmp_dir) @@ -386,103 +413,113 @@ class TestFindOldCompose(unittest.TestCase): shutil.rmtree(self.tmp_dir) def test_finds_single(self): - touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0/STATUS', 'FINISHED') - old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide', '') - self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-20160229.0') + touch(self.tmp_dir + "/Fedora-Rawhide-20160229.0/STATUS", "FINISHED") + old = util.find_old_compose(self.tmp_dir, "Fedora", "Rawhide", "") + self.assertEqual(old, self.tmp_dir + "/Fedora-Rawhide-20160229.0") def test_ignores_in_progress(self): - touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0/STATUS', 'STARTED') - old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide', '') + touch(self.tmp_dir + "/Fedora-Rawhide-20160229.0/STATUS", "STARTED") + old = util.find_old_compose(self.tmp_dir, "Fedora", "Rawhide", "") self.assertIsNone(old) def test_only_considers_allowed_status(self): - touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0/STATUS', 'FINISHED') - old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide', '', - allowed_statuses=['DOOMED']) + touch(self.tmp_dir + "/Fedora-Rawhide-20160229.0/STATUS", "FINISHED") + old = util.find_old_compose( + self.tmp_dir, "Fedora", "Rawhide", "", allowed_statuses=["DOOMED"] + ) self.assertIsNone(old) def test_finds_latest(self): - touch(self.tmp_dir + '/Fedora-Rawhide-20160228.0/STATUS', 'DOOMED') - touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0/STATUS', 'FINISHED') - touch(self.tmp_dir + '/Fedora-Rawhide-20160229.1/STATUS', 'FINISHED_INCOMPLETE') - old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide', '') - self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-20160229.1') + touch(self.tmp_dir + "/Fedora-Rawhide-20160228.0/STATUS", "DOOMED") + touch(self.tmp_dir + "/Fedora-Rawhide-20160229.0/STATUS", "FINISHED") + touch(self.tmp_dir + "/Fedora-Rawhide-20160229.1/STATUS", "FINISHED_INCOMPLETE") + old = util.find_old_compose(self.tmp_dir, "Fedora", "Rawhide", "") + self.assertEqual(old, self.tmp_dir + "/Fedora-Rawhide-20160229.1") def test_find_correct_type(self): - touch(self.tmp_dir + '/Fedora-26-updates-20160229.0/STATUS', 'FINISHED') - touch(self.tmp_dir + '/Fedora-26-updates-testing-20160229.0/STATUS', 'FINISHED') - old = util.find_old_compose(self.tmp_dir, 'Fedora', '26', '-updates') - self.assertEqual(old, self.tmp_dir + '/Fedora-26-updates-20160229.0') - old = util.find_old_compose(self.tmp_dir, 'Fedora', '26', '-updates-testing') - self.assertEqual(old, self.tmp_dir + '/Fedora-26-updates-testing-20160229.0') + touch(self.tmp_dir + "/Fedora-26-updates-20160229.0/STATUS", "FINISHED") + touch(self.tmp_dir + "/Fedora-26-updates-testing-20160229.0/STATUS", "FINISHED") + old = util.find_old_compose(self.tmp_dir, "Fedora", "26", "-updates") + self.assertEqual(old, self.tmp_dir + "/Fedora-26-updates-20160229.0") + old = util.find_old_compose(self.tmp_dir, "Fedora", "26", "-updates-testing") + self.assertEqual(old, self.tmp_dir + "/Fedora-26-updates-testing-20160229.0") def test_find_latest_with_two_digit_respin(self): - touch(self.tmp_dir + '/Fedora-Rawhide-20160228.n.9/STATUS', 'FINISHED') - touch(self.tmp_dir + '/Fedora-Rawhide-20160228.n.10/STATUS', 'FINISHED') - old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide', '') - self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-20160228.n.10') + touch(self.tmp_dir + "/Fedora-Rawhide-20160228.n.9/STATUS", "FINISHED") + touch(self.tmp_dir + "/Fedora-Rawhide-20160228.n.10/STATUS", "FINISHED") + old = util.find_old_compose(self.tmp_dir, "Fedora", "Rawhide", "") + self.assertEqual(old, self.tmp_dir + "/Fedora-Rawhide-20160228.n.10") def test_finds_ignores_other_files(self): - touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0', 'not a compose') - touch(self.tmp_dir + '/Fedora-Rawhide-20160228.0/STATUS/file', 'also not a compose') - touch(self.tmp_dir + '/Fedora-24-20160229.0/STATUS', 'FINISHED') - touch(self.tmp_dir + '/Another-Rawhide-20160229.0/STATUS', 'FINISHED') - old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide', '') + touch(self.tmp_dir + "/Fedora-Rawhide-20160229.0", "not a compose") + touch( + self.tmp_dir + "/Fedora-Rawhide-20160228.0/STATUS/file", + "also not a compose", + ) + touch(self.tmp_dir + "/Fedora-24-20160229.0/STATUS", "FINISHED") + touch(self.tmp_dir + "/Another-Rawhide-20160229.0/STATUS", "FINISHED") + old = util.find_old_compose(self.tmp_dir, "Fedora", "Rawhide", "") self.assertIsNone(old) def test_search_in_file(self): - touch(self.tmp_dir + '/file') - old = util.find_old_compose(self.tmp_dir + '/file', 'Fedora', 'Rawhide', '') + touch(self.tmp_dir + "/file") + old = util.find_old_compose(self.tmp_dir + "/file", "Fedora", "Rawhide", "") self.assertIsNone(old) def test_skips_symlink(self): - os.symlink(self.tmp_dir, self.tmp_dir + '/Fedora-Rawhide-20160229.0') - old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide', '') + os.symlink(self.tmp_dir, self.tmp_dir + "/Fedora-Rawhide-20160229.0") + old = util.find_old_compose(self.tmp_dir, "Fedora", "Rawhide", "") self.assertIsNone(old) def test_finds_layered_product(self): - touch(self.tmp_dir + '/Fedora-Rawhide-Base-1-20160229.0/STATUS', 'FINISHED') - old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide', '', - base_product_short='Base', base_product_version='1') - self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-Base-1-20160229.0') + touch(self.tmp_dir + "/Fedora-Rawhide-Base-1-20160229.0/STATUS", "FINISHED") + old = util.find_old_compose( + self.tmp_dir, + "Fedora", + "Rawhide", + "", + base_product_short="Base", + base_product_version="1", + ) + self.assertEqual(old, self.tmp_dir + "/Fedora-Rawhide-Base-1-20160229.0") class TestHelpers(PungiTestCase): def test_process_args(self): - self.assertEqual(util.process_args('--opt=%s', None), []) - self.assertEqual(util.process_args('--opt=%s', []), []) - self.assertEqual(util.process_args('--opt=%s', ['foo', 'bar']), - ['--opt=foo', '--opt=bar']) - self.assertEqual(util.process_args('--opt=%s', 'foo'), ['--opt=foo']) + self.assertEqual(util.process_args("--opt=%s", None), []) + self.assertEqual(util.process_args("--opt=%s", []), []) + self.assertEqual( + util.process_args("--opt=%s", ["foo", "bar"]), ["--opt=foo", "--opt=bar"] + ) + self.assertEqual(util.process_args("--opt=%s", "foo"), ["--opt=foo"]) def test_makedirs(self): - util.makedirs(self.topdir + '/foo/bar/baz') - self.assertTrue(os.path.isdir(self.topdir + '/foo/bar/baz')) + util.makedirs(self.topdir + "/foo/bar/baz") + self.assertTrue(os.path.isdir(self.topdir + "/foo/bar/baz")) def test_makedirs_on_existing(self): - os.makedirs(self.topdir + '/foo/bar/baz') + os.makedirs(self.topdir + "/foo/bar/baz") try: - util.makedirs(self.topdir + '/foo/bar/baz') + util.makedirs(self.topdir + "/foo/bar/baz") except OSError: - self.fail('makedirs raised exception on existing directory') + self.fail("makedirs raised exception on existing directory") class TestLevenshtein(unittest.TestCase): def test_edit_dist_empty_str(self): - self.assertEqual(util.levenshtein('', ''), 0) + self.assertEqual(util.levenshtein("", ""), 0) def test_edit_dist_same_str(self): - self.assertEqual(util.levenshtein('aaa', 'aaa'), 0) + self.assertEqual(util.levenshtein("aaa", "aaa"), 0) def test_edit_dist_one_change(self): - self.assertEqual(util.levenshtein('aab', 'aaa'), 1) + self.assertEqual(util.levenshtein("aab", "aaa"), 1) def test_edit_dist_different_words(self): - self.assertEqual(util.levenshtein('kitten', 'sitting'), 3) + self.assertEqual(util.levenshtein("kitten", "sitting"), 3) class TestRecursiveFileList(unittest.TestCase): - def setUp(self): self.tmp_dir = tempfile.mkdtemp() @@ -491,7 +528,7 @@ class TestRecursiveFileList(unittest.TestCase): def test_flat_file_list(self): """Build a directory containing files and assert they are listed.""" - expected_files = sorted(['file1', 'file2', 'file3']) + expected_files = sorted(["file1", "file2", "file3"]) for expected_file in [os.path.join(self.tmp_dir, f) for f in expected_files]: touch(expected_file) @@ -500,7 +537,7 @@ class TestRecursiveFileList(unittest.TestCase): def test_nested_file_list(self): """Build a directory containing files and assert they are listed.""" - expected_files = sorted(['file1', 'subdir/file2', 'sub/subdir/file3']) + expected_files = sorted(["file1", "subdir/file2", "sub/subdir/file3"]) for expected_file in [os.path.join(self.tmp_dir, f) for f in expected_files]: touch(expected_file) @@ -518,12 +555,12 @@ class TestTempFiles(unittest.TestCase): with self.assertRaises(RuntimeError): with util.temp_dir() as tmp: self.assertTrue(os.path.isdir(tmp)) - raise RuntimeError('BOOM') + raise RuntimeError("BOOM") self.assertFalse(os.path.exists(tmp)) def test_temp_dir_in_non_existing_dir(self): with util.temp_dir() as playground: - root = os.path.join(playground, 'missing') + root = os.path.join(playground, "missing") with util.temp_dir(dir=root) as tmp: self.assertTrue(os.path.isdir(tmp)) self.assertTrue(os.path.isdir(root)) @@ -531,219 +568,318 @@ class TestTempFiles(unittest.TestCase): class TestUnmountCmd(unittest.TestCase): - - def _fakeProc(self, ret, err='', out=''): + def _fakeProc(self, ret, err="", out=""): proc = mock.Mock(returncode=ret) proc.communicate.return_value = (out, err) return proc - @mock.patch('subprocess.Popen') + @mock.patch("subprocess.Popen") def test_unmount_cmd_success(self, mockPopen): - cmd = 'unmount' - mockPopen.side_effect = [self._fakeProc(0, '')] + cmd = "unmount" + mockPopen.side_effect = [self._fakeProc(0, "")] util.run_unmount_cmd(cmd) - self.assertEqual(mockPopen.call_args_list, - [mock.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, - universal_newlines=True)]) + self.assertEqual( + mockPopen.call_args_list, + [ + mock.call( + cmd, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True, + ) + ], + ) - @mock.patch('subprocess.Popen') + @mock.patch("subprocess.Popen") def test_unmount_cmd_fail_other_reason(self, mockPopen): - cmd = 'unmount' - mockPopen.side_effect = [self._fakeProc(1, 'It is broken')] + cmd = "unmount" + mockPopen.side_effect = [self._fakeProc(1, "It is broken")] with self.assertRaises(RuntimeError) as ctx: util.run_unmount_cmd(cmd) - self.assertEqual(str(ctx.exception), - "Unhandled error when running 'unmount': 'It is broken'") - self.assertEqual(mockPopen.call_args_list, - [mock.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, - universal_newlines=True)]) + self.assertEqual( + str(ctx.exception), "Unhandled error when running 'unmount': 'It is broken'" + ) + self.assertEqual( + mockPopen.call_args_list, + [ + mock.call( + cmd, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True, + ) + ], + ) - @mock.patch('time.sleep') - @mock.patch('subprocess.Popen') + @mock.patch("time.sleep") + @mock.patch("subprocess.Popen") def test_unmount_cmd_fail_then_retry(self, mockPopen, mock_sleep): - cmd = 'unmount' - mockPopen.side_effect = [self._fakeProc(1, 'Device or resource busy'), - self._fakeProc(1, 'Device or resource busy'), - self._fakeProc(0, '')] + cmd = "unmount" + mockPopen.side_effect = [ + self._fakeProc(1, "Device or resource busy"), + self._fakeProc(1, "Device or resource busy"), + self._fakeProc(0, ""), + ] util.run_unmount_cmd(cmd) - self.assertEqual(mockPopen.call_args_list, - [mock.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, - universal_newlines=True)] * 3) - self.assertEqual(mock_sleep.call_args_list, - [mock.call(0), mock.call(1)]) + self.assertEqual( + mockPopen.call_args_list, + [ + mock.call( + cmd, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True, + ) + ] + * 3, + ) + self.assertEqual(mock_sleep.call_args_list, [mock.call(0), mock.call(1)]) - @mock.patch('time.sleep') - @mock.patch('subprocess.Popen') + @mock.patch("time.sleep") + @mock.patch("subprocess.Popen") def test_unmount_cmd_fail_then_retry_and_fail(self, mockPopen, mock_sleep): - cmd = 'unmount' - mockPopen.side_effect = [self._fakeProc(1, 'Device or resource busy'), - self._fakeProc(1, 'Device or resource busy'), - self._fakeProc(1, 'Device or resource busy')] + cmd = "unmount" + mockPopen.side_effect = [ + self._fakeProc(1, "Device or resource busy"), + self._fakeProc(1, "Device or resource busy"), + self._fakeProc(1, "Device or resource busy"), + ] with self.assertRaises(RuntimeError) as ctx: util.run_unmount_cmd(cmd, max_retries=3) - self.assertEqual(mockPopen.call_args_list, - [mock.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, - universal_newlines=True)] * 3) - self.assertEqual(mock_sleep.call_args_list, - [mock.call(0), mock.call(1), mock.call(2)]) - self.assertEqual(str(ctx.exception), "Failed to run 'unmount': Device or resource busy.") + self.assertEqual( + mockPopen.call_args_list, + [ + mock.call( + cmd, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True, + ) + ] + * 3, + ) + self.assertEqual( + mock_sleep.call_args_list, [mock.call(0), mock.call(1), mock.call(2)] + ) + self.assertEqual( + str(ctx.exception), "Failed to run 'unmount': Device or resource busy." + ) - @mock.patch('time.sleep') - @mock.patch('subprocess.Popen') - def test_fusermount_fail_then_retry_and_fail_with_debug(self, mockPopen, mock_sleep): + @mock.patch("time.sleep") + @mock.patch("subprocess.Popen") + def test_fusermount_fail_then_retry_and_fail_with_debug( + self, mockPopen, mock_sleep + ): logger = mock.Mock() - mockPopen.side_effect = [self._fakeProc(1, 'Device or resource busy'), - self._fakeProc(1, 'Device or resource busy'), - self._fakeProc(1, 'Device or resource busy'), - self._fakeProc(0, out='list of files'), - self._fakeProc(0, out='It is very busy'), - self._fakeProc(1, out='lsof output')] + mockPopen.side_effect = [ + self._fakeProc(1, "Device or resource busy"), + self._fakeProc(1, "Device or resource busy"), + self._fakeProc(1, "Device or resource busy"), + self._fakeProc(0, out="list of files"), + self._fakeProc(0, out="It is very busy"), + self._fakeProc(1, out="lsof output"), + ] with self.assertRaises(RuntimeError) as ctx: - util.run_unmount_cmd(['fusermount', '-u', '/path'], path='/path', max_retries=3, logger=logger) - cmd = ['fusermount', '-u', '/path'] - expected = [mock.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, - universal_newlines=True), - mock.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, - universal_newlines=True), - mock.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, - universal_newlines=True), - mock.call(['ls', '-lA', '/path'], - stderr=subprocess.STDOUT, stdout=subprocess.PIPE, - universal_newlines=True), - mock.call(['fuser', '-vm', '/path'], - stderr=subprocess.STDOUT, stdout=subprocess.PIPE, - universal_newlines=True), - mock.call(['lsof', '+D', '/path'], - stderr=subprocess.STDOUT, stdout=subprocess.PIPE, - universal_newlines=True)] + util.run_unmount_cmd( + ["fusermount", "-u", "/path"], + path="/path", + max_retries=3, + logger=logger, + ) + cmd = ["fusermount", "-u", "/path"] + expected = [ + mock.call( + cmd, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True, + ), + mock.call( + cmd, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True, + ), + mock.call( + cmd, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True, + ), + mock.call( + ["ls", "-lA", "/path"], + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + universal_newlines=True, + ), + mock.call( + ["fuser", "-vm", "/path"], + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + universal_newlines=True, + ), + mock.call( + ["lsof", "+D", "/path"], + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + universal_newlines=True, + ), + ] self.assertEqual(mockPopen.call_args_list, expected) - self.assertEqual(mock_sleep.call_args_list, - [mock.call(0), mock.call(1), mock.call(2)]) - self.assertEqual(str(ctx.exception), - "Failed to run ['fusermount', '-u', '/path']: Device or resource busy.") - self.assertEqual(logger.mock_calls, - [mock.call.debug('`%s` exited with %s and following output:\n%s', - 'ls -lA /path', 0, 'list of files'), - mock.call.debug('`%s` exited with %s and following output:\n%s', - 'fuser -vm /path', 0, 'It is very busy'), - mock.call.debug('`%s` exited with %s and following output:\n%s', - 'lsof +D /path', 1, 'lsof output')]) + self.assertEqual( + mock_sleep.call_args_list, [mock.call(0), mock.call(1), mock.call(2)] + ) + self.assertEqual( + str(ctx.exception), + "Failed to run ['fusermount', '-u', '/path']: Device or resource busy.", + ) + self.assertEqual( + logger.mock_calls, + [ + mock.call.debug( + "`%s` exited with %s and following output:\n%s", + "ls -lA /path", + 0, + "list of files", + ), + mock.call.debug( + "`%s` exited with %s and following output:\n%s", + "fuser -vm /path", + 0, + "It is very busy", + ), + mock.call.debug( + "`%s` exited with %s and following output:\n%s", + "lsof +D /path", + 1, + "lsof output", + ), + ], + ) class TranslatePathTestCase(unittest.TestCase): def test_does_nothing_without_config(self): - compose = mock.Mock(conf={'translate_paths': []}) - ret = util.translate_path(compose, '/mnt/koji/compose/rawhide/XYZ') - self.assertEqual(ret, '/mnt/koji/compose/rawhide/XYZ') + compose = mock.Mock(conf={"translate_paths": []}) + ret = util.translate_path(compose, "/mnt/koji/compose/rawhide/XYZ") + self.assertEqual(ret, "/mnt/koji/compose/rawhide/XYZ") def test_translates_prefix(self): - compose = mock.Mock(conf={ - 'translate_paths': [('/mnt/koji', 'http://example.com')] - }) - ret = util.translate_path(compose, '/mnt/koji/compose/rawhide/XYZ') - self.assertEqual(ret, 'http://example.com/compose/rawhide/XYZ') + compose = mock.Mock( + conf={"translate_paths": [("/mnt/koji", "http://example.com")]} + ) + ret = util.translate_path(compose, "/mnt/koji/compose/rawhide/XYZ") + self.assertEqual(ret, "http://example.com/compose/rawhide/XYZ") def test_does_not_translate_not_matching(self): - compose = mock.Mock(conf={ - 'translate_paths': [('/mnt/koji', 'http://example.com')] - }) - ret = util.translate_path(compose, '/mnt/fedora_koji/compose/rawhide/XYZ') - self.assertEqual(ret, '/mnt/fedora_koji/compose/rawhide/XYZ') + compose = mock.Mock( + conf={"translate_paths": [("/mnt/koji", "http://example.com")]} + ) + ret = util.translate_path(compose, "/mnt/fedora_koji/compose/rawhide/XYZ") + self.assertEqual(ret, "/mnt/fedora_koji/compose/rawhide/XYZ") class GetRepoFuncsTestCase(unittest.TestCase): - @mock.patch('pungi.compose.ComposeInfo') + @mock.patch("pungi.compose.ComposeInfo") def setUp(self, ci): self.tmp_dir = tempfile.mkdtemp() - conf = { - 'translate_paths': [(self.tmp_dir, 'http://example.com')] - } + conf = {"translate_paths": [(self.tmp_dir, "http://example.com")]} ci.return_value.compose.respin = 0 - ci.return_value.compose.id = 'RHEL-8.0-20180101.n.0' - ci.return_value.compose.date = '20160101' - ci.return_value.compose.type = 'nightly' - ci.return_value.compose.type_suffix = '.n' - ci.return_value.compose.label = 'RC-1.0' - ci.return_value.compose.label_major_version = '1' + ci.return_value.compose.id = "RHEL-8.0-20180101.n.0" + ci.return_value.compose.date = "20160101" + ci.return_value.compose.type = "nightly" + ci.return_value.compose.type_suffix = ".n" + ci.return_value.compose.label = "RC-1.0" + ci.return_value.compose.label_major_version = "1" compose_dir = os.path.join(self.tmp_dir, ci.return_value.compose.id) self.compose = compose.Compose(conf, compose_dir) - server_variant = mock.Mock(uid='Server', type='variant') - client_variant = mock.Mock(uid='Client', type='variant') + server_variant = mock.Mock(uid="Server", type="variant") + client_variant = mock.Mock(uid="Client", type="variant") self.compose.all_variants = { - 'Server': server_variant, - 'Client': client_variant, + "Server": server_variant, + "Client": client_variant, } def tearDown(self): shutil.rmtree(self.tmp_dir) def test_get_repo_url_from_normal_url(self): - url = util.get_repo_url(self.compose, 'http://example.com/repo') - self.assertEqual(url, 'http://example.com/repo') + url = util.get_repo_url(self.compose, "http://example.com/repo") + self.assertEqual(url, "http://example.com/repo") def test_get_repo_url_from_path(self): url = util.get_repo_url(self.compose, os.path.join(self.tmp_dir, "repo")) self.assertEqual(url, "http://example.com/repo") def test_get_repo_url_from_variant_uid(self): - url = util.get_repo_url(self.compose, 'Server') - self.assertEqual(url, 'http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os') + url = util.get_repo_url(self.compose, "Server") + self.assertEqual( + url, "http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os" + ) def test_get_repo_url_from_repo_dict(self): - repo = {'baseurl': 'http://example.com/repo'} + repo = {"baseurl": "http://example.com/repo"} url = util.get_repo_url(self.compose, repo) - self.assertEqual(url, 'http://example.com/repo') + self.assertEqual(url, "http://example.com/repo") - repo = {'baseurl': 'Server'} + repo = {"baseurl": "Server"} url = util.get_repo_url(self.compose, repo) - self.assertEqual(url, 'http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os') + self.assertEqual( + url, "http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os" + ) def test_get_repo_urls(self): repos = [ - 'http://example.com/repo', - 'Server', - {'baseurl': 'Client'}, - {'baseurl': 'ftp://example.com/linux/repo'}, + "http://example.com/repo", + "Server", + {"baseurl": "Client"}, + {"baseurl": "ftp://example.com/linux/repo"}, ] expect = [ - 'http://example.com/repo', - 'http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os', - 'http://example.com/RHEL-8.0-20180101.n.0/compose/Client/$basearch/os', - 'ftp://example.com/linux/repo', + "http://example.com/repo", + "http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os", + "http://example.com/RHEL-8.0-20180101.n.0/compose/Client/$basearch/os", + "ftp://example.com/linux/repo", ] self.assertEqual(util.get_repo_urls(self.compose, repos), expect) def test_get_repo_dict_from_normal_url(self): - repo_dict = util.get_repo_dict('http://example.com/repo') - expect = {'name': 'http:__example.com_repo', 'baseurl': 'http://example.com/repo'} + repo_dict = util.get_repo_dict("http://example.com/repo") + expect = { + "name": "http:__example.com_repo", + "baseurl": "http://example.com/repo", + } self.assertEqual(repo_dict, expect) def test_get_repo_dict_from_variant_uid(self): - repo_dict = util.get_repo_dict('Server') # this repo format is deprecated + repo_dict = util.get_repo_dict("Server") # this repo format is deprecated expect = {} self.assertEqual(repo_dict, expect) def test_get_repo_dict_from_repo_dict(self): - repo = {'baseurl': 'Server'} # this repo format is deprecated + repo = {"baseurl": "Server"} # this repo format is deprecated expect = {} repo_dict = util.get_repo_dict(repo) self.assertEqual(repo_dict, expect) def test_get_repo_dicts(self): repos = [ - 'http://example.com/repo', - 'Server', # this repo format is deprecated (and will not be included into final repo_dict) - {'baseurl': 'Client'}, # this repo format is deprecated - {'baseurl': 'ftp://example.com/linux/repo'}, - {'name': 'testrepo', 'baseurl': 'ftp://example.com/linux/repo'}, + "http://example.com/repo", + "Server", # this repo format is deprecated (and will not be included into final repo_dict) + {"baseurl": "Client"}, # this repo format is deprecated + {"baseurl": "ftp://example.com/linux/repo"}, + {"name": "testrepo", "baseurl": "ftp://example.com/linux/repo"}, ] expect = [ - {'name': 'http:__example.com_repo', 'baseurl': 'http://example.com/repo'}, - {'name': 'ftp:__example.com_linux_repo', 'baseurl': 'ftp://example.com/linux/repo'}, - {'name': 'testrepo', 'baseurl': 'ftp://example.com/linux/repo'}, + {"name": "http:__example.com_repo", "baseurl": "http://example.com/repo"}, + { + "name": "ftp:__example.com_linux_repo", + "baseurl": "ftp://example.com/linux/repo", + }, + {"name": "testrepo", "baseurl": "ftp://example.com/linux/repo"}, ] repos = util.get_repo_dicts(repos) self.assertEqual(repos, expect) @@ -753,37 +889,40 @@ class TestVersionGenerator(unittest.TestCase): def setUp(self): ci = mock.MagicMock() ci.respin = 0 - ci.id = 'RHEL-8.0-20180101.0' - ci.release.version = '8' - ci.type = 'nightly' - ci.type_suffix = '' - ci.label = 'RC-1.0' - ci.label_major_version = '1' + ci.id = "RHEL-8.0-20180101.0" + ci.release.version = "8" + ci.type = "nightly" + ci.type_suffix = "" + ci.label = "RC-1.0" + ci.label_major_version = "1" self.compose = mock.MagicMock() self.compose.ci_base = ci self.compose.compose_respin = 0 - self.compose.compose_date = '20160101' + self.compose.compose_date = "20160101" def test_unknown_generator(self): compose = mock.Mock() with self.assertRaises(RuntimeError) as ctx: - util.version_generator(compose, '!GIMME_VERSION') + util.version_generator(compose, "!GIMME_VERSION") - self.assertEqual(str(ctx.exception), - "Unknown version generator '!GIMME_VERSION'") + self.assertEqual( + str(ctx.exception), "Unknown version generator '!GIMME_VERSION'" + ) def test_passthrough_value(self): compose = mock.Mock() - self.assertEqual(util.version_generator(compose, '1.2.3'), '1.2.3') + self.assertEqual(util.version_generator(compose, "1.2.3"), "1.2.3") def test_passthrough_none(self): compose = mock.Mock() self.assertEqual(util.version_generator(compose, None), None) def test_release_from_version_date_respin(self): - self.assertEqual(util.version_generator(self.compose, '!VERSION_FROM_VERSION_DATE_RESPIN'), - '8.20160101.0') + self.assertEqual( + util.version_generator(self.compose, "!VERSION_FROM_VERSION_DATE_RESPIN"), + "8.20160101.0", + ) def test_release_from_date_respin(self): self.assertEqual( @@ -793,50 +932,48 @@ class TestVersionGenerator(unittest.TestCase): def test_version_from_version(self): self.assertEqual( - util.version_generator(self.compose, "!VERSION_FROM_VERSION"), - "8", + util.version_generator(self.compose, "!VERSION_FROM_VERSION"), "8", ) class TestTZOffset(unittest.TestCase): - @mock.patch('time.daylight', new=False) - @mock.patch('time.altzone', new=7200) - @mock.patch('time.timezone', new=3600) - @mock.patch('time.localtime', new=lambda: mock.Mock(tm_isdst=0)) + @mock.patch("time.daylight", new=False) + @mock.patch("time.altzone", new=7200) + @mock.patch("time.timezone", new=3600) + @mock.patch("time.localtime", new=lambda: mock.Mock(tm_isdst=0)) def test_zone_without_dst(self): self.assertEqual(util.get_tz_offset(), "-01:00") - @mock.patch('time.daylight', new=True) - @mock.patch('time.altzone', new=7200) - @mock.patch('time.timezone', new=3600) - @mock.patch('time.localtime', new=lambda: mock.Mock(tm_isdst=0)) + @mock.patch("time.daylight", new=True) + @mock.patch("time.altzone", new=7200) + @mock.patch("time.timezone", new=3600) + @mock.patch("time.localtime", new=lambda: mock.Mock(tm_isdst=0)) def test_with_active_dst(self): self.assertEqual(util.get_tz_offset(), "-01:00") - @mock.patch('time.daylight', new=True) - @mock.patch('time.altzone', new=-9000) - @mock.patch('time.timezone', new=-3600) - @mock.patch('time.localtime', new=lambda: mock.Mock(tm_isdst=1)) + @mock.patch("time.daylight", new=True) + @mock.patch("time.altzone", new=-9000) + @mock.patch("time.timezone", new=-3600) + @mock.patch("time.localtime", new=lambda: mock.Mock(tm_isdst=1)) def test_with_inactive_dst(self): self.assertEqual(util.get_tz_offset(), "+02:30") - @mock.patch('time.daylight', new=False) - @mock.patch('time.altzone', new=0) - @mock.patch('time.timezone', new=0) - @mock.patch('time.localtime', new=lambda: mock.Mock(tm_isdst=0)) + @mock.patch("time.daylight", new=False) + @mock.patch("time.altzone", new=0) + @mock.patch("time.timezone", new=0) + @mock.patch("time.localtime", new=lambda: mock.Mock(tm_isdst=0)) def test_utc(self): self.assertEqual(util.get_tz_offset(), "+00:00") class TestParseKojiEvent(PungiTestCase): - def test_number(self): self.assertEqual(util.parse_koji_event("1234"), 1234) def test_correct_path(self): touch( - os.path.join(self.topdir, 'work/global/koji-event'), - '{"id": 19769058, "ts": 1527641311.22855}' + os.path.join(self.topdir, "work/global/koji-event"), + '{"id": 19769058, "ts": 1527641311.22855}', ) self.assertEqual(util.parse_koji_event(self.topdir), 19769058) @@ -847,7 +984,6 @@ class TestParseKojiEvent(PungiTestCase): class TestCopyAll(PungiTestCase): - def setUp(self): super(TestCopyAll, self).setUp() self.src = os.path.join(self.topdir, "src") diff --git a/tox.ini b/tox.ini index c475542d..c3eff203 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,8 @@ filename = *.py # H306: imports not in alphabetical order # E226: missing whitespace around arithmetic operator # W503: line break occured before a binary operator -ignore = E501,E402,H301,H306,E226,W503 +# E203: whitespace before ':' +ignore = E501,E402,H301,H306,E226,W503,E203 [run] omit = tests/*