Basic notifications drivers and tests
This commit is contained in:
@@ -354,3 +354,6 @@ DEFINE_string('host', socket.gethostname(),
|
||||
|
||||
DEFINE_string('node_availability_zone', 'nova',
|
||||
'availability zone of this node')
|
||||
|
||||
DEFINE_string('notification_driver', 'nova.notifier.no_op_driver.NoopDriver',
|
||||
'Default driver for sending notifications')
|
||||
|
||||
19
nova/notifier/__init__.py
Normal file
19
nova/notifier/__init__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
def notify(model):
|
||||
"""Sends a notification using the specified driver"""
|
||||
driver = FLAGS.notification_driver
|
||||
driver.notify(model)
|
||||
19
nova/notifier/no_op_notifier.py
Normal file
19
nova/notifier/no_op_notifier.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
class NoopNotifier(object):
|
||||
def notify(self, model):
|
||||
"""Notifies the recipient of the desired event given the model"""
|
||||
pass
|
||||
24
nova/notifier/rabbit_notifier.py
Normal file
24
nova/notifier/rabbit_notifier.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
class RabbitNotifier(object):
|
||||
"""Sends notifications to a specific RabbitMQ server and topic"""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def notify(self, model):
|
||||
"""Sends a notification to the RabbitMQ"""
|
||||
pass
|
||||
41
nova/tests/test_notifier.py
Normal file
41
nova/tests/test_notifier.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova import notifier
|
||||
from nova import test
|
||||
|
||||
import stubout
|
||||
|
||||
class NotifierTestCase(test.TestCase):
|
||||
"""Test case for notifications"""
|
||||
def setUp(self):
|
||||
super(NotifierTestCase, self).setUp()
|
||||
self.stubs = stubout.StubOutForTesting()
|
||||
|
||||
def tearDown(self):
|
||||
self.stubs.UnsetAll()
|
||||
super(NotifierTestCase, self).tearDown()
|
||||
|
||||
def test_send_notification(self):
|
||||
self.notify_called = False
|
||||
def mock_notify(self, model):
|
||||
self.notify_called = True
|
||||
|
||||
self.stubs.set(nova.notifier.no_op_notifier.NoopNotifier, 'notify',
|
||||
mock_notify)
|
||||
|
||||
model = dict(x=1, y=2)
|
||||
notifier.notify(model)
|
||||
self.assertEqual(True, self.notify_called)
|
||||
Reference in New Issue
Block a user