2016-01-15 12:19:50 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import mock
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
|
2016-01-18 13:42:38 +00:00
|
|
|
from pungi.phases.live_images import LiveImagesPhase, CreateLiveImageThread
|
2016-01-15 12:19:50 +00:00
|
|
|
from pungi.util import get_arch_variant_data
|
|
|
|
|
|
|
|
|
|
|
|
class _DummyCompose(object):
|
|
|
|
def __init__(self, config):
|
2016-01-18 13:42:38 +00:00
|
|
|
self.compose_id = 'Test-20151203.0.t'
|
2016-02-22 07:38:19 +00:00
|
|
|
self.compose_date = '20151203'
|
|
|
|
self.compose_respin = '0'
|
2016-01-15 12:19:50 +00:00
|
|
|
self.conf = config
|
|
|
|
self.paths = mock.Mock(
|
|
|
|
compose=mock.Mock(
|
2016-02-22 10:19:11 +00:00
|
|
|
topdir=mock.Mock(return_value='/top'),
|
2016-01-15 12:19:50 +00:00
|
|
|
repository=mock.Mock(
|
|
|
|
side_effect=lambda arch, variant, create_dir=False: os.path.join('/repo', arch, variant.uid)
|
|
|
|
),
|
|
|
|
iso_dir=mock.Mock(
|
|
|
|
side_effect=lambda arch, variant, symlink_to: os.path.join(
|
2016-02-22 10:19:11 +00:00
|
|
|
'/top/iso_dir', arch, variant.uid
|
2016-01-15 12:19:50 +00:00
|
|
|
)
|
|
|
|
),
|
2016-02-22 09:13:04 +00:00
|
|
|
image_dir=mock.Mock(
|
|
|
|
side_effect=lambda variant, symlink_to: os.path.join(
|
2016-02-22 10:19:11 +00:00
|
|
|
'/top/image_dir/%(arch)s', variant.uid
|
2016-02-22 09:13:04 +00:00
|
|
|
)
|
|
|
|
),
|
2016-01-15 12:19:50 +00:00
|
|
|
),
|
|
|
|
log=mock.Mock(
|
|
|
|
log_file=mock.Mock(return_value='/a/b/log/log_file')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self._logger = mock.Mock()
|
|
|
|
self.variants = {
|
2016-02-19 07:50:17 +00:00
|
|
|
'Server': mock.Mock(uid='Server', arches=['x86_64', 'amd64'], is_empty=False),
|
|
|
|
'Client': mock.Mock(uid='Client', arches=['amd64'], is_empty=False),
|
|
|
|
'Everything': mock.Mock(uid='Everything', arches=['x86_64', 'amd64'], is_empty=False),
|
2016-01-15 12:19:50 +00:00
|
|
|
}
|
|
|
|
self.log_error = mock.Mock()
|
|
|
|
self.get_image_name = mock.Mock(return_value='image-name')
|
2016-02-22 10:19:11 +00:00
|
|
|
self.im = mock.Mock()
|
2016-01-15 12:19:50 +00:00
|
|
|
|
|
|
|
def get_arches(self):
|
|
|
|
return ['x86_64', 'amd64']
|
|
|
|
|
|
|
|
def get_variants(self, arch=None, types=None):
|
|
|
|
return [v for v in self.variants.values() if not arch or arch in v.arches]
|
|
|
|
|
|
|
|
def can_fail(self, variant, arch, deliverable):
|
|
|
|
failable = get_arch_variant_data(self.conf, 'failable_deliverables', arch, variant)
|
|
|
|
return deliverable in failable
|
|
|
|
|
|
|
|
|
|
|
|
class TestLiveImagesPhase(unittest.TestCase):
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.live_images.ThreadPool')
|
2016-02-17 13:35:28 +00:00
|
|
|
def test_live_image_build(self, ThreadPool):
|
2016-01-15 12:19:50 +00:00
|
|
|
compose = _DummyCompose({
|
|
|
|
'live_images': [
|
|
|
|
('^Client$', {
|
|
|
|
'amd64': {
|
2016-02-17 13:35:28 +00:00
|
|
|
'kickstart': 'test.ks',
|
2016-01-15 12:19:50 +00:00
|
|
|
'additional_repos': ['http://example.com/repo/'],
|
2016-02-22 07:48:12 +00:00
|
|
|
'repo_from': ['Everything'],
|
2016-02-22 07:38:19 +00:00
|
|
|
'release': None,
|
2016-01-15 12:19:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = LiveImagesPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertTrue(phase.pool.add.called)
|
|
|
|
self.maxDiff = None
|
|
|
|
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
|
|
|
|
[mock.call((compose,
|
2016-02-17 13:35:28 +00:00
|
|
|
{'ks_file': 'test.ks',
|
2016-01-15 12:19:50 +00:00
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/iso_dir/amd64/Client',
|
2016-01-15 12:19:50 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
2016-02-22 07:21:51 +00:00
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
2016-02-22 09:13:04 +00:00
|
|
|
'filename': 'image-name',
|
|
|
|
'version': None,
|
|
|
|
'specfile': None,
|
|
|
|
'sign': False,
|
|
|
|
'type': 'live',
|
|
|
|
'release': '20151203.0',
|
|
|
|
'ksurl': None},
|
|
|
|
compose.variants['Client'],
|
|
|
|
'amd64'))])
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.live_images.ThreadPool')
|
|
|
|
def test_live_image_build_without_rename(self, ThreadPool):
|
|
|
|
compose = _DummyCompose({
|
|
|
|
'live_images_no_rename': True,
|
|
|
|
'live_images': [
|
|
|
|
('^Client$', {
|
|
|
|
'amd64': {
|
|
|
|
'kickstart': 'test.ks',
|
|
|
|
'additional_repos': ['http://example.com/repo/'],
|
|
|
|
'repo_from': ['Everything'],
|
|
|
|
'release': None,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = LiveImagesPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertTrue(phase.pool.add.called)
|
|
|
|
self.maxDiff = None
|
|
|
|
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
|
|
|
|
[mock.call((compose,
|
|
|
|
{'ks_file': 'test.ks',
|
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/iso_dir/amd64/Client',
|
2016-02-22 09:13:04 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
|
|
|
'filename': None,
|
2016-02-22 07:21:51 +00:00
|
|
|
'version': None,
|
|
|
|
'specfile': None,
|
|
|
|
'sign': False,
|
|
|
|
'type': 'live',
|
2016-02-22 07:38:19 +00:00
|
|
|
'release': '20151203.0',
|
2016-02-22 07:21:51 +00:00
|
|
|
'ksurl': None},
|
|
|
|
compose.variants['Client'],
|
|
|
|
'amd64'))])
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.live_images.ThreadPool')
|
|
|
|
def test_live_image_build_two_images(self, ThreadPool):
|
|
|
|
compose = _DummyCompose({
|
|
|
|
'live_images': [
|
|
|
|
('^Client$', {
|
|
|
|
'amd64': [{
|
|
|
|
'kickstart': 'test.ks',
|
|
|
|
'additional_repos': ['http://example.com/repo/'],
|
2016-02-22 07:48:12 +00:00
|
|
|
'repo_from': ['Everything'],
|
2016-02-22 07:21:51 +00:00
|
|
|
}, {
|
|
|
|
'kickstart': 'another.ks',
|
|
|
|
'additional_repos': ['http://example.com/repo/'],
|
2016-02-22 07:48:12 +00:00
|
|
|
'repo_from': ['Everything'],
|
2016-02-22 07:21:51 +00:00
|
|
|
}]
|
|
|
|
})
|
|
|
|
],
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = LiveImagesPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertTrue(phase.pool.add.called)
|
|
|
|
self.maxDiff = None
|
|
|
|
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
|
|
|
|
[mock.call((compose,
|
|
|
|
{'ks_file': 'test.ks',
|
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/iso_dir/amd64/Client',
|
2016-02-22 07:21:51 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
2016-02-22 09:13:04 +00:00
|
|
|
'filename': 'image-name',
|
2016-02-22 07:21:51 +00:00
|
|
|
'version': None,
|
|
|
|
'specfile': None,
|
|
|
|
'sign': False,
|
|
|
|
'type': 'live',
|
2016-02-22 07:38:19 +00:00
|
|
|
'release': None,
|
2016-02-22 07:21:51 +00:00
|
|
|
'ksurl': None},
|
|
|
|
compose.variants['Client'],
|
|
|
|
'amd64')),
|
|
|
|
mock.call((compose,
|
|
|
|
{'ks_file': 'another.ks',
|
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/iso_dir/amd64/Client',
|
2016-02-22 07:21:51 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
2016-01-15 12:19:50 +00:00
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
2016-02-22 09:13:04 +00:00
|
|
|
'filename': 'image-name',
|
2016-01-15 12:19:50 +00:00
|
|
|
'version': None,
|
2016-02-11 10:54:30 +00:00
|
|
|
'specfile': None,
|
2016-02-12 12:00:19 +00:00
|
|
|
'sign': False,
|
2016-02-17 13:35:28 +00:00
|
|
|
'type': 'live',
|
2016-02-22 07:38:19 +00:00
|
|
|
'release': None,
|
2016-02-17 13:35:28 +00:00
|
|
|
'ksurl': None},
|
2016-02-11 10:54:30 +00:00
|
|
|
compose.variants['Client'],
|
|
|
|
'amd64'))])
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.live_images.ThreadPool')
|
2016-02-17 13:35:28 +00:00
|
|
|
@mock.patch('pungi.phases.live_images.resolve_git_url')
|
|
|
|
def test_spin_appliance(self, resolve_git_url, ThreadPool):
|
2016-02-11 10:54:30 +00:00
|
|
|
compose = _DummyCompose({
|
|
|
|
'live_images': [
|
|
|
|
('^Client$', {
|
|
|
|
'amd64': {
|
2016-02-17 13:35:28 +00:00
|
|
|
'kickstart': 'test.ks',
|
|
|
|
'ksurl': 'https://git.example.com/kickstarts.git?#HEAD',
|
2016-02-11 10:54:30 +00:00
|
|
|
'additional_repos': ['http://example.com/repo/'],
|
2016-02-22 07:48:12 +00:00
|
|
|
'repo_from': ['Everything'],
|
2016-02-11 10:54:30 +00:00
|
|
|
'type': 'appliance',
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
})
|
|
|
|
|
2016-02-17 13:35:28 +00:00
|
|
|
resolve_git_url.return_value = 'https://git.example.com/kickstarts.git?#CAFEBABE'
|
2016-02-11 10:54:30 +00:00
|
|
|
|
|
|
|
phase = LiveImagesPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertTrue(phase.pool.add.called)
|
|
|
|
self.maxDiff = None
|
|
|
|
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
|
|
|
|
[mock.call((compose,
|
2016-02-17 13:35:28 +00:00
|
|
|
{'ks_file': 'test.ks',
|
2016-02-11 10:54:30 +00:00
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/image_dir/amd64/Client',
|
2016-02-11 10:54:30 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
2016-02-22 09:13:04 +00:00
|
|
|
'filename': 'image-name',
|
2016-02-11 10:54:30 +00:00
|
|
|
'version': None,
|
|
|
|
'specfile': None,
|
2016-02-12 12:00:19 +00:00
|
|
|
'sign': False,
|
2016-02-17 13:35:28 +00:00
|
|
|
'type': 'appliance',
|
2016-02-22 07:38:19 +00:00
|
|
|
'release': None,
|
2016-02-17 13:35:28 +00:00
|
|
|
'ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE'},
|
2016-01-15 12:19:50 +00:00
|
|
|
compose.variants['Client'],
|
|
|
|
'amd64'))])
|
2016-02-17 13:35:28 +00:00
|
|
|
self.assertEqual(resolve_git_url.mock_calls,
|
|
|
|
[mock.call('https://git.example.com/kickstarts.git?#HEAD')])
|
2016-01-15 12:19:50 +00:00
|
|
|
|
|
|
|
|
2016-01-18 13:42:38 +00:00
|
|
|
class TestCreateLiveImageThread(unittest.TestCase):
|
|
|
|
|
2016-02-22 10:19:11 +00:00
|
|
|
@mock.patch('pungi.phases.live_images.Image')
|
2016-01-18 13:42:38 +00:00
|
|
|
@mock.patch('shutil.copy2')
|
|
|
|
@mock.patch('pungi.phases.live_images.run')
|
|
|
|
@mock.patch('pungi.phases.live_images.KojiWrapper')
|
2016-02-22 10:19:11 +00:00
|
|
|
def test_process(self, KojiWrapper, run, copy2, Image):
|
2016-01-18 13:42:38 +00:00
|
|
|
compose = _DummyCompose({'koji_profile': 'koji'})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cmd = {
|
|
|
|
'ks_file': '/path/to/ks_file',
|
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/iso_dir/amd64/Client',
|
2016-01-18 13:42:38 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
2016-02-22 09:13:04 +00:00
|
|
|
'filename': 'image-name',
|
2016-01-18 13:42:38 +00:00
|
|
|
'version': None,
|
2016-02-11 10:54:30 +00:00
|
|
|
'specfile': None,
|
|
|
|
'type': 'live',
|
2016-02-17 13:35:28 +00:00
|
|
|
'ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE',
|
2016-02-22 07:38:19 +00:00
|
|
|
'release': None,
|
2016-02-11 10:54:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
koji_wrapper = KojiWrapper.return_value
|
|
|
|
koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...'
|
|
|
|
koji_wrapper.run_blocking_cmd.return_value = {
|
|
|
|
'retcode': 0,
|
|
|
|
'output': 'some output',
|
|
|
|
'task_id': 123
|
|
|
|
}
|
2016-02-22 08:36:25 +00:00
|
|
|
koji_wrapper.get_image_path.return_value = ['/path/to/image.iso']
|
2016-02-11 10:54:30 +00:00
|
|
|
|
|
|
|
t = CreateLiveImageThread(pool)
|
2016-02-22 10:19:11 +00:00
|
|
|
with mock.patch('os.stat') as stat:
|
|
|
|
with mock.patch('os.path.getsize') as getsize:
|
|
|
|
with mock.patch('time.sleep'):
|
|
|
|
getsize.return_value = 1024
|
|
|
|
stat.return_value.st_mtime = 13579
|
|
|
|
t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1)
|
2016-02-11 10:54:30 +00:00
|
|
|
|
|
|
|
self.assertEqual(koji_wrapper.run_blocking_cmd.mock_calls,
|
|
|
|
[mock.call('koji spin-livecd ...', log_file='/a/b/log/log_file')])
|
|
|
|
self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)])
|
|
|
|
self.assertEqual(copy2.mock_calls,
|
2016-02-22 10:19:11 +00:00
|
|
|
[mock.call('/path/to/image.iso', '/top/iso_dir/amd64/Client/image-name')])
|
2016-02-11 10:54:30 +00:00
|
|
|
|
|
|
|
write_manifest_cmd = ' && '.join([
|
2016-02-22 10:19:11 +00:00
|
|
|
'cd /top/iso_dir/amd64/Client',
|
2016-02-11 10:54:30 +00:00
|
|
|
'isoinfo -R -f -i image-name | grep -v \'/TRANS.TBL$\' | sort >> image-name.manifest'
|
|
|
|
])
|
|
|
|
self.assertEqual(run.mock_calls, [mock.call(write_manifest_cmd)])
|
|
|
|
self.assertEqual(koji_wrapper.get_create_image_cmd.mock_calls,
|
|
|
|
[mock.call('Test', '20151203.0.t', 'rhel-7.0-candidate',
|
|
|
|
'amd64', '/path/to/ks_file',
|
|
|
|
['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
image_type='live',
|
|
|
|
archive=False,
|
|
|
|
specfile=None,
|
2016-02-17 13:35:28 +00:00
|
|
|
wait=True,
|
2016-02-22 07:38:19 +00:00
|
|
|
release=None,
|
2016-02-17 13:35:28 +00:00
|
|
|
ksurl='https://git.example.com/kickstarts.git?#CAFEBABE')])
|
2016-02-22 10:19:11 +00:00
|
|
|
self.assertEqual(Image.return_value.type, 'live')
|
|
|
|
self.assertEqual(Image.return_value.format, 'iso')
|
|
|
|
self.assertEqual(Image.return_value.path, 'iso_dir/amd64/Client/image-name')
|
|
|
|
self.assertEqual(Image.return_value.size, 1024)
|
|
|
|
self.assertEqual(Image.return_value.mtime, 13579)
|
|
|
|
self.assertEqual(Image.return_value.arch, 'amd64')
|
|
|
|
self.assertEqual(Image.return_value.disc_number, 1)
|
|
|
|
self.assertEqual(Image.return_value.disc_count, 1)
|
|
|
|
self.assertTrue(Image.return_value.bootable)
|
|
|
|
self.assertEqual(compose.im.add.mock_calls,
|
|
|
|
[mock.call(variant='Client', arch='amd64', image=Image.return_value)])
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.live_images.Image')
|
2016-02-22 09:13:04 +00:00
|
|
|
@mock.patch('shutil.copy2')
|
|
|
|
@mock.patch('pungi.phases.live_images.run')
|
|
|
|
@mock.patch('pungi.phases.live_images.KojiWrapper')
|
2016-02-22 10:19:11 +00:00
|
|
|
def test_process_no_rename(self, KojiWrapper, run, copy2, Image):
|
2016-02-22 09:13:04 +00:00
|
|
|
compose = _DummyCompose({'koji_profile': 'koji'})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cmd = {
|
|
|
|
'ks_file': '/path/to/ks_file',
|
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/iso_dir/amd64/Client',
|
2016-02-22 09:13:04 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
|
|
|
'filename': None,
|
|
|
|
'version': None,
|
|
|
|
'specfile': None,
|
|
|
|
'type': 'live',
|
|
|
|
'ksurl': 'https://git.example.com/kickstarts.git?#CAFEBABE',
|
|
|
|
'release': None,
|
|
|
|
}
|
|
|
|
|
|
|
|
koji_wrapper = KojiWrapper.return_value
|
|
|
|
koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...'
|
|
|
|
koji_wrapper.run_blocking_cmd.return_value = {
|
|
|
|
'retcode': 0,
|
|
|
|
'output': 'some output',
|
|
|
|
'task_id': 123
|
|
|
|
}
|
|
|
|
koji_wrapper.get_image_path.return_value = ['/path/to/image.iso']
|
|
|
|
|
|
|
|
t = CreateLiveImageThread(pool)
|
2016-02-22 10:19:11 +00:00
|
|
|
with mock.patch('os.stat') as stat:
|
|
|
|
with mock.patch('os.path.getsize') as getsize:
|
|
|
|
getsize.return_value = 1024
|
|
|
|
getsize.return_value = 1024
|
|
|
|
getsize.return_value = 1024
|
|
|
|
getsize.return_value = 1024
|
|
|
|
with mock.patch('time.sleep'):
|
|
|
|
getsize.return_value = 1024
|
|
|
|
stat.return_value.st_mtime = 13579
|
|
|
|
t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1)
|
2016-02-22 09:13:04 +00:00
|
|
|
|
|
|
|
self.assertEqual(koji_wrapper.run_blocking_cmd.mock_calls,
|
|
|
|
[mock.call('koji spin-livecd ...', log_file='/a/b/log/log_file')])
|
|
|
|
self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)])
|
|
|
|
self.assertEqual(copy2.mock_calls,
|
2016-02-22 10:19:11 +00:00
|
|
|
[mock.call('/path/to/image.iso', '/top/iso_dir/amd64/Client/image.iso')])
|
2016-02-22 09:13:04 +00:00
|
|
|
|
|
|
|
write_manifest_cmd = ' && '.join([
|
2016-02-22 10:19:11 +00:00
|
|
|
'cd /top/iso_dir/amd64/Client',
|
2016-02-22 09:13:04 +00:00
|
|
|
'isoinfo -R -f -i image.iso | grep -v \'/TRANS.TBL$\' | sort >> image.iso.manifest'
|
|
|
|
])
|
|
|
|
self.assertEqual(run.mock_calls, [mock.call(write_manifest_cmd)])
|
|
|
|
self.assertEqual(koji_wrapper.get_create_image_cmd.mock_calls,
|
|
|
|
[mock.call('Test', '20151203.0.t', 'rhel-7.0-candidate',
|
|
|
|
'amd64', '/path/to/ks_file',
|
|
|
|
['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
image_type='live',
|
|
|
|
archive=False,
|
|
|
|
specfile=None,
|
|
|
|
wait=True,
|
|
|
|
release=None,
|
|
|
|
ksurl='https://git.example.com/kickstarts.git?#CAFEBABE')])
|
|
|
|
|
2016-02-22 10:19:11 +00:00
|
|
|
self.assertEqual(Image.return_value.type, 'live')
|
|
|
|
self.assertEqual(Image.return_value.format, 'iso')
|
|
|
|
self.assertEqual(Image.return_value.path, 'iso_dir/amd64/Client/image.iso')
|
|
|
|
self.assertEqual(Image.return_value.size, 1024)
|
|
|
|
self.assertEqual(Image.return_value.mtime, 13579)
|
|
|
|
self.assertEqual(Image.return_value.arch, 'amd64')
|
|
|
|
self.assertEqual(Image.return_value.disc_number, 1)
|
|
|
|
self.assertEqual(Image.return_value.disc_count, 1)
|
|
|
|
self.assertTrue(Image.return_value.bootable)
|
|
|
|
self.assertEqual(compose.im.add.mock_calls,
|
|
|
|
[mock.call(variant='Client', arch='amd64', image=Image.return_value)])
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.live_images.Image')
|
2016-02-11 10:54:30 +00:00
|
|
|
@mock.patch('shutil.copy2')
|
|
|
|
@mock.patch('pungi.phases.live_images.run')
|
|
|
|
@mock.patch('pungi.phases.live_images.KojiWrapper')
|
2016-02-22 10:19:11 +00:00
|
|
|
def test_process_applicance(self, KojiWrapper, run, copy2, Image):
|
2016-02-11 10:54:30 +00:00
|
|
|
compose = _DummyCompose({'koji_profile': 'koji'})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cmd = {
|
|
|
|
'ks_file': '/path/to/ks_file',
|
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/iso_dir/amd64/Client',
|
2016-02-11 10:54:30 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
2016-02-22 09:13:04 +00:00
|
|
|
'filename': 'image-name',
|
2016-02-11 10:54:30 +00:00
|
|
|
'version': None,
|
|
|
|
'specfile': None,
|
|
|
|
'type': 'appliance',
|
2016-02-17 13:35:28 +00:00
|
|
|
'ksurl': None,
|
2016-02-22 07:38:19 +00:00
|
|
|
'release': None,
|
2016-01-18 13:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
koji_wrapper = KojiWrapper.return_value
|
|
|
|
koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...'
|
2016-01-28 13:58:24 +00:00
|
|
|
koji_wrapper.run_blocking_cmd.return_value = {
|
2016-01-18 13:42:38 +00:00
|
|
|
'retcode': 0,
|
|
|
|
'output': 'some output',
|
|
|
|
'task_id': 123
|
|
|
|
}
|
2016-02-22 10:19:11 +00:00
|
|
|
koji_wrapper.get_image_path.return_value = ['/path/to/image.raw.xz']
|
2016-01-18 13:42:38 +00:00
|
|
|
|
|
|
|
t = CreateLiveImageThread(pool)
|
2016-02-22 10:19:11 +00:00
|
|
|
with mock.patch('os.stat') as stat:
|
|
|
|
with mock.patch('os.path.getsize') as getsize:
|
|
|
|
with mock.patch('time.sleep'):
|
|
|
|
getsize.return_value = 1024
|
|
|
|
stat.return_value.st_mtime = 13579
|
|
|
|
t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1)
|
2016-01-18 13:42:38 +00:00
|
|
|
|
2016-01-28 13:58:24 +00:00
|
|
|
self.assertEqual(koji_wrapper.run_blocking_cmd.mock_calls,
|
2016-01-18 13:42:38 +00:00
|
|
|
[mock.call('koji spin-livecd ...', log_file='/a/b/log/log_file')])
|
|
|
|
self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)])
|
|
|
|
self.assertEqual(copy2.mock_calls,
|
2016-02-22 10:19:11 +00:00
|
|
|
[mock.call('/path/to/image.raw.xz', '/top/iso_dir/amd64/Client/image-name')])
|
2016-01-18 13:42:38 +00:00
|
|
|
|
|
|
|
write_manifest_cmd = ' && '.join([
|
2016-02-22 10:19:11 +00:00
|
|
|
'cd /top/iso_dir/amd64/Client',
|
2016-01-18 13:42:38 +00:00
|
|
|
'isoinfo -R -f -i image-name | grep -v \'/TRANS.TBL$\' | sort >> image-name.manifest'
|
|
|
|
])
|
|
|
|
self.assertEqual(run.mock_calls, [mock.call(write_manifest_cmd)])
|
2016-02-11 10:54:30 +00:00
|
|
|
self.assertEqual(koji_wrapper.get_create_image_cmd.mock_calls,
|
|
|
|
[mock.call('Test', '20151203.0.t', 'rhel-7.0-candidate',
|
|
|
|
'amd64', '/path/to/ks_file',
|
|
|
|
['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
image_type='appliance',
|
|
|
|
archive=False,
|
|
|
|
specfile=None,
|
2016-02-17 13:35:28 +00:00
|
|
|
wait=True,
|
2016-02-22 07:38:19 +00:00
|
|
|
release=None,
|
2016-02-17 13:35:28 +00:00
|
|
|
ksurl=None)])
|
2016-01-18 13:42:38 +00:00
|
|
|
|
2016-02-22 10:19:11 +00:00
|
|
|
self.assertEqual(Image.return_value.type, 'appliance')
|
|
|
|
self.assertEqual(Image.return_value.format, 'raw.xz')
|
|
|
|
self.assertEqual(Image.return_value.path, 'iso_dir/amd64/Client/image-name')
|
|
|
|
self.assertEqual(Image.return_value.size, 1024)
|
|
|
|
self.assertEqual(Image.return_value.mtime, 13579)
|
|
|
|
self.assertEqual(Image.return_value.arch, 'amd64')
|
|
|
|
self.assertEqual(Image.return_value.disc_number, 1)
|
|
|
|
self.assertEqual(Image.return_value.disc_count, 1)
|
|
|
|
self.assertTrue(Image.return_value.bootable)
|
|
|
|
self.assertEqual(compose.im.add.mock_calls,
|
|
|
|
[mock.call(variant='Client', arch='amd64', image=Image.return_value)])
|
|
|
|
|
2016-01-18 13:42:38 +00:00
|
|
|
@mock.patch('shutil.copy2')
|
|
|
|
@mock.patch('pungi.phases.live_images.run')
|
|
|
|
@mock.patch('pungi.phases.live_images.KojiWrapper')
|
|
|
|
def test_process_handles_fail(self, KojiWrapper, run, copy2):
|
|
|
|
compose = _DummyCompose({
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
'failable_deliverables': [('^.+$', {'*': ['live']})],
|
|
|
|
})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cmd = {
|
|
|
|
'ks_file': '/path/to/ks_file',
|
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/iso_dir/amd64/Client',
|
2016-01-18 13:42:38 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
2016-02-22 09:13:04 +00:00
|
|
|
'filename': 'image-name',
|
2016-01-18 13:42:38 +00:00
|
|
|
'version': None,
|
2016-02-17 13:35:28 +00:00
|
|
|
'specfile': None,
|
|
|
|
'ksurl': None,
|
2016-01-18 13:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
koji_wrapper = KojiWrapper.return_value
|
|
|
|
koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...'
|
2016-01-28 13:58:24 +00:00
|
|
|
koji_wrapper.run_blocking_cmd.return_value = {
|
2016-01-18 13:42:38 +00:00
|
|
|
'retcode': 1,
|
|
|
|
'output': 'some output',
|
|
|
|
'task_id': 123
|
|
|
|
}
|
|
|
|
|
|
|
|
t = CreateLiveImageThread(pool)
|
|
|
|
with mock.patch('time.sleep'):
|
|
|
|
t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1)
|
|
|
|
|
|
|
|
@mock.patch('shutil.copy2')
|
|
|
|
@mock.patch('pungi.phases.live_images.run')
|
|
|
|
@mock.patch('pungi.phases.live_images.KojiWrapper')
|
|
|
|
def test_process_handles_exception(self, KojiWrapper, run, copy2):
|
|
|
|
compose = _DummyCompose({
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
'failable_deliverables': [('^.+$', {'*': ['live']})],
|
|
|
|
})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cmd = {
|
|
|
|
'ks_file': '/path/to/ks_file',
|
|
|
|
'build_arch': 'amd64',
|
2016-02-22 10:19:11 +00:00
|
|
|
'dest_dir': '/top/iso_dir/amd64/Client',
|
2016-01-18 13:42:38 +00:00
|
|
|
'scratch': False,
|
|
|
|
'repos': ['/repo/amd64/Client',
|
|
|
|
'http://example.com/repo/',
|
|
|
|
'/repo/amd64/Everything'],
|
|
|
|
'label': '',
|
|
|
|
'name': None,
|
2016-02-22 10:19:11 +00:00
|
|
|
'filename': 'image-name',
|
2016-01-18 13:42:38 +00:00
|
|
|
'version': None,
|
2016-02-17 13:35:28 +00:00
|
|
|
'specfile': None,
|
|
|
|
'ksurl': None,
|
2016-01-18 13:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def boom(*args, **kwargs):
|
|
|
|
raise RuntimeError('BOOM')
|
|
|
|
|
|
|
|
koji_wrapper = KojiWrapper.return_value
|
|
|
|
koji_wrapper.get_create_image_cmd.side_effect = boom
|
|
|
|
|
|
|
|
t = CreateLiveImageThread(pool)
|
|
|
|
with mock.patch('time.sleep'):
|
|
|
|
t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1)
|
|
|
|
|
|
|
|
|
2016-01-15 12:19:50 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|