Commit 47bb7e5a authored by Xavier Thompson's avatar Xavier Thompson

software/html5as-base: Add custom promise demo

parent de45e89a
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
[template-cfg] [template-cfg]
filename = instance.cfg.in filename = instance.cfg.in
md5sum = 9e486efe4ab1aba8cb72b04f6c6da8ad md5sum = 51292164b96db5889010e0962c96ee96
[instance_html5as] [instance_html5as]
_update_hash_filename_ = instance_html5as.cfg.in _update_hash_filename_ = instance_html5as.cfg.in
md5sum = f8d1777c43b173a900cfbdf104dec990 md5sum = 98b880debb61556066c5d720c1cb86e3
[template_nginx_conf] [template_nginx_conf]
_update_hash_filename_ = templates/nginx_conf.in _update_hash_filename_ = templates/nginx_conf.in
...@@ -46,3 +46,7 @@ md5sum = 1c0ee16966e1fcdb3fd11c09f12ee2b2 ...@@ -46,3 +46,7 @@ md5sum = 1c0ee16966e1fcdb3fd11c09f12ee2b2
[template_instance_replicate] [template_instance_replicate]
_update_hash_filename_ = instance_replicate.cfg.in _update_hash_filename_ = instance_replicate.cfg.in
md5sum = 7ff7e11d05145115f53564ec1af205ef md5sum = 7ff7e11d05145115f53564ec1af205ef
[custom-promise]
_update_hash_filename_ = promise/check_index_exists.py
md5sum = a98d598136629e667e7e43e1d3746b53
...@@ -15,6 +15,7 @@ template_launcher = {{ template_launcher_target }} ...@@ -15,6 +15,7 @@ template_launcher = {{ template_launcher_target }}
template_index_html = {{ template_index_html_target }} template_index_html = {{ template_index_html_target }}
template_graceful = {{ template_graceful_target }} template_graceful = {{ template_graceful_target }}
template_monitor = {{ template_monitor }} template_monitor = {{ template_monitor }}
custom_promise = {{ custom_promise }}
[instance-html5as] [instance-html5as]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
......
...@@ -14,6 +14,7 @@ parts = ...@@ -14,6 +14,7 @@ parts =
launcher launcher
nginx-graceful nginx-graceful
port-listening-promise port-listening-promise
index-exists-promise
logrotate-entry-nginx logrotate-entry-nginx
publish-connection-information publish-connection-information
...@@ -240,3 +241,11 @@ name = html5as-http-frontend.py ...@@ -240,3 +241,11 @@ name = html5as-http-frontend.py
url = ${html5as-frontend:connection-secure_access} url = ${html5as-frontend:connection-secure_access}
config-url = ${:url} config-url = ${:url}
config-check-secure = 1 config-check-secure = 1
# Add the custom promise to check that the index file exists
[index-exists-promise]
recipe = slapos.cookbook:promise.plugin
eggs = slapos.core
file = {{ parameter_list['custom_promise'] }}
output = ${directory:plugins}/check-index-exists.py
config-filepath = ${html5as:default_index}
import os
from zope.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise
@implementer(interface.IPromise)
class RunPromise(GenericPromise):
def __init__(self, config):
"""
Called when initialising the promise before testing.
Sets the configuration and the periodicity.
"""
super(RunPromise, self).__init__(config)
self.setPeriodicity(minute=2)
def sense(self):
"""
Called every time the promise is tested.
Signals a positive or negative result.
In this case, check whether the file exists.
"""
path = self.getConfig('filepath')
if os.path.isfile(path):
self.logger.info("filepath %s exists and is a file", path)
else:
self.logger.error("filepath %s does not exist or is not a file", path)
def test(self):
"""
Called after sense() if the instance is still converging.
Returns success or failure based on sense results.
In this case, fail if the previous sensor result is negative.
"""
return self._test(result_count=1, failure_amount=1)
def anomaly(self):
"""
Called after sense() if the instance has finished converging.
Returns success or failure based on sense results.
Failure signals the instance has diverged.
In this case, fail if two out of the last three results are negative.
"""
return self._anomaly(result_count=3, failure_amount=2)
...@@ -44,6 +44,7 @@ context = ...@@ -44,6 +44,7 @@ context =
key template_graceful_target template_graceful:target key template_graceful_target template_graceful:target
key template_instance_replicate template_instance_replicate:target key template_instance_replicate template_instance_replicate:target
key template_monitor monitor2-template:rendered key template_monitor monitor2-template:rendered
key custom_promise custom-promise:target
[download-base] [download-base]
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
...@@ -77,3 +78,7 @@ mode = 0644 ...@@ -77,3 +78,7 @@ mode = 0644
recipe = zc.recipe.egg recipe = zc.recipe.egg
eggs = eggs =
plone.recipe.command plone.recipe.command
# Download the custom promise
[custom-promise]
<= download-base
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