2016-02-01 09:50:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mock
|
2016-02-26 09:31:43 +00:00
|
|
|
import os
|
2016-02-11 14:15:36 +00:00
|
|
|
import unittest
|
|
|
|
import tempfile
|
|
|
|
import shutil
|
2016-02-01 09:50:28 +00:00
|
|
|
|
|
|
|
from pungi.util import get_arch_variant_data
|
2016-02-11 14:15:36 +00:00
|
|
|
from pungi import paths
|
|
|
|
|
|
|
|
|
|
|
|
class PungiTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.topdir = tempfile.mkdtemp()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
shutil.rmtree(self.topdir)
|
2016-02-01 09:50:28 +00:00
|
|
|
|
|
|
|
|
2016-02-22 14:58:34 +00:00
|
|
|
class DummyCompose(object):
|
2016-02-11 14:15:36 +00:00
|
|
|
def __init__(self, topdir, config):
|
2016-02-11 15:45:56 +00:00
|
|
|
self.supported = True
|
2016-02-01 09:50:28 +00:00
|
|
|
self.compose_date = '20151203'
|
|
|
|
self.compose_type_suffix = '.t'
|
|
|
|
self.compose_respin = 0
|
|
|
|
self.compose_id = 'Test-20151203.0.t'
|
2016-03-16 07:33:43 +00:00
|
|
|
self.compose_label = None
|
2016-02-01 09:50:28 +00:00
|
|
|
self.ci_base = mock.Mock(
|
|
|
|
release_id='Test-1.0',
|
|
|
|
release=mock.Mock(
|
|
|
|
short='test',
|
|
|
|
version='1.0',
|
2016-02-29 11:58:21 +00:00
|
|
|
is_layered=False,
|
2016-02-01 09:50:28 +00:00
|
|
|
),
|
|
|
|
)
|
2016-02-11 14:15:36 +00:00
|
|
|
self.topdir = topdir
|
2016-02-01 09:50:28 +00:00
|
|
|
self.conf = config
|
2016-02-11 14:15:36 +00:00
|
|
|
self.paths = paths.Paths(self)
|
2016-02-01 09:50:28 +00:00
|
|
|
self._logger = mock.Mock()
|
|
|
|
self.variants = {
|
2016-02-11 14:15:36 +00:00
|
|
|
'Server': mock.Mock(uid='Server', arches=['x86_64', 'amd64'],
|
|
|
|
type='variant', is_empty=False),
|
|
|
|
'Client': mock.Mock(uid='Client', arches=['amd64'],
|
|
|
|
type='variant', is_empty=False),
|
|
|
|
'Everything': mock.Mock(uid='Everything', arches=['x86_64', 'amd64'],
|
|
|
|
type='variant', is_empty=False),
|
2016-02-01 09:50:28 +00:00
|
|
|
}
|
2016-02-26 09:31:43 +00:00
|
|
|
self.log_info = mock.Mock()
|
2016-02-01 09:50:28 +00:00
|
|
|
self.log_error = mock.Mock()
|
2016-02-11 15:45:56 +00:00
|
|
|
self.log_debug = mock.Mock()
|
2016-02-29 08:21:49 +00:00
|
|
|
self.log_warning = mock.Mock()
|
2016-02-01 09:50:28 +00:00
|
|
|
self.get_image_name = mock.Mock(return_value='image-name')
|
|
|
|
self.image = mock.Mock(path='Client/i386/iso/image.iso')
|
|
|
|
self.im = mock.Mock(images={'Client': {'i386': [self.image]}})
|
2016-02-29 11:58:21 +00:00
|
|
|
self.old_composes = []
|
2016-03-10 12:22:11 +00:00
|
|
|
self.config_dir = '/home/releng/config'
|
2016-02-01 09:50:28 +00:00
|
|
|
|
|
|
|
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
|
2016-02-11 15:45:56 +00:00
|
|
|
|
|
|
|
def get_arches(self):
|
|
|
|
result = set()
|
|
|
|
for variant in self.variants.itervalues():
|
|
|
|
result |= set(variant.arches)
|
|
|
|
return result
|
2016-02-26 09:31:43 +00:00
|
|
|
|
|
|
|
|
2016-02-29 12:35:55 +00:00
|
|
|
def touch(path, content=None):
|
2016-02-26 09:31:43 +00:00
|
|
|
"""Helper utility that creates an dummy file in given location. Directories
|
|
|
|
will be created."""
|
2016-02-29 12:35:55 +00:00
|
|
|
content = content or (path + '\n')
|
2016-02-26 09:31:43 +00:00
|
|
|
try:
|
|
|
|
os.makedirs(os.path.dirname(path))
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
with open(path, 'w') as f:
|
2016-02-29 12:35:55 +00:00
|
|
|
f.write(content)
|
2016-02-29 08:21:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def copy_fixture(fixture_name, dest):
|
|
|
|
src = os.path.join(os.path.dirname(__file__), 'fixtures', fixture_name)
|
|
|
|
touch(dest)
|
|
|
|
shutil.copy2(src, dest)
|
2016-03-10 12:22:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def union(*args):
|
|
|
|
"""Create a new dict as a union of all arguments."""
|
|
|
|
res = {}
|
|
|
|
for arg in args:
|
|
|
|
res.update(arg)
|
|
|
|
return res
|