Merge #294 [ostree] Initialize empty repo

This commit is contained in:
Dennis Gilmore 2016-05-16 13:39:55 +00:00
commit e998bbe436
4 changed files with 55 additions and 6 deletions

View File

@ -31,7 +31,7 @@ def make_log_file(log_dir, filename):
def init_ostree_repo(repo, log_dir=None): 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) or not os.listdir(repo):
ensure_dir(repo) ensure_dir(repo)
shortcuts.run(['ostree', 'init', '--repo={}'.format(repo), '--mode=archive-z2'], shortcuts.run(['ostree', 'init', '--repo={}'.format(repo), '--mode=archive-z2'],
show_cmd=True, stdout=True, logfile=log_file) show_cmd=True, stdout=True, logfile=log_file)

View File

@ -55,6 +55,10 @@ class OSTreeThread(WorkerThread):
self._clone_repo(repodir, config['config_url'], config.get('config_branch', 'master')) self._clone_repo(repodir, config['config_url'], config.get('config_branch', 'master'))
self._tweak_mirrorlist(repodir, source_repo) self._tweak_mirrorlist(repodir, source_repo)
# Ensure target directory exists, otherwise Koji task will fail to
# mount it.
util.makedirs(config['ostree_repo'])
self._run_ostree_cmd(compose, variant, arch, config, repodir) self._run_ostree_cmd(compose, variant, arch, config, repodir)
self.pool.log_info('[DONE ] %s' % msg) self.pool.log_info('[DONE ] %s' % msg)

View File

@ -74,6 +74,10 @@ class OSTreePhaseTest(helpers.PungiTestCase):
class OSTreeThreadTest(helpers.PungiTestCase): class OSTreeThreadTest(helpers.PungiTestCase):
def setUp(self):
super(OSTreeThreadTest, self).setUp()
self.repo = os.path.join(self.topdir, 'place/for/atomic')
def _dummy_config_repo(self, scm_dict, target, logger=None): def _dummy_config_repo(self, scm_dict, target, logger=None):
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'),
@ -101,7 +105,7 @@ class OSTreeThreadTest(helpers.PungiTestCase):
'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',
'treefile': 'fedora-atomic-docker-host.json', 'treefile': 'fedora-atomic-docker-host.json',
'ostree_repo': '/other/place/for/atomic' 'ostree_repo': self.repo
} }
koji = KojiWrapper.return_value koji = KojiWrapper.return_value
koji.run_runroot_cmd.return_value = { koji.run_runroot_cmd.return_value = {
@ -124,8 +128,8 @@ class OSTreeThreadTest(helpers.PungiTestCase):
'--log-dir={}/logs/x86_64/ostree'.format(self.topdir), '--log-dir={}/logs/x86_64/ostree'.format(self.topdir),
'--treefile={}/fedora-atomic-docker-host.json'.format( '--treefile={}/fedora-atomic-docker-host.json'.format(
self.topdir + '/work/ostree/config_repo'), self.topdir + '/work/ostree/config_repo'),
'/other/place/for/atomic'], self.repo],
channel=None, mounts=[self.topdir, '/other/place/for/atomic'], channel=None, mounts=[self.topdir, self.repo],
packages=['pungi', 'ostree', 'rpm-ostree'], packages=['pungi', 'ostree', 'rpm-ostree'],
task_id=True, use_shell=True)]) task_id=True, use_shell=True)])
self.assertEqual(koji.run_runroot_cmd.call_args_list, self.assertEqual(koji.run_runroot_cmd.call_args_list,
@ -141,6 +145,7 @@ class OSTreeThreadTest(helpers.PungiTestCase):
with open(self.topdir + '/work/ostree/config_repo/fedora-23.repo') as f: with open(self.topdir + '/work/ostree/config_repo/fedora-23.repo') as f:
self.assertIn('baseurl=http://example.com/Everything/x86_64/os'.format(self.topdir), self.assertIn('baseurl=http://example.com/Everything/x86_64/os'.format(self.topdir),
f.read()) f.read())
self.assertTrue(os.path.isdir(self.repo))
@mock.patch('pungi.wrappers.scm.get_dir_from_scm') @mock.patch('pungi.wrappers.scm.get_dir_from_scm')
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
@ -160,7 +165,7 @@ class OSTreeThreadTest(helpers.PungiTestCase):
'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',
'treefile': 'fedora-atomic-docker-host.json', 'treefile': 'fedora-atomic-docker-host.json',
'ostree_repo': '/other/place/for/atomic' 'ostree_repo': self.repo,
} }
koji = KojiWrapper.return_value koji = KojiWrapper.return_value
koji.run_runroot_cmd.return_value = { koji.run_runroot_cmd.return_value = {
@ -197,7 +202,7 @@ class OSTreeThreadTest(helpers.PungiTestCase):
'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',
'treefile': 'fedora-atomic-docker-host.json', 'treefile': 'fedora-atomic-docker-host.json',
'ostree_repo': '/other/place/for/atomic' 'ostree_repo': self.repo,
} }
koji = KojiWrapper.return_value koji = KojiWrapper.return_value
koji.run_runroot_cmd.side_effect = helpers.boom koji.run_runroot_cmd.side_effect = helpers.boom

View File

@ -36,6 +36,46 @@ class OstreeScriptTest(helpers.PungiTestCase):
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)])
@mock.patch('kobo.shortcuts.run')
def test_run_on_existing_empty_dir(self, run):
repo = os.path.join(self.topdir, 'atomic')
os.mkdir(repo)
ostree.main([
'--log-dir={}'.format(os.path.join(self.topdir, 'logs', 'Atomic')),
'--treefile={}/fedora-atomic-docker-host.json'.format(self.topdir),
repo,
])
self.maxDiff = None
self.assertItemsEqual(
run.call_args_list,
[mock.call(['ostree', 'init', '--repo={}'.format(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={}'.format(repo),
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_run_on_initialized_repo(self, run):
repo = os.path.join(self.topdir, 'atomic')
helpers.touch(os.path.join(repo, 'initialized'))
ostree.main([
'--log-dir={}'.format(os.path.join(self.topdir, 'logs', 'Atomic')),
'--treefile={}/fedora-atomic-docker-host.json'.format(self.topdir),
repo,
])
self.maxDiff = None
self.assertItemsEqual(
run.call_args_list,
[mock.call(['rpm-ostree', 'compose', 'tree', '--repo={}'.format(repo),
self.topdir + '/fedora-atomic-docker-host.json'],
logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()