diff --git a/src/pylorax/api/compose.py b/src/pylorax/api/compose.py index 08873bf0..a740c578 100644 --- a/src/pylorax/api/compose.py +++ b/src/pylorax/api/compose.py @@ -75,7 +75,7 @@ def test_templates(dbo, share_dir): ks.readKickstartFromString(ks_template+"\n%end\n") pkgs = [(name, "*") for name in ks.handler.packages.packageList] try: - _ = projects_depsolve(dbo, pkgs) + _ = projects_depsolve(dbo, pkgs, []) except ProjectsError as e: template_errors.append("Error depsolving %s: %s" % (compose_type, str(e))) @@ -258,7 +258,7 @@ def start_build(cfg, dnflock, gitlock, branch, recipe_name, compose_type, test_m deps = [] try: with dnflock.lock: - (installed_size, deps) = projects_depsolve_with_size(dnflock.dbo, projects, with_core=False) + (installed_size, deps) = projects_depsolve_with_size(dnflock.dbo, projects, recipe.group_names, with_core=False) except ProjectsError as e: log.error("start_build depsolve: %s", str(e)) raise RuntimeError("Problem depsolving %s: %s" % (recipe["name"], str(e))) @@ -274,7 +274,7 @@ def start_build(cfg, dnflock, gitlock, branch, recipe_name, compose_type, test_m ks_projects = [(name, "*") for name in ks.handler.packages.packageList] try: with dnflock.lock: - (template_size, _) = projects_depsolve_with_size(dnflock.dbo, ks_projects, + (template_size, _) = projects_depsolve_with_size(dnflock.dbo, ks_projects, [], with_core=not ks.handler.packages.nocore) except ProjectsError as e: log.error("start_build depsolve: %s", str(e)) diff --git a/src/pylorax/api/projects.py b/src/pylorax/api/projects.py index d84fc642..62233ffa 100644 --- a/src/pylorax/api/projects.py +++ b/src/pylorax/api/projects.py @@ -182,13 +182,15 @@ def projects_info(dbo, project_names): pkgs = dbo.sack.query().available() return sorted(map(pkg_to_project_info, pkgs), key=lambda p: p["name"].lower()) -def _depsolve(dbo, projects): +def _depsolve(dbo, projects, groups): """Add projects to a new transaction :param dbo: dnf base object :type dbo: dnf.Base :param projects: The projects and version globs to find the dependencies for :type projects: List of tuples + :param groups: The groups to include in dependency solving + :type groups: List of str :returns: None :rtype: None :raises: ProjectsError if there was a problem installing something @@ -196,6 +198,12 @@ def _depsolve(dbo, projects): # This resets the transaction dbo.reset(goal=True) install_errors = [] + for name in groups: + try: + dbo.group_install(name, ["mandatory", "default"]) + except dnf.exceptions.MarkingError as e: + install_errors.append(("Group %s" % (name), str(e))) + for name, version in projects: try: if not version: @@ -214,18 +222,20 @@ def _depsolve(dbo, projects): raise ProjectsError("The following package(s) had problems: %s" % ",".join(["%s (%s)" % (pattern, err) for pattern, err in install_errors])) -def projects_depsolve(dbo, projects): +def projects_depsolve(dbo, projects, groups): """Return the dependencies for a list of projects :param dbo: dnf base object :type dbo: dnf.Base :param projects: The projects to find the dependencies for :type projects: List of Strings + :param groups: The groups to include in dependency solving + :type groups: List of str :returns: NEVRA's of the project and its dependencies :rtype: list of dicts :raises: ProjectsError if there was a problem installing something """ - _depsolve(dbo, projects) + _depsolve(dbo, projects, groups) try: dbo.resolve() @@ -259,18 +269,20 @@ def estimate_size(packages, block_size=6144): return installed_size -def projects_depsolve_with_size(dbo, projects, with_core=True): +def projects_depsolve_with_size(dbo, projects, groups, with_core=True): """Return the dependencies and installed size for a list of projects :param dbo: dnf base object :type dbo: dnf.Base :param project_names: The projects to find the dependencies for :type project_names: List of Strings + :param groups: The groups to include in dependency solving + :type groups: List of str :returns: installed size and a list of NEVRA's of the project and its dependencies :rtype: tuple of (int, list of dicts) :raises: ProjectsError if there was a problem installing something """ - _depsolve(dbo, projects) + _depsolve(dbo, projects, groups) if with_core: dbo.group_install("core", ['mandatory', 'default', 'optional']) @@ -323,7 +335,7 @@ def modules_info(dbo, module_names): # Add the dependency info to each one for module in modules: - module["dependencies"] = projects_depsolve(dbo, [(module["name"], "*.*")]) + module["dependencies"] = projects_depsolve(dbo, [(module["name"], "*.*")], []) return modules diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index a0adf4ad..e268809b 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -1278,7 +1278,7 @@ def v0_api(api): deps = [] try: with api.config["DNFLOCK"].lock: - deps = projects_depsolve(api.config["DNFLOCK"].dbo, projects) + deps = projects_depsolve(api.config["DNFLOCK"].dbo, projects, blueprint.group_names) except ProjectsError as e: errors.append("%s: %s" % (blueprint_name, str(e))) log.error("(v0_blueprints_freeze) %s", str(e)) @@ -1330,7 +1330,7 @@ def v0_api(api): deps = [] try: with api.config["DNFLOCK"].lock: - deps = projects_depsolve(api.config["DNFLOCK"].dbo, projects) + deps = projects_depsolve(api.config["DNFLOCK"].dbo, projects, blueprint.group_names) except ProjectsError as e: errors.append("%s: %s" % (blueprint_name, str(e))) log.error("(v0_blueprints_depsolve) %s", str(e)) @@ -1385,7 +1385,7 @@ def v0_api(api): """Return detailed information about the listed projects""" try: with api.config["DNFLOCK"].lock: - deps = projects_depsolve(api.config["DNFLOCK"].dbo, [(n, "*") for n in project_names.split(",")]) + deps = projects_depsolve(api.config["DNFLOCK"].dbo, [(n, "*") for n in project_names.split(",")], []) except ProjectsError as e: log.error("(v0_projects_depsolve) %s", str(e)) return jsonify(status=False, errors=[str(e)]), 400 diff --git a/tests/pylorax/test_projects.py b/tests/pylorax/test_projects.py index 4ea57ad7..d22f3b44 100644 --- a/tests/pylorax/test_projects.py +++ b/tests/pylorax/test_projects.py @@ -156,27 +156,27 @@ class ProjectsTest(unittest.TestCase): self.assertEqual(projects[0]["builds"][0]["source"]["license"], "GPLv3+") def test_projects_depsolve(self): - deps = projects_depsolve(self.dbo, [("bash", "*.*")]) - + deps = projects_depsolve(self.dbo, [("bash", "*.*")], []) + self.assertTrue(len(deps) > 3) self.assertEqual(deps[0]["name"], "basesystem") def test_projects_depsolve_version(self): """Test that depsolving with a partial wildcard version works""" - deps = projects_depsolve(self.dbo, [("bash", "4.*")]) + deps = projects_depsolve(self.dbo, [("bash", "4.*")], []) self.assertEqual(deps[1]["name"], "bash") - deps = projects_depsolve(self.dbo, [("bash", "4.4.*")]) + deps = projects_depsolve(self.dbo, [("bash", "4.4.*")], []) self.assertEqual(deps[1]["name"], "bash") def test_projects_depsolve_oldversion(self): """Test that depsolving a specific non-existant version fails""" with self.assertRaises(ProjectsError): - deps = projects_depsolve(self.dbo, [("bash", "1.0.0")]) + deps = projects_depsolve(self.dbo, [("bash", "1.0.0")], []) self.assertEqual(deps[1]["name"], "bash") def test_projects_depsolve_fail(self): with self.assertRaises(ProjectsError): - projects_depsolve(self.dbo, [("nada-package", "*.*")]) + projects_depsolve(self.dbo, [("nada-package", "*.*")], []) def test_modules_list_all(self): modules = modules_list(self.dbo, None)