Don't send confirmation notification if it's not enabled

Currently even though the 'require_confirmation' option is False,
Zaqar will send the confirmation notification anyway, which is
breaking the backward compatibility. This patch will fix it and
add a test for that.

Closes-Bug: #1633222

Change-Id: I2d6363feab90ff737684d5c1d903c2c2d7abe106
This commit is contained in:
Fei Long Wang 2016-11-02 14:59:59 +13:00
parent 0af1fe3e0b
commit c19d0a0153
2 changed files with 21 additions and 1 deletions

View File

@ -82,6 +82,11 @@ class NotifierDriver(object):
def send_confirm_notification(self, queue, subscription, conf, def send_confirm_notification(self, queue, subscription, conf,
project=None, expires=None, project=None, expires=None,
api_version=None): api_version=None):
# NOTE(flwang): If the confirmation feature isn't enabled, just do
# nothing.
if not self.require_confirmation:
return
key = conf.signed_url.secret_key key = conf.signed_url.secret_key
if not key: if not key:
LOG.error(_LE("Can't send confirm notification due to the value of" LOG.error(_LE("Can't send confirm notification due to the value of"

View File

@ -18,6 +18,7 @@ import uuid
import mock import mock
from zaqar.common import urls
from zaqar.notification import notifier from zaqar.notification import notifier
from zaqar import tests as testing from zaqar import tests as testing
@ -269,7 +270,8 @@ class NotifierTest(testing.TestBase):
'options': {}} 'options': {}}
ctlr = mock.MagicMock() ctlr = mock.MagicMock()
ctlr.list = mock.Mock(return_value=subscription) ctlr.list = mock.Mock(return_value=subscription)
driver = notifier.NotifierDriver(subscription_controller=ctlr) driver = notifier.NotifierDriver(subscription_controller=ctlr,
require_confirmation=True)
self.conf.signed_url.secret_key = 'test_key' self.conf.signed_url.secret_key = 'test_key'
driver.send_confirm_notification('test_queue', subscription, self.conf, driver.send_confirm_notification('test_queue', subscription, self.conf,
str(self.project), str(self.project),
@ -298,3 +300,16 @@ class NotifierTest(testing.TestBase):
driver.executor.shutdown() driver.executor.shutdown()
self.assertEqual(0, mock_request.call_count) self.assertEqual(0, mock_request.call_count)
@mock.patch.object(urls, 'create_signed_url')
def test_require_confirmation_false(self, mock_create_signed_url):
subscription = [{'subscriber': 'http://trigger_me',
'source': 'fake_queue', 'options': {}}]
ctlr = mock.MagicMock()
driver = notifier.NotifierDriver(subscription_controller=ctlr,
require_confirmation=False)
driver.send_confirm_notification('test_queue', subscription, self.conf,
str(self.project), self.api_version)
self.assertFalse(mock_create_signed_url.called)