diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index a80238da..9f7295dc 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -23,6 +23,7 @@ from pykickstart.version import makeVersion, RHEL7 from pylorax.api.crossdomain import crossdomain from pylorax.api.recipes import list_branch_files, read_recipe_commit, recipe_filename, list_commits from pylorax.api.recipes import recipe_from_dict, recipe_from_toml, commit_recipe, delete_recipe, revert_recipe +from pylorax.api.recipes import tag_recipe_commit from pylorax.api.workspace import workspace_read, workspace_write, workspace_delete from pylorax.creator import DRACUT_DEFAULT, mount_boot_part_over_root from pylorax.creator import make_appliance, make_image, make_livecd, make_live_images @@ -219,3 +220,15 @@ def v0_api(api): return jsonify(status=False, error={"msg":str(e)}), 400 else: return jsonify(status=True) + + @api.route("/api/v0/recipes/tag/", methods=["POST"]) + @crossdomain(origin="*") + def v0_recipes_tag(recipe_name): + """Tag a recipe's latest recipe commit as a 'revision'""" + try: + with api.config["GITLOCK"].lock: + tag_recipe_commit(api.config["GITLOCK"].repo, "master", recipe_name) + except Exception as e: + return jsonify(status=False, error={"msg":str(e)}), 400 + else: + return jsonify(status=True) diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index 92e57ad8..29f13482 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -286,3 +286,20 @@ class ServerTestCase(unittest.TestCase): expected_msg = "Recipe glusterfs.toml reverted to commit %s" % commit self.assertEqual(changes[0]["message"], expected_msg) + + def test_12_recipes_tag(self): + """Test POST /api/v0/recipes/tag/""" + resp = self.server.post("/api/v0/recipes/tag/glusterfs") + data = json.loads(resp.data) + self.assertEqual(data, {"status":True}) + + resp = self.server.get("/api/v0/recipes/changes/glusterfs") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + + # Revert it to the first commit + recipes = data.get("recipes") + self.assertNotEqual(recipes, None) + changes = recipes[0].get("changes") + self.assertEqual(len(changes) > 1, True) + self.assertEqual(changes[0]["revision"], 1)