2016-01-05 08:27:20 +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__), ".."))
|
|
|
|
|
|
|
|
from pungi.phases.image_build import ImageBuildPhase, CreateImageBuildThread
|
2016-02-22 14:58:34 +00:00
|
|
|
from tests.helpers import DummyCompose, PungiTestCase
|
2016-01-11 16:14:51 +00:00
|
|
|
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2016-02-11 14:15:36 +00:00
|
|
|
class TestImageBuildPhase(PungiTestCase):
|
2016-01-05 08:27:20 +00:00
|
|
|
|
|
|
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
|
|
|
def test_image_build(self, ThreadPool):
|
2016-02-22 14:58:34 +00:00
|
|
|
compose = DummyCompose(self.topdir, {
|
2016-01-05 08:27:20 +00:00
|
|
|
'image_build': {
|
|
|
|
'^Client|Server$': [
|
|
|
|
{
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
|
|
|
'format': [('docker', 'tar.xz')],
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'target': 'f24',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'kickstart': "fedora-docker-base.ks",
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
'disk_size': 3
|
|
|
|
}
|
2016-01-05 08:27:20 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = ImageBuildPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
2016-02-11 12:22:03 +00:00
|
|
|
self.maxDiff = None
|
2016-01-05 08:27:20 +00:00
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertTrue(phase.pool.add.called)
|
|
|
|
client_args = {
|
|
|
|
"format": [('docker', 'tar.xz')],
|
|
|
|
"image_conf": {
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
2016-02-11 14:15:36 +00:00
|
|
|
'install_tree': self.topdir + '/compose/Client/$arch/os',
|
2016-02-11 12:22:03 +00:00
|
|
|
'kickstart': 'fedora-docker-base.ks',
|
|
|
|
'format': 'docker',
|
2016-02-11 14:15:36 +00:00
|
|
|
'repo': self.topdir + '/compose/Client/$arch/os',
|
2016-02-11 12:22:03 +00:00
|
|
|
'variant': compose.variants['Client'],
|
|
|
|
'target': 'f24',
|
|
|
|
'disk_size': 3,
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'arches': 'amd64',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
}
|
2016-01-05 08:27:20 +00:00
|
|
|
},
|
2016-02-11 14:15:36 +00:00
|
|
|
"conf_file": self.topdir + '/work/image-build/Client/docker_Fedora-Docker-Base.cfg',
|
|
|
|
"image_dir": self.topdir + '/compose/Client/%(arch)s/images',
|
|
|
|
"relative_image_dir": 'Client/%(arch)s/images',
|
2016-01-05 08:27:20 +00:00
|
|
|
"link_type": 'hardlink-or-copy',
|
2016-01-26 11:46:50 +00:00
|
|
|
"scratch": False,
|
2016-01-05 08:27:20 +00:00
|
|
|
}
|
|
|
|
server_args = {
|
|
|
|
"format": [('docker', 'tar.xz')],
|
|
|
|
"image_conf": {
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
2016-02-11 14:15:36 +00:00
|
|
|
'install_tree': self.topdir + '/compose/Server/$arch/os',
|
2016-02-11 12:22:03 +00:00
|
|
|
'kickstart': 'fedora-docker-base.ks',
|
|
|
|
'format': 'docker',
|
2016-02-11 14:15:36 +00:00
|
|
|
'repo': self.topdir + '/compose/Server/$arch/os',
|
2016-02-11 12:22:03 +00:00
|
|
|
'variant': compose.variants['Server'],
|
|
|
|
'target': 'f24',
|
|
|
|
'disk_size': 3,
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'arches': 'amd64,x86_64',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
}
|
2016-01-05 08:27:20 +00:00
|
|
|
},
|
2016-02-11 14:15:36 +00:00
|
|
|
"conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg',
|
|
|
|
"image_dir": self.topdir + '/compose/Server/%(arch)s/images',
|
|
|
|
"relative_image_dir": 'Server/%(arch)s/images',
|
2016-01-05 08:27:20 +00:00
|
|
|
"link_type": 'hardlink-or-copy',
|
2016-01-26 11:46:50 +00:00
|
|
|
"scratch": False,
|
2016-01-05 08:27:20 +00:00
|
|
|
}
|
2016-02-11 14:15:36 +00:00
|
|
|
self.maxDiff = None
|
2016-01-05 08:27:20 +00:00
|
|
|
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
|
|
|
|
[mock.call((compose, client_args)),
|
|
|
|
mock.call((compose, server_args))])
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
|
|
|
def test_image_build_filter_all_variants(self, ThreadPool):
|
2016-02-22 14:58:34 +00:00
|
|
|
compose = DummyCompose(self.topdir, {
|
2016-01-05 08:27:20 +00:00
|
|
|
'image_build': {
|
|
|
|
'^Client|Server$': [
|
|
|
|
{
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
|
|
|
'format': [('docker', 'tar.xz')],
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'target': 'f24',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'kickstart': "fedora-docker-base.ks",
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
'disk_size': 3,
|
|
|
|
'arches': ['non-existing'],
|
|
|
|
}
|
2016-01-05 08:27:20 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = ImageBuildPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertFalse(phase.pool.add.called)
|
|
|
|
self.assertFalse(phase.pool.queue_put.called)
|
|
|
|
|
2016-01-08 12:37:09 +00:00
|
|
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
|
|
|
def test_image_build_set_install_tree(self, ThreadPool):
|
2016-02-22 14:58:34 +00:00
|
|
|
compose = DummyCompose(self.topdir, {
|
2016-01-08 12:37:09 +00:00
|
|
|
'image_build': {
|
|
|
|
'^Server$': [
|
|
|
|
{
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
|
|
|
'format': [('docker', 'tar.xz')],
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'target': 'f24',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'kickstart': "fedora-docker-base.ks",
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
'disk_size': 3,
|
|
|
|
'arches': ['x86_64'],
|
|
|
|
'install_tree_from': 'Everything',
|
|
|
|
}
|
2016-01-08 12:37:09 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = ImageBuildPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertTrue(phase.pool.add.called)
|
|
|
|
|
|
|
|
self.assertTrue(phase.pool.queue_put.called_once)
|
|
|
|
args, kwargs = phase.pool.queue_put.call_args
|
|
|
|
self.assertEqual(args[0][0], compose)
|
|
|
|
self.maxDiff = None
|
|
|
|
self.assertDictEqual(args[0][1], {
|
|
|
|
"format": [('docker', 'tar.xz')],
|
|
|
|
"image_conf": {
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
2016-02-11 14:15:36 +00:00
|
|
|
'install_tree': self.topdir + '/compose/Everything/$arch/os',
|
2016-02-11 12:22:03 +00:00
|
|
|
'kickstart': 'fedora-docker-base.ks',
|
|
|
|
'format': 'docker',
|
2016-02-11 14:15:36 +00:00
|
|
|
'repo': self.topdir + '/compose/Server/$arch/os',
|
2016-02-11 12:22:03 +00:00
|
|
|
'variant': compose.variants['Server'],
|
|
|
|
'target': 'f24',
|
|
|
|
'disk_size': 3,
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'arches': 'x86_64',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
}
|
2016-01-08 12:37:09 +00:00
|
|
|
},
|
2016-02-11 14:15:36 +00:00
|
|
|
"conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg',
|
|
|
|
"image_dir": self.topdir + '/compose/Server/%(arch)s/images',
|
|
|
|
"relative_image_dir": 'Server/%(arch)s/images',
|
2016-01-11 08:03:04 +00:00
|
|
|
"link_type": 'hardlink-or-copy',
|
2016-01-26 11:46:50 +00:00
|
|
|
"scratch": False,
|
2016-01-11 08:03:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
|
|
|
def test_image_build_set_extra_repos(self, ThreadPool):
|
2016-02-22 14:58:34 +00:00
|
|
|
compose = DummyCompose(self.topdir, {
|
2016-01-11 08:03:04 +00:00
|
|
|
'image_build': {
|
|
|
|
'^Server$': [
|
|
|
|
{
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
|
|
|
'format': [('docker', 'tar.xz')],
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'target': 'f24',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'kickstart': "fedora-docker-base.ks",
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
'disk_size': 3,
|
|
|
|
'arches': ['x86_64'],
|
|
|
|
'repo_from': 'Everything',
|
|
|
|
}
|
2016-01-11 08:03:04 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = ImageBuildPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertTrue(phase.pool.add.called)
|
|
|
|
|
|
|
|
self.assertTrue(phase.pool.queue_put.called_once)
|
|
|
|
args, kwargs = phase.pool.queue_put.call_args
|
|
|
|
self.assertEqual(args[0][0], compose)
|
|
|
|
self.maxDiff = None
|
|
|
|
self.assertDictEqual(args[0][1], {
|
|
|
|
"format": [('docker', 'tar.xz')],
|
|
|
|
"image_conf": {
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
2016-02-11 14:15:36 +00:00
|
|
|
'install_tree': self.topdir + '/compose/Server/$arch/os',
|
2016-02-11 12:22:03 +00:00
|
|
|
'kickstart': 'fedora-docker-base.ks',
|
|
|
|
'format': 'docker',
|
2016-02-11 14:15:36 +00:00
|
|
|
'repo': ','.join([self.topdir + '/compose/Everything/$arch/os',
|
|
|
|
self.topdir + '/compose/Server/$arch/os']),
|
2016-02-11 12:22:03 +00:00
|
|
|
'variant': compose.variants['Server'],
|
|
|
|
'target': 'f24',
|
|
|
|
'disk_size': 3,
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'arches': 'x86_64',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
}
|
2016-01-11 08:03:04 +00:00
|
|
|
},
|
2016-02-11 14:15:36 +00:00
|
|
|
"conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg',
|
|
|
|
"image_dir": self.topdir + '/compose/Server/%(arch)s/images',
|
|
|
|
"relative_image_dir": 'Server/%(arch)s/images',
|
2016-01-08 12:37:09 +00:00
|
|
|
"link_type": 'hardlink-or-copy',
|
2016-01-26 11:46:50 +00:00
|
|
|
"scratch": False,
|
2016-01-08 12:37:09 +00:00
|
|
|
})
|
|
|
|
|
2016-01-21 13:30:44 +00:00
|
|
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
|
|
|
def test_image_build_create_release(self, ThreadPool):
|
2016-02-22 14:58:34 +00:00
|
|
|
compose = DummyCompose(self.topdir, {
|
2016-01-21 13:30:44 +00:00
|
|
|
'image_build': {
|
|
|
|
'^Server$': [
|
|
|
|
{
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
|
|
|
'format': [('docker', 'tar.xz')],
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'target': 'f24',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'kickstart': "fedora-docker-base.ks",
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
'disk_size': 3,
|
|
|
|
'arches': ['x86_64'],
|
|
|
|
'release': None,
|
|
|
|
}
|
2016-01-21 13:30:44 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = ImageBuildPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertTrue(phase.pool.add.called)
|
|
|
|
|
|
|
|
self.assertTrue(phase.pool.queue_put.called_once)
|
|
|
|
args, kwargs = phase.pool.queue_put.call_args
|
2016-02-11 12:22:03 +00:00
|
|
|
self.assertEqual(args[0][1].get('image_conf', {}).get('image-build', {}).get('release'),
|
2016-01-21 13:30:44 +00:00
|
|
|
'20151203.0')
|
|
|
|
|
2016-01-26 11:46:50 +00:00
|
|
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
|
|
|
def test_image_build_scratch_build(self, ThreadPool):
|
2016-02-22 14:58:34 +00:00
|
|
|
compose = DummyCompose(self.topdir, {
|
2016-01-26 11:46:50 +00:00
|
|
|
'image_build': {
|
|
|
|
'^Server$': [
|
|
|
|
{
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
|
|
|
'format': [('docker', 'tar.xz')],
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'target': 'f24',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'kickstart': "fedora-docker-base.ks",
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
'disk_size': 3,
|
|
|
|
'arches': ['x86_64'],
|
|
|
|
'scratch': True,
|
|
|
|
}
|
2016-01-26 11:46:50 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'koji_profile': 'koji',
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = ImageBuildPhase(compose)
|
|
|
|
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
# assert at least one thread was started
|
|
|
|
self.assertTrue(phase.pool.add.called)
|
|
|
|
|
|
|
|
self.assertTrue(phase.pool.queue_put.called_once)
|
|
|
|
args, kwargs = phase.pool.queue_put.call_args
|
|
|
|
self.assertTrue(args[0][1].get('scratch'))
|
|
|
|
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2016-02-11 14:15:36 +00:00
|
|
|
class TestCreateImageBuildThread(PungiTestCase):
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2016-02-11 14:15:36 +00:00
|
|
|
@mock.patch('pungi.phases.image_build.get_mtime')
|
|
|
|
@mock.patch('pungi.phases.image_build.get_file_size')
|
2016-01-05 08:27:20 +00:00
|
|
|
@mock.patch('pungi.phases.image_build.KojiWrapper')
|
|
|
|
@mock.patch('pungi.phases.image_build.Linker')
|
2016-02-11 14:15:36 +00:00
|
|
|
def test_process(self, Linker, KojiWrapper, get_file_size, get_mtime):
|
2016-02-22 14:58:34 +00:00
|
|
|
compose = DummyCompose(self.topdir, {
|
2016-01-05 08:27:20 +00:00
|
|
|
'koji_profile': 'koji'
|
|
|
|
})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cmd = {
|
|
|
|
"format": [('docker', 'tar.xz'), ('qcow2', 'qcow2')],
|
|
|
|
"image_conf": {
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
|
|
|
'install_tree': '/ostree/$arch/Client',
|
|
|
|
'kickstart': 'fedora-docker-base.ks',
|
|
|
|
'format': 'docker',
|
|
|
|
'repo': '/ostree/$arch/Client',
|
|
|
|
'variant': compose.variants['Client'],
|
|
|
|
'target': 'f24',
|
|
|
|
'disk_size': 3,
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'arches': 'amd64,x86_64',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
}
|
2016-01-05 08:27:20 +00:00
|
|
|
},
|
|
|
|
"conf_file": 'amd64,x86_64-Client-Fedora-Docker-Base-docker',
|
2016-02-11 14:15:36 +00:00
|
|
|
"image_dir": self.topdir + '/compose/Client/%(arch)s/images',
|
2016-01-05 08:27:20 +00:00
|
|
|
"relative_image_dir": 'image_dir/Client/%(arch)s',
|
|
|
|
"link_type": 'hardlink-or-copy',
|
2016-01-26 11:46:50 +00:00
|
|
|
"scratch": False,
|
2016-01-05 08:27:20 +00:00
|
|
|
}
|
|
|
|
koji_wrapper = KojiWrapper.return_value
|
2016-01-28 13:58:24 +00:00
|
|
|
koji_wrapper.run_blocking_cmd.return_value = {
|
2016-01-05 08:27:20 +00:00
|
|
|
"retcode": 0,
|
|
|
|
"output": None,
|
|
|
|
"task_id": 1234,
|
|
|
|
}
|
2016-01-28 13:58:24 +00:00
|
|
|
koji_wrapper.get_image_paths.return_value = {
|
2016-01-05 08:27:20 +00:00
|
|
|
'amd64': [
|
|
|
|
'/koji/task/1235/tdl-amd64.xml',
|
|
|
|
'/koji/task/1235/Fedora-Docker-Base-20160103.amd64.qcow2',
|
|
|
|
'/koji/task/1235/Fedora-Docker-Base-20160103.amd64.tar.xz'
|
|
|
|
],
|
|
|
|
'x86_64': [
|
|
|
|
'/koji/task/1235/tdl-x86_64.xml',
|
|
|
|
'/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.qcow2',
|
|
|
|
'/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.tar.xz'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
linker = Linker.return_value
|
2016-02-11 14:15:36 +00:00
|
|
|
get_file_size.return_value = 1024
|
|
|
|
get_mtime.return_value = 13579
|
2016-01-05 08:27:20 +00:00
|
|
|
|
|
|
|
t = CreateImageBuildThread(pool)
|
2016-02-11 14:15:36 +00:00
|
|
|
with mock.patch('time.sleep'):
|
|
|
|
t.process((compose, cmd), 1)
|
2016-01-05 08:27:20 +00:00
|
|
|
|
|
|
|
self.assertItemsEqual(
|
|
|
|
linker.mock_calls,
|
|
|
|
[mock.call('/koji/task/1235/Fedora-Docker-Base-20160103.amd64.qcow2',
|
2016-02-11 14:15:36 +00:00
|
|
|
self.topdir + '/compose/Client/amd64/images/Fedora-Docker-Base-20160103.amd64.qcow2',
|
2016-01-05 08:27:20 +00:00
|
|
|
link_type='hardlink-or-copy'),
|
|
|
|
mock.call('/koji/task/1235/Fedora-Docker-Base-20160103.amd64.tar.xz',
|
2016-02-11 14:15:36 +00:00
|
|
|
self.topdir + '/compose/Client/amd64/images/Fedora-Docker-Base-20160103.amd64.tar.xz',
|
2016-01-05 08:27:20 +00:00
|
|
|
link_type='hardlink-or-copy'),
|
|
|
|
mock.call('/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.qcow2',
|
2016-02-11 14:15:36 +00:00
|
|
|
self.topdir + '/compose/Client/x86_64/images/Fedora-Docker-Base-20160103.x86_64.qcow2',
|
2016-01-05 08:27:20 +00:00
|
|
|
link_type='hardlink-or-copy'),
|
|
|
|
mock.call('/koji/task/1235/Fedora-Docker-Base-20160103.x86_64.tar.xz',
|
2016-02-11 14:15:36 +00:00
|
|
|
self.topdir + '/compose/Client/x86_64/images/Fedora-Docker-Base-20160103.x86_64.tar.xz',
|
2016-01-05 08:27:20 +00:00
|
|
|
link_type='hardlink-or-copy')])
|
|
|
|
|
|
|
|
image_relative_paths = {
|
|
|
|
'image_dir/Client/amd64/Fedora-Docker-Base-20160103.amd64.qcow2': {
|
|
|
|
'format': 'qcow2',
|
|
|
|
'type': 'qcow2',
|
|
|
|
'arch': 'amd64',
|
|
|
|
},
|
|
|
|
'image_dir/Client/amd64/Fedora-Docker-Base-20160103.amd64.tar.xz': {
|
|
|
|
'format': 'tar.xz',
|
|
|
|
'type': 'docker',
|
|
|
|
'arch': 'amd64',
|
|
|
|
},
|
|
|
|
'image_dir/Client/x86_64/Fedora-Docker-Base-20160103.x86_64.qcow2': {
|
|
|
|
'format': 'qcow2',
|
|
|
|
'type': 'qcow2',
|
|
|
|
'arch': 'x86_64',
|
|
|
|
},
|
|
|
|
'image_dir/Client/x86_64/Fedora-Docker-Base-20160103.x86_64.tar.xz': {
|
|
|
|
'format': 'tar.xz',
|
|
|
|
'type': 'docker',
|
|
|
|
'arch': 'x86_64',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
# Assert there are 4 images added to manifest and the arguments are sane
|
|
|
|
self.assertEqual(len(compose.im.add.call_args_list), 4)
|
|
|
|
for call in compose.im.add.call_args_list:
|
|
|
|
_, kwargs = call
|
|
|
|
image = kwargs['image']
|
|
|
|
self.assertEqual(kwargs['variant'], 'Client')
|
|
|
|
self.assertIn(kwargs['arch'], ('amd64', 'x86_64'))
|
|
|
|
self.assertEqual(kwargs['arch'], image.arch)
|
|
|
|
self.assertIn(image.path, image_relative_paths)
|
|
|
|
data = image_relative_paths.pop(image.path)
|
|
|
|
self.assertEqual(data['format'], image.format)
|
|
|
|
self.assertEqual(data['type'], image.type)
|
|
|
|
|
2016-02-11 14:15:36 +00:00
|
|
|
self.assertTrue(os.path.isdir(self.topdir + '/compose/Client/amd64/images'))
|
|
|
|
self.assertTrue(os.path.isdir(self.topdir + '/compose/Client/x86_64/images'))
|
2016-01-19 07:24:02 +00:00
|
|
|
|
2016-01-11 16:14:51 +00:00
|
|
|
@mock.patch('pungi.phases.image_build.KojiWrapper')
|
|
|
|
@mock.patch('pungi.phases.image_build.Linker')
|
|
|
|
def test_process_handle_fail(self, Linker, KojiWrapper):
|
2016-02-22 14:58:34 +00:00
|
|
|
compose = DummyCompose(self.topdir, {
|
2016-01-11 16:14:51 +00:00
|
|
|
'koji_profile': 'koji',
|
|
|
|
'failable_deliverables': [
|
|
|
|
('^.*$', {
|
|
|
|
'*': ['image-build']
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cmd = {
|
|
|
|
"format": [('docker', 'tar.xz'), ('qcow2', 'qcow2')],
|
|
|
|
"image_conf": {
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
|
|
|
'install_tree': '/ostree/$arch/Client',
|
|
|
|
'kickstart': 'fedora-docker-base.ks',
|
|
|
|
'format': 'docker',
|
|
|
|
'repo': '/ostree/$arch/Client',
|
|
|
|
'variant': compose.variants['Client'],
|
|
|
|
'target': 'f24',
|
|
|
|
'disk_size': 3,
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'arches': 'amd64,x86_64',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
}
|
2016-01-11 16:14:51 +00:00
|
|
|
},
|
|
|
|
"conf_file": 'amd64,x86_64-Client-Fedora-Docker-Base-docker',
|
|
|
|
"image_dir": '/image_dir/Client/%(arch)s',
|
|
|
|
"relative_image_dir": 'image_dir/Client/%(arch)s',
|
|
|
|
"link_type": 'hardlink-or-copy',
|
2016-02-08 09:54:24 +00:00
|
|
|
'scratch': False,
|
2016-01-11 16:14:51 +00:00
|
|
|
}
|
|
|
|
koji_wrapper = KojiWrapper.return_value
|
2016-01-28 13:58:24 +00:00
|
|
|
koji_wrapper.run_blocking_cmd.return_value = {
|
2016-01-11 16:14:51 +00:00
|
|
|
"retcode": 1,
|
|
|
|
"output": None,
|
|
|
|
"task_id": 1234,
|
|
|
|
}
|
|
|
|
|
|
|
|
t = CreateImageBuildThread(pool)
|
|
|
|
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), 1)
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.image_build.KojiWrapper')
|
|
|
|
@mock.patch('pungi.phases.image_build.Linker')
|
|
|
|
def test_process_handle_exception(self, Linker, KojiWrapper):
|
2016-02-22 14:58:34 +00:00
|
|
|
compose = DummyCompose(self.topdir, {
|
2016-01-11 16:14:51 +00:00
|
|
|
'koji_profile': 'koji',
|
|
|
|
'failable_deliverables': [
|
|
|
|
('^.*$', {
|
|
|
|
'*': ['image-build']
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
pool = mock.Mock()
|
|
|
|
cmd = {
|
|
|
|
"format": [('docker', 'tar.xz'), ('qcow2', 'qcow2')],
|
|
|
|
"image_conf": {
|
2016-02-11 12:22:03 +00:00
|
|
|
'image-build': {
|
|
|
|
'install_tree': '/ostree/$arch/Client',
|
|
|
|
'kickstart': 'fedora-docker-base.ks',
|
|
|
|
'format': 'docker',
|
|
|
|
'repo': '/ostree/$arch/Client',
|
|
|
|
'variant': compose.variants['Client'],
|
|
|
|
'target': 'f24',
|
|
|
|
'disk_size': 3,
|
|
|
|
'name': 'Fedora-Docker-Base',
|
|
|
|
'arches': 'amd64,x86_64',
|
|
|
|
'version': 'Rawhide',
|
|
|
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
|
|
|
'distro': 'Fedora-20',
|
|
|
|
}
|
2016-01-11 16:14:51 +00:00
|
|
|
},
|
|
|
|
"conf_file": 'amd64,x86_64-Client-Fedora-Docker-Base-docker',
|
|
|
|
"image_dir": '/image_dir/Client/%(arch)s',
|
|
|
|
"relative_image_dir": 'image_dir/Client/%(arch)s',
|
|
|
|
"link_type": 'hardlink-or-copy',
|
2016-02-08 09:54:24 +00:00
|
|
|
'scratch': False,
|
2016-01-11 16:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def boom(*args, **kwargs):
|
|
|
|
raise RuntimeError('BOOM')
|
|
|
|
|
|
|
|
koji_wrapper = KojiWrapper.return_value
|
2016-01-28 13:58:24 +00:00
|
|
|
koji_wrapper.run_blocking_cmd.side_effect = boom
|
2016-01-11 16:14:51 +00:00
|
|
|
|
|
|
|
t = CreateImageBuildThread(pool)
|
|
|
|
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), 1)
|
|
|
|
|
2016-01-05 08:27:20 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|