| |
@@ -0,0 +1,244 @@
|
| |
+ #!/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_live_image as ostree
|
| |
+
|
| |
+
|
| |
+ class OSTreeLiveImagePhaseTest(helpers.PungiTestCase):
|
| |
+
|
| |
+ def test_validate(self):
|
| |
+ compose = helpers.DummyCompose(self.topdir, {
|
| |
+ 'ostree_live_image': [
|
| |
+ ("^Atomic$", {
|
| |
+ "x86_64": {
|
| |
+ "source_repo_from": "Everything",
|
| |
+ "config_url": "https://git.fedorahosted.org/git/fedora-atomic.git",
|
| |
+ "config": "config.ini",
|
| |
+ "tdl": "fedora-atomic-rawhide.tdl",
|
| |
+ "ksurl": "https://git.fedorahosted.org/git/spin-kickstarts.git",
|
| |
+ "kickstart": "fedora-atomic.ks",
|
| |
+ "ostree_repo": "/mnt/koji/compose/atomic/rawhide/"
|
| |
+ }
|
| |
+ })
|
| |
+ ]
|
| |
+ })
|
| |
+
|
| |
+ phase = ostree.OSTreeLiveImagePhase(compose)
|
| |
+ try:
|
| |
+ phase.validate()
|
| |
+ except:
|
| |
+ self.fail('Correct config must validate')
|
| |
+
|
| |
+ def test_validate_bad_conf(self):
|
| |
+ compose = helpers.DummyCompose(self.topdir, {
|
| |
+ 'ostree_live_image': 'yes please'
|
| |
+ })
|
| |
+
|
| |
+ phase = ostree.OSTreeLiveImagePhase(compose)
|
| |
+ with self.assertRaises(ValueError):
|
| |
+ phase.validate()
|
| |
+
|
| |
+ @mock.patch('pungi.phases.ostree_live_image.ThreadPool')
|
| |
+ def test_run(self, ThreadPool):
|
| |
+ cfg = mock.Mock()
|
| |
+ compose = helpers.DummyCompose(self.topdir, {
|
| |
+ 'ostree_live_image': [
|
| |
+ ('^Everything$', {'x86_64': cfg})
|
| |
+ ]
|
| |
+ })
|
| |
+
|
| |
+ pool = ThreadPool.return_value
|
| |
+
|
| |
+ phase = ostree.OSTreeLiveImagePhase(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_live_image.ThreadPool')
|
| |
+ def test_skip_without_config(self, ThreadPool):
|
| |
+ compose = helpers.DummyCompose(self.topdir, {})
|
| |
+ compose.just_phases = None
|
| |
+ compose.skip_phases = []
|
| |
+ phase = ostree.OSTreeLiveImagePhase(compose)
|
| |
+ self.assertTrue(phase.skip())
|
| |
+
|
| |
+
|
| |
+ class OSTreeLiveImageThreadTest(helpers.PungiTestCase):
|
| |
+
|
| |
+ def setUp(self):
|
| |
+ super(OSTreeLiveImageThreadTest, self).setUp()
|
| |
+ self.repo = os.path.join(self.topdir, 'place/for/atomic')
|
| |
+
|
| |
+ def _dummy_config_repo(self, target, url, branch, logger=None):
|
| |
+ helpers.touch(os.path.join(target, 'fedora-atomic-docker-host.json'))
|
| |
+ helpers.touch(os.path.join(target, 'fedora-rawhide.repo'),
|
| |
+ 'mirrorlist=mirror-mirror-on-the-wall')
|
| |
+ 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?')
|
| |
+
|
| |
+ @mock.patch('pungi.wrappers.scm.clone_repo')
|
| |
+ @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
|
| |
+ def test_run(self, KojiWrapper, clone_repo):
|
| |
+ # will be called twice, one for config repo, another for kickstart repo
|
| |
+ clone_repo.side_effect = self._dummy_config_repo
|
| |
+
|
| |
+ compose = helpers.DummyCompose(self.topdir, {
|
| |
+ 'koji_profile': 'koji',
|
| |
+ 'runroot_tag': 'rrt',
|
| |
+ 'translate_paths': [
|
| |
+ (self.topdir + '/compose', 'http://example.com')
|
| |
+ ]
|
| |
+ })
|
| |
+ pool = mock.Mock()
|
| |
+ cfg = {
|
| |
+ 'source_repo_from': 'Everything',
|
| |
+ 'config_url': 'https://git.fedorahosted.org/git/fedora-atomic.git',
|
| |
+ 'config': 'config.ini',
|
| |
+ 'config_branch': 'master',
|
| |
+ 'tdl': 'fedora-atomic-rawhide.tdl',
|
| |
+ 'ksurl': 'https://git.fedorahosted.org/git/spin-kickstarts.git',
|
| |
+ 'kickstart': 'fedora-cloud-atomic-pxetolive.ks',
|
| |
+ 'ostree_repo': self.repo
|
| |
+ }
|
| |
+
|
| |
+ koji = KojiWrapper.return_value
|
| |
+ koji.run_runroot_cmd.return_value = {
|
| |
+ 'task_id': 1234,
|
| |
+ 'retcode': 0,
|
| |
+ 'output': 'Foo bar\n',
|
| |
+ }
|
| |
+
|
| |
+ t = ostree.OSTreeLiveImageThread(pool)
|
| |
+
|
| |
+ t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)
|
| |
+
|
| |
+ clone_repo.assert_has_calls([
|
| |
+ mock.call(self.topdir + '/work/ostree-live-image-1/config_repo',
|
| |
+ 'https://git.fedorahosted.org/git/fedora-atomic.git', 'master', logger=pool._logger),
|
| |
+ mock.call(self.topdir + '/work/ostree-live-image-1/kickstart_repo',
|
| |
+ 'https://git.fedorahosted.org/git/spin-kickstarts.git', 'master', logger=pool._logger)
|
| |
+ ])
|
| |
+
|
| |
+ self.assertEqual(koji.get_runroot_cmd.call_args_list,
|
| |
+ [mock.call('rrt', 'x86_64',
|
| |
+ ['rpm-ostree-toolbox',
|
| |
+ 'liveimage',
|
| |
+ '--config=%s/config.ini' % (self.topdir + '/work/ostree-live-image-1/config_repo'),
|
| |
+ '--preserve-ks-url',
|
| |
+ '--ostreerepo=%s' % self.repo,
|
| |
+ '--tdl=%s/fedora-atomic-rawhide.tdl' % (
|
| |
+ self.topdir + '/work/ostree-live-image-1/config_repo'),
|
| |
+ '--kickstart=%s/fedora-cloud-atomic-pxetolive.ks' % (
|
| |
+ self.topdir + '/work/ostree-live-image-1/kickstart_repo'),
|
| |
+ '--outputdir=%s' % (
|
| |
+ self.topdir + '/work/x86_64/Everything/ostree_live_image'),
|
| |
+ ],
|
| |
+ channel=None, mounts=[self.topdir, self.repo],
|
| |
+ packages=['rpm-ostree-toolbox'],
|
| |
+ task_id=True, use_shell=True)])
|
| |
+ self.assertEqual(koji.run_runroot_cmd.call_args_list,
|
| |
+ [mock.call(koji.get_runroot_cmd.return_value,
|
| |
+ log_file=self.topdir + '/logs/x86_64/ostree-live-image-1/runroot.log')])
|
| |
+
|
| |
+ with open(self.topdir + '/work/ostree-live-image-1/config_repo/fedora-rawhide.repo') as f:
|
| |
+ self.assertIn('baseurl=http://example.com/Everything/x86_64/os',
|
| |
+ f.read())
|
| |
+ with open(self.topdir + '/work/ostree-live-image-1/config_repo/fedora-24.repo') as f:
|
| |
+ self.assertIn('baseurl=http://example.com/Everything/x86_64/os',
|
| |
+ f.read())
|
| |
+ with open(self.topdir + '/work/ostree-live-image-1/config_repo/fedora-23.repo') as f:
|
| |
+ self.assertIn('baseurl=http://example.com/Everything/x86_64/os',
|
| |
+ f.read())
|
| |
+
|
| |
+ @mock.patch('pungi.wrappers.scm.clone_repo')
|
| |
+ @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
|
| |
+ def test_run_fail(self, KojiWrapper, clone_repo):
|
| |
+ clone_repo.side_effect = self._dummy_config_repo
|
| |
+
|
| |
+ compose = helpers.DummyCompose(self.topdir, {
|
| |
+ 'koji_profile': 'koji',
|
| |
+ 'runroot_tag': 'rrt',
|
| |
+ 'failable_deliverables': [
|
| |
+ ('^.*$', {'*': ['ostree-live-image']})
|
| |
+ ]
|
| |
+ })
|
| |
+ pool = mock.Mock()
|
| |
+ cfg = {
|
| |
+ 'source_repo_from': 'Everything',
|
| |
+ 'config_url': 'https://git.fedorahosted.org/git/fedora-atomic.git',
|
| |
+ 'config': 'config.ini',
|
| |
+ 'config_branch': 'master',
|
| |
+ 'tdl': 'fedora-atomic-rawhide.tdl',
|
| |
+ 'ksurl': 'https://git.fedorahosted.org/git/spin-kickstarts.git',
|
| |
+ 'kickstart': 'fedora-cloud-atomic-pxetolive.ks',
|
| |
+ 'ostree_repo': self.repo
|
| |
+ }
|
| |
+ koji = KojiWrapper.return_value
|
| |
+ koji.run_runroot_cmd.return_value = {
|
| |
+ 'task_id': 1234,
|
| |
+ 'retcode': 1,
|
| |
+ 'output': 'Foo bar\n',
|
| |
+ }
|
| |
+
|
| |
+ t = ostree.OSTreeLiveImageThread(pool)
|
| |
+
|
| |
+ t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)
|
| |
+
|
| |
+ compose.log_info.assert_has_calls([
|
| |
+ mock.call('[FAIL] Ostree live image (variant Everything, arch x86_64) failed, but going on anyway.'),
|
| |
+ mock.call('Runroot task failed: 1234. See %s for more details.'
|
| |
+ % (self.topdir + '/logs/x86_64/ostree-live-image-1/runroot.log'))
|
| |
+ ])
|
| |
+
|
| |
+ @mock.patch('pungi.wrappers.scm.clone_repo')
|
| |
+ @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
|
| |
+ def test_run_handle_exception(self, KojiWrapper, clone_repo):
|
| |
+ clone_repo.side_effect = self._dummy_config_repo
|
| |
+
|
| |
+ compose = helpers.DummyCompose(self.topdir, {
|
| |
+ 'koji_profile': 'koji',
|
| |
+ 'runroot_tag': 'rrt',
|
| |
+ 'failable_deliverables': [
|
| |
+ ('^.*$', {'*': ['ostree-live-image']})
|
| |
+ ]
|
| |
+ })
|
| |
+ pool = mock.Mock()
|
| |
+ cfg = {
|
| |
+ 'source_repo_from': 'Everything',
|
| |
+ 'config_url': 'https://git.fedorahosted.org/git/fedora-atomic.git',
|
| |
+ 'config': 'config.ini',
|
| |
+ 'config_branch': 'master',
|
| |
+ 'tdl': 'fedora-atomic-rawhide.tdl',
|
| |
+ 'ksurl': 'https://git.fedorahosted.org/git/spin-kickstarts.git',
|
| |
+ 'kickstart': 'fedora-cloud-atomic-pxetolive.ks',
|
| |
+ 'ostree_repo': self.repo
|
| |
+ }
|
| |
+ koji = KojiWrapper.return_value
|
| |
+ koji.run_runroot_cmd.side_effect = helpers.boom
|
| |
+
|
| |
+ t = ostree.OSTreeLiveImageThread(pool)
|
| |
+
|
| |
+ t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)
|
| |
+
|
| |
+ compose.log_info.assert_has_calls([
|
| |
+ mock.call('[FAIL] Ostree live image (variant Everything, arch x86_64) failed, but going on anyway.'),
|
| |
+ mock.call('BOOM')
|
| |
+ ])
|
| |
+
|
| |
+
|
| |
+ if __name__ == '__main__':
|
| |
+ unittest.main()
|
| |
We can not run rpm-ostree-toolbox at least the last time i looked at it the logging and information it provided was not sufficient. additionally there is no /dev/kvm in the buildroots, so any virt would be unaccelerated. this really needs implemented as a process that builds the image, then feeds it to livemedia-creator. I have been working with Brian Lane to get livemedia-creator to be able to make the pxe-to-live in a single livemedia-creator run