Commit 19f683ef authored by Łukasz Nowak's avatar Łukasz Nowak

slapos.cookbook: Add _failsafe publish type recipes

In some contexts it's required to not stop buildout processing on publishing
errors, thus such recipe is required in those cases.

By providing -error-status-file it's possible to check status of the publish,
the file will be created on error and removed on successful call or during
uninstall. It's responsibility of the caller to handle such errors, for example
by using proper promises.
parent 40836b97
Pipeline #25348 failed with stage
......@@ -131,6 +131,8 @@ setup(name=name,
'publish-early = slapos.recipe.publish_early:Recipe',
'publishsection = slapos.recipe.publish:PublishSection',
'publishurl = slapos.recipe.publishurl:Recipe',
'publish_failsafe = slapos.recipe.publish:RecipeFailsafe',
'publish.serialised_failsafe = slapos.recipe.publish:SerialisedFailsafe',
'random.time = slapos.recipe.random:Time',
'random.integer = slapos.recipe.random:Integer',
'readline = slapos.recipe.readline:Recipe',
......
......@@ -29,10 +29,12 @@ import zc.buildout
from slapos.recipe.librecipe import wrap
from slapos.recipe.librecipe import GenericSlapRecipe
import six
import os
CONNECTION_PARAMETER_STRING = 'connection-'
class Recipe(GenericSlapRecipe):
return_list = []
def __init__(self, buildout, name, options):
super(Recipe, self).__init__(buildout, name, options)
# Tell buildout about the sections we will access during install.
......@@ -55,7 +57,7 @@ class Recipe(GenericSlapRecipe):
for k in publish:
publish_dict[k] = section[k]
self._setConnectionDict(publish_dict, self.options.get('-slave-reference'))
return []
return self.return_list
def _setConnectionDict(self, publish_dict, slave_reference=None):
return self.setConnectionDict(publish_dict, slave_reference)
......@@ -65,6 +67,32 @@ class Serialised(Recipe):
return super(Serialised, self)._setConnectionDict(wrap(publish_dict), slave_reference)
class Failsafe(object):
def _setConnectionDict(self, publish_dict, slave_reference):
error_status_file = self.options.get('-error-status-file')
if error_status_file:
self.return_list = [error_status_file]
else:
self.return_list = []
try:
super(Failsafe, self)._setConnectionDict(publish_dict, slave_reference)
except Exception:
if error_status_file is not None:
with open(error_status_file, 'w') as fh:
fh.write('')
else:
if error_status_file is not None:
if os.path.exists(error_status_file):
os.unlink(error_status_file)
class RecipeFailsafe(Failsafe, Recipe):
pass
class SerialisedFailsafe(Failsafe, Serialised):
pass
class PublishSection(GenericSlapRecipe):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment