lorax-composer: Handle RecipeError in commit_recipe_directory
A recipe that is valid TOML can still be an invalid recipe (eg. missing the 'name' field) so this should also catch RecipeError. Also added tests for this, as well as making sure commit_recipe_file() raises the correct errors. Resolves: rhbz#1755068
This commit is contained in:
parent
3aac31482c
commit
697233c14a
@ -841,7 +841,7 @@ def commit_recipe_directory(repo, branch, directory):
|
||||
# Skip files with errors, but try the others
|
||||
try:
|
||||
commit_recipe_file(repo, branch, joinpaths(directory, f))
|
||||
except (RecipeFileError, toml.TomlError):
|
||||
except (RecipeError, RecipeFileError, toml.TomlError):
|
||||
pass
|
||||
|
||||
def tag_recipe_commit(repo, branch, recipe_name):
|
||||
|
@ -648,6 +648,16 @@ version = "0.0.1"
|
||||
[[packages]]
|
||||
name = "python"
|
||||
version = "2.7.*"
|
||||
""")
|
||||
|
||||
def _create_bad_toml_file(self):
|
||||
open(self.new_recipe, 'w').write("""customizations]
|
||||
hostname = "testing-bad-recipe"
|
||||
""")
|
||||
|
||||
def _create_bad_recipe(self):
|
||||
open(self.new_recipe, 'w').write("""[customizations]
|
||||
hostname = "testing-bad-recipe"
|
||||
""")
|
||||
|
||||
def test_01_repo_creation(self):
|
||||
@ -690,6 +700,18 @@ version = "2.7.*"
|
||||
with self.assertRaises(recipes.RecipeFileError):
|
||||
recipes.commit_recipe_file(self.repo, "master", recipe_path)
|
||||
|
||||
def test_04_commit_recipe_file_bad_toml(self):
|
||||
"""Test committing an invalid TOML file"""
|
||||
self._create_bad_toml_file()
|
||||
with self.assertRaises(TomlError):
|
||||
recipes.commit_recipe_file(self.repo, "master", self.new_recipe)
|
||||
|
||||
def test_04_commit_recipe_file_bad_recipe(self):
|
||||
"""Test committing an invalid recipe file"""
|
||||
self._create_bad_recipe()
|
||||
with self.assertRaises(recipes.RecipeError):
|
||||
recipes.commit_recipe_file(self.repo, "master", self.new_recipe)
|
||||
|
||||
def test_05_commit_toml_dir(self):
|
||||
"""Test committing a directory of TOML files"""
|
||||
# first verify that the newly created file isn't present
|
||||
@ -716,6 +738,10 @@ version = "2.7.*"
|
||||
# then create it and commit the entire directory
|
||||
self._create_another_recipe()
|
||||
|
||||
# try to commit while raising RecipeError
|
||||
with mock.patch('pylorax.api.recipes.commit_recipe_file', side_effect=recipes.RecipeError('TESTING')):
|
||||
recipes.commit_recipe_directory(self.repo, "master", self.examples_path)
|
||||
|
||||
# try to commit while raising RecipeFileError
|
||||
with mock.patch('pylorax.api.recipes.commit_recipe_file', side_effect=recipes.RecipeFileError('TESTING')):
|
||||
recipes.commit_recipe_directory(self.repo, "master", self.examples_path)
|
||||
|
Loading…
Reference in New Issue
Block a user