[ostree] Use explicit work directory
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
96e7ddd3ea
commit
5b1b6c1c4f
@ -8,17 +8,26 @@ It is expected to be runnable in Koji runroot.
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
from kobo import shortcuts
|
from kobo import shortcuts
|
||||||
import tempfile
|
|
||||||
import shutil
|
|
||||||
import re
|
import re
|
||||||
|
import errno
|
||||||
|
|
||||||
from .wrappers import scm
|
from .wrappers import scm
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_dir(path):
|
||||||
|
try:
|
||||||
|
os.makedirs(path)
|
||||||
|
except OSError as err:
|
||||||
|
if err.errno != errno.EEXIST:
|
||||||
|
raise
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
def make_log_file(log_dir, filename):
|
def make_log_file(log_dir, filename):
|
||||||
"""Return path to log file with given name, if log_dir is set."""
|
"""Return path to log file with given name, if log_dir is set."""
|
||||||
if not log_dir:
|
if not log_dir:
|
||||||
return None
|
return None
|
||||||
|
ensure_dir(log_dir)
|
||||||
return os.path.join(log_dir, '{}.log'.format(filename))
|
return os.path.join(log_dir, '{}.log'.format(filename))
|
||||||
|
|
||||||
|
|
||||||
@ -26,14 +35,15 @@ def init_ostree_repo(repo, log_dir=None):
|
|||||||
"""If the ostree repo does not exist, initialize it."""
|
"""If the ostree repo does not exist, initialize it."""
|
||||||
log_file = make_log_file(log_dir, 'init-ostree-repo')
|
log_file = make_log_file(log_dir, 'init-ostree-repo')
|
||||||
if not os.path.isdir(repo):
|
if not os.path.isdir(repo):
|
||||||
|
ensure_dir(repo)
|
||||||
shortcuts.run(['ostree', 'init', '--repo={}'.format(repo), '--mode=archive-z2'],
|
shortcuts.run(['ostree', 'init', '--repo={}'.format(repo), '--mode=archive-z2'],
|
||||||
logfile=log_file)
|
show_cmd=True, logfile=log_file)
|
||||||
|
|
||||||
|
|
||||||
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={}'.format(repo), config],
|
shortcuts.run(['rpm-ostree', 'compose', 'tree', '--repo={}'.format(repo), config],
|
||||||
logfile=log_file)
|
show_cmd=True, logfile=log_file)
|
||||||
|
|
||||||
|
|
||||||
def clone_repo(repodir, url, branch):
|
def clone_repo(repodir, url, branch):
|
||||||
@ -52,7 +62,7 @@ def tweak_file(path, source_repo):
|
|||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
contents = f.read()
|
contents = f.read()
|
||||||
replacement = 'baseurl={}'.format(source_repo)
|
replacement = 'baseurl={}'.format(source_repo)
|
||||||
contents = re.sub(r'^mirrorlist=.*$', replacement, contents)
|
contents = re.sub(r'^mirrorlist=.*$', replacement, contents, flags=re.MULTILINE)
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
|
||||||
@ -65,19 +75,21 @@ def prepare_config(workdir, config_url, config_branch, source_repo):
|
|||||||
|
|
||||||
|
|
||||||
def run(opts):
|
def run(opts):
|
||||||
workdir = tempfile.mkdtemp()
|
workdir = ensure_dir(opts.work_dir)
|
||||||
repodir = prepare_config(workdir, opts.config_url, opts.config_branch,
|
repodir = prepare_config(workdir, opts.config_url, opts.config_branch,
|
||||||
opts.source_repo)
|
opts.source_repo)
|
||||||
|
ensure_dir(repodir)
|
||||||
init_ostree_repo(opts.ostree_repo, log_dir=opts.log_dir)
|
init_ostree_repo(opts.ostree_repo, log_dir=opts.log_dir)
|
||||||
treefile = os.path.join(repodir, opts.treefile)
|
treefile = os.path.join(repodir, opts.treefile)
|
||||||
make_ostree_repo(opts.ostree_repo, treefile, log_dir=opts.log_dir)
|
make_ostree_repo(opts.ostree_repo, treefile, log_dir=opts.log_dir)
|
||||||
shutil.rmtree(workdir)
|
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--log-dir',
|
parser.add_argument('--log-dir',
|
||||||
help='where to log output')
|
help='where to log output')
|
||||||
|
parser.add_argument('--work-dir', required=True,
|
||||||
|
help='where to put temporary files')
|
||||||
|
|
||||||
parser.add_argument('ostree_repo', metavar='OSTREE_REPO',
|
parser.add_argument('ostree_repo', metavar='OSTREE_REPO',
|
||||||
help='where to put the ostree repo')
|
help='where to put the ostree repo')
|
||||||
|
@ -51,9 +51,11 @@ class OSTreeThread(WorkerThread):
|
|||||||
self.pool.log_info('[DONE ] %s' % msg)
|
self.pool.log_info('[DONE ] %s' % msg)
|
||||||
|
|
||||||
def _run_ostree_cmd(self, compose, variant, arch, config, source_repo):
|
def _run_ostree_cmd(self, compose, variant, arch, config, source_repo):
|
||||||
|
workdir = os.path.join(compose.paths.work.topdir(arch), 'ostree')
|
||||||
cmd = [
|
cmd = [
|
||||||
'pungi-make-ostree',
|
'pungi-make-ostree',
|
||||||
'--log-dir={}'.format(self.logdir),
|
'--log-dir={}'.format(self.logdir),
|
||||||
|
'--work-dir={}'.format(workdir),
|
||||||
'--treefile={}'.format(config['treefile']),
|
'--treefile={}'.format(config['treefile']),
|
||||||
'--config-url={}'.format(config['config_url']),
|
'--config-url={}'.format(config['config_url']),
|
||||||
'--config-branch={}'.format(config.get('config_branch', 'master')),
|
'--config-branch={}'.format(config.get('config_branch', 'master')),
|
||||||
|
@ -103,6 +103,7 @@ class OSTreeThreadTest(helpers.PungiTestCase):
|
|||||||
[mock.call('rrt', 'x86_64',
|
[mock.call('rrt', 'x86_64',
|
||||||
['pungi-make-ostree',
|
['pungi-make-ostree',
|
||||||
'--log-dir={}/logs/x86_64/ostree'.format(self.topdir),
|
'--log-dir={}/logs/x86_64/ostree'.format(self.topdir),
|
||||||
|
'--work-dir={}/work/x86_64/ostree'.format(self.topdir),
|
||||||
'--treefile=fedora-atomic-docker-host.json',
|
'--treefile=fedora-atomic-docker-host.json',
|
||||||
'--config-url=https://git.fedorahosted.org/git/fedora-atomic.git',
|
'--config-url=https://git.fedorahosted.org/git/fedora-atomic.git',
|
||||||
'--config-branch=f24',
|
'--config-branch=f24',
|
||||||
|
@ -21,17 +21,16 @@ class OstreeScriptTest(helpers.PungiTestCase):
|
|||||||
helpers.touch(os.path.join(target, 'fedora-atomic-docker-host.json'))
|
helpers.touch(os.path.join(target, 'fedora-atomic-docker-host.json'))
|
||||||
helpers.touch(os.path.join(target, 'fedora-rawhide.repo'))
|
helpers.touch(os.path.join(target, 'fedora-rawhide.repo'))
|
||||||
|
|
||||||
@mock.patch('tempfile.mkdtemp')
|
|
||||||
@mock.patch('kobo.shortcuts.run')
|
@mock.patch('kobo.shortcuts.run')
|
||||||
@mock.patch('pungi.wrappers.scm.get_dir_from_scm')
|
@mock.patch('pungi.wrappers.scm.get_dir_from_scm')
|
||||||
def test_full_run(self, get_dir_from_scm, run, tempfile):
|
def test_full_run(self, get_dir_from_scm, run):
|
||||||
tempfile.return_value = self.topdir
|
|
||||||
get_dir_from_scm.side_effect = self._dummy_config_repo
|
get_dir_from_scm.side_effect = self._dummy_config_repo
|
||||||
|
|
||||||
repo = os.path.join(self.topdir, 'atomic')
|
repo = os.path.join(self.topdir, 'atomic')
|
||||||
|
|
||||||
ostree.main([
|
ostree.main([
|
||||||
'--log-dir={}'.format(os.path.join(self.topdir, 'logs', 'Atomic')),
|
'--log-dir={}'.format(os.path.join(self.topdir, 'logs', 'Atomic')),
|
||||||
|
'--work-dir={}'.format(self.topdir),
|
||||||
'--treefile={}'.format('fedora-atomic-docker-host.json'),
|
'--treefile={}'.format('fedora-atomic-docker-host.json'),
|
||||||
'--config-url=https://git.fedorahosted.org/git/fedora-atomic.git',
|
'--config-url=https://git.fedorahosted.org/git/fedora-atomic.git',
|
||||||
'--config-branch=f24',
|
'--config-branch=f24',
|
||||||
@ -47,10 +46,10 @@ class OstreeScriptTest(helpers.PungiTestCase):
|
|||||||
self.assertItemsEqual(
|
self.assertItemsEqual(
|
||||||
run.call_args_list,
|
run.call_args_list,
|
||||||
[mock.call(['ostree', 'init', '--repo={}'.format(repo), '--mode=archive-z2'],
|
[mock.call(['ostree', 'init', '--repo={}'.format(repo), '--mode=archive-z2'],
|
||||||
logfile=self.topdir + '/logs/Atomic/init-ostree-repo.log'),
|
logfile=self.topdir + '/logs/Atomic/init-ostree-repo.log', show_cmd=True),
|
||||||
mock.call(['rpm-ostree', 'compose', 'tree', '--repo={}'.format(repo),
|
mock.call(['rpm-ostree', 'compose', 'tree', '--repo={}'.format(repo),
|
||||||
self.topdir + '/config_repo/fedora-atomic-docker-host.json'],
|
self.topdir + '/config_repo/fedora-atomic-docker-host.json'],
|
||||||
logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log')])
|
logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True)])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user