From 639d325a0c14a8596a60861a35355199dc3905cc Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 13 Nov 2017 15:14:24 -0800 Subject: [PATCH] Change read_recipe_commit to use the recipe name Callers really shouldn't need to know the details of the filenames, so change it to convert it internally. --- src/pylorax/api/recipes.py | 10 +++++----- src/pylorax/api/v0.py | 5 ++--- tests/pylorax/test_recipes.py | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/pylorax/api/recipes.py b/src/pylorax/api/recipes.py index 87429ea7..485833d1 100644 --- a/src/pylorax/api/recipes.py +++ b/src/pylorax/api/recipes.py @@ -292,15 +292,15 @@ def read_commit(repo, branch, filename, commit=None): """ return read_commit_spec(repo, "%s:%s" % (commit or branch, filename)) -def read_recipe_commit(repo, branch, filename, commit=None): +def read_recipe_commit(repo, branch, recipe_name, commit=None): """Read a recipe commit from git and return a Recipe object :param repo: Open repository :type repo: Git.Repository :param branch: Branch name :type branch: str - :param filename: filename to read - :type filename: str + :param recipe_name: Recipe name to read + :type recipe_name: str :param commit: Optional commit hash :type commit: str :returns: A Recipe object @@ -310,7 +310,7 @@ def read_recipe_commit(repo, branch, filename, commit=None): If no commit is passed the master:filename is returned, otherwise it will be commit:filename """ - recipe_toml = read_commit(repo, branch, filename, commit) + recipe_toml = read_commit(repo, branch, recipe_filename(recipe_name), commit) return recipe_from_toml(recipe_toml) def list_branch_files(repo, branch): @@ -441,7 +441,7 @@ def commit_recipe(repo, branch, recipe): :raises: Can raise errors from Ggit """ try: - old_recipe = read_recipe_commit(repo, branch, recipe.filename) + old_recipe = read_recipe_commit(repo, branch, recipe["name"]) old_version = old_recipe["version"] except Exception: old_version = None diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 1278231f..a22b23e8 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -75,7 +75,6 @@ def v0_api(api): errors = [] for recipe_name in [n.strip() for n in recipe_names.split(",")]: exceptions = [] - filename = recipe_filename(recipe_name) # Get the workspace version (if it exists) try: with api.config["GITLOCK"].lock: @@ -87,7 +86,7 @@ def v0_api(api): # Get the git version (if it exists) try: with api.config["GITLOCK"].lock: - git_recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", filename) + git_recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", recipe_name) except Exception as e: git_recipe = None exceptions.append(str(e)) @@ -157,7 +156,7 @@ def v0_api(api): commit_recipe(api.config["GITLOCK"].repo, "master", recipe) # Read the recipe with new version and write it to the workspace - recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", recipe.filename) + recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", recipe["name"]) workspace_write(api.config["GITLOCK"].repo, "master", recipe) except Exception as e: return jsonify(status=False, error={"msg":str(e)}), 400 diff --git a/tests/pylorax/test_recipes.py b/tests/pylorax/test_recipes.py index 6f1b2277..37f76a79 100644 --- a/tests/pylorax/test_recipes.py +++ b/tests/pylorax/test_recipes.py @@ -151,12 +151,12 @@ class GitRecipesTest(unittest.TestCase): commits = recipes.list_commits(self.repo, "master", "http-server.toml") self.assertEqual(len(commits), 1, "Wrong number of commits: %s" % commits) - recipe = recipes.read_recipe_commit(self.repo, "master", "http-server.toml") + recipe = recipes.read_recipe_commit(self.repo, "master", "http-server") self.assertNotEqual(recipe, None) self.assertEqual(recipe["name"], "http-server") # Read by commit id - recipe = recipes.read_recipe_commit(self.repo, "master", "http-server.toml", commits[0].commit) + recipe = recipes.read_recipe_commit(self.repo, "master", "http-server", commits[0].commit) self.assertNotEqual(recipe, None) self.assertEqual(recipe["name"], "http-server") @@ -193,7 +193,7 @@ class GitRecipesTest(unittest.TestCase): def test_10_tag_new_commit(self): """Test tagging a newer commit of a recipe""" - recipe = recipes.read_recipe_commit(self.repo, "master", "http-server.toml") + recipe = recipes.read_recipe_commit(self.repo, "master", "http-server") recipe["description"] = "A modified description" oid = recipes.commit_recipe(self.repo, "master", recipe) self.assertNotEqual(oid, None)