Commit 569439d5 authored by Julien Muchembled's avatar Julien Muchembled

resilient: fix notifier.callback parts installing the same path

parent 58f40553
...@@ -28,7 +28,7 @@ from setuptools import setup, find_packages ...@@ -28,7 +28,7 @@ from setuptools import setup, find_packages
import glob import glob
import os import os
version = '1.0.142' version = '1.0.143'
name = 'slapos.cookbook' name = 'slapos.cookbook'
long_description = open("README.rst").read() long_description = open("README.rst").read()
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
# #
############################################################################## ##############################################################################
import errno import errno
import io
import logging import logging
import os import os
import sys import sys
...@@ -124,21 +123,6 @@ class GenericBaseRecipe(object): ...@@ -124,21 +123,6 @@ class GenericBaseRecipe(object):
def createExecutable(self, name, content, mode=0o700): def createExecutable(self, name, content, mode=0o700):
return self.createFile(name, content, mode) return self.createFile(name, content, mode)
def addLineToFile(self, filepath, line, encoding='utf8'):
"""Append a single line to a text file, if the line does not exist yet.
line must be unicode."""
if os.path.exists(filepath):
lines = [l.rstrip('\n') for l in io.open(filepath, 'r', encoding=encoding)]
else:
lines = []
if not line in lines:
lines.append(line)
with io.open(filepath, 'w+', encoding=encoding) as f:
f.write(u'\n'.join(lines))
def createPythonScript(self, name, absolute_function, args=(), kw={}): def createPythonScript(self, name, absolute_function, args=(), kw={}):
"""Create a python script using zc.buildout.easy_install.scripts """Create a python script using zc.buildout.easy_install.scripts
......
...@@ -46,20 +46,16 @@ class Recipe(GenericBaseRecipe): ...@@ -46,20 +46,16 @@ class Recipe(GenericBaseRecipe):
class Callback(GenericBaseRecipe): class Callback(GenericBaseRecipe):
def createCallback(self, notification_id, callback): def install(self):
options = self.options
notification_id = options['on-notification-id']
# XXX: hashing the name here and in # XXX: hashing the name here and in
# slapos.toolbox/slapos/pubsub/__init__.py is completely messed up and # slapos.toolbox/slapos/pubsub/__init__.py is completely messed up and
# prevent any debug. # prevent any debug.
callback_id = sha512(str2bytes(notification_id)).hexdigest() callback_id = sha512(str2bytes(notification_id)).hexdigest()
filepath = os.path.join(self.options['callbacks'], callback_id) return self.createFile(os.path.join(options['directory'], callback_id),
self.addLineToFile(filepath, callback) options['callbacks'])
return filepath
def install(self):
# XXX this path is returned multiple times, one for each callback that has been added.
return [self.createCallback(self.options['on-notification-id'],
self.options['callback'])]
class Notify(GenericBaseRecipe): class Notify(GenericBaseRecipe):
......
...@@ -26,7 +26,7 @@ md5sum = 2852689640b632fc713d7a603ce66207 ...@@ -26,7 +26,7 @@ md5sum = 2852689640b632fc713d7a603ce66207
[instance-runner-import] [instance-runner-import]
filename = instance-runner-import.cfg.in filename = instance-runner-import.cfg.in
md5sum = 9a3adacb4a833b1af3715e7097d31aad md5sum = a582be15f0fb797fc75cfc39cd1d12ab
[instance-runner-export] [instance-runner-export]
filename = instance-runner-export.cfg.in filename = instance-runner-export.cfg.in
......
...@@ -29,8 +29,6 @@ parts += ...@@ -29,8 +29,6 @@ parts +=
software-release-deployment-promise software-release-deployment-promise
resilient-software-release-information resilient-software-release-information
# have to repeat the next one, as it's not inherited from pbsready-import
import-on-notification
monitor-base monitor-base
......
...@@ -94,7 +94,7 @@ extends = ${instance-mysoftware:output} ...@@ -94,7 +94,7 @@ extends = ${instance-mysoftware:output}
parts += parts +=
mysoftware mysoftware
import-on-notification notify-callback
[importer] [importer]
recipe = YourImportRecipe recipe = YourImportRecipe
......
...@@ -18,7 +18,7 @@ md5sum = 66331047b7dbf2513c5726d5d1647320 ...@@ -18,7 +18,7 @@ md5sum = 66331047b7dbf2513c5726d5d1647320
[pbsready-import] [pbsready-import]
filename = pbsready-import.cfg.in filename = pbsready-import.cfg.in
md5sum = d813c43ed00eff868fb13bc75b045336 md5sum = 6f32cede10cf0d6430c017f49fe5aa30
[pbsready-export] [pbsready-export]
filename = pbsready-export.cfg.in filename = pbsready-export.cfg.in
......
...@@ -7,8 +7,7 @@ parts += ...@@ -7,8 +7,7 @@ parts +=
resilient-web-takeover-httpd-wrapper resilient-web-takeover-httpd-wrapper
resilient-web-takeover-httpd-promise resilient-web-takeover-httpd-promise
check-backup-integrity-on-notification notify-callback
import-on-notification
backup-checksum-integrity-promise backup-checksum-integrity-promise
resilient-publish-connection-parameter resilient-publish-connection-parameter
...@@ -39,13 +38,17 @@ minimum = 65516 ...@@ -39,13 +38,17 @@ minimum = 65516
maximum = 65525 maximum = 65525
ip = $${notifier:host} ip = $${notifier:host}
[import-on-notification] [notify-callback]
# notifier.callback runs a script when a notification (sent by a parent PBS) # notifier.callback runs a script when a notification (sent by a parent PBS)
# is received # is received
<= notifier
recipe = slapos.cookbook:notifier.callback recipe = slapos.cookbook:notifier.callback
directory = $${notifier:callbacks}
on-notification-id = $${slap-parameter:on-notification} on-notification-id = $${slap-parameter:on-notification}
callback = $${importer:wrapper} callbacks =
# import on notification
$${importer:wrapper}
# check backup integrity on notification
$${post-notification-run:output}
[post-notification-run] [post-notification-run]
recipe = collective.recipe.template recipe = collective.recipe.template
...@@ -59,12 +62,6 @@ input = inline: ...@@ -59,12 +62,6 @@ input = inline:
output = $${rootdirectory:bin}/post-notification-run output = $${rootdirectory:bin}/post-notification-run
mode = 0700 mode = 0700
[check-backup-integrity-on-notification]
<= notifier
recipe = slapos.cookbook:notifier.callback
on-notification-id = $${slap-parameter:on-notification}
callback = $${post-notification-run:output}
[backup-checksum-integrity-promise-bin] [backup-checksum-integrity-promise-bin]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
template = inline: template = inline:
......
...@@ -137,7 +137,7 @@ pyparsing = 2.2.0 ...@@ -137,7 +137,7 @@ pyparsing = 2.2.0
pytz = 2016.10 pytz = 2016.10
requests = 2.13.0 requests = 2.13.0
six = 1.12.0 six = 1.12.0
slapos.cookbook = 1.0.142 slapos.cookbook = 1.0.143
slapos.core = 1.5.9 slapos.core = 1.5.9
slapos.extension.strip = 0.4 slapos.extension.strip = 0.4
slapos.extension.shared = 1.0 slapos.extension.shared = 1.0
......
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