def test_notification_driver_option(self): self.config(rpc_backend='qpid') self.config(notification_driver='messaging') self.config(notifier_strategy='rabbit') notify = notifier.Notifier() self.assertEqual(str(notify._transport._driver._url), 'rabbit:///') self.config(notifier_strategy='default') notify = notifier.Notifier() self.assertEqual(str(notify._transport._driver._url), 'qpid:///')
def setUp(self): self.stubs = stubout.StubOutForTesting() def _fake_connect(rabbit_self): rabbit_self.connection_errors = () rabbit_self.connection = 'fake_connection' rabbit_self.exchange = self._fake_exchange() return None def dummy(*args, **kwargs): pass self.stubs.Set(kombu.entity.Exchange, 'publish', dummy) self.stubs.Set(glance.notifier.notify_kombu.RabbitStrategy, '_connect', _fake_connect) self.called = False self.conf = utils.TestConfigOpts({ "notifier_strategy": "rabbit", "rabbit_retry_backoff": 0, "rabbit_notification_topic": "fake_topic" }) self.notifier = notifier.Notifier(self.conf) super(TestRabbitContentType, self).setUp()
def _process_v2_request(self, request, image_id, image_iterator): # We do some contortions to get the image_metadata so # that we can provide it to 'size_checked_iter' which # will generate a notification. # TODO(mclaren): Make notification happen more # naturally once caching is part of the domain model. db_api = glance.db.get_api() image_repo = glance.db.ImageRepo(request.context, db_api) image = image_repo.get(image_id) image_meta = glance.notifier.format_image_notification(image) self._verify_metadata(image_meta) response = webob.Response(request=request) response.app_iter = size_checked_iter(response, image_meta, image_meta['size'], image_iterator, notifier.Notifier()) # NOTE (flwang): Set the content-type, content-md5 and content-length # explicitly to be consistent with the non-cache scenario. # Besides, it's not worth the candle to invoke the "download" method # of ResponseSerializer under image_data. Because method "download" # will reset the app_iter. Then we have to call method # "size_checked_iter" to avoid missing any notification. But after # call "size_checked_iter", we will lose the content-md5 and # content-length got by the method "download" because of this issue: # https://github.com/Pylons/webob/issues/86 response.headers['Content-Type'] = 'application/octet-stream' response.headers['Content-MD5'] = image.checksum response.headers['Content-Length'] = str(image.size) return response
def test_connection_error_on_send_message_reconnects(self): info = {'send_called': 0, 'conn_called': 0} class MyException(Exception): pass def _connect(rabbit_self): info['conn_called'] += 1 rabbit_self.connection_errors = (MyException, ) rabbit_self.connection = 'fake_connection' def _send_message(rabbit_self, msg, routing_key): info['send_called'] += 1 if info['send_called'] == 1: raise MyException('meow') self._send_message(msg, routing_key) self.notify_kombu.RabbitStrategy._connect = _connect self.notify_kombu.RabbitStrategy._send_message = _send_message notifier_ = notifier.Notifier() notifier_.error('test_event', 'test_message') if self.called is False: self.fail("Did not call _send_message properly.") self.assertEquals("test_message", self.called["message"]["payload"]) self.assertEquals("ERROR", self.called["message"]["priority"]) self.assertEquals(info['send_called'], 2) self.assertEquals(info['conn_called'], 2)
def __init__(self): create_stores() self.verify_scheme_or_exit(CONF.default_store) self.notifier = notifier.Notifier() registry.configure_registry_client() self.policy = policy.Enforcer() self.pool = eventlet.GreenPool(size=1024)
def _test_load_strategy(self, mock_get_transport, mock_notifier, url, driver): nfier = notifier.Notifier() mock_get_transport.assert_called_with(cfg.CONF) self.assertIsNotNone(nfier._transport) mock_notifier.assert_called_with(nfier._transport, publisher_id='image.localhost') self.assertIsNotNone(nfier._notifier)
def __init__(self, conf): self.conf = conf self.conf.register_opt(default_store_opt) create_stores(self.conf) self.verify_scheme_or_exit(self.conf.default_store) self.notifier = notifier.Notifier(conf) registry.configure_registry_client(conf) self.policy = policy.Enforcer(conf)
def __init__(self): self.notifier = notifier.Notifier() registry.configure_registry_client() self.policy = policy.Enforcer() self.pool = eventlet.GreenPool(size=1024) if property_utils.is_property_protection_enabled(): self.prop_enforcer = property_utils.PropertyRules(self.policy) else: self.prop_enforcer = None
def test_unknown_error_on_send_message_raises(self): class MyException(Exception): pass def _send_message(rabbit_self, msg, routing_key): raise MyException('meow') self.notify_kombu.RabbitStrategy._send_message = _send_message notifier_ = notifier.Notifier() self.assertRaises(MyException, notifier_.error, 'a', 'b')
def _process_v2_request(self, request, image_id, image_iterator): # We do some contortions to get the image_metadata so # that we can provide it to 'size_checked_iter' which # will generate a notification. # TODO(mclaren): Make notification happen more # naturally once caching is part of the domain model. db_api = glance.db.get_api() image_repo = glance.db.ImageRepo(request.context, db_api) image = image_repo.get(image_id) image_meta = glance.notifier.format_image_notification(image) self._verify_metadata(image_meta) response = webob.Response(request=request) response.app_iter = size_checked_iter(response, image_meta, image_meta['size'], image_iterator, notifier.Notifier()) return response
def setUp(self): super(TestRabbitNotifier, self).setUp() def _fake_connect(rabbit_self): rabbit_self.connection_errors = () rabbit_self.connection = 'fake_connection' return None self.notify_kombu = importutils.import_module("glance.notifier." "notify_kombu") self.notify_kombu.RabbitStrategy._send_message = self._send_message self.notify_kombu.RabbitStrategy._connect = _fake_connect self.called = False self.config(notifier_strategy="rabbit", rabbit_retry_backoff=0, rabbit_notification_topic="fake_topic") self.notifier = notifier.Notifier()
def test_timeout_on_connect_reconnects(self): info = {'num_called': 0} def _connect(rabbit_self): rabbit_self.connection_errors = () info['num_called'] += 1 if info['num_called'] == 1: raise Exception('foo timeout foo') rabbit_self.connection = 'fake_connection' self.notify_kombu.RabbitStrategy._connect = _connect notifier_ = notifier.Notifier() notifier_.error('test_event', 'test_message') if self.called is False: self.fail("Did not call _send_message properly.") self.assertEquals("test_message", self.called["message"]["payload"]) self.assertEquals("ERROR", self.called["message"]["priority"]) self.assertEquals(info['num_called'], 2)
def setUp(self): def _fake_connect(rabbit_self): rabbit_self.connection_errors = () rabbit_self.connection = 'fake_connection' return None self.notify_kombu = common_utils.import_object( "glance.notifier.notify_kombu") self.notify_kombu.RabbitStrategy._send_message = self._send_message self.notify_kombu.RabbitStrategy._connect = _fake_connect self.called = False self.conf = utils.TestConfigOpts({ "notifier_strategy": "rabbit", "rabbit_retry_backoff": 0, "rabbit_notification_topic": "fake_topic" }) self.notifier = notifier.Notifier(self.conf)
def test_custom_strategy(self): st = "glance.notifier.notify_noop.NoopStrategy" self.config(notifier_strategy=st) #NOTE(bcwaldon): the fact that Notifier is instantiated means we're ok notifier.Notifier()
def setUp(self): conf = utils.TestConfigOpts({"notifier_strategy": "logging"}) self.called = False self.logger = logging.getLogger("glance.notifier.logging_notifier") self.notifier = notifier.Notifier(conf)
def setUp(self): conf = utils.TestConfigOpts({"notifier_strategy": "noop"}) self.notifier = notifier.Notifier(conf)
def setUp(self): super(TestNoopNotifier, self).setUp() self.config(notifier_strategy="noop") self.notifier = notifier.Notifier()
def __init__(self, conf): self.conf = conf self.notifier = notifier.Notifier(conf)
def __init__(self): self.notifier = notifier.Notifier()
def __init__(self): self.notifier = notifier.Notifier() registry.configure_registry_client() self.policy = policy.Enforcer() self.pool = eventlet.GreenPool(size=1024)
def __init__(self, conf): self.conf = conf self.conf.register_opt(self.default_store_opt) glance.store.create_stores(conf) self.notifier = notifier.Notifier(conf) registry.configure_registry_client(conf)
def setUp(self): super(TestLoggingNotifier, self).setUp() self.config(notifier_strategy="logging") self.called = False self.logger = logging.getLogger("glance.notifier.notify_log") self.notifier = notifier.Notifier()
def test_transport_url(self): transport_url = "qpid://superhost:5672/" self.config(transport_url=transport_url) notify = notifier.Notifier() self.assertEqual(str(notify._transport._driver._url), transport_url)
def test_load_qpid(self): nfier = notifier.Notifier('qpid') self.assertIsNotNone(nfier._transport) self.assertEqual(str(nfier._transport._driver._url), 'qpid:///')
def test_load_rabbit(self): nfier = notifier.Notifier('rabbit') self.assertIsNotNone(nfier._transport)
def test_notifier_strategy(self): self.config(notifier_strategy='qpid') nfier = notifier.Notifier() self.assertIsNotNone(nfier._transport) self.assertEqual(str(nfier._transport._driver._url), 'qpid:///')