ostree: Use the write-commitid-to feature rather than parsing ostree logs

This depends on an rpm-ostree release with
98332a3be4

Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
This commit is contained in:
Patrick Uiterwijk 2016-10-17 20:22:06 +00:00
parent c5bd99da9e
commit 754458823c
4 changed files with 36 additions and 10 deletions

View File

@ -678,6 +678,7 @@ def _make_schema():
"ostree_repo": {"type": "string"}, "ostree_repo": {"type": "string"},
"failable": {"$ref": "#/definitions/list_of_strings"}, "failable": {"$ref": "#/definitions/list_of_strings"},
"config_branch": {"type": "string"}, "config_branch": {"type": "string"},
"tag_ref": {"type": "boolean"},
}, },
"required": ["treefile", "config_url", "source_repo_from", "ostree_repo"], "required": ["treefile", "config_url", "source_repo_from", "ostree_repo"],
"additionalProperties": False, "additionalProperties": False,

View File

@ -39,7 +39,9 @@ def init_ostree_repo(repo, log_dir=None):
def make_ostree_repo(repo, config, log_dir=None): def make_ostree_repo(repo, config, log_dir=None):
log_file = make_log_file(log_dir, 'create-ostree-repo') log_file = make_log_file(log_dir, 'create-ostree-repo')
shortcuts.run(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, config], shortcuts.run(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo,
'--write-commitid-to=%s' % make_log_file(log_dir, 'commitid'),
config],
show_cmd=True, stdout=True, logfile=log_file) show_cmd=True, stdout=True, logfile=log_file)

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json
import os import os
from kobo.threads import ThreadPool, WorkerThread from kobo.threads import ThreadPool, WorkerThread
import re import re
@ -58,9 +59,21 @@ class OSTreeThread(WorkerThread):
util.makedirs(config['ostree_repo']) util.makedirs(config['ostree_repo'])
self._run_ostree_cmd(compose, variant, arch, config, repodir) self._run_ostree_cmd(compose, variant, arch, config, repodir)
ref, commitid = self._get_commit_info(config, repodir)
if config.get('tag_ref', True) and ref and commitid:
# Let's write the tag out ourselves
heads_dir = os.path.join(config['ostree_repo'], 'refs', 'heads')
if not os.path.exists(heads_dir):
raise RuntimeError('Refs/heads did not exist in ostree repo')
ref_path = os.path.join(heads_dir, ref)
if not os.path.exists(os.path.dirname(ref_path)):
os.makedirs(os.path.dirname(ref_path))
with open(ref_path, 'w') as f:
f.write(commitid + '\n')
if compose.notifier: if compose.notifier:
ref, commitid = self._get_commit_info()
compose.notifier.send('ostree', compose.notifier.send('ostree',
variant=variant.uid, variant=variant.uid,
arch=arch, arch=arch,
@ -69,14 +82,21 @@ class OSTreeThread(WorkerThread):
self.pool.log_info('[DONE ] %s' % msg) self.pool.log_info('[DONE ] %s' % msg)
def _get_commit_info(self): def _get_commit_info(self, config, config_repo):
with open(os.path.join(self.logdir, 'create-ostree-repo.log'), 'r') as f: ref = None
for line in f.readlines(): commitid = None
if ' => ' in line: with open(os.path.join(config_repo, config['treefile']), 'r') as f:
line = line.replace('\n', '') try:
ref, _, commitid = line.partition(' => ') parsed = json.loads(f.read())
return ref, commitid ref = parsed['ref']
return None, None except ValueError:
return None, None
if os.path.exists(os.path.join(self.logdir, 'commitid')):
with open(os.path.join(self.logdir, 'commitid'), 'r') as f:
commitid = f.read().replace('\n', '')
else:
return None, None
return ref, commitid
def _run_ostree_cmd(self, compose, variant, arch, config, config_repo): def _run_ostree_cmd(self, compose, variant, arch, config, config_repo):
cmd = [ cmd = [

View File

@ -33,6 +33,7 @@ class OstreeScriptTest(helpers.PungiTestCase):
[mock.call(['ostree', 'init', '--repo=%s' % repo, '--mode=archive-z2'], [mock.call(['ostree', 'init', '--repo=%s' % repo, '--mode=archive-z2'],
logfile=self.topdir + '/logs/Atomic/init-ostree-repo.log', show_cmd=True, stdout=True), logfile=self.topdir + '/logs/Atomic/init-ostree-repo.log', show_cmd=True, stdout=True),
mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, 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'], self.topdir + '/fedora-atomic-docker-host.json'],
logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)]) logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)])
@ -54,6 +55,7 @@ class OstreeScriptTest(helpers.PungiTestCase):
[mock.call(['ostree', 'init', '--repo=%s' % repo, '--mode=archive-z2'], [mock.call(['ostree', 'init', '--repo=%s' % repo, '--mode=archive-z2'],
logfile=self.topdir + '/logs/Atomic/init-ostree-repo.log', show_cmd=True, stdout=True), logfile=self.topdir + '/logs/Atomic/init-ostree-repo.log', show_cmd=True, stdout=True),
mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, 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'], self.topdir + '/fedora-atomic-docker-host.json'],
logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)]) logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)])
@ -73,6 +75,7 @@ class OstreeScriptTest(helpers.PungiTestCase):
self.assertItemsEqual( self.assertItemsEqual(
run.call_args_list, run.call_args_list,
[mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, [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'], self.topdir + '/fedora-atomic-docker-host.json'],
logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)]) logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)])