Remove debug mode

This was already discouraged to not be used, and is a bad idea in
current setup anyway. Removing this can simplify the code.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-07-24 13:36:23 +02:00
parent 0891bfbe59
commit 6efaae19fd
13 changed files with 156 additions and 345 deletions

View File

@ -76,12 +76,6 @@ def main():
action="append",
help="Path to directory with old composes. Reuse an existing repodata from the most recent compose.",
)
parser.add_argument(
"--debug-mode",
action="store_true",
default=False,
help="run pungi in DEBUG mode (DANGEROUS!)",
)
parser.add_argument(
"--config",
help="Config file",
@ -252,7 +246,6 @@ def main():
compose = Compose(conf,
topdir=compose_dir,
debug=opts.debug_mode,
skip_phases=opts.skip_phase,
just_phases=opts.just_phase,
old_composes=opts.old_composes,

View File

@ -106,7 +106,7 @@ def get_compose_dir(topdir, conf, compose_type="production", compose_date=None,
class Compose(kobo.log.LoggingBase):
def __init__(self, conf, topdir, debug=False, skip_phases=None, just_phases=None, old_composes=None, koji_event=None, supported=False, logger=None, notifier=None):
def __init__(self, conf, topdir, skip_phases=None, just_phases=None, old_composes=None, koji_event=None, supported=False, logger=None, notifier=None):
kobo.log.LoggingBase.__init__(self, logger)
# TODO: check if minimal conf values are set
self.conf = conf
@ -122,9 +122,6 @@ class Compose(kobo.log.LoggingBase):
self.koji_event = koji_event or conf.get("koji_event")
self.notifier = notifier
# intentionally upper-case (visible in the code)
self.DEBUG = debug
# path definitions
self.paths = Paths(self)
@ -142,17 +139,6 @@ class Compose(kobo.log.LoggingBase):
self.supported = True
self.im = Images()
if self.DEBUG:
try:
self.im.load(self.paths.compose.metadata("images.json"))
except RuntimeError:
pass
# images.json doesn't exists
except IOError:
pass
# images.json is not a valid json file, for example, it's an empty file
except ValueError:
pass
self.im.compose.id = self.compose_id
self.im.compose.type = self.compose_type
self.im.compose.date = self.compose_date
@ -235,14 +221,13 @@ class Compose(kobo.log.LoggingBase):
variants_file = self.paths.work.variants_file(arch="global")
msg = "Writing variants file: %s" % variants_file
if self.DEBUG and os.path.isfile(variants_file):
self.log_warning("[SKIP ] %s" % msg)
else:
scm_dict = self.conf["variants_file"]
if isinstance(scm_dict, dict):
file_name = os.path.basename(scm_dict["file"])
if scm_dict["scm"] == "file":
scm_dict["file"] = os.path.join(self.config_dir, os.path.basename(scm_dict["file"]))
scm_dict["file"] = os.path.join(
self.config_dir, os.path.basename(scm_dict["file"])
)
else:
file_name = os.path.basename(scm_dict)
scm_dict = os.path.join(self.config_dir, os.path.basename(scm_dict))

View File

@ -122,10 +122,6 @@ def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None)
return
createrepo_dirs.add(repo_dir)
if compose.DEBUG and os.path.isdir(os.path.join(repo_dir, "repodata")):
compose.log_warning("[SKIP ] %s" % msg)
return
compose.log_info("[BEGIN] %s" % msg)
# We only want delta RPMs for binary repos.

View File

@ -91,11 +91,6 @@ class GatherPhase(PhaseBase):
raise ValueError('\n'.join(errors))
def _write_manifest(self):
if self.compose.DEBUG and os.path.isfile(self.manifest_file):
self.compose.log_info(
"Skipping writing RPM manifest, already exists: %s" % self.manifest_file
)
else:
self.compose.log_info("Writing RPM manifest: %s" % self.manifest_file)
self.manifest.dump(self.manifest_file)
@ -517,9 +512,6 @@ def write_prepopulate_file(compose):
prepopulate_file = os.path.join(compose.paths.work.topdir(arch="global"), "prepopulate.json")
msg = "Writing prepopulate file: %s" % prepopulate_file
if compose.DEBUG and os.path.isfile(prepopulate_file):
compose.log_warning("[SKIP ] %s" % msg)
else:
scm_dict = compose.conf["gather_prepopulate"]
if isinstance(scm_dict, dict):
file_name = os.path.basename(scm_dict["file"])

View File

@ -89,10 +89,6 @@ def write_pungi_config(compose, arch, variant, packages, groups, filter_packages
pungi_cfg = compose.paths.work.pungi_conf(variant=variant, arch=arch, source_name=source_name)
msg = "Writing pungi config (arch: %s, variant: %s): %s" % (arch, variant, pungi_cfg)
if compose.DEBUG and os.path.isfile(pungi_cfg):
compose.log_warning("[SKIP ] %s" % msg)
return
compose.log_info(msg)
repos = {
@ -160,11 +156,6 @@ def resolve_deps(compose, arch, variant, source_name=None):
pungi_log = compose.paths.work.pungi_log(arch, variant, source_name=source_name)
msg = "Running pungi (arch: %s, variant: %s)" % (arch, variant)
if compose.DEBUG and os.path.exists(pungi_log):
compose.log_warning("[SKIP ] %s" % msg)
with open(pungi_log, "r") as f:
res, broken_deps, _ = pungi_wrapper.parse_log(f)
return res, broken_deps
compose.log_info("[BEGIN] %s" % msg)
pungi_conf = compose.paths.work.pungi_conf(arch, variant, source_name=source_name)

View File

@ -90,9 +90,6 @@ def write_global_comps(compose):
comps_file_global = compose.paths.work.comps(arch="global")
msg = "Writing global comps file: %s" % comps_file_global
if compose.DEBUG and os.path.isfile(comps_file_global):
compose.log_warning("[SKIP ] %s" % msg)
else:
scm_dict = compose.conf["comps_file"]
if isinstance(scm_dict, dict):
comps_name = os.path.basename(scm_dict["file"])
@ -115,10 +112,6 @@ def write_arch_comps(compose, arch):
comps_file_arch = compose.paths.work.comps(arch=arch)
msg = "Writing comps file for arch '%s': %s" % (arch, comps_file_arch)
if compose.DEBUG and os.path.isfile(comps_file_arch):
compose.log_warning("[SKIP ] %s" % msg)
return
compose.log_debug(msg)
run(["comps_filter", "--arch=%s" % arch, "--no-cleanup",
"--output=%s" % comps_file_arch,
@ -145,17 +138,6 @@ def write_variant_comps(compose, arch, variant):
comps_file = compose.paths.work.comps(arch=arch, variant=variant)
msg = "Writing comps file (arch: %s, variant: %s): %s" % (arch, variant, comps_file)
if compose.DEBUG and os.path.isfile(comps_file):
# read display_order and groups for environments (needed for live images)
comps = CompsWrapper(comps_file)
# groups = variant.groups
comps.filter_groups(variant.groups)
if compose.conf["comps_filter_environments"]:
comps.filter_environments(variant.environments)
compose.log_warning("[SKIP ] %s" % msg)
return
compose.log_debug(msg)
cmd = [
"comps_filter",
@ -194,16 +176,16 @@ def create_comps_repo(compose, arch, variant):
comps_repo = compose.paths.work.comps_repo(arch=arch, variant=variant)
comps_path = compose.paths.work.comps(arch=arch, variant=variant)
msg = "Creating comps repo for arch '%s' variant '%s'" % (arch, variant.uid if variant else None)
if compose.DEBUG and os.path.isdir(os.path.join(comps_repo, "repodata")):
compose.log_warning("[SKIP ] %s" % msg)
else:
compose.log_info("[BEGIN] %s" % msg)
cmd = repo.get_createrepo_cmd(comps_repo, database=False,
outputdir=comps_repo, groupfile=comps_path,
checksum=createrepo_checksum)
logfile = 'comps_repo-%s' % variant if variant else 'comps_repo'
run(cmd, logfile=compose.paths.log.log_file(arch, logfile),
show_cmd=True)
cmd = repo.get_createrepo_cmd(
comps_repo, database=False,
outputdir=comps_repo,
groupfile=comps_path,
checksum=createrepo_checksum,
)
logfile = "comps_repo-%s" % variant if variant else "comps_repo"
run(cmd, logfile=compose.paths.log.log_file(arch, logfile), show_cmd=True)
compose.log_info("[DONE ] %s" % msg)

View File

@ -48,10 +48,6 @@ def get_create_global_repo_cmd(compose, path_prefix):
repo = CreaterepoWrapper(createrepo_c=createrepo_c)
repo_dir_global = compose.paths.work.arch_repo(arch="global")
if compose.DEBUG and os.path.isdir(os.path.join(repo_dir_global, "repodata")):
compose.log_warning("[SKIP ] Running createrepo for the global package set")
return
# find an old compose suitable for repodata reuse
old_compose_path = None
update_md_path = None
@ -108,10 +104,6 @@ def _create_arch_repo(worker_thread, args, task_num):
repo_dir = compose.paths.work.arch_repo(arch=arch)
msg = "Running createrepo for arch '%s'" % arch
if compose.DEBUG and os.path.isdir(os.path.join(repo_dir, "repodata")):
compose.log_warning("[SKIP ] %s" % msg)
return
compose.log_info("[BEGIN] %s" % msg)
cmd = repo.get_createrepo_cmd(path_prefix, update=True, database=False, skip_stat=True,
pkglist=compose.paths.work.package_list(arch=arch), outputdir=repo_dir,

View File

@ -600,14 +600,7 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event):
inherit = compose.conf["pkgset_koji_inherit"]
inherit_modules = compose.conf["pkgset_koji_inherit_modules"]
global_pkgset_path = os.path.join(
compose.paths.work.topdir(arch="global"), "pkgset_global.pickle")
if compose.DEBUG and os.path.isfile(global_pkgset_path):
msg = "Populating the global package set from tag '%s'" % compose_tags
compose.log_warning("[SKIP ] %s" % msg)
with open(global_pkgset_path, "rb") as f:
global_pkgset = pickle.load(f)
else:
global_pkgset = pungi.phases.pkgset.pkgsets.KojiPackageSet(
koji_wrapper, compose.conf["sigkeys"], logger=compose._logger,
arches=all_arches)
@ -625,8 +618,9 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event):
# list. Also prepare per-variant pkgset, because we do not have list
# of binary RPMs in module definition - there is just list of SRPMs.
for compose_tag in compose_tags:
compose.log_info("Populating the global package set from tag "
"'%s'" % compose_tag)
compose.log_info(
"Populating the global package set from tag '%s'" % compose_tag
)
if compose_tag in pkgset_koji_tags:
extra_builds = force_list(compose.conf.get("pkgset_koji_builds", []))
else:
@ -644,8 +638,9 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event):
# name is included in filename, so any slashes in it are replaced
# with underscores just to be safe.
logfile = compose.paths.log.log_file(
None, 'packages_from_%s' % compose_tag.replace('/', '_'))
is_traditional = compose_tag in compose.conf.get('pkgset_koji_tag', [])
None, "packages_from_%s" % compose_tag.replace("/", "_")
)
is_traditional = compose_tag in compose.conf.get("pkgset_koji_tag", [])
should_inherit = inherit if is_traditional else inherit_modules
# If we're processing a modular tag, we have an exact list of
@ -695,7 +690,11 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event):
global_pkgset = pkgset
else:
global_pkgset.fast_merge(pkgset)
with open(global_pkgset_path, 'wb') as f:
global_pkgset_path = os.path.join(
compose.paths.work.topdir(arch="global"), "pkgset_global.pickle"
)
with open(global_pkgset_path, "wb") as f:
data = pickle.dumps(global_pkgset, protocol=pickle.HIGHEST_PROTOCOL)
f.write(data)
@ -711,10 +710,6 @@ def get_koji_event_info(compose, koji_wrapper):
event_file = os.path.join(compose.paths.work.topdir(arch="global"), "koji-event")
msg = "Getting koji event"
if compose.DEBUG and os.path.exists(event_file):
compose.log_warning("[SKIP ] %s" % msg)
result = json.load(open(event_file, "r"))
else:
result = get_koji_event_raw(koji_wrapper, compose.koji_event, event_file)
if compose.koji_event:
compose.log_info("Setting koji event to a custom value: %s" % compose.koji_event)

View File

@ -140,13 +140,11 @@ def populate_global_pkgset(compose, file_list, path_prefix):
msg = "Populating the global package set from a file list"
global_pkgset_path = os.path.join(compose.paths.work.topdir(arch="global"), "packages.pickle")
if compose.DEBUG and os.path.isfile(global_pkgset_path):
compose.log_warning("[SKIP ] %s" % msg)
with open(global_pkgset_path, "rb") as f:
pkgset = pickle.load(f)
else:
compose.log_info(msg)
pkgset = pungi.phases.pkgset.pkgsets.FilelistPackageSet(compose.conf["sigkeys"], logger=compose._logger, arches=ALL_ARCHES)
pkgset = pungi.phases.pkgset.pkgsets.FilelistPackageSet(
compose.conf["sigkeys"], logger=compose._logger, arches=ALL_ARCHES
)
pkgset.populate(file_list)
with open(global_pkgset_path, "wb") as f:
pickle.dump(pkgset, f, protocol=pickle.HIGHEST_PROTOCOL)
@ -162,10 +160,6 @@ def write_pungi_config(compose, arch, variant, repos=None, comps_repo=None, pack
pungi_cfg = compose.paths.work.pungi_conf(variant=variant, arch=arch)
msg = "Writing pungi config (arch: %s, variant: %s): %s" % (arch, variant, pungi_cfg)
if compose.DEBUG and os.path.isfile(pungi_cfg):
compose.log_warning("[SKIP ] %s" % msg)
return
compose.log_info(msg)
packages, grps = get_packages_to_gather(compose, arch, variant)

View File

@ -175,8 +175,6 @@ class DummyCompose(object):
self.should_create_yum_database = True
self.cache_region = None
self.DEBUG = False
def setup_optional(self):
self.all_variants['Server-optional'] = MockVariant(
uid='Server-optional', arches=['x86_64'], type='optional')

View File

@ -861,26 +861,6 @@ class TestGatherPhase(helpers.PungiTestCase):
self.assertEqual(gather_wrapper.call_args_list, [])
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')
def test_does_not_write_in_debug_mode(self, gather_wrapper, link_files):
pkgset_phase = mock.Mock()
compose = helpers.DummyCompose(self.topdir, {})
compose.notifier = mock.Mock()
compose.DEBUG = True
rpms_file = helpers.touch(
os.path.join(self.topdir, 'compose', 'metadata', 'rpms.json'), "hello"
)
phase = gather.GatherPhase(compose, pkgset_phase)
phase.stop()
self.assertEqual(gather_wrapper.call_args_list, [])
self.assertTrue(os.path.isfile(rpms_file))
with open(rpms_file) as fh:
self.assertEqual(fh.read(), "hello")
def test_validates_wrong_requiring_variant(self):
pkgset_phase = mock.Mock()
compose = helpers.DummyCompose(

View File

@ -185,16 +185,6 @@ class TestWriteArchComps(PungiTestCase):
'--output=%s/work/x86_64/comps/comps-x86_64.xml' % self.topdir,
self.topdir + '/work/global/comps/comps-global.xml'])])
@mock.patch('pungi.phases.init.run')
def test_run_in_debug(self, run):
compose = DummyCompose(self.topdir, {})
compose.DEBUG = True
touch(self.topdir + '/work/x86_64/comps/comps-x86_64.xml')
init.write_arch_comps(compose, 'x86_64')
self.assertEqual(run.mock_calls, [])
class TestCreateCompsRepo(PungiTestCase):
@ -232,33 +222,9 @@ class TestCreateCompsRepo(PungiTestCase):
logfile=self.topdir + '/logs/x86_64/comps_repo-Server.x86_64.log',
show_cmd=True)])
@mock.patch('pungi.phases.init.run')
def test_run_in_debug(self, run):
compose = DummyCompose(self.topdir, {
'createrepo_checksum': 'sha256',
})
compose.DEBUG = True
os.makedirs(self.topdir + '/work/x86_64/comps_repo/repodata')
init.create_comps_repo(compose, 'x86_64', None)
self.assertEqual(run.mock_calls, [])
class TestWriteGlobalComps(PungiTestCase):
@mock.patch('shutil.copy2')
@mock.patch('pungi.phases.init.get_file_from_scm')
def test_run_in_debug(self, get_file, copy2):
compose = DummyCompose(self.topdir, {'comps_file': 'some-file.xml'})
compose.DEBUG = True
touch(self.topdir + '/work/global/comps/comps-global.xml')
init.write_global_comps(compose)
self.assertEqual(get_file.mock_calls, [])
self.assertEqual(copy2.mock_calls, [])
@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'})
@ -417,25 +383,6 @@ class TestWriteVariantComps(PungiTestCase):
[mock.call(init.UNMATCHED_GROUP_MSG % ('Server', 'x86_64', 'foo')),
mock.call(init.UNMATCHED_GROUP_MSG % ('Server', 'x86_64', 'bar'))])
@mock.patch('pungi.phases.init.run')
@mock.patch('pungi.phases.init.CompsWrapper')
def test_run_in_debug(self, CompsWrapper, run):
compose = DummyCompose(self.topdir, {})
compose.DEBUG = True
variant = compose.variants['Server']
touch(self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')
init.write_variant_comps(compose, 'x86_64', variant)
self.assertEqual(run.mock_calls, [])
self.assertEqual(CompsWrapper.call_args_list,
[mock.call(self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')])
comps = CompsWrapper.return_value
self.assertEqual(comps.filter_groups.mock_calls, [mock.call(variant.groups)])
self.assertEqual(comps.filter_environments.mock_calls,
[mock.call(variant.environments)])
self.assertEqual(comps.write_comps.mock_calls, [])
class TestGetLookasideGroups(PungiTestCase):
def test_toplevel_variant(self):

View File

@ -72,19 +72,6 @@ class TestGetKojiEvent(helpers.PungiTestCase):
with open(self.event_file) as f:
self.assertEqual(json.load(f), EVENT_INFO)
def test_gets_last_event_in_debug_mode(self):
self.compose.DEBUG = True
self.compose.koji_event = None
koji_wrapper = mock.Mock()
helpers.touch(self.event_file, json.dumps(EVENT_INFO))
event = source_koji.get_koji_event_info(self.compose, koji_wrapper)
self.assertEqual(event, EVENT_INFO)
self.assertItemsEqual(koji_wrapper.mock_calls, [])
with open(self.event_file) as f:
self.assertEqual(json.load(f), EVENT_INFO)
class TestPopulateGlobalPkgset(helpers.PungiTestCase):
def setUp(self):
@ -180,27 +167,6 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase):
with open(self.pkgset_path) as f:
self.assertEqual(f.read(), 'DATA')
@mock.patch('six.moves.cPickle.load')
def test_populate_in_debug_mode(self, pickle_load):
helpers.touch(self.pkgset_path, 'DATA')
self.compose.DEBUG = True
pickle_load.return_value
with mock.patch('pungi.phases.pkgset.sources.source_koji.open',
mock.mock_open(), create=True) as m:
pkgset = source_koji.populate_global_pkgset(
self.compose, self.koji_wrapper, '/prefix', 123456)
self.assertEqual(pickle_load.call_args_list,
[mock.call(m.return_value)])
self.assertIs(pkgset, pickle_load.return_value)
self.assertEqual(
pkgset.mock_calls,
[mock.call.save_file_list(self.topdir + '/work/global/package_list/global.conf',
remove_path_prefix='/prefix'),
mock.call.save_file_cache(self.topdir + '/work/global/pkgset_file_cache.pickle')])
@mock.patch('six.moves.cPickle.dumps')
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet.populate')
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet.save_file_list')