diff --git a/src/pylorax/api/projects.py b/src/pylorax/api/projects.py index 7092b7e8..59b3d813 100644 --- a/src/pylorax/api/projects.py +++ b/src/pylorax/api/projects.py @@ -202,7 +202,7 @@ def projects_depsolve(yb, project_names): return sorted(map(tm_to_dep, yb.tsInfo.installed + yb.tsInfo.depinstalled), key=lambda p: p["name"].lower()) -def modules_list(yb): +def modules_list(yb, module_names): """Return a list of modules :param yb: yum base object @@ -218,7 +218,7 @@ def modules_list(yb): and sets the type to "rpm" """ try: - ybl = yb.doPackageLists(pkgnarrow="available", showdups=False) + ybl = yb.doPackageLists(pkgnarrow="available", patterns=module_names, showdups=False) except YumBaseError as e: raise ProjectsError("There was a problem listing modules: %s" % str(e)) return sorted(map(yaps_to_module, ybl.available), key=lambda p: p["name"].lower()) diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index b196083a..63c503e9 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -443,18 +443,22 @@ def v0_api(api): return jsonify(projects=deps) @api.route("/api/v0/modules/list") + @api.route("/api/v0/modules/list/") @crossdomain(origin="*") - def v0_modules_list(): - """List all of the available modules""" + def v0_modules_list(module_names=None): + """List available modules, filtering by module_names""" try: limit = int(request.args.get("limit", "20")) offset = int(request.args.get("offset", "0")) except ValueError as e: return jsonify(error={"msg":str(e)}), 400 + if module_names: + module_names = module_names.split(",") + try: with api.config["YUMLOCK"].lock: - available = modules_list(api.config["YUMLOCK"].yb) + available = modules_list(api.config["YUMLOCK"].yb, module_names) except ProjectsError as e: log.error("(v0_modules_list) %s", str(e)) return jsonify(error={"msg":str(e)}), 400 diff --git a/tests/pylorax/test_projects.py b/tests/pylorax/test_projects.py index 664d4d5e..dfbd56f3 100644 --- a/tests/pylorax/test_projects.py +++ b/tests/pylorax/test_projects.py @@ -147,11 +147,14 @@ class ProjectsTest(unittest.TestCase): projects_depsolve(self.yb, ["nada-package"]) def test_modules_list(self): - modules = modules_list(self.yb) + modules = modules_list(self.yb, None) self.assertEqual(len(modules) > 10, True) self.assertEqual(modules[0]["group_type"], "rpm") + modules = modules_list(self.yb, ["g*"]) + self.assertEqual(modules[0]["name"].startswith("g"), True) + def test_modules_info(self): modules = modules_info(self.yb, ["bash"]) diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index c4bd6552..606b1cdb 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -419,6 +419,14 @@ class ServerTestCase(unittest.TestCase): self.assertEqual(len(modules) > 10, True) self.assertEqual(modules[0]["group_type"], "rpm") + resp = self.server.get("/api/v0/modules/list/d*") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + print(data) + modules = data.get("modules") + self.assertEqual(len(modules) > 0, True) + self.assertEqual(modules[0]["name"].startswith("d"), True) + def test_modules_info(self): """Test /api/v0/modules/info""" resp = self.server.get("/api/v0/modules/info/bash")