2015-12-10 14:49:00 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mock
|
2016-05-25 11:39:02 +00:00
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
2015-12-10 14:49:00 +00:00
|
|
|
import os
|
2019-10-04 12:45:03 +00:00
|
|
|
import six
|
2015-12-10 14:49:00 +00:00
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
|
|
|
|
from pungi.compose import Compose
|
|
|
|
|
|
|
|
|
2016-03-29 14:07:24 +00:00
|
|
|
class ConfigWrapper(dict):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(ConfigWrapper, self).__init__(*args, **kwargs)
|
|
|
|
self._open_file = '%s/fixtures/config.conf' % os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
|
2015-12-10 14:49:00 +00:00
|
|
|
class ComposeTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.tmp_dir = tempfile.mkdtemp()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
shutil.rmtree(self.tmp_dir)
|
|
|
|
|
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_can_fail(self, ci):
|
|
|
|
conf = {
|
|
|
|
'failable_deliverables': [
|
|
|
|
('^.*$', {
|
|
|
|
'*': ['buildinstall'],
|
|
|
|
'i386': ['buildinstall', 'live', 'iso'],
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
variant = mock.Mock(uid='Server')
|
|
|
|
|
|
|
|
self.assertTrue(compose.can_fail(variant, 'x86_64', 'buildinstall'))
|
|
|
|
self.assertFalse(compose.can_fail(variant, 'x86_64', 'live'))
|
|
|
|
self.assertTrue(compose.can_fail(variant, 'i386', 'live'))
|
|
|
|
|
|
|
|
self.assertFalse(compose.can_fail(None, 'x86_64', 'live'))
|
|
|
|
self.assertTrue(compose.can_fail(None, 'i386', 'live'))
|
|
|
|
|
2016-01-11 16:14:51 +00:00
|
|
|
self.assertTrue(compose.can_fail(variant, '*', 'buildinstall'))
|
|
|
|
self.assertFalse(compose.can_fail(variant, '*', 'live'))
|
|
|
|
|
2016-01-06 11:24:01 +00:00
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_get_image_name(self, ci):
|
|
|
|
conf = {}
|
|
|
|
variant = mock.Mock(uid='Server', type='variant')
|
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.id = 'compose_id'
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'nightly'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
|
|
|
ci.return_value.compose.label = 'RC-1.0'
|
|
|
|
ci.return_value.compose.label_major_version = '1'
|
|
|
|
|
|
|
|
ci.return_value.release.version = '3.0'
|
|
|
|
ci.return_value.release.short = 'rel_short'
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
|
|
|
keys = ['arch', 'compose_id', 'date', 'disc_num', 'disc_type',
|
|
|
|
'label', 'label_major_version', 'release_short', 'respin',
|
|
|
|
'suffix', 'type', 'type_suffix', 'variant', 'version']
|
|
|
|
format = '-'.join(['%(' + k + ')s' for k in keys])
|
|
|
|
name = compose.get_image_name('x86_64', variant, format=format,
|
|
|
|
disc_num=7, disc_type='live', suffix='.iso')
|
|
|
|
|
|
|
|
self.assertEqual(name, '-'.join(['x86_64', 'compose_id', '20160107', '7', 'live',
|
|
|
|
'RC-1.0', '1', 'rel_short', '2', '.iso', 'nightly',
|
|
|
|
'.n', 'Server', '3.0']))
|
|
|
|
|
2018-11-01 09:07:38 +00:00
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_get_image_name_variant_mapping(self, ci):
|
|
|
|
conf = {"image_name_format": {"^Server$": "whatever"}}
|
|
|
|
variant = mock.Mock(uid='Server', type='variant')
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
|
|
|
name = compose.get_image_name(
|
|
|
|
'x86_64', variant, disc_num=7, disc_type='live', suffix='.iso'
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(name, "whatever")
|
|
|
|
|
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_get_image_name_variant_mapping_no_match(self, ci):
|
|
|
|
conf = {"image_name_format": {"^Client$": "whatever"}}
|
|
|
|
variant = mock.Mock(uid='Server', type='variant')
|
|
|
|
ci.return_value.compose.id = 'compose_id'
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
name = compose.get_image_name(
|
|
|
|
'x86_64', variant, disc_num=7, disc_type='live', suffix='.iso'
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(name, "compose_id-Server-x86_64-live7.iso")
|
|
|
|
|
2016-10-17 13:15:01 +00:00
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_get_image_name_layered_product(self, ci):
|
|
|
|
conf = {}
|
|
|
|
variant = mock.Mock(uid='Server-LP', type='layered-product')
|
|
|
|
variant.parent = mock.Mock(uid='Server')
|
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.id = 'compose_id'
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'nightly'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
|
|
|
ci.return_value.compose.label = 'RC-1.0'
|
|
|
|
ci.return_value.compose.label_major_version = '1'
|
|
|
|
|
|
|
|
ci.return_value.release.version = '3.0'
|
|
|
|
ci.return_value.release.short = 'rel_short'
|
|
|
|
|
|
|
|
ci.return_value['Server-LP'].compose_id = 'Gluster 1.0'
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
|
|
|
format = '{compose_id} {variant}'
|
|
|
|
name = compose.get_image_name('x86_64', variant, format=format,
|
|
|
|
disc_num=7, disc_type='live', suffix='.iso')
|
|
|
|
|
|
|
|
self.assertEqual(name, 'Gluster 1.0 Server')
|
|
|
|
|
2016-03-11 07:55:21 +00:00
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_get_image_name_type_netinst(self, ci):
|
|
|
|
conf = {}
|
|
|
|
variant = mock.Mock(uid='Server', type='variant')
|
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.id = 'compose_id'
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'nightly'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
|
|
|
ci.return_value.compose.label = 'RC-1.0'
|
|
|
|
ci.return_value.compose.label_major_version = '1'
|
|
|
|
|
|
|
|
ci.return_value.release.version = '3.0'
|
|
|
|
ci.return_value.release.short = 'rel_short'
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
|
|
|
keys = ['arch', 'compose_id', 'date', 'disc_num', 'disc_type',
|
|
|
|
'label', 'label_major_version', 'release_short', 'respin',
|
|
|
|
'suffix', 'type', 'type_suffix', 'variant', 'version']
|
|
|
|
format = '-'.join(['%(' + k + ')s' for k in keys])
|
|
|
|
name = compose.get_image_name('x86_64', variant, format=format,
|
|
|
|
disc_num=7, disc_type='netinst', suffix='.iso')
|
|
|
|
|
|
|
|
self.assertEqual(name, '-'.join(['x86_64', 'compose_id', '20160107', '7', 'netinst',
|
|
|
|
'RC-1.0', '1', 'rel_short', '2', '.iso', 'nightly',
|
|
|
|
'.n', 'Server', '3.0']))
|
|
|
|
|
2016-03-22 07:56:51 +00:00
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_image_release(self, ci):
|
|
|
|
conf = {}
|
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'nightly'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
2016-08-25 13:22:55 +00:00
|
|
|
ci.return_value.compose.label = None
|
2016-03-22 07:56:51 +00:00
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
|
|
|
self.assertEqual(compose.image_release, '20160107.n.2')
|
|
|
|
|
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_image_release_production(self, ci):
|
|
|
|
conf = {}
|
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'production'
|
2016-08-30 07:51:36 +00:00
|
|
|
ci.return_value.compose.type_suffix = ''
|
2016-08-25 13:22:55 +00:00
|
|
|
ci.return_value.compose.label = None
|
2016-03-22 07:56:51 +00:00
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
2016-08-30 07:51:36 +00:00
|
|
|
self.assertEqual(compose.image_release, '20160107.2')
|
2016-03-22 07:56:51 +00:00
|
|
|
|
2016-08-25 13:22:55 +00:00
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_image_release_from_label(self, ci):
|
|
|
|
conf = {}
|
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'production'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
|
|
|
ci.return_value.compose.label = 'Alpha-1.2'
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
|
|
|
self.assertEqual(compose.image_release, '1.2')
|
|
|
|
|
2016-08-30 07:51:36 +00:00
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_image_version_without_label(self, ci):
|
|
|
|
conf = {}
|
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'nightly'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
|
|
|
ci.return_value.compose.label = None
|
|
|
|
ci.return_value.release.version = '25'
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
|
|
|
self.assertEqual(compose.image_version, '25')
|
|
|
|
|
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_image_version_with_label(self, ci):
|
|
|
|
conf = {}
|
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'nightly'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
|
|
|
ci.return_value.compose.label = 'Alpha-1.2'
|
|
|
|
ci.return_value.release.version = '25'
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
|
|
|
self.assertEqual(compose.image_version, '25_Alpha')
|
|
|
|
|
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_image_version_with_label_rc(self, ci):
|
|
|
|
conf = {}
|
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'nightly'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
|
|
|
ci.return_value.compose.label = 'RC-1.2'
|
|
|
|
ci.return_value.release.version = '25'
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
|
|
|
|
self.assertEqual(compose.image_version, '25')
|
|
|
|
|
2016-03-29 14:07:24 +00:00
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_get_variant_arches_without_filter(self, ci):
|
2017-01-09 07:40:24 +00:00
|
|
|
ci.return_value.compose.id = 'composeid'
|
|
|
|
|
2016-03-29 14:07:24 +00:00
|
|
|
conf = ConfigWrapper(
|
|
|
|
variants_file={'scm': 'file',
|
|
|
|
'repo': None,
|
|
|
|
'file': 'variants.xml'},
|
|
|
|
release_name='Test',
|
|
|
|
release_version='1.0',
|
|
|
|
release_short='test',
|
2016-08-22 14:08:25 +00:00
|
|
|
release_type='ga',
|
2016-12-06 11:35:57 +00:00
|
|
|
release_internal=False,
|
2016-03-29 14:07:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
compose.read_variants()
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
self.assertEqual(sorted(v.uid for v in compose.variants.values()),
|
2016-03-29 14:07:24 +00:00
|
|
|
['Client', 'Crashy', 'Live', 'Server'])
|
2017-09-05 08:01:21 +00:00
|
|
|
self.assertEqual(sorted(v.uid for v in compose.variants['Server'].variants.values()),
|
2016-03-29 14:07:24 +00:00
|
|
|
['Server-Gluster', 'Server-ResilientStorage', 'Server-optional'])
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self, compose.variants["Client"].arches, ["i386", "x86_64"]
|
|
|
|
)
|
|
|
|
self.assertEqual(compose.variants["Crashy"].arches, ["ppc64le"])
|
|
|
|
self.assertEqual(compose.variants["Live"].arches, ["x86_64"])
|
|
|
|
six.assertCountEqual(
|
|
|
|
self, compose.variants["Server"].arches, ["s390x", "x86_64"]
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
compose.variants["Server"].variants["Gluster"].arches, ["x86_64"]
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
compose.variants["Server"].variants["ResilientStorage"].arches, ["x86_64"]
|
|
|
|
)
|
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
compose.variants["Server"].variants["optional"].arches,
|
|
|
|
["s390x", "x86_64"]
|
|
|
|
)
|
2016-03-29 14:07:24 +00:00
|
|
|
|
|
|
|
self.assertEqual([v.uid for v in compose.get_variants()],
|
|
|
|
['Client', 'Crashy', 'Live', 'Server', 'Server-Gluster',
|
|
|
|
'Server-ResilientStorage', 'Server-optional'])
|
|
|
|
self.assertEqual(compose.get_arches(), ['i386', 'ppc64le', 's390x', 'x86_64'])
|
|
|
|
|
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_get_variant_arches_with_arch_filter(self, ci):
|
2017-01-09 07:40:24 +00:00
|
|
|
ci.return_value.compose.id = 'composeid'
|
|
|
|
|
2016-03-29 14:07:24 +00:00
|
|
|
conf = ConfigWrapper(
|
|
|
|
variants_file={'scm': 'file',
|
|
|
|
'repo': None,
|
|
|
|
'file': 'variants.xml'},
|
|
|
|
release_name='Test',
|
|
|
|
release_version='1.0',
|
|
|
|
release_short='test',
|
2016-08-22 14:08:25 +00:00
|
|
|
release_type='ga',
|
2016-12-06 11:35:57 +00:00
|
|
|
release_internal=False,
|
2016-03-29 14:07:24 +00:00
|
|
|
tree_arches=['x86_64'],
|
|
|
|
)
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
compose.read_variants()
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
self.assertEqual(sorted(v.uid for v in compose.variants.values()),
|
2016-03-29 14:07:24 +00:00
|
|
|
['Client', 'Live', 'Server'])
|
2017-09-05 08:01:21 +00:00
|
|
|
self.assertEqual(sorted(v.uid for v in compose.variants['Server'].variants.values()),
|
2016-03-29 14:07:24 +00:00
|
|
|
['Server-Gluster', 'Server-ResilientStorage', 'Server-optional'])
|
2019-10-04 12:45:03 +00:00
|
|
|
self.assertEqual(compose.variants["Client"].arches, ["x86_64"])
|
|
|
|
self.assertEqual(compose.variants["Live"].arches, ["x86_64"])
|
|
|
|
self.assertEqual(compose.variants["Server"].arches, ["x86_64"])
|
|
|
|
self.assertEqual(
|
|
|
|
compose.variants["Server"].variants["Gluster"].arches, ["x86_64"]
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
compose.variants["Server"].variants["ResilientStorage"].arches, ["x86_64"]
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
compose.variants["Server"].variants["optional"].arches, ["x86_64"]
|
|
|
|
)
|
2016-03-29 14:07:24 +00:00
|
|
|
|
|
|
|
self.assertEqual(compose.get_arches(), ['x86_64'])
|
|
|
|
self.assertEqual([v.uid for v in compose.get_variants()],
|
|
|
|
['Client', 'Live', 'Server', 'Server-Gluster',
|
|
|
|
'Server-ResilientStorage', 'Server-optional'])
|
|
|
|
|
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_get_variant_arches_with_variant_filter(self, ci):
|
2017-01-09 07:40:24 +00:00
|
|
|
ci.return_value.compose.id = 'composeid'
|
2016-03-29 14:07:24 +00:00
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'production'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
|
|
|
|
|
|
|
conf = ConfigWrapper(
|
|
|
|
variants_file={'scm': 'file',
|
|
|
|
'repo': None,
|
|
|
|
'file': 'variants.xml'},
|
|
|
|
release_name='Test',
|
|
|
|
release_version='1.0',
|
|
|
|
release_short='test',
|
2016-08-22 14:08:25 +00:00
|
|
|
release_type='ga',
|
2016-12-06 11:35:57 +00:00
|
|
|
release_internal=False,
|
2016-03-29 14:07:24 +00:00
|
|
|
tree_variants=['Server', 'Client', 'Server-Gluster'],
|
|
|
|
)
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
compose.read_variants()
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
self.assertEqual(sorted(v.uid for v in compose.variants.values()),
|
2016-03-29 14:07:24 +00:00
|
|
|
['Client', 'Server'])
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self, compose.variants["Client"].arches, ["i386", "x86_64"]
|
|
|
|
)
|
|
|
|
six.assertCountEqual(
|
|
|
|
self, compose.variants["Server"].arches, ["s390x", "x86_64"]
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
compose.variants["Server"].variants["Gluster"].arches, ["x86_64"]
|
|
|
|
)
|
2016-03-29 14:07:24 +00:00
|
|
|
|
|
|
|
self.assertEqual(compose.get_arches(), ['i386', 's390x', 'x86_64'])
|
|
|
|
self.assertEqual([v.uid for v in compose.get_variants()],
|
|
|
|
['Client', 'Server', 'Server-Gluster'])
|
|
|
|
|
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_get_variant_arches_with_both_filters(self, ci):
|
2017-01-09 07:40:24 +00:00
|
|
|
ci.return_value.compose.id = 'composeid'
|
2016-03-29 14:07:24 +00:00
|
|
|
ci.return_value.compose.respin = 2
|
|
|
|
ci.return_value.compose.date = '20160107'
|
|
|
|
ci.return_value.compose.type = 'production'
|
|
|
|
ci.return_value.compose.type_suffix = '.n'
|
|
|
|
|
|
|
|
logger = mock.Mock()
|
2019-09-18 09:48:37 +00:00
|
|
|
logger.handlers = []
|
2016-03-29 14:07:24 +00:00
|
|
|
|
|
|
|
conf = ConfigWrapper(
|
|
|
|
variants_file={'scm': 'file',
|
|
|
|
'repo': None,
|
|
|
|
'file': 'variants.xml'},
|
|
|
|
release_name='Test',
|
|
|
|
release_version='1.0',
|
|
|
|
release_short='test',
|
2016-08-22 14:08:25 +00:00
|
|
|
release_type='ga',
|
2016-12-06 11:35:57 +00:00
|
|
|
release_internal=False,
|
2016-03-29 14:07:24 +00:00
|
|
|
tree_variants=['Server', 'Client', 'Server-optional'],
|
|
|
|
tree_arches=['x86_64'],
|
|
|
|
)
|
|
|
|
|
|
|
|
compose = Compose(conf, self.tmp_dir, logger=logger)
|
|
|
|
compose.read_variants()
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
self.assertEqual(sorted(v.uid for v in compose.variants.values()),
|
2016-03-29 14:07:24 +00:00
|
|
|
['Client', 'Server'])
|
2019-10-04 12:45:03 +00:00
|
|
|
self.assertEqual(compose.variants["Client"].arches, ["x86_64"])
|
|
|
|
self.assertEqual(compose.variants["Server"].arches, ["x86_64"])
|
|
|
|
self.assertEqual(
|
|
|
|
compose.variants["Server"].variants["optional"].arches, ["x86_64"]
|
|
|
|
)
|
2016-03-29 14:07:24 +00:00
|
|
|
|
|
|
|
self.assertEqual(compose.get_arches(), ['x86_64'])
|
|
|
|
self.assertEqual([v.uid for v in compose.get_variants()],
|
|
|
|
['Client', 'Server', 'Server-optional'])
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2016-03-29 14:07:24 +00:00
|
|
|
logger.info.call_args_list,
|
|
|
|
[mock.call('Excluding variant Live: filtered by configuration.'),
|
|
|
|
mock.call('Excluding variant Crashy: all its arches are filtered.'),
|
|
|
|
mock.call('Excluding variant Server-ResilientStorage: filtered by configuration.'),
|
|
|
|
mock.call('Excluding variant Server-Gluster: filtered by configuration.')]
|
|
|
|
)
|
|
|
|
|
2017-01-09 07:40:24 +00:00
|
|
|
@mock.patch('pungi.compose.ComposeInfo')
|
|
|
|
def test_mkdtemp(self, ci):
|
|
|
|
ci.return_value.compose.id = 'composeid'
|
|
|
|
conf = ConfigWrapper(
|
|
|
|
variants_file={'scm': 'file',
|
|
|
|
'repo': None,
|
|
|
|
'file': 'variants.xml'},
|
|
|
|
release_name='Test',
|
|
|
|
release_version='1.0',
|
|
|
|
release_short='test',
|
|
|
|
release_type='ga',
|
|
|
|
release_internal=False,
|
|
|
|
tree_variants=['Server', 'Client', 'Server-optional'],
|
|
|
|
tree_arches=['x86_64'],
|
|
|
|
)
|
|
|
|
compose = Compose(conf, self.tmp_dir)
|
|
|
|
d = compose.mkdtemp()
|
|
|
|
self.assertTrue(os.path.isdir(d))
|
|
|
|
d = compose.mkdtemp(prefix='tweak_buildinstall')
|
|
|
|
self.assertTrue(os.path.isdir(d))
|
|
|
|
|
2015-12-10 14:49:00 +00:00
|
|
|
|
2016-01-12 12:29:14 +00:00
|
|
|
class StatusTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.tmp_dir = tempfile.mkdtemp()
|
|
|
|
self.logger = mock.Mock()
|
2019-09-18 09:48:37 +00:00
|
|
|
self.logger.handlers = []
|
2016-01-12 12:29:14 +00:00
|
|
|
with mock.patch('pungi.compose.ComposeInfo'):
|
|
|
|
self.compose = Compose({}, self.tmp_dir, logger=self.logger)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
shutil.rmtree(self.tmp_dir)
|
|
|
|
|
|
|
|
def test_get_status_non_existing(self):
|
|
|
|
status = self.compose.get_status()
|
|
|
|
self.assertIsNone(status)
|
|
|
|
|
|
|
|
def test_get_status_existing(self):
|
|
|
|
with open(os.path.join(self.tmp_dir, 'STATUS'), 'w') as f:
|
|
|
|
f.write('FOOBAR')
|
|
|
|
|
|
|
|
self.assertEqual(self.compose.get_status(), 'FOOBAR')
|
|
|
|
|
|
|
|
def test_get_status_is_dir(self):
|
|
|
|
os.mkdir(os.path.join(self.tmp_dir, 'STATUS'))
|
|
|
|
|
|
|
|
self.assertIsNone(self.compose.get_status())
|
|
|
|
|
|
|
|
def test_write_status(self):
|
|
|
|
self.compose.write_status('DOOMED')
|
|
|
|
|
|
|
|
with open(os.path.join(self.tmp_dir, 'STATUS'), 'r') as f:
|
|
|
|
self.assertEqual(f.read(), 'DOOMED\n')
|
|
|
|
|
|
|
|
def test_write_non_standard_status(self):
|
|
|
|
self.compose.write_status('FOOBAR')
|
|
|
|
|
|
|
|
self.assertEqual(self.logger.log.call_count, 1)
|
|
|
|
with open(os.path.join(self.tmp_dir, 'STATUS'), 'r') as f:
|
|
|
|
self.assertEqual(f.read(), 'FOOBAR\n')
|
|
|
|
|
|
|
|
def test_write_status_on_finished(self):
|
|
|
|
self.compose.write_status('FINISHED')
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError):
|
|
|
|
self.compose.write_status('NOT REALLY')
|
|
|
|
|
|
|
|
def test_write_status_with_failed_deliverables(self):
|
|
|
|
self.compose.conf = {
|
|
|
|
'failable_deliverables': [
|
|
|
|
('^.+$', {
|
|
|
|
'*': ['live', 'build-image'],
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
variant = mock.Mock(uid='Server')
|
2016-04-13 11:44:17 +00:00
|
|
|
self.compose.fail_deliverable(variant, 'x86_64', 'live')
|
|
|
|
self.compose.fail_deliverable(None, '*', 'build-image')
|
2016-01-12 12:29:14 +00:00
|
|
|
|
|
|
|
self.compose.write_status('FINISHED')
|
|
|
|
|
|
|
|
self.logger.log.assert_has_calls(
|
2016-04-13 11:44:17 +00:00
|
|
|
[mock.call(20, 'Failed build-image on variant <>, arch <*>, subvariant <None>.'),
|
|
|
|
mock.call(20, 'Failed live on variant <Server>, arch <x86_64>, subvariant <None>.')],
|
2016-01-12 12:29:14 +00:00
|
|
|
any_order=True)
|
|
|
|
|
|
|
|
with open(os.path.join(self.tmp_dir, 'STATUS'), 'r') as f:
|
|
|
|
self.assertEqual(f.read(), 'FINISHED_INCOMPLETE\n')
|
|
|
|
|
|
|
|
def test_calls_notifier(self):
|
|
|
|
self.compose.notifier = mock.Mock()
|
|
|
|
self.compose.write_status('FINISHED')
|
|
|
|
|
|
|
|
self.assertTrue(self.compose.notifier.send.call_count, 1)
|
|
|
|
|
2018-05-18 08:17:41 +00:00
|
|
|
def test_no_database_with_dnf_backend(self):
|
|
|
|
self.compose.conf['gather_backend'] = 'dnf'
|
|
|
|
self.assertFalse(self.compose.should_create_yum_database)
|
|
|
|
|
|
|
|
def test_no_database_with_dnf_backend_config_override(self):
|
|
|
|
self.compose.conf['gather_backend'] = 'dnf'
|
|
|
|
self.compose.conf['createrepo_database'] = True
|
|
|
|
self.assertTrue(self.compose.should_create_yum_database)
|
|
|
|
|
|
|
|
def test_no_database_with_yum_backend(self):
|
|
|
|
self.compose.conf['gather_backend'] = 'yum'
|
|
|
|
self.assertTrue(self.compose.should_create_yum_database)
|
|
|
|
|
|
|
|
def test_no_database_with_yum_backend_config_override(self):
|
|
|
|
self.compose.conf['gather_backend'] = 'yum'
|
|
|
|
self.compose.conf['createrepo_database'] = False
|
|
|
|
self.assertFalse(self.compose.should_create_yum_database)
|