Correctifs pour le commit précédent, et de quoi tester le chaînage.

This commit is contained in:
Pierre-Elliott Bécue 2015-03-10 20:06:18 +01:00
parent 201377528c
commit f228493399
12 changed files with 99 additions and 16 deletions

View file

@ -39,12 +39,11 @@ def ack(ob_id, service_name):
if todo is None:
todo = EventTracker.get_off_record(ob_id)
logger.info("Emptied one list in the chain %r. Trying to continue. Got %r", ob_id, todo)
else:
todo = []
if todo:
for msg in todo:
logger.info("Sending %r on the road \\o/", msg)
# XXX - uncomment this when in production
trigger_send(*msg)
else:
logger.info("Aaaaaand, nothing.")

View file

@ -41,7 +41,7 @@ else:
dhcp_omapi_key = None
ldap_conn = None
@record_service
@record_service()
def dhcp(ob_id, body=None):
"""Regenerates dhcp service taking body into account.

View file

@ -123,7 +123,7 @@ class EventTracker(object):
if dico == True:
return []
if isinstance(bool, dico):
if isinstance(dico, bool):
dico = {}
return [
@ -257,9 +257,10 @@ def event(ob_id, before, after, more):
#In [16]: b
#Out[16]: [('7', 3), (5, 6), ('lol', 'lal'), (3, 'lol')]
functions = list(set([function for function in itertools.chain(*[TriggerFactory.get_parser(key) for key in diff]) if function is not None]))
LOGGER.debug("[%r] in service event, functions are %r.", ob_id, functions)
# Compute the whole list of messages. This returns a list of 2-tuples. We remove None messages, which
# may occur, since there is chained-services.
# should not occcur... But, whatever.
msgs_to_send = [msg for msg in [function(ob_id, (before, after), diff) for function in functions] if msg is not None]
LOGGER.debug("[%r] in service event, messages are %r.", ob_id, msgs_to_send)
@ -278,5 +279,5 @@ def event(ob_id, before, after, more):
def trigger_send(ob_id, routing_key, body):
"""Sends a message via civet/trigger"""
body = tuple([ob_id] + [elem for elem in body])
body = tuple([ob_id] + [body])
PRODUCER.send_message("trigger.%s" % (routing_key,), body)

View file

@ -41,7 +41,7 @@ class FwFactory(object):
def fwrecord(fun):
FwFactory.register(fun.func_name, fun)
@record_service
@record_service()
def firewall(ob_id, body=()):
"""Regens the specific service

View file

@ -0,0 +1,37 @@
#!/bin/bash /usr/scripts/python.sh
# -*- coding: utf-8 -*-
#
# Service in charge of firewall for trigger.
# Contains multiple subservices for each special
# part of firewall.
#
# Author : Pierre-Elliott Bécue <becue@crans.org>
# Licence : GPLv3
# Date : 15/06/2014
"""
Firewall service module. is uses the firewall library as it's, it
is not designed to replace it, just to call specific functions from
it to regenerate what needs to.
"""
import cranslib.clogger as clogger
import gestion.config.trigger as trigger_config
logger = clogger.CLogger("trigger", "secours", trigger_config.log_level, trigger_config.debug)
import lc_ldap.shortcuts
from gestion.trigger.host import record_service
import gestion.trigger.firewall4.firewall4 as firewall4
@record_service()
def secours(ob_id, body=()):
"""Regens the specific service
"""
if len(body) != 2:
logger.warning("Received body %r, this format is incorrect, discarding.", body)
return
(service, data) = body
logger.info("Calling service %s for data %r", service, data)
# XXX - Uncomment when in prod
#FwFactory.get(service)(data)