2016-03-10 09:12:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2024-01-26 07:38:32 +00:00
|
|
|
try:
|
|
|
|
from unittest import mock
|
|
|
|
except ImportError:
|
|
|
|
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
|
2016-03-10 09:12:23 +00:00
|
|
|
import os
|
2017-09-05 08:01:21 +00:00
|
|
|
from six import StringIO
|
2016-03-10 09:12:23 +00:00
|
|
|
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
import kobo.conf
|
|
|
|
|
2016-03-10 09:12:23 +00:00
|
|
|
from pungi import checks
|
|
|
|
|
2017-08-03 12:42:40 +00:00
|
|
|
|
2016-03-10 09:12:23 +00:00
|
|
|
class CheckDependenciesTestCase(unittest.TestCase):
|
2016-03-10 09:44:21 +00:00
|
|
|
def dont_find(self, paths):
|
|
|
|
return lambda path: path not in paths
|
|
|
|
|
2016-03-10 09:12:23 +00:00
|
|
|
def test_all_deps_missing(self):
|
|
|
|
def custom_exists(path):
|
|
|
|
return False
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
2016-03-10 09:12:23 +00:00
|
|
|
exists.side_effect = custom_exists
|
|
|
|
result = checks.check({})
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertGreater(len(out.getvalue().strip().split("\n")), 1)
|
2016-03-10 09:12:23 +00:00
|
|
|
self.assertFalse(result)
|
|
|
|
|
|
|
|
def test_all_deps_ok(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("platform.machine") as machine:
|
|
|
|
machine.return_value = "x86_64"
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
2016-03-10 17:54:14 +00:00
|
|
|
exists.side_effect = self.dont_find([])
|
2017-08-11 13:19:25 +00:00
|
|
|
result = checks.check({})
|
2016-03-10 09:12:23 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual("", out.getvalue())
|
2016-03-10 09:12:23 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_does_not_require_jigdo_if_not_configured(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
conf = {"create_jigdo": False}
|
2016-03-10 09:12:23 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("platform.machine") as machine:
|
|
|
|
machine.return_value = "x86_64"
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/jigdo-lite"])
|
2017-08-11 13:19:25 +00:00
|
|
|
result = checks.check(conf)
|
2016-03-10 09:44:21 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual("", out.getvalue())
|
2016-03-10 09:44:21 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_isohybrid_not_required_without_productimg_phase(self):
|
|
|
|
conf = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"bootable": True,
|
|
|
|
"productimg": False,
|
|
|
|
"runroot_tag": "dummy_tag",
|
2016-03-10 09:44:21 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/isohybrid"])
|
2017-08-11 13:19:25 +00:00
|
|
|
result = checks.check(conf)
|
2016-03-10 09:44:21 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual("", out.getvalue())
|
2016-03-10 09:44:21 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_isohybrid_not_required_on_not_bootable(self):
|
|
|
|
conf = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"bootable": False,
|
|
|
|
"runroot_tag": "dummy_tag",
|
2016-03-10 09:44:21 +00:00
|
|
|
}
|
2016-03-10 09:12:23 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/isohybrid"])
|
2017-08-11 13:19:25 +00:00
|
|
|
result = checks.check(conf)
|
2016-03-10 09:12:23 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual("", out.getvalue())
|
2016-03-10 09:12:23 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
2016-03-10 09:44:21 +00:00
|
|
|
def test_isohybrid_not_required_on_arm(self):
|
|
|
|
conf = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"buildinstall_method": "lorax",
|
|
|
|
"runroot_tag": "",
|
2016-03-10 09:44:21 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("platform.machine") as machine:
|
|
|
|
machine.return_value = "armhfp"
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/isohybrid"])
|
2017-08-11 13:19:25 +00:00
|
|
|
result = checks.check(conf)
|
2016-03-10 09:44:21 +00:00
|
|
|
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(out.getvalue(), r"^Not checking.*Expect failures.*$")
|
2016-03-10 09:44:21 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_isohybrid_not_needed_in_runroot(self):
|
|
|
|
conf = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"runroot_tag": "dummy_tag",
|
2016-03-10 09:44:21 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/isohybrid"])
|
2017-08-11 13:19:25 +00:00
|
|
|
result = checks.check(conf)
|
2016-03-10 10:23:45 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual("", out.getvalue())
|
2016-03-10 10:23:45 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_genisoimg_not_needed_in_runroot(self):
|
|
|
|
conf = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"runroot_tag": "dummy_tag",
|
2016-03-10 10:23:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/genisoimage"])
|
2017-08-11 13:19:25 +00:00
|
|
|
result = checks.check(conf)
|
2016-03-10 10:23:45 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual("", out.getvalue())
|
2016-03-10 10:23:45 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
2016-10-25 13:43:19 +00:00
|
|
|
def test_requires_modifyrepo(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/modifyrepo"])
|
|
|
|
result = checks.check({"createrepo_c": False})
|
2016-10-25 13:43:19 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertIn("createrepo", out.getvalue())
|
2016-10-25 13:43:19 +00:00
|
|
|
self.assertFalse(result)
|
|
|
|
|
2017-12-04 10:08:40 +00:00
|
|
|
def test_requires_modifyrepo_c(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/modifyrepo_c"])
|
|
|
|
result = checks.check({"createrepo_c": True})
|
2017-12-04 10:08:40 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertIn("createrepo_c", out.getvalue())
|
2017-12-04 10:08:40 +00:00
|
|
|
self.assertFalse(result)
|
|
|
|
|
2016-10-25 13:43:19 +00:00
|
|
|
def test_requires_createrepo_c(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/createrepo_c"])
|
2021-11-04 09:17:02 +00:00
|
|
|
result = checks.check({"createrepo_c": True})
|
2016-10-25 13:43:19 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertIn("createrepo_c", out.getvalue())
|
2016-10-25 13:43:19 +00:00
|
|
|
self.assertFalse(result)
|
|
|
|
|
|
|
|
def test_doesnt_require_createrepo_c_if_configured(self):
|
|
|
|
conf = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"createrepo_c": False,
|
2016-10-25 13:43:19 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
with mock.patch("os.path.exists") as exists:
|
|
|
|
exists.side_effect = self.dont_find(["/usr/bin/createrepo_c"])
|
2017-08-11 13:19:25 +00:00
|
|
|
result = checks.check(conf)
|
2016-10-25 13:43:19 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertNotIn("createrepo_c", out.getvalue())
|
2016-10-25 13:43:19 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
2016-03-10 09:12:23 +00:00
|
|
|
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
class TestSchemaValidator(unittest.TestCase):
|
|
|
|
def _load_conf_from_string(self, string):
|
|
|
|
conf = kobo.conf.PyConfigParser()
|
|
|
|
conf.load_from_string(string)
|
|
|
|
return conf
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
def test_property(self, make_schema):
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"release_name": {"type": "string", "alias": "product_name"},
|
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
"required": ["release_name"],
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
release_name = "dummy product"
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 0)
|
|
|
|
self.assertEqual(len(warnings), 0)
|
|
|
|
self.assertEqual(config.get("release_name", None), "dummy product")
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
def test_alias_property(self, make_schema):
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"release_name": {"type": "string", "alias": "product_name"},
|
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
product_name = "dummy product"
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 0)
|
2017-03-23 15:18:15 +00:00
|
|
|
self.assertEqual(len(warnings), 1)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[0],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
self.assertEqual(config.get("release_name", None), "dummy product")
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
def test_required_is_missing(self, make_schema):
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"release_name": {"type": "string", "alias": "product_name"},
|
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
"required": ["release_name"],
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
name = "dummy product"
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 1)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertIn(
|
|
|
|
"Failed validation in : 'release_name' is a required property", errors
|
|
|
|
)
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
self.assertEqual(len(warnings), 1)
|
|
|
|
self.assertIn("WARNING: Unrecognized config option: name.", warnings)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
def test_required_is_in_alias(self, make_schema):
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"release_name": {"type": "string", "alias": "product_name"},
|
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
"required": ["release_name"],
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
product_name = "dummy product"
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 0)
|
2017-03-23 15:18:15 +00:00
|
|
|
self.assertEqual(len(warnings), 1)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[0],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
self.assertEqual(config.get("release_name", None), "dummy product")
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
def test_redundant_alias(self, make_schema):
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"release_name": {"type": "string", "alias": "product_name"},
|
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
"required": ["release_name"],
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
product_name = "dummy product"
|
|
|
|
release_name = "dummy product"
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 1)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
errors[0],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^ERROR: Config option 'product_name' is an alias of 'release_name', only one can be used.*", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
2017-03-23 15:18:15 +00:00
|
|
|
self.assertEqual(len(warnings), 1)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[0],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
self.assertEqual(config.get("release_name", None), "dummy product")
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
def test_properties_in_deep(self, make_schema):
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"release_name": {"type": "string", "alias": "product_name"},
|
2020-01-22 10:02:22 +00:00
|
|
|
"keys": {"type": "array", "items": {"type": "string"}},
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
"foophase": {
|
|
|
|
"type": "object",
|
2020-01-22 10:02:22 +00:00
|
|
|
"properties": {"repo": {"type": "string", "alias": "tree"}},
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
"additionalProperties": False,
|
|
|
|
"required": ["repo"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
"required": ["release_name"],
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
product_name = "dummy product"
|
|
|
|
foophase = {
|
|
|
|
"tree": "http://www.exampe.com/os"
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 0)
|
2017-03-23 15:18:15 +00:00
|
|
|
self.assertEqual(len(warnings), 2)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[0],
|
|
|
|
r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*",
|
|
|
|
)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[1],
|
|
|
|
r"^WARNING: Config option '.+' is deprecated and now an alias to '.+'.*",
|
|
|
|
)
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
self.assertEqual(config.get("release_name", None), "dummy product")
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
config.get("foophase", {}).get("repo", None), "http://www.exampe.com/os"
|
|
|
|
)
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
def test_append_option(self, make_schema):
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"definitions": {
|
2020-01-22 10:02:22 +00:00
|
|
|
"list_of_strings": {"type": "array", "items": {"type": "string"}},
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
"strings": {
|
|
|
|
"anyOf": [
|
|
|
|
{"type": "string"},
|
|
|
|
{"$ref": "#/definitions/list_of_strings"},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"release_name": {"type": "string"},
|
2020-01-22 10:02:22 +00:00
|
|
|
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"},
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
release_name = "dummy product"
|
|
|
|
repo = "http://url/to/repo"
|
|
|
|
repo_from = 'Server'
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 0)
|
|
|
|
self.assertEqual(len(warnings), 2)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[0],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[1],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Value from config option 'repo_from' is now appended to option 'repo'", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
self.assertEqual(config.get("release_name", None), "dummy product")
|
|
|
|
self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server"])
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
def test_append_to_nonexist_option(self, make_schema):
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"definitions": {
|
2020-01-22 10:02:22 +00:00
|
|
|
"list_of_strings": {"type": "array", "items": {"type": "string"}},
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
"strings": {
|
|
|
|
"anyOf": [
|
|
|
|
{"type": "string"},
|
|
|
|
{"$ref": "#/definitions/list_of_strings"},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"release_name": {"type": "string"},
|
2020-01-22 10:02:22 +00:00
|
|
|
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"},
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
release_name = "dummy product"
|
|
|
|
repo_from = ['http://url/to/repo', 'Server']
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 0)
|
|
|
|
self.assertEqual(len(warnings), 2)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[0],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[1],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
self.assertEqual(config.get("release_name", None), "dummy product")
|
|
|
|
self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server"])
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
def test_multiple_appends(self, make_schema):
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"definitions": {
|
2020-01-22 10:02:22 +00:00
|
|
|
"list_of_strings": {"type": "array", "items": {"type": "string"}},
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
"strings": {
|
|
|
|
"anyOf": [
|
|
|
|
{"type": "string"},
|
|
|
|
{"$ref": "#/definitions/list_of_strings"},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"release_name": {"type": "string"},
|
|
|
|
"repo": {
|
|
|
|
"$ref": "#/definitions/strings",
|
2020-01-22 10:02:22 +00:00
|
|
|
"append": ["repo_from", "source_repo_from"],
|
|
|
|
},
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
release_name = "dummy product"
|
|
|
|
repo_from = ['http://url/to/repo', 'Server']
|
|
|
|
source_repo_from = 'Client'
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 0)
|
|
|
|
self.assertEqual(len(warnings), 4)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[0],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[1],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified,", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[2],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'source_repo_from' is deprecated, its value will be appended to option 'repo'", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[3],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Value from config option 'source_repo_from' is now appended to option 'repo'.", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
self.assertEqual(config.get("release_name", None), "dummy product")
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
config.get("repo", None), ["http://url/to/repo", "Server", "Client"]
|
|
|
|
)
|
checks.py: support 'append' option
If 'append' is defined for a property, append the values from append
options to the property. Note: The property must support to be a list
of values.
For example:
with schema:
schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"definitions": {
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
},
"properties": {
"release_name": {"type": "string"},
"repo": {"$ref": "#/definitions/strings", "append": "repo_from"}
},
"additionalProperties": False,
}
and config:
repo = "http://url/to/repo"
repo_from = "Server"
config will be updated to:
repo = ["http://url/to/repo", "Server"]
It supports multiple append options too, like:
"repo": {
"$ref": "#/definitions/strings",
"append": ["repo_from", "source_repo_from"],
}
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-03-24 19:19:31 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
2017-04-14 05:12:35 +00:00
|
|
|
def test_anyof_validator_not_raise_our_warnings_as_error(self, make_schema):
|
|
|
|
# https://pagure.io/pungi/issue/598
|
|
|
|
schema = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"definitions": {
|
|
|
|
"live_image_config": {
|
|
|
|
"type": "object",
|
2020-01-22 10:02:22 +00:00
|
|
|
"properties": {"repo": {"type": "string", "append": "repo_from"}},
|
2017-04-14 05:12:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"properties": {
|
2020-01-22 10:02:22 +00:00
|
|
|
"live_images": checks._variant_arch_mapping(
|
|
|
|
{
|
|
|
|
"anyOf": [
|
|
|
|
{"$ref": "#/definitions/live_image_config"},
|
|
|
|
{
|
|
|
|
"type": "array",
|
|
|
|
"items": {"$ref": "#/definitions/live_image_config"},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),
|
2017-04-14 05:12:35 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
make_schema.return_value = schema
|
|
|
|
|
|
|
|
string = """
|
|
|
|
live_images = [
|
|
|
|
('^Spins$', {
|
|
|
|
'armhfp': {
|
|
|
|
'repo_from': 'Everything',
|
|
|
|
}}),
|
|
|
|
]
|
|
|
|
"""
|
|
|
|
config = self._load_conf_from_string(string)
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(len(errors), 0)
|
|
|
|
self.assertEqual(len(warnings), 2)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[0],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'repo_from' is deprecated, its value will be appended to option 'repo'.*", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2020-01-22 10:02:22 +00:00
|
|
|
warnings[1],
|
2020-02-06 07:09:32 +00:00
|
|
|
r"^WARNING: Config option 'repo' is not found, but 'repo_from' is specified, value from 'repo_from' is now added as 'repo'.*", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
config.get("live_images")[0][1]["armhfp"]["repo"], "Everything"
|
|
|
|
)
|
2017-04-14 05:12:35 +00:00
|
|
|
|
2018-11-21 09:56:22 +00:00
|
|
|
@mock.patch("pungi.util.resolve_git_url")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
2018-11-21 09:56:22 +00:00
|
|
|
def test_resolve_url(self, make_schema, resolve_git_url):
|
|
|
|
resolve_git_url.return_value = "git://example.com/repo.git#CAFE"
|
|
|
|
make_schema.return_value = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {"foo": {"type": "url"}},
|
|
|
|
}
|
|
|
|
config = self._load_conf_from_string("foo = 'git://example.com/repo.git#HEAD'")
|
|
|
|
errors, warnings = checks.validate(config)
|
|
|
|
self.assertEqual(errors, [])
|
|
|
|
self.assertEqual(warnings, [])
|
|
|
|
self.assertEqual(config["foo"], resolve_git_url.return_value)
|
|
|
|
|
|
|
|
@mock.patch("pungi.util.resolve_git_url")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.checks.make_schema")
|
2018-11-21 09:56:22 +00:00
|
|
|
def test_resolve_url_when_offline(self, make_schema, resolve_git_url):
|
|
|
|
make_schema.return_value = {
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"title": "Pungi Configuration",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {"foo": {"type": "url"}},
|
|
|
|
}
|
|
|
|
config = self._load_conf_from_string("foo = 'git://example.com/repo.git#HEAD'")
|
|
|
|
errors, warnings = checks.validate(config, offline=True)
|
|
|
|
self.assertEqual(errors, [])
|
|
|
|
self.assertEqual(warnings, [])
|
|
|
|
self.assertEqual(config["foo"], "git://example.com/repo.git#HEAD")
|
|
|
|
self.assertEqual(resolve_git_url.call_args_list, [])
|
|
|
|
|
2020-02-03 11:43:27 +00:00
|
|
|
def test_update_schema(self):
|
|
|
|
schema = checks.make_schema()
|
|
|
|
schema_override = {
|
|
|
|
"definitions": {
|
|
|
|
"scm_dict": {
|
|
|
|
"properties": {
|
2020-02-07 05:53:20 +00:00
|
|
|
"scm": {"enum": ["git"]},
|
|
|
|
"repo": {"enum": ["git://localhost/pungi-fedora.git"]},
|
2020-02-03 11:43:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
schema = checks.update_schema(schema, schema_override)
|
|
|
|
scm_dict_properties = schema["definitions"]["scm_dict"]["properties"]
|
|
|
|
self.assertEqual(
|
2020-02-07 05:53:20 +00:00
|
|
|
scm_dict_properties["scm"], {"enum": ["git"], "type": "string"}
|
|
|
|
)
|
2020-02-03 11:43:27 +00:00
|
|
|
self.assertEqual(
|
|
|
|
scm_dict_properties["repo"],
|
2020-02-07 05:53:20 +00:00
|
|
|
{"enum": ["git://localhost/pungi-fedora.git"], "type": "string"},
|
|
|
|
)
|
2020-02-03 11:43:27 +00:00
|
|
|
self.assertEqual(scm_dict_properties["file"], {"type": "string"})
|
checks: extend validator with 'alias'
When a property has 'alias' defined, and it's not present in instance,
if the alias property is present, add the property with value from alias
property before remove the alias property from instance.
Examples:
with schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pungi Configuration",
"type": "object",
"properties": {
"release_name": {"type": "string", "alias": "product_name"},
},
"required": ["release_name"],
"additionalProperties": False,
}
1. config = {"release_name": "dummy product"}:
validate pass, config not changed after validation.
2. config = {"product_name": "dummy product"}:
validate pass, config updated to the following after validation:
config: {"release_name": "dummy product"}
3. config = {"name": "dummy product"}:
validate fail, errror message is "Failed validation in : 'release_name' is a required property",
and warning message is "WARNING: Unrecognized config option: name."
4. config = {"product_name": "dummy product", "release_name": "dummy product"}
validate fail, error message is "Failed validation in : product_name is an alias of release_name, only one can be used."
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2017-02-20 14:45:51 +00:00
|
|
|
|
2020-02-07 02:50:25 +00:00
|
|
|
|
2016-03-31 07:45:50 +00:00
|
|
|
class TestUmask(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.orig_umask = os.umask(0)
|
|
|
|
os.umask(self.orig_umask)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
os.umask(self.orig_umask)
|
|
|
|
|
|
|
|
def test_no_warning_with_0022(self):
|
|
|
|
os.umask(0o022)
|
|
|
|
logger = mock.Mock()
|
|
|
|
checks.check_umask(logger)
|
2019-10-04 12:45:03 +00:00
|
|
|
self.assertEqual(logger.mock_calls, [])
|
2016-03-31 07:45:50 +00:00
|
|
|
|
|
|
|
def test_no_warning_with_0000(self):
|
|
|
|
os.umask(0o000)
|
|
|
|
logger = mock.Mock()
|
|
|
|
checks.check_umask(logger)
|
2019-10-04 12:45:03 +00:00
|
|
|
self.assertEqual(logger.mock_calls, [])
|
2016-03-31 07:45:50 +00:00
|
|
|
|
|
|
|
def test_warning_with_0044(self):
|
|
|
|
os.umask(0o044)
|
|
|
|
logger = mock.Mock()
|
|
|
|
checks.check_umask(logger)
|
2019-10-04 12:45:03 +00:00
|
|
|
self.assertEqual(
|
2016-03-31 07:45:50 +00:00
|
|
|
logger.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call.warning(
|
|
|
|
"Unusually strict umask detected (0%03o), "
|
|
|
|
"expect files with broken permissions.",
|
|
|
|
0o044,
|
|
|
|
)
|
|
|
|
],
|
2016-03-31 07:45:50 +00:00
|
|
|
)
|
2020-01-06 03:42:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestCheckSkipPhases(unittest.TestCase):
|
|
|
|
def test_skip_phase(self):
|
|
|
|
logger = mock.Mock()
|
|
|
|
passed = checks.check_skip_phases(logger, ["gather"], [])
|
|
|
|
self.assertFalse(passed)
|
|
|
|
self.assertEqual(
|
|
|
|
logger.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call.error(
|
|
|
|
"gather phase is skipped but it's needed by createrepo phase"
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_just_phase(self):
|
|
|
|
logger = mock.Mock()
|
|
|
|
passed = checks.check_skip_phases(logger, [], ["gather"])
|
|
|
|
self.assertFalse(passed)
|
|
|
|
self.assertEqual(
|
|
|
|
logger.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call.error(
|
|
|
|
"pkgset phase is skipped but it's needed by gather phase"
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|