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