From c19d0a0153a0e63d6806616092ed234431d4599d Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Wed, 2 Nov 2016 14:59:59 +1300 Subject: [PATCH] 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 --- zaqar/notification/notifier.py | 5 +++++ zaqar/tests/unit/notification/test_notifier.py | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/zaqar/notification/notifier.py b/zaqar/notification/notifier.py index de9283631..4c56ef8b7 100644 --- a/zaqar/notification/notifier.py +++ b/zaqar/notification/notifier.py @@ -82,6 +82,11 @@ class NotifierDriver(object): def send_confirm_notification(self, queue, subscription, conf, project=None, expires=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 if not key: LOG.error(_LE("Can't send confirm notification due to the value of" diff --git a/zaqar/tests/unit/notification/test_notifier.py b/zaqar/tests/unit/notification/test_notifier.py index efc12f137..07933ab37 100644 --- a/zaqar/tests/unit/notification/test_notifier.py +++ b/zaqar/tests/unit/notification/test_notifier.py @@ -18,6 +18,7 @@ import uuid import mock +from zaqar.common import urls from zaqar.notification import notifier from zaqar import tests as testing @@ -269,7 +270,8 @@ class NotifierTest(testing.TestBase): 'options': {}} ctlr = mock.MagicMock() 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' driver.send_confirm_notification('test_queue', subscription, self.conf, str(self.project), @@ -298,3 +300,16 @@ class NotifierTest(testing.TestBase): driver.executor.shutdown() 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)