lorax-composer: Catch dnf unknown group error

dnf-4.2.23-4 is raising a ValueError if the group doesn't exist, catch
that and add it to the error list when depsolving. Includes tests for
depsolve and freeze.

NOTE: Later versions of dnf (eg. at least dnf-4.4.2 and later) do not
raise any kind of error so these tests will fail on any system using the
newer dnf.

Resolves: rhbz#1943206
This commit is contained in:
Brian C. Lane 2021-04-08 15:58:47 -07:00
parent 98555e9d16
commit 859f75de25
2 changed files with 122 additions and 1 deletions

View File

@ -235,7 +235,7 @@ def _depsolve(dbo, projects, groups):
for name in groups:
try:
dbo.group_install(name, ["mandatory", "default"])
except dnf.exceptions.MarkingError as e:
except (dnf.exceptions.MarkingError, ValueError) as e:
install_errors.append(("Group %s" % (name), str(e)))
for name, version in projects:

View File

@ -1553,6 +1553,127 @@ class ServerTestCase(unittest.TestCase):
self.assertTrue(len(data["errors"]) > 0)
self.assertEqual(data["errors"][0]["id"], "UnknownBlueprint")
## Order matters, run these last
def test_zz_depsolve_groups(self):
"""Test depsolving with a group"""
test_blueprint = """
name = "server-group-blueprint-test"
description = "A test blueprint with a group"
version = "0.0.1"
[[packages]]
name="openssh-server"
version="*"
[[groups]]
name="base"
"""
resp = self.server.post("/api/v0/blueprints/new",
data=test_blueprint,
content_type="text/x-toml")
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/depsolve/server-group-blueprint-test")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
self.assertNotEqual(blueprints, None)
self.assertEqual(len(blueprints), 1)
self.assertEqual(blueprints[0]["blueprint"]["name"], "server-group-blueprint-test")
self.assertEqual(len(blueprints[0]["dependencies"]) > 10, True)
self.assertFalse(data.get("errors"))
def test_zz_freeze_groups(self):
"""Test freeze with a group"""
test_blueprint = """
name = "server-group-blueprint-test"
description = "A test blueprint with a group"
version = "0.0.1"
[[packages]]
name="openssh-server"
version="*"
[[groups]]
name="base"
"""
resp = self.server.post("/api/v0/blueprints/new",
data=test_blueprint,
content_type="text/x-toml")
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/freeze/server-group-blueprint-test")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
self.assertNotEqual(blueprints, None)
self.assertEqual(len(blueprints), 1)
self.assertEqual(blueprints[0]["blueprint"]["name"], "server-group-blueprint-test")
self.assertEqual(len(blueprints[0]["blueprint"]["packages"]) > 0, True)
self.assertFalse(data.get("errors"))
def test_zz_depsolve_unknown_groups(self):
"""Test depsolving with an unknown group"""
test_blueprint = """
name = "unknown-group-blueprint-test"
description = "A test blueprint with an unknown group"
version = "0.0.1"
[[packages]]
name="openssh-server"
version="*"
[[groups]]
name="unknown-group"
"""
resp = self.server.post("/api/v0/blueprints/new",
data=test_blueprint,
content_type="text/x-toml")
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/depsolve/unknown-group-blueprint-test")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
self.assertNotEqual(blueprints, None)
self.assertEqual(len(blueprints), 1)
self.assertEqual(blueprints[0]["blueprint"]["name"], "unknown-group-blueprint-test")
self.assertTrue(len(data.get("errors")) > 0)
self.assertTrue("unknown-group" in data["errors"][0]["msg"])
def test_zz_freeze_unknown_groups(self):
"""Test freeze with an unknown group"""
test_blueprint = """
name = "unknown-group-blueprint-test"
description = "A test blueprint with an unknown group"
version = "0.0.1"
[[packages]]
name="openssh-server"
version="*"
[[groups]]
name="unknown-group"
"""
resp = self.server.post("/api/v0/blueprints/new",
data=test_blueprint,
content_type="text/x-toml")
data = json.loads(resp.data)
self.assertEqual(data, {"status":True})
resp = self.server.get("/api/v0/blueprints/freeze/unknown-group-blueprint-test")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
blueprints = data.get("blueprints")
self.assertNotEqual(blueprints, None)
self.assertEqual(len(blueprints), 1)
self.assertEqual(blueprints[0]["blueprint"]["name"], "unknown-group-blueprint-test")
self.assertTrue(len(data.get("errors")) > 0)
self.assertTrue("unknown-group" in data["errors"][0]["msg"])
@contextmanager
def in_tempdir(prefix='tmp'):
"""Execute a block of code with chdir in a temporary location"""