Allow users to set periodic notifications on all notification types
In some cases, users may want to send periodic notifications for notification types other than webhooks. Change-Id: I0256e9a8c3dacaf8bc6066b00daefaa993460a2d Story: 2006837 Task: 37420
This commit is contained in:
parent
a6ff997871
commit
b228dfa61e
@ -98,21 +98,12 @@ class TestNotificationsShellV2(base.BaseTestCase):
|
||||
self._patch_test(mc, args, data)
|
||||
|
||||
@mock.patch('monascaclient.osc.migration.make_client')
|
||||
def test_bad_notifications_patch(self, mc):
|
||||
mc.return_value = c = FakeV2Client()
|
||||
|
||||
id_str = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
|
||||
raw_args = ('{0} --type EMAIL --address john.doe@hpe.com '
|
||||
'--period 60').format(id_str).split(' ')
|
||||
name, cmd_clazz = migr.create_command_class('do_notification_patch',
|
||||
shell)
|
||||
cmd = cmd_clazz(mock.Mock(), mock.Mock())
|
||||
|
||||
parser = cmd.get_parser(name)
|
||||
parsed_args = parser.parse_args(raw_args)
|
||||
cmd.run(parsed_args)
|
||||
|
||||
c.notifications.patch.assert_not_called()
|
||||
def test_good_notifications_patch_recurring_email(self, mc):
|
||||
args = '--type EMAIL --address john.doe@hpe.com --period 60'
|
||||
data = {'type': 'EMAIL',
|
||||
'address': 'john.doe@hpe.com',
|
||||
'period': 60}
|
||||
self._patch_test(mc, args, data)
|
||||
|
||||
@mock.patch('monascaclient.osc.migration.make_client')
|
||||
def test_good_notifications_update(self, mc):
|
||||
|
@ -554,13 +554,6 @@ def do_metric_statistics(mc, args):
|
||||
formatters=formatters)
|
||||
|
||||
|
||||
def _validate_notification_period(period, notification_type):
|
||||
if notification_type != 'WEBHOOK' and period != 0:
|
||||
print("Invalid period, can only be non zero for webhooks")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@utils.arg('name', metavar='<NOTIFICATION_NAME>',
|
||||
help='Name of the notification to create.')
|
||||
@utils.arg('type', metavar='<TYPE>',
|
||||
@ -568,7 +561,7 @@ def _validate_notification_period(period, notification_type):
|
||||
@utils.arg('address', metavar='<ADDRESS>',
|
||||
help='A valid EMAIL Address, URL, or SERVICE KEY.')
|
||||
@utils.arg('--period', metavar='<PERIOD>', type=int, default=0,
|
||||
help='A period for the notification method. Can only be non zero with webhooks')
|
||||
help='A period for the notification method.')
|
||||
def do_notification_create(mc, args):
|
||||
'''Create notification.'''
|
||||
|
||||
@ -577,8 +570,6 @@ def do_notification_create(mc, args):
|
||||
fields['type'] = args.type
|
||||
fields['address'] = args.address
|
||||
if args.period:
|
||||
if not _validate_notification_period(args.period, args.type.upper()):
|
||||
return
|
||||
fields['period'] = args.period
|
||||
try:
|
||||
notification = mc.notifications.create(**fields)
|
||||
@ -696,7 +687,7 @@ def do_notification_delete(mc, args):
|
||||
@utils.arg('address', metavar='<ADDRESS>',
|
||||
help='A valid EMAIL Address, URL, or SERVICE KEY.')
|
||||
@utils.arg('period', metavar='<PERIOD>', type=int,
|
||||
help='A period for the notification method. Can only be non zero with webhooks')
|
||||
help='A period for the notification method.')
|
||||
def do_notification_update(mc, args):
|
||||
'''Update notification.'''
|
||||
fields = {}
|
||||
@ -705,8 +696,6 @@ def do_notification_update(mc, args):
|
||||
|
||||
fields['type'] = args.type
|
||||
fields['address'] = args.address
|
||||
if not _validate_notification_period(args.period, args.type.upper()):
|
||||
return
|
||||
fields['period'] = args.period
|
||||
try:
|
||||
notification = mc.notifications.update(**fields)
|
||||
@ -725,7 +714,7 @@ def do_notification_update(mc, args):
|
||||
@utils.arg('--address', metavar='<ADDRESS>',
|
||||
help='A valid EMAIL Address, URL, or SERVICE KEY.')
|
||||
@utils.arg('--period', metavar='<PERIOD>', type=int,
|
||||
help='A period for the notification method. Can only be non zero with webhooks')
|
||||
help='A period for the notification method.')
|
||||
def do_notification_patch(mc, args):
|
||||
'''Patch notification.'''
|
||||
fields = {}
|
||||
@ -738,9 +727,6 @@ def do_notification_patch(mc, args):
|
||||
if args.address:
|
||||
fields['address'] = args.address
|
||||
if args.period or args.period == 0:
|
||||
if args.type and not _validate_notification_period(
|
||||
args.period, args.type.upper()):
|
||||
return
|
||||
fields['period'] = args.period
|
||||
try:
|
||||
notification = mc.notifications.patch(**fields)
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds support for setting notification period for all types.
|
Loading…
Reference in New Issue
Block a user