From 06ba3b8551e8cae30d82172e1753295a7b2f0907 Mon Sep 17 00:00:00 2001 From: Qixiang Wan Date: Thu, 3 Nov 2016 20:59:00 +0800 Subject: [PATCH] [ostree] New option to enable generating ostree summary file Added new option '--update-summary' to pungi-make-ostree, and this can be enabled in ostree settings with 'update_summary'. A summary file will be generated (or re-generated if it was presented in an existing ostree repo) when it is enabled. Signed-off-by: Qixiang Wan --- doc/configuration.rst | 5 ++++- pungi/checks.py | 1 + pungi/ostree.py | 10 ++++++++++ pungi/phases/ostree.py | 7 ++++++- tests/test_ostree_phase.py | 38 +++++++++++++++++++++++++++++++++++++ tests/test_ostree_script.py | 23 ++++++++++++++++++++++ 6 files changed, 82 insertions(+), 2 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index cfb29385..5021b74d 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1088,6 +1088,8 @@ runroot environment. ``master``. * ``failable`` -- (*[str]*) List of architectures for which this deliverable is not release blocking. + * ``update_summary`` -- (*bool*) Update summary metadata after tree composing. + Defaults to ``False``. Example config @@ -1100,7 +1102,8 @@ Example config "treefile": "fedora-atomic-docker-host.json", "config_url": "https://git.fedorahosted.org/git/fedora-atomic.git", "source_repo_from": "Everything", - "ostree_repo": "/mnt/koji/compose/atomic/Rawhide/" + "ostree_repo": "/mnt/koji/compose/atomic/Rawhide/", + "update_summary": True } }) ] diff --git a/pungi/checks.py b/pungi/checks.py index 798a8fbd..bf0aa90c 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -677,6 +677,7 @@ def _make_schema(): "source_repo_from": {"type": "string"}, "ostree_repo": {"type": "string"}, "failable": {"$ref": "#/definitions/list_of_strings"}, + "update_summary": {"type": "boolean"}, "config_branch": {"type": "string"}, "tag_ref": {"type": "boolean"}, }, diff --git a/pungi/ostree.py b/pungi/ostree.py index 1d43aa89..a04f6f8c 100644 --- a/pungi/ostree.py +++ b/pungi/ostree.py @@ -45,9 +45,17 @@ def make_ostree_repo(repo, config, log_dir=None): show_cmd=True, stdout=True, logfile=log_file) +def update_ostree_summary(repo, log_dir=None): + log_file = make_log_file(log_dir, 'ostree-summary') + shortcuts.run(['ostree', 'summary', '-u', '--repo=%s' % repo], + show_cmd=True, stdout=True, logfile=log_file) + + def run(opts): init_ostree_repo(opts.ostree_repo, log_dir=opts.log_dir) make_ostree_repo(opts.ostree_repo, opts.treefile, log_dir=opts.log_dir) + if opts.update_summary: + update_ostree_summary(opts.ostree_repo, log_dir=opts.log_dir) def main(args=None): @@ -59,6 +67,8 @@ def main(args=None): help='where to put the ostree repo') parser.add_argument('--treefile', required=True, help='treefile for rpm-ostree') + parser.add_argument('--update-summary', action='store_true', + help='update summary metadata') opts = parser.parse_args(args) diff --git a/pungi/phases/ostree.py b/pungi/phases/ostree.py index c6bd2a40..64a6e1f3 100644 --- a/pungi/phases/ostree.py +++ b/pungi/phases/ostree.py @@ -103,9 +103,14 @@ class OSTreeThread(WorkerThread): 'pungi-make-ostree', '--log-dir=%s' % os.path.join(self.logdir), '--treefile=%s' % os.path.join(config_repo, config['treefile']), - config['ostree_repo'] ] + if config.get('update_summary', False): + cmd.append('--update-summary') + + # positional argument: ostree_repo + cmd.append(config['ostree_repo']) + runroot_channel = compose.conf.get("runroot_channel") runroot_tag = compose.conf["runroot_tag"] diff --git a/tests/test_ostree_phase.py b/tests/test_ostree_phase.py index c4794087..6d63e171 100644 --- a/tests/test_ostree_phase.py +++ b/tests/test_ostree_phase.py @@ -225,6 +225,44 @@ class OSTreeThreadTest(helpers.PungiTestCase): 1) self.assertEqual(self.compose.notifier.send.mock_calls, []) + @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 + + get_dir_from_scm.side_effect = self._dummy_config_repo + + koji = KojiWrapper.return_value + koji.run_runroot_cmd.side_effect = self._mock_runroot(0) + + t = ostree.OSTreeThread(self.pool) + + 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', logger=self.pool._logger)]) + self.assertEqual(koji.get_runroot_cmd.call_args_list, + [mock.call('rrt', 'x86_64', + ['pungi-make-ostree', + '--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'), + '--update-summary', self.repo], + channel=None, mounts=[self.topdir, self.repo], + packages=['pungi', 'ostree', 'rpm-ostree'], + task_id=True, use_shell=True, new_chroot=True)]) + 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')]) + + for fp in ['fedora-rawhide.repo', 'fedora-24.repo', 'fedora-24.repo']: + with open(os.path.join(self.topdir, 'work/ostree-1/config_repo', fp)) as f: + self.assertIn('baseurl=http://example.com/Everything/$basearch/os', + f.read()) + self.assertTrue(os.path.isdir(self.repo)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_ostree_script.py b/tests/test_ostree_script.py index f615f79a..197d2c8a 100644 --- a/tests/test_ostree_script.py +++ b/tests/test_ostree_script.py @@ -79,6 +79,29 @@ class OstreeScriptTest(helpers.PungiTestCase): self.topdir + '/fedora-atomic-docker-host.json'], logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)]) + @mock.patch('kobo.shortcuts.run') + def test_update_summary(self, run): + repo = os.path.join(self.topdir, 'atomic') + + ostree.main([ + '--log-dir=%s' % os.path.join(self.topdir, 'logs', 'Atomic'), + '--treefile=%s/fedora-atomic-docker-host.json' % self.topdir, + '--update-summary', + repo, + ]) + + self.maxDiff = None + self.assertItemsEqual( + run.call_args_list, + [mock.call(['ostree', 'init', '--repo=%s' % repo, '--mode=archive-z2'], + logfile=self.topdir + '/logs/Atomic/init-ostree-repo.log', show_cmd=True, stdout=True), + mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, + '--write-commitid-to=%s' % (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], + logfile=self.topdir + '/logs/Atomic/ostree-summary.log', show_cmd=True, stdout=True)]), + if __name__ == '__main__': unittest.main()