[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 <qwan@redhat.com>
This commit is contained in:
Qixiang Wan 2016-11-03 20:59:00 +08:00
parent a49510a9fb
commit 06ba3b8551
6 changed files with 82 additions and 2 deletions

View File

@ -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
}
})
]

View File

@ -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"},
},

View File

@ -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)

View File

@ -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"]

View File

@ -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()

View File

@ -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()