From 90a8798f4c14276534e0e2d882c966556e0250ba Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Tue, 7 Nov 2017 15:14:58 -0800 Subject: [PATCH] Move the git repo into a subdirectory And fix the import of recipes (needs to have full path passed in). --- src/pylorax/api/recipes.py | 11 ++++++----- tests/pylorax/test_recipes.py | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pylorax/api/recipes.py b/src/pylorax/api/recipes.py index 700662f9..fe3c1685 100644 --- a/src/pylorax/api/recipes.py +++ b/src/pylorax/api/recipes.py @@ -200,15 +200,16 @@ def open_or_create_repo(path): :rtype: Git.Repository :raises: Can raise errors from Ggit - A bare git repo will be created in at the specified path. + A bare git repo will be created in the git directory of the specified path. If a repo already exists it will be opened and returned instead of creating a new one. """ Git.init() - if os.path.exists(joinpaths(path, "HEAD")): - return Git.Repository.open(gfile(path)) + git_path = joinpaths(path, "git") + if os.path.exists(joinpaths(git_path, "HEAD")): + return Git.Repository.open(gfile(git_path)) - repo = Git.Repository.init_repository(gfile(path), True) + repo = Git.Repository.init_repository(gfile(git_path), True) # Make an initial empty commit sig = Git.Signature.new_now("bdcs-api-server", "user-email") @@ -445,7 +446,7 @@ def commit_recipe_directory(repo, branch, directory): for f in new_files: # Skip files with errors, but try the others try: - commit_recipe_file(repo, branch, f) + commit_recipe_file(repo, branch, joinpaths(directory, f)) except (RecipeFileError, toml.TomlError): pass diff --git a/tests/pylorax/test_recipes.py b/tests/pylorax/test_recipes.py index cd6110cc..39b2b643 100644 --- a/tests/pylorax/test_recipes.py +++ b/tests/pylorax/test_recipes.py @@ -105,6 +105,7 @@ class GitRecipesTest(unittest.TestCase): self.repo = recipes.open_or_create_repo(self.repo_dir) self.results_path = "./tests/pylorax/results/" + self.examples_path = "./tests/pylorax/recipes/" @classmethod def tearDownClass(self): @@ -143,7 +144,7 @@ class GitRecipesTest(unittest.TestCase): def test_05_commit_toml_dir(self): """Test committing a directory of TOML files""" # It worked if it doesn't raise errors - recipes.commit_recipe_directory(self.repo, "master", self.results_path) + recipes.commit_recipe_directory(self.repo, "master", self.examples_path) def test_06_read_recipe(self): """Test reading a recipe from a commit"""