From 859f75de25c44fe7845743567e1c5ca09006022b Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 8 Apr 2021 15:58:47 -0700 Subject: [PATCH] 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 --- src/pylorax/api/projects.py | 2 +- tests/pylorax/test_server.py | 121 +++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 1 deletion(-) diff --git a/src/pylorax/api/projects.py b/src/pylorax/api/projects.py index 6411e236..bb8ab51b 100644 --- a/src/pylorax/api/projects.py +++ b/src/pylorax/api/projects.py @@ -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: diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index 34615496..c4d74ffc 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -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"""