conf settings for ignoring errors

* basic template for error ignoring in the conf
  - Not a catch all automatic system.
  - Mainly a guideline for the conf, as actually
    ignoring the error means having the code there to
    do so. This just helps define how to put it in
    the conf.
* also clearly differentiating between error notification
  and standard for the purposes of notification engines.

Change-Id: I0d793541d6a5a402772d3030619c39e1563a9290
This commit is contained in:
adriant 2016-02-02 17:16:05 +13:00 committed by Dale Smith
parent 8b7f8d854a
commit 7867e9a784
4 changed files with 113 additions and 35 deletions

View File

@ -79,18 +79,32 @@ DEFAULT_TASK_SETTINGS:
template: completed.txt
html_template: completed.txt
notifications:
EmailNotification:
emails:
- example@example.com
reply: no-reply@example.com
template: notification.txt
html_template: completed.txt
RTNotification:
url: http://localhost/rt/REST/1.0/
queue: helpdesk
username: example@example.com
password: password
template: notification.txt
standard:
EmailNotification:
emails:
- example@example.com
reply: no-reply@example.com
template: notification.txt
html_template: completed.txt
RTNotification:
url: http://localhost/rt/REST/1.0/
queue: helpdesk
username: example@example.com
password: password
template: notification.txt
error:
EmailNotification:
emails:
- example@example.com
reply: no-reply@example.com
template: notification.txt
html_template: completed.txt
RTNotification:
url: http://localhost/rt/REST/1.0/
queue: errors
username: example@example.com
password: password
template: notification.txt
# These are cascading overrides for the default settings:
TASK_SETTINGS:
@ -101,10 +115,27 @@ TASK_SETTINGS:
actions:
- AddAdminToProject
- DefaultProjectResources
notifications:
standard:
EmailNotification:
emails:
- signups@example.com
RTNotification:
queue: signups
error:
EmailNotification:
emails:
- signups@example.com
RTNotification:
queue: signups
invite_user:
emails:
# To not send this email, set the value to null
initial: null
errors:
SMTPException:
notification: acknowledge
engines: False
reset_password:
handle_duplicates: cancel
emails:
@ -114,6 +145,10 @@ TASK_SETTINGS:
reply: no-reply@example.com
template: password_reset.txt
html_template: password_reset.txt
errors:
SMTPException:
notification: acknowledge
engines: False
force_password:
handle_duplicates: cancel
emails:
@ -123,6 +158,10 @@ TASK_SETTINGS:
reply: no-reply@example.com
template: initial_password.txt
html_template: initial_password.txt
errors:
SMTPException:
notification: acknowledge
engines: False
edit_user:
emails:
initial: null
@ -167,3 +206,4 @@ ROLES_MAPPING:
- project_mod
- heat_stack_owner
- _member_

View File

@ -28,7 +28,7 @@ def create_token(task):
return token
def send_email(registration, email_conf, token=None):
def send_email(task, email_conf, token=None):
if not email_conf:
return
@ -37,7 +37,7 @@ def send_email(registration, email_conf, token=None):
emails = set()
actions = []
for action in registration.actions:
for action in task.actions:
act = action.get_action()
email = act.get_email()
if email:
@ -48,20 +48,20 @@ def send_email(registration, email_conf, token=None):
notes = {
'errors':
(("Error: Unable to send token, More than one email for" +
" registration: %s") % registration.uuid)
" task: %s") % task.uuid)
}
create_notification(registration, notes, error=True)
create_notification(task, notes, error=True)
return
if token:
context = {
'registration': registration,
'task': task,
'actions': actions,
'tokenurl': settings.TOKEN_SUBMISSION_URL,
'token': token.token,
}
else:
context = {'registration': registration, 'actions': actions}
context = {'task': task, 'actions': actions}
try:
message = template.render(context)
@ -72,13 +72,27 @@ def send_email(registration, email_conf, token=None):
except SMTPException as e:
notes = {
'errors':
("Error: '%s' while emailing token for registration: %s" %
(e, registration.uuid))
("Error: '%s' while emailing token for task: %s" %
(e, task.uuid))
}
create_notification(registration, notes, error=True)
errors_conf = settings.TASK_SETTINGS.get(
task.task_type, {}).get('errors', {}).get(
"SMTPException", {})
if errors_conf:
notification = create_notification(
task, notes, error=True,
engines=errors_conf.get('engines', True))
if errors_conf.get('notification') == "acknowledge":
notification.acknowledged = True
notification.save()
else:
create_notification(task, notes, error=True)
def create_notification(task, notes, error=False):
def create_notification(task, notes, error=False, engines=True):
notification = Notification.objects.create(
task=task,
notes=notes,
@ -86,15 +100,23 @@ def create_notification(task, notes, error=False):
)
notification.save()
if not engines:
return notification
class_conf = settings.TASK_SETTINGS.get(task.task_type, {})
# NOTE(adriant): some form of error handling is probably needed:
for note_engine, conf in class_conf.get('notifications', {}).iteritems():
if error:
conf = conf.get('error', {})
else:
conf = conf.get('standard', {})
if not conf:
continue
engine = settings.NOTIFICATION_ENGINES[note_engine](conf)
engine.notify(task, notification)
return notification
def create_task_hash(task_type, action_list):
hashable_list = [task_type, ]

View File

@ -40,12 +40,20 @@ class EmailNotification(NotificationEngine):
Example conf:
<TaskView>:
notifications:
EmailNotification:
emails:
- example@example.com
reply: no-reply@example.com
template: notification.txt
html_template: completed.txt
standard:
EmailNotification:
emails:
- example@example.com
reply: no-reply@example.com
template: notification.txt
html_template: completed.txt
error:
EmailNotification:
emails:
- errors@example.com
reply: no-reply@example.com
template: notification.txt
html_template: completed.txt
<other notification>:
...
"""

View File

@ -29,12 +29,20 @@ class RTNotification(NotificationEngine):
Example conf:
<TaskView>:
notifications:
RTNotification:
url: http://localhost/rt/REST/1.0/
queue: helpdesk
username: example@example.com
password: password
template: notification.txt
standard:
RTNotification:
url: http://localhost/rt/REST/1.0/
queue: helpdesk
username: example@example.com
password: password
template: notification.txt
error:
RTNotification:
url: http://localhost/rt/REST/1.0/
queue: errors
username: example@example.com
password: password
template: notification.txt
<other notification>:
...
"""