Merge "Fix webhook channel"

This commit is contained in:
Jenkins 2017-07-21 09:06:51 +00:00 committed by Gerrit Code Review
commit e49865bbe1
3 changed files with 5 additions and 5 deletions

View File

@ -68,7 +68,7 @@ class Receiver(object):
self.params = kwargs.get('params', {})
self.channel = kwargs.get('channel', {})
def store(self, context):
def store(self, context, update=False):
"""Store the receiver in database and return its ID.
:param context: Context for DB operations.
@ -91,12 +91,11 @@ class Receiver(object):
'channel': self.channel,
}
if self.id:
if update:
self.updated_at = timestamp
values['updated_at'] = timestamp
ro.Receiver.update(context, self.id, values)
else:
self.id = uuidutils.generate_uuid()
self.created_at = timestamp
values['created_at'] = timestamp
receiver = ro.Receiver.create(context, values)
@ -120,6 +119,7 @@ class Receiver(object):
kwargs['user'] = context.user
kwargs['project'] = context.project
kwargs['domain'] = context.domain
kwargs['id'] = uuidutils.generate_uuid()
cluster_id = cluster.id if cluster else None
obj = cls(rtype, cluster_id, action, **kwargs)
obj.initialize_channel(context)

View File

@ -2386,7 +2386,7 @@ class EngineService(service.Service):
receiver.params = req.params
changed = True
if changed:
receiver.store(ctx)
receiver.store(ctx, update=True)
else:
msg = _("No property needs an update.")
raise exception.BadRequest(msg=msg)

View File

@ -307,7 +307,7 @@ class ReceiverTest(base.SenlinTestCase):
mock_load.assert_called_once_with(self.ctx, receiver_obj=x_obj)
self.assertEqual('NEW_NAME', x_receiver.name)
self.assertEqual({'count': '3'}, x_receiver.params)
x_receiver.store.assert_called_once_with(self.ctx)
x_receiver.store.assert_called_once_with(self.ctx, update=True)
@mock.patch.object(ro.Receiver, 'find')
def test_receiver_update_not_found(self, mock_find):