summaryrefslogtreecommitdiff
path: root/nova/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'nova/tests/unit')
-rw-r--r--nova/tests/unit/api/openstack/compute/test_server_tags.py22
-rw-r--r--nova/tests/unit/notifications/test_base.py18
-rw-r--r--nova/tests/unit/test_notifications.py8
3 files changed, 39 insertions, 9 deletions
diff --git a/nova/tests/unit/api/openstack/compute/test_server_tags.py b/nova/tests/unit/api/openstack/compute/test_server_tags.py
index 7545eb8e82..5c53a4f60f 100644
--- a/nova/tests/unit/api/openstack/compute/test_server_tags.py
+++ b/nova/tests/unit/api/openstack/compute/test_server_tags.py
@@ -88,8 +88,9 @@ class ServerTagsTest(test.TestCase):
self.assertEqual(TAGS, res.get('tags'))
mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID)
+ @mock.patch('nova.notifications.base.send_instance_update_notification')
@mock.patch('nova.db.instance_tag_set')
- def test_update_all(self, mock_db_set_inst_tags):
+ def test_update_all(self, mock_db_set_inst_tags, mock_notify):
self.stub_out('nova.api.openstack.common.get_instance', return_server)
fake_tags = [self._get_tag(tag) for tag in TAGS]
mock_db_set_inst_tags.return_value = fake_tags
@@ -99,6 +100,7 @@ class ServerTagsTest(test.TestCase):
self.assertEqual(TAGS, res['tags'])
mock_db_set_inst_tags.assert_called_once_with(mock.ANY, UUID, TAGS)
+ self.assertEqual(1, mock_notify.call_count)
def test_update_all_too_many_tags(self):
self.stub_out('nova.api.openstack.common.get_instance', return_server)
@@ -160,9 +162,11 @@ class ServerTagsTest(test.TestCase):
self.assertRaises(exc.HTTPNotFound, self.controller.show,
req, UUID, TAG1)
+ @mock.patch('nova.notifications.base.send_instance_update_notification')
@mock.patch('nova.db.instance_tag_add')
@mock.patch('nova.db.instance_tag_get_by_instance_uuid')
- def test_update(self, mock_db_get_inst_tags, mock_db_add_inst_tags):
+ def test_update(self, mock_db_get_inst_tags, mock_db_add_inst_tags,
+ mock_notify):
self.stub_out('nova.api.openstack.common.get_instance', return_server)
mock_db_get_inst_tags.return_value = [self._get_tag(TAG1)]
mock_db_add_inst_tags.return_value = self._get_tag(TAG2)
@@ -176,7 +180,8 @@ class ServerTagsTest(test.TestCase):
self.assertEqual(0, len(res.body))
self.assertEqual(location, res.headers['Location'])
mock_db_add_inst_tags.assert_called_once_with(mock.ANY, UUID, TAG2)
- mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID)
+ self.assertEqual(2, mock_db_get_inst_tags.call_count)
+ self.assertEqual(1, mock_notify.call_count)
@mock.patch('nova.db.instance_tag_get_by_instance_uuid')
def test_update_existing_tag(self, mock_db_get_inst_tags):
@@ -232,13 +237,18 @@ class ServerTagsTest(test.TestCase):
self.assertRaises(exc.HTTPConflict, self.controller.update, req, UUID,
TAG1, body=None)
+ @mock.patch('nova.db.instance_tag_get_by_instance_uuid')
+ @mock.patch('nova.notifications.base.send_instance_update_notification')
@mock.patch('nova.db.instance_tag_delete')
- def test_delete(self, mock_db_delete_inst_tags):
+ def test_delete(self, mock_db_delete_inst_tags, mock_notify,
+ mock_db_get_inst_tags):
self.stub_out('nova.api.openstack.common.get_instance', return_server)
req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, TAG2), 'DELETE')
self.controller.delete(req, UUID, TAG2)
mock_db_delete_inst_tags.assert_called_once_with(mock.ANY, UUID, TAG2)
+ mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID)
+ self.assertEqual(1, mock_notify.call_count)
@mock.patch('nova.db.instance_tag_delete')
def test_delete_non_existing_tag(self, mock_db_delete_inst_tags):
@@ -263,12 +273,14 @@ class ServerTagsTest(test.TestCase):
self.assertRaises(exc.HTTPConflict, self.controller.delete, req, UUID,
TAG1)
+ @mock.patch('nova.notifications.base.send_instance_update_notification')
@mock.patch('nova.db.instance_tag_delete_all')
- def test_delete_all(self, mock_db_delete_inst_tags):
+ def test_delete_all(self, mock_db_delete_inst_tags, mock_notify):
self.stub_out('nova.api.openstack.common.get_instance', return_server)
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'DELETE')
self.controller.delete_all(req, UUID)
mock_db_delete_inst_tags.assert_called_once_with(mock.ANY, UUID)
+ self.assertEqual(1, mock_notify.call_count)
def test_delete_all_invalid_instance_state(self):
self.stub_out('nova.api.openstack.common.get_instance',
diff --git a/nova/tests/unit/notifications/test_base.py b/nova/tests/unit/notifications/test_base.py
index b5b622ad0c..2136c48926 100644
--- a/nova/tests/unit/notifications/test_base.py
+++ b/nova/tests/unit/notifications/test_base.py
@@ -14,6 +14,8 @@
# under the License.
import datetime
+import mock
+
from nova.notifications import base
from nova import test
from nova import utils
@@ -44,3 +46,19 @@ class TestNullSafeUtils(test.NoDBTestCase):
self.assertEqual('', base.null_safe_int(number))
number = 10
self.assertEqual(number, base.null_safe_int(number))
+
+
+class TestSendInstanceUpdateNotification(test.NoDBTestCase):
+
+ @mock.patch.object(base, 'info_from_instance',
+ new_callable=mock.NonCallableMock) # asserts not called
+ # TODO(mriedem): Rather than mock is_enabled, it would be better to
+ # configure oslo_messaging_notifications.driver=['noop']
+ @mock.patch('nova.rpc.NOTIFIER.is_enabled', return_value=False)
+ def test_send_instance_update_notification_disabled(self, mock_enabled,
+ mock_info):
+ """Tests the case that notifications are disabled which makes
+ send_instance_update_notification a noop.
+ """
+ base.send_instance_update_notification(mock.sentinel.ctxt,
+ mock.sentinel.instance)
diff --git a/nova/tests/unit/test_notifications.py b/nova/tests/unit/test_notifications.py
index 7b0b6d78c5..d94b54b364 100644
--- a/nova/tests/unit/test_notifications.py
+++ b/nova/tests/unit/test_notifications.py
@@ -551,7 +551,7 @@ class NotificationsTestCase(test.TestCase):
def sending_no_state_change(context, instance, **kwargs):
called[0] = True
self.stub_out('nova.notifications.base.'
- '_send_instance_update_notification',
+ 'send_instance_update_notification',
sending_no_state_change)
notifications.send_update(self.context, self.instance, self.instance)
self.assertTrue(called[0])
@@ -560,7 +560,7 @@ class NotificationsTestCase(test.TestCase):
def fail_sending(context, instance, **kwargs):
raise Exception('failed to notify')
self.stub_out('nova.notifications.base.'
- '_send_instance_update_notification',
+ 'send_instance_update_notification',
fail_sending)
notifications.send_update(self.context, self.instance, self.instance)
@@ -572,7 +572,7 @@ class NotificationsTestCase(test.TestCase):
# not logged as an error.
notfound = exception.InstanceNotFound(instance_id=self.instance.uuid)
with mock.patch.object(notifications,
- '_send_instance_update_notification',
+ 'send_instance_update_notification',
side_effect=notfound):
notifications.send_update(
self.context, self.instance, self.instance)
@@ -586,7 +586,7 @@ class NotificationsTestCase(test.TestCase):
# not logged as an error.
notfound = exception.InstanceNotFound(instance_id=self.instance.uuid)
with mock.patch.object(notifications,
- '_send_instance_update_notification',
+ 'send_instance_update_notification',
side_effect=notfound):
notifications.send_update_with_states(
self.context, self.instance,