Add POST /recipes/tag/ route and tests

This commit is contained in:
Brian C. Lane 2017-11-13 16:34:23 -08:00
parent 7f1adf120c
commit a76e95dcb5
2 changed files with 30 additions and 0 deletions

View File

@ -23,6 +23,7 @@ from pykickstart.version import makeVersion, RHEL7
from pylorax.api.crossdomain import crossdomain 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 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 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.api.workspace import workspace_read, workspace_write, workspace_delete
from pylorax.creator import DRACUT_DEFAULT, mount_boot_part_over_root from pylorax.creator import DRACUT_DEFAULT, mount_boot_part_over_root
from pylorax.creator import make_appliance, make_image, make_livecd, make_live_images 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 return jsonify(status=False, error={"msg":str(e)}), 400
else: else:
return jsonify(status=True) return jsonify(status=True)
@api.route("/api/v0/recipes/tag/<recipe_name>", 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)

View File

@ -286,3 +286,20 @@ class ServerTestCase(unittest.TestCase):
expected_msg = "Recipe glusterfs.toml reverted to commit %s" % commit expected_msg = "Recipe glusterfs.toml reverted to commit %s" % commit
self.assertEqual(changes[0]["message"], expected_msg) self.assertEqual(changes[0]["message"], expected_msg)
def test_12_recipes_tag(self):
"""Test POST /api/v0/recipes/tag/<recipe_name>"""
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)