[atomic] Add a script to create ostree repo
This is a wrapper over ostree and rpm-ostree. It is intended to be run in either Koji or Mock chroot. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
6230b0ff3e
commit
282058dafe
15
bin/pungi-make-ostree
Executable file
15
bin/pungi-make-ostree
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
here = sys.path[0]
|
||||||
|
if here != '/usr/bin':
|
||||||
|
sys.path.insert(0, os.path.dirname(here))
|
||||||
|
|
||||||
|
from pungi import atomic
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
atomic.main()
|
51
pungi/atomic.py
Normal file
51
pungi/atomic.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
This module contains functions required by pungi-make-atomic.
|
||||||
|
It is expected to be runnable in Koji runroot.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
from kobo import shortcuts
|
||||||
|
|
||||||
|
|
||||||
|
def make_log_file(log_dir, filename):
|
||||||
|
"""Return path to log file with given name, if log_dir is set."""
|
||||||
|
if not log_dir:
|
||||||
|
return None
|
||||||
|
return os.path.join(log_dir, '{}.log'.format(filename))
|
||||||
|
|
||||||
|
|
||||||
|
def init_atomic_repo(repo, log_dir=None):
|
||||||
|
"""If the atomic repo does not exist, initialize it."""
|
||||||
|
log_file = make_log_file(log_dir, 'init-atomic-repo')
|
||||||
|
if not os.path.isdir(repo):
|
||||||
|
shortcuts.run(['ostree', 'init', '--repo={}'.format(repo), '--mode=archive-z2'],
|
||||||
|
log_file=log_file)
|
||||||
|
|
||||||
|
|
||||||
|
def make_ostree_repo(repo, config, log_dir=None):
|
||||||
|
log_file = make_log_file(log_dir, 'create-atomic-repo')
|
||||||
|
shortcuts.run(['rpm-ostree', 'compose', 'tree', '--repo={}'.format(repo), config],
|
||||||
|
log_file=log_file)
|
||||||
|
|
||||||
|
|
||||||
|
def run(opts):
|
||||||
|
init_atomic_repo(opts.atomic_repo, log_dir=opts.log_dir)
|
||||||
|
make_ostree_repo(opts.atomic_repo, opts.treefile, log_dir=opts.log_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def main(args=None):
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--log-dir',
|
||||||
|
help='where to log output')
|
||||||
|
|
||||||
|
parser.add_argument('atomic_repo', metavar='ATOMIC_REPO',
|
||||||
|
help='where to put the atomic repo')
|
||||||
|
parser.add_argument('--treefile', required=True,
|
||||||
|
help='treefile for rpm-ostree')
|
||||||
|
|
||||||
|
opts = parser.parse_args(args)
|
||||||
|
|
||||||
|
run(opts)
|
38
tests/test_atomic_script.py
Executable file
38
tests/test_atomic_script.py
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import mock
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'bin'))
|
||||||
|
|
||||||
|
from tests import helpers
|
||||||
|
from pungi import atomic
|
||||||
|
|
||||||
|
|
||||||
|
class OstreeScriptTest(helpers.PungiTestCase):
|
||||||
|
|
||||||
|
@mock.patch('kobo.shortcuts.run')
|
||||||
|
def test_full_run(self, run):
|
||||||
|
atomic.main([
|
||||||
|
'--log-dir={}'.format(os.path.join(self.topdir, 'logs', 'Atomic')),
|
||||||
|
'--treefile={}'.format(os.path.join(self.topdir, 'work', 'fedora-atomic-docker-host.json')),
|
||||||
|
os.path.join(self.topdir, 'atomic'),
|
||||||
|
])
|
||||||
|
self.maxDiff = None
|
||||||
|
self.assertItemsEqual(
|
||||||
|
run.call_args_list,
|
||||||
|
[mock.call(['ostree', 'init', '--repo={}/atomic'.format(self.topdir), '--mode=archive-z2'],
|
||||||
|
log_file=self.topdir + '/logs/Atomic/init-atomic-repo.log'),
|
||||||
|
mock.call(['rpm-ostree', 'compose', 'tree', '--repo={}/atomic'.format(self.topdir),
|
||||||
|
self.topdir + '/work/fedora-atomic-docker-host.json'],
|
||||||
|
log_file=self.topdir + '/logs/Atomic/create-atomic-repo.log')])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user