2016-03-23 09:38:34 +00:00
|
|
|
#!/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__), '..'))
|
|
|
|
|
|
|
|
from tests import helpers
|
|
|
|
from pungi.phases import ostree
|
|
|
|
|
|
|
|
|
|
|
|
class OSTreePhaseTest(helpers.PungiTestCase):
|
|
|
|
|
2016-04-01 05:28:59 +00:00
|
|
|
def test_validate(self):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'ostree': [
|
|
|
|
("^Atomic$", {
|
|
|
|
"x86_64": {
|
|
|
|
"treefile": "fedora-atomic-docker-host.json",
|
|
|
|
"config_url": "https://git.fedorahosted.org/git/fedora-atomic.git",
|
|
|
|
"source_repo_from": "Everything",
|
2016-04-05 07:13:01 +00:00
|
|
|
"ostree_repo": "/mnt/koji/compose/atomic/Rawhide/"
|
2016-04-01 05:28:59 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = ostree.OSTreePhase(compose)
|
|
|
|
try:
|
|
|
|
phase.validate()
|
|
|
|
except:
|
|
|
|
self.fail('Correct config must validate')
|
|
|
|
|
|
|
|
def test_validate_bad_conf(self):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'ostree': 'yes please'
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = ostree.OSTreePhase(compose)
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
phase.validate()
|
|
|
|
|
2016-03-23 09:38:34 +00:00
|
|
|
@mock.patch('pungi.phases.ostree.ThreadPool')
|
|
|
|
def test_run(self, ThreadPool):
|
|
|
|
cfg = mock.Mock()
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'ostree': [
|
|
|
|
('^Everything$', {'x86_64': cfg})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
pool = ThreadPool.return_value
|
|
|
|
|
|
|
|
phase = ostree.OSTreePhase(compose)
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
self.assertEqual(len(pool.add.call_args_list), 1)
|
|
|
|
self.assertEqual(pool.queue_put.call_args_list,
|
|
|
|
[mock.call((compose, compose.variants['Everything'], 'x86_64', cfg))])
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.ostree.ThreadPool')
|
|
|
|
def test_skip_without_config(self, ThreadPool):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
compose.just_phases = None
|
|
|
|
compose.skip_phases = []
|
|
|
|
phase = ostree.OSTreePhase(compose)
|
|
|
|
self.assertTrue(phase.skip())
|
|
|
|
|
|
|
|
|
|
|
|
class OSTreeThreadTest(helpers.PungiTestCase):
|
|
|
|
|
2016-05-09 13:59:02 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(OSTreeThreadTest, self).setUp()
|
|
|
|
self.repo = os.path.join(self.topdir, 'place/for/atomic')
|
|
|
|
|
2016-04-07 12:33:37 +00:00
|
|
|
def _dummy_config_repo(self, scm_dict, target, logger=None):
|
|
|
|
helpers.touch(os.path.join(target, 'fedora-atomic-docker-host.json'))
|
2016-04-07 13:42:20 +00:00
|
|
|
helpers.touch(os.path.join(target, 'fedora-rawhide.repo'),
|
|
|
|
'mirrorlist=mirror-mirror-on-the-wall')
|
2016-04-15 06:17:40 +00:00
|
|
|
helpers.touch(os.path.join(target, 'fedora-24.repo'),
|
|
|
|
'metalink=who-is-the-fairest-of-them-all')
|
|
|
|
helpers.touch(os.path.join(target, 'fedora-23.repo'),
|
|
|
|
'baseurl=why-not-zoidberg?')
|
2016-04-07 12:33:37 +00:00
|
|
|
|
|
|
|
@mock.patch('pungi.wrappers.scm.get_dir_from_scm')
|
2016-03-23 09:38:34 +00:00
|
|
|
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
|
2016-04-07 12:33:37 +00:00
|
|
|
def test_run(self, KojiWrapper, get_dir_from_scm):
|
|
|
|
get_dir_from_scm.side_effect = self._dummy_config_repo
|
|
|
|
|
2016-03-23 09:38:34 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
'runroot_tag': 'rrt',
|
2016-04-07 13:42:20 +00:00
|
|
|
'translate_paths': [
|
|
|
|
(self.topdir + '/compose', 'http://example.com')
|
|
|
|
]
|
2016-03-23 09:38:34 +00:00
|
|
|
})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cfg = {
|
|
|
|
'source_repo_from': 'Everything',
|
|
|
|
'config_url': 'https://git.fedorahosted.org/git/fedora-atomic.git',
|
|
|
|
'config_branch': 'f24',
|
|
|
|
'treefile': 'fedora-atomic-docker-host.json',
|
2016-05-09 13:59:02 +00:00
|
|
|
'ostree_repo': self.repo
|
2016-03-23 09:38:34 +00:00
|
|
|
}
|
|
|
|
koji = KojiWrapper.return_value
|
|
|
|
koji.run_runroot_cmd.return_value = {
|
|
|
|
'task_id': 1234,
|
|
|
|
'retcode': 0,
|
|
|
|
'output': 'Foo bar\n',
|
|
|
|
}
|
|
|
|
|
|
|
|
t = ostree.OSTreeThread(pool)
|
|
|
|
|
|
|
|
t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)
|
|
|
|
|
2016-04-07 12:33:37 +00:00
|
|
|
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': '.'},
|
2016-05-18 06:03:31 +00:00
|
|
|
self.topdir + '/work/ostree-1/config_repo', logger=pool._logger)])
|
2016-03-23 09:38:34 +00:00
|
|
|
self.assertEqual(koji.get_runroot_cmd.call_args_list,
|
|
|
|
[mock.call('rrt', 'x86_64',
|
|
|
|
['pungi-make-ostree',
|
2016-05-25 11:37:39 +00:00
|
|
|
'--log-dir=%s/logs/x86_64/Everything/ostree-1' % self.topdir,
|
|
|
|
'--treefile=%s/fedora-atomic-docker-host.json' % (
|
2016-05-18 06:03:31 +00:00
|
|
|
self.topdir + '/work/ostree-1/config_repo'),
|
2016-05-09 13:59:02 +00:00
|
|
|
self.repo],
|
|
|
|
channel=None, mounts=[self.topdir, self.repo],
|
2016-03-23 09:38:34 +00:00
|
|
|
packages=['pungi', 'ostree', 'rpm-ostree'],
|
|
|
|
task_id=True, use_shell=True)])
|
|
|
|
self.assertEqual(koji.run_runroot_cmd.call_args_list,
|
|
|
|
[mock.call(koji.get_runroot_cmd.return_value,
|
2016-05-18 06:03:31 +00:00
|
|
|
log_file=self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log')])
|
2016-03-23 09:38:34 +00:00
|
|
|
|
2016-05-18 06:03:31 +00:00
|
|
|
with open(self.topdir + '/work/ostree-1/config_repo/fedora-rawhide.repo') as f:
|
2016-05-25 11:37:39 +00:00
|
|
|
self.assertIn('baseurl=http://example.com/Everything/x86_64/os',
|
2016-04-07 13:42:20 +00:00
|
|
|
f.read())
|
2016-05-18 06:03:31 +00:00
|
|
|
with open(self.topdir + '/work/ostree-1/config_repo/fedora-24.repo') as f:
|
2016-05-25 11:37:39 +00:00
|
|
|
self.assertIn('baseurl=http://example.com/Everything/x86_64/os',
|
2016-04-15 06:17:40 +00:00
|
|
|
f.read())
|
2016-05-18 06:03:31 +00:00
|
|
|
with open(self.topdir + '/work/ostree-1/config_repo/fedora-23.repo') as f:
|
2016-05-25 11:37:39 +00:00
|
|
|
self.assertIn('baseurl=http://example.com/Everything/x86_64/os',
|
2016-04-15 06:17:40 +00:00
|
|
|
f.read())
|
2016-05-09 13:59:02 +00:00
|
|
|
self.assertTrue(os.path.isdir(self.repo))
|
2016-04-07 13:42:20 +00:00
|
|
|
|
2016-04-07 12:33:37 +00:00
|
|
|
@mock.patch('pungi.wrappers.scm.get_dir_from_scm')
|
2016-04-06 12:57:12 +00:00
|
|
|
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
|
2016-04-07 12:33:37 +00:00
|
|
|
def test_run_fail(self, KojiWrapper, get_dir_from_scm):
|
|
|
|
get_dir_from_scm.side_effect = self._dummy_config_repo
|
|
|
|
|
2016-04-06 12:57:12 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
'runroot_tag': 'rrt',
|
|
|
|
'failable_deliverables': [
|
|
|
|
('^.*$', {'*': ['ostree']})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cfg = {
|
|
|
|
'source_repo_from': 'Everything',
|
|
|
|
'config_url': 'https://git.fedorahosted.org/git/fedora-atomic.git',
|
|
|
|
'config_branch': 'f24',
|
|
|
|
'treefile': 'fedora-atomic-docker-host.json',
|
2016-05-09 13:59:02 +00:00
|
|
|
'ostree_repo': self.repo,
|
2016-04-06 12:57:12 +00:00
|
|
|
}
|
|
|
|
koji = KojiWrapper.return_value
|
|
|
|
koji.run_runroot_cmd.return_value = {
|
|
|
|
'task_id': 1234,
|
|
|
|
'retcode': 1,
|
|
|
|
'output': 'Foo bar\n',
|
|
|
|
}
|
|
|
|
|
|
|
|
t = ostree.OSTreeThread(pool)
|
|
|
|
|
|
|
|
t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)
|
|
|
|
|
|
|
|
compose.log_info.assert_has_calls([
|
|
|
|
mock.call('[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway.'),
|
2016-05-25 11:37:39 +00:00
|
|
|
mock.call('Runroot task failed: 1234. See %s for more details.'
|
|
|
|
% (self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log'))
|
2016-04-06 12:57:12 +00:00
|
|
|
])
|
|
|
|
|
2016-04-07 12:33:37 +00:00
|
|
|
@mock.patch('pungi.wrappers.scm.get_dir_from_scm')
|
2016-04-06 12:57:12 +00:00
|
|
|
@mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
|
2016-04-07 12:33:37 +00:00
|
|
|
def test_run_handle_exception(self, KojiWrapper, get_dir_from_scm):
|
|
|
|
get_dir_from_scm.side_effect = self._dummy_config_repo
|
|
|
|
|
2016-04-06 12:57:12 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
'runroot_tag': 'rrt',
|
|
|
|
'failable_deliverables': [
|
|
|
|
('^.*$', {'*': ['ostree']})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cfg = {
|
|
|
|
'source_repo_from': 'Everything',
|
|
|
|
'config_url': 'https://git.fedorahosted.org/git/fedora-atomic.git',
|
|
|
|
'config_branch': 'f24',
|
|
|
|
'treefile': 'fedora-atomic-docker-host.json',
|
2016-05-09 13:59:02 +00:00
|
|
|
'ostree_repo': self.repo,
|
2016-04-06 12:57:12 +00:00
|
|
|
}
|
|
|
|
koji = KojiWrapper.return_value
|
|
|
|
koji.run_runroot_cmd.side_effect = helpers.boom
|
|
|
|
|
|
|
|
t = ostree.OSTreeThread(pool)
|
|
|
|
|
|
|
|
t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)
|
|
|
|
|
|
|
|
compose.log_info.assert_has_calls([
|
|
|
|
mock.call('[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway.'),
|
|
|
|
mock.call('BOOM')
|
|
|
|
])
|
|
|
|
|
2016-03-23 09:38:34 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|