From 36c347eb796fd9414ebac10838b044164401cfde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 13 Sep 2018 15:50:22 +0200 Subject: [PATCH] ostree: Use --touch-if-changed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are three different cases: * we expect commitid and it's there * we expect commitid and it's missing * we don't expect commitid This patch helps differentiate between the second two. In former one we should report an error and mark the phase as failed. The latter is perfectly fine and no error should be reported Fixes: https://pagure.io/pungi/issue/1046 Signed-off-by: Lubomír Sedlář --- pungi/ostree/tree.py | 13 +++++++++++-- pungi/ostree/utils.py | 15 ++++++--------- pungi/phases/ostree.py | 10 +++++++--- tests/test_ostree_phase.py | 1 + tests/test_ostree_script.py | 5 +++++ 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/pungi/ostree/tree.py b/pungi/ostree/tree.py index fceca6f0..f2d2942d 100644 --- a/pungi/ostree/tree.py +++ b/pungi/ostree/tree.py @@ -28,8 +28,17 @@ class Tree(OSTree): def _make_tree(self): """Compose OSTree tree""" log_file = make_log_file(self.logdir, 'create-ostree-repo') - cmd = ['rpm-ostree', 'compose', 'tree', '--repo=%s' % self.repo, - '--write-commitid-to=%s' % self.commitid_file] + cmd = [ + "rpm-ostree", + "compose", + "tree", + "--repo=%s" % self.repo, + "--write-commitid-to=%s" % self.commitid_file, + # Touch the file if a new commit was created. This can help us tell + # if the commitid file is missing because no commit was created or + # because something went wrong. + "--touch-if-changed=%s.stamp" % self.commitid_file, + ] if self.version: # Add versioning metadata cmd.append('--add-metadata-string=version=%s' % self.version) diff --git a/pungi/ostree/utils.py b/pungi/ostree/utils.py index d76422b0..06494dfa 100644 --- a/pungi/ostree/utils.py +++ b/pungi/ostree/utils.py @@ -56,16 +56,13 @@ def get_ref_from_treefile(treefile, arch=None, logger=None): return ref -def get_commitid_from_commitid_file(commitid_file, logger=None): +def get_commitid_from_commitid_file(commitid_file): """Return commit id which is read from the commitid file""" - logger = logger or logging.getLogger(__name__) - commitid = None - if os.path.isfile(commitid_file): - with open(commitid_file, 'r') as f: - commitid = f.read().replace('\n', '') - else: - logger.error('Unable to find commitid file') - return commitid + if not os.path.exists(commitid_file + ".stamp"): + # The stamp does not exist, so no new commit. + return None + with open(commitid_file, 'r') as f: + return f.read().replace('\n', '') def tweak_treeconf(treeconf, source_repos=None, keep_original_sources=False, update_dict=None): diff --git a/pungi/phases/ostree.py b/pungi/phases/ostree.py index 2918fff8..ae8505ac 100644 --- a/pungi/phases/ostree.py +++ b/pungi/phases/ostree.py @@ -95,9 +95,13 @@ class OSTreeThread(WorkerThread): if compose.notifier: ref = get_ref_from_treefile(os.path.join(repodir, config['treefile']), arch, logger=self.pool._logger) - # 'pungi-make-ostree tree' writes commitid to commitid.log in logdir - commitid = get_commitid_from_commitid_file(os.path.join(self.logdir, 'commitid.log'), - logger=self.pool._logger) + # 'pungi-make-ostree tree' writes commitid to commitid.log in + # logdir, except if there was no new commit we will get None + # instead. If the commit id could not be read, an exception will be + # raised. + commitid = get_commitid_from_commitid_file( + os.path.join(self.logdir, 'commitid.log') + ) compose.notifier.send('ostree', variant=variant.uid, arch=arch, diff --git a/tests/test_ostree_phase.py b/tests/test_ostree_phase.py index c2986bc8..9bce3dad 100644 --- a/tests/test_ostree_phase.py +++ b/tests/test_ostree_phase.py @@ -145,6 +145,7 @@ class OSTreeThreadTest(helpers.PungiTestCase): for filename in writefiles: 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 fake_runroot diff --git a/tests/test_ostree_script.py b/tests/test_ostree_script.py index ce211c3e..7e066bae 100644 --- a/tests/test_ostree_script.py +++ b/tests/test_ostree_script.py @@ -48,6 +48,7 @@ class OstreeTreeScriptTest(helpers.PungiTestCase): run.call_args_list, [mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, '--write-commitid-to=%s' % (self.topdir + '/logs/Atomic/commitid.log'), + '--touch-if-changed=%s.stamp' % (self.topdir + '/logs/Atomic/commitid.log'), self.topdir + '/fedora-atomic-docker-host.json'], logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)]) @@ -90,6 +91,7 @@ class OstreeTreeScriptTest(helpers.PungiTestCase): run.call_args_list, [mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, '--write-commitid-to=%s' % (self.topdir + '/logs/Atomic/commitid.log'), + '--touch-if-changed=%s.stamp' % (self.topdir + '/logs/Atomic/commitid.log'), self.topdir + '/fedora-atomic-docker-host.json'], logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)]) @@ -110,6 +112,7 @@ class OstreeTreeScriptTest(helpers.PungiTestCase): run.call_args_list, [mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, '--write-commitid-to=%s' % (self.topdir + '/logs/Atomic/commitid.log'), + '--touch-if-changed=%s.stamp' % (self.topdir + '/logs/Atomic/commitid.log'), self.topdir + '/fedora-atomic-docker-host.json'], logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True), mock.call(['ostree', 'summary', '-u', '--repo=%s' % repo], @@ -132,6 +135,7 @@ class OstreeTreeScriptTest(helpers.PungiTestCase): run.call_args_list, [mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, '--write-commitid-to=%s' % (self.topdir + '/logs/Atomic/commitid.log'), + '--touch-if-changed=%s.stamp' % (self.topdir + '/logs/Atomic/commitid.log'), '--add-metadata-string=version=24', self.topdir + '/fedora-atomic-docker-host.json'], logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)]) @@ -219,6 +223,7 @@ class OstreeTreeScriptTest(helpers.PungiTestCase): run.call_args_list, [mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, '--write-commitid-to=%s' % (self.topdir + '/logs/Atomic/commitid.log'), + '--touch-if-changed=%s.stamp' % (self.topdir + '/logs/Atomic/commitid.log'), '--force-nocache', self.topdir + '/fedora-atomic-docker-host.json'], logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)])