Skip to content

Commit d64edd3

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use NotificationFixture for legacy notifications too"
2 parents 620a931 + b14f6ba commit d64edd3

14 files changed

+212
-224
lines changed

nova/tests/fixtures/notifications.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ def wait_for_versioned_notifications(
3737
@property
3838
def versioned_notifications(self):
3939
return fake_notifier.VERSIONED_NOTIFICATIONS
40+
41+
@property
42+
def notifications(self):
43+
return fake_notifier.NOTIFICATIONS

nova/tests/functional/regressions/test_bug_1713783.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from nova.tests.functional import fixtures as func_fixtures
2222
from nova.tests.functional import integrated_helpers
2323
from nova.tests.unit import fake_network
24-
from nova.tests.unit import fake_notifier
2524

2625

2726
LOG = logging.getLogger(__name__)
@@ -64,8 +63,8 @@ def setUp(self):
6463
def _wait_for_notification_event_type(self, event_type, max_retries=10):
6564
retry_counter = 0
6665
while True:
67-
if len(fake_notifier.NOTIFICATIONS) > 0:
68-
for notification in fake_notifier.NOTIFICATIONS:
66+
if len(self.notifier.notifications) > 0:
67+
for notification in self.notifier.notifications:
6968
if notification.event_type == event_type:
7069
return
7170
if retry_counter == max_retries:

nova/tests/functional/regressions/test_bug_1837955.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from nova import exception
1616
from nova.tests.functional import integrated_helpers
17-
from nova.tests.unit import fake_notifier
1817

1918

2019
class BuildRescheduleClaimFailsTestCase(
@@ -29,12 +28,12 @@ class BuildRescheduleClaimFailsTestCase(
2928

3029
def _wait_for_unversioned_notification(self, event_type):
3130
for x in range(20): # wait up to 10 seconds
32-
for notification in fake_notifier.NOTIFICATIONS:
31+
for notification in self.notifier.notifications:
3332
if notification.event_type == event_type:
3433
return notification
3534
time.sleep(.5)
3635
self.fail('Timed out waiting for unversioned notification %s. Got: %s'
37-
% (event_type, fake_notifier.NOTIFICATIONS))
36+
% (event_type, self.notifier.notifications))
3837

3938
def test_build_reschedule_alt_host_alloc_fails(self):
4039
# Start two compute services so we have one alternate host.

nova/tests/unit/compute/test_compute.py

Lines changed: 135 additions & 138 deletions
Large diffs are not rendered by default.

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
from nova.tests.unit import fake_instance
6969
from nova.tests.unit import fake_network
7070
from nova.tests.unit import fake_network_cache_model
71-
from nova.tests.unit import fake_notifier
7271
from nova.tests.unit.objects import test_instance_fault
7372
from nova.tests.unit.objects import test_instance_info_cache
7473
from nova.tests.unit.objects import test_instance_numa
@@ -9619,19 +9618,19 @@ def _do_test(force_complete, get_by_id, gen_img_url, mock_notify):
96199618

96209619
force_complete.assert_called_once_with(self.instance)
96219620

9622-
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
9621+
self.assertEqual(2, len(self.notifier.notifications))
96239622
self.assertEqual(
96249623
'compute.instance.live.migration.force.complete.start',
9625-
fake_notifier.NOTIFICATIONS[0].event_type)
9624+
self.notifier.notifications[0].event_type)
96269625
self.assertEqual(
96279626
self.instance.uuid,
9628-
fake_notifier.NOTIFICATIONS[0].payload['instance_id'])
9627+
self.notifier.notifications[0].payload['instance_id'])
96299628
self.assertEqual(
96309629
'compute.instance.live.migration.force.complete.end',
9631-
fake_notifier.NOTIFICATIONS[1].event_type)
9630+
self.notifier.notifications[1].event_type)
96329631
self.assertEqual(
96339632
self.instance.uuid,
9634-
fake_notifier.NOTIFICATIONS[1].payload['instance_id'])
9633+
self.notifier.notifications[1].payload['instance_id'])
96359634
self.assertEqual(2, mock_notify.call_count)
96369635
mock_notify.assert_has_calls([
96379636
mock.call(self.context, self.instance, self.compute.host,

nova/tests/unit/compute/test_compute_utils.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from nova.tests.unit import fake_crypto
4949
from nova.tests.unit import fake_instance
5050
from nova.tests.unit import fake_network
51-
from nova.tests.unit import fake_notifier
5251
from nova.tests.unit import fake_server_actions
5352
from nova.tests.unit.objects import test_flavor
5453

@@ -385,8 +384,8 @@ def test_notify_usage_exists(self):
385384
instance.save()
386385
compute_utils.notify_usage_exists(
387386
rpc.get_notifier('compute'), self.context, instance, 'fake-host')
388-
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
389-
msg = fake_notifier.NOTIFICATIONS[0]
387+
self.assertEqual(len(self.notifier.notifications), 1)
388+
msg = self.notifier.notifications[0]
390389
self.assertEqual(msg.priority, 'INFO')
391390
self.assertEqual(msg.event_type, 'compute.instance.exists')
392391
payload = msg.payload
@@ -450,7 +449,7 @@ def test_notify_usage_exists_deleted_instance(self):
450449
self.compute.terminate_instance(self.context, instance, [])
451450
compute_utils.notify_usage_exists(
452451
rpc.get_notifier('compute'), self.context, instance, 'fake-host')
453-
msg = fake_notifier.NOTIFICATIONS[-1]
452+
msg = self.notifier.notifications[-1]
454453
self.assertEqual(msg.priority, 'INFO')
455454
self.assertEqual(msg.event_type, 'compute.instance.exists')
456455
payload = msg.payload
@@ -814,7 +813,7 @@ def test_notify_usage_exists_instance_not_found(self):
814813
self.compute.terminate_instance(self.context, instance, [])
815814
compute_utils.notify_usage_exists(
816815
rpc.get_notifier('compute'), self.context, instance, 'fake-host')
817-
msg = fake_notifier.NOTIFICATIONS[-1]
816+
msg = self.notifier.notifications[-1]
818817
self.assertEqual(msg.priority, 'INFO')
819818
self.assertEqual(msg.event_type, 'compute.instance.exists')
820819
payload = msg.payload
@@ -887,8 +886,8 @@ def test_notify_about_instance_usage(self):
887886
rpc.get_notifier('compute'),
888887
self.context, instance, 'create.start',
889888
extra_usage_info=extra_usage_info)
890-
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
891-
msg = fake_notifier.NOTIFICATIONS[0]
889+
self.assertEqual(len(self.notifier.notifications), 1)
890+
msg = self.notifier.notifications[0]
892891
self.assertEqual(msg.priority, 'INFO')
893892
self.assertEqual(msg.event_type, 'compute.instance.create.start')
894893
payload = msg.payload
@@ -916,8 +915,8 @@ def test_notify_about_aggregate_update_with_id(self):
916915
compute_utils.notify_about_aggregate_update(self.context,
917916
"create.end",
918917
aggregate_payload)
919-
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
920-
msg = fake_notifier.NOTIFICATIONS[0]
918+
self.assertEqual(len(self.notifier.notifications), 1)
919+
msg = self.notifier.notifications[0]
921920
self.assertEqual(msg.priority, 'INFO')
922921
self.assertEqual(msg.event_type, 'aggregate.create.end')
923922
payload = msg.payload
@@ -929,8 +928,8 @@ def test_notify_about_aggregate_update_with_name(self):
929928
compute_utils.notify_about_aggregate_update(self.context,
930929
"create.start",
931930
aggregate_payload)
932-
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
933-
msg = fake_notifier.NOTIFICATIONS[0]
931+
self.assertEqual(len(self.notifier.notifications), 1)
932+
msg = self.notifier.notifications[0]
934933
self.assertEqual(msg.priority, 'INFO')
935934
self.assertEqual(msg.event_type, 'aggregate.create.start')
936935
payload = msg.payload
@@ -942,7 +941,7 @@ def test_notify_about_aggregate_update_without_name_id(self):
942941
compute_utils.notify_about_aggregate_update(self.context,
943942
"create.start",
944943
aggregate_payload)
945-
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
944+
self.assertEqual(len(self.notifier.notifications), 0)
946945

947946

948947
class ComputeUtilsGetValFromSysMetadata(test.NoDBTestCase):

nova/tests/unit/compute/test_host_api.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from nova import test
2828
from nova.tests import fixtures as nova_fixtures
2929
from nova.tests.unit.api.openstack import fakes
30-
from nova.tests.unit import fake_notifier
3130
from nova.tests.unit.objects import test_objects
3231
from nova.tests.unit.objects import test_service
3332

@@ -38,7 +37,8 @@ def setUp(self):
3837
self.host_api = compute.HostAPI()
3938
self.aggregate_api = compute.AggregateAPI()
4039
self.ctxt = context.get_admin_context()
41-
self.useFixture(nova_fixtures.NotificationFixture(self))
40+
self.notifier = self.useFixture(
41+
nova_fixtures.NotificationFixture(self))
4242
self.req = fakes.HTTPRequest.blank('')
4343
self.controller = services.ServiceController()
4444
self.useFixture(nova_fixtures.SingleCellSimple())
@@ -54,7 +54,6 @@ def _compare_objs(self, obj_list, db_obj_list):
5454
self._compare_obj(obj, db_obj_list[index])
5555

5656
def test_set_host_enabled(self):
57-
fake_notifier.NOTIFICATIONS = []
5857

5958
@mock.patch.object(self.host_api.rpcapi, 'set_host_enabled',
6059
return_value='fake-result')
@@ -64,14 +63,14 @@ def _do_test(mock_assert_host_exists, mock_set_host_enabled):
6463
result = self.host_api.set_host_enabled(self.ctxt, 'fake_host',
6564
'fake_enabled')
6665
self.assertEqual('fake-result', result)
67-
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
68-
msg = fake_notifier.NOTIFICATIONS[0]
66+
self.assertEqual(2, len(self.notifier.notifications))
67+
msg = self.notifier.notifications[0]
6968
self.assertEqual('HostAPI.set_enabled.start', msg.event_type)
7069
self.assertEqual('api.fake_host', msg.publisher_id)
7170
self.assertEqual('INFO', msg.priority)
7271
self.assertEqual('fake_enabled', msg.payload['enabled'])
7372
self.assertEqual('fake_host', msg.payload['host_name'])
74-
msg = fake_notifier.NOTIFICATIONS[1]
73+
msg = self.notifier.notifications[1]
7574
self.assertEqual('HostAPI.set_enabled.end', msg.event_type)
7675
self.assertEqual('api.fake_host', msg.publisher_id)
7776
self.assertEqual('INFO', msg.priority)
@@ -116,7 +115,6 @@ def _do_test(mock_service_is_up, mock_service_get_by_compute_host):
116115
_do_test()
117116

118117
def test_host_power_action(self):
119-
fake_notifier.NOTIFICATIONS = []
120118

121119
@mock.patch.object(self.host_api.rpcapi, 'host_power_action',
122120
return_value='fake-result')
@@ -126,14 +124,14 @@ def _do_test(mock_assert_host_exists, mock_host_power_action):
126124
result = self.host_api.host_power_action(self.ctxt, 'fake_host',
127125
'fake_action')
128126
self.assertEqual('fake-result', result)
129-
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
130-
msg = fake_notifier.NOTIFICATIONS[0]
127+
self.assertEqual(2, len(self.notifier.notifications))
128+
msg = self.notifier.notifications[0]
131129
self.assertEqual('HostAPI.power_action.start', msg.event_type)
132130
self.assertEqual('api.fake_host', msg.publisher_id)
133131
self.assertEqual('INFO', msg.priority)
134132
self.assertEqual('fake_action', msg.payload['action'])
135133
self.assertEqual('fake_host', msg.payload['host_name'])
136-
msg = fake_notifier.NOTIFICATIONS[1]
134+
msg = self.notifier.notifications[1]
137135
self.assertEqual('HostAPI.power_action.end', msg.event_type)
138136
self.assertEqual('api.fake_host', msg.publisher_id)
139137
self.assertEqual('INFO', msg.priority)
@@ -143,7 +141,6 @@ def _do_test(mock_assert_host_exists, mock_host_power_action):
143141
_do_test()
144142

145143
def test_set_host_maintenance(self):
146-
fake_notifier.NOTIFICATIONS = []
147144

148145
@mock.patch.object(self.host_api.rpcapi, 'host_maintenance_mode',
149146
return_value='fake-result')
@@ -153,14 +150,14 @@ def _do_test(mock_assert_host_exists, mock_host_maintenance_mode):
153150
result = self.host_api.set_host_maintenance(self.ctxt, 'fake_host',
154151
'fake_mode')
155152
self.assertEqual('fake-result', result)
156-
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
157-
msg = fake_notifier.NOTIFICATIONS[0]
153+
self.assertEqual(2, len(self.notifier.notifications))
154+
msg = self.notifier.notifications[0]
158155
self.assertEqual('HostAPI.set_maintenance.start', msg.event_type)
159156
self.assertEqual('api.fake_host', msg.publisher_id)
160157
self.assertEqual('INFO', msg.priority)
161158
self.assertEqual('fake_host', msg.payload['host_name'])
162159
self.assertEqual('fake_mode', msg.payload['mode'])
163-
msg = fake_notifier.NOTIFICATIONS[1]
160+
msg = self.notifier.notifications[1]
164161
self.assertEqual('HostAPI.set_maintenance.end', msg.event_type)
165162
self.assertEqual('api.fake_host', msg.publisher_id)
166163
self.assertEqual('INFO', msg.priority)

nova/tests/unit/compute/test_keypairs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from nova import quota
2626
from nova.tests.unit.compute import test_compute
2727
from nova.tests.unit import fake_crypto
28-
from nova.tests.unit import fake_notifier
2928
from nova.tests.unit.objects import test_keypair
3029
from nova.tests.unit import utils as test_utils
3130

@@ -82,17 +81,17 @@ def db_key_pair_get(context, user_id, name):
8281
self.stub_out("nova.db.api.key_pair_get", db_key_pair_get)
8382

8483
def _check_notifications(self, action='create', key_name='foo'):
85-
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
84+
self.assertEqual(2, len(self.notifier.notifications))
8685

87-
n1 = fake_notifier.NOTIFICATIONS[0]
86+
n1 = self.notifier.notifications[0]
8887
self.assertEqual('INFO', n1.priority)
8988
self.assertEqual('keypair.%s.start' % action, n1.event_type)
9089
self.assertEqual('api.%s' % CONF.host, n1.publisher_id)
9190
self.assertEqual('fake', n1.payload['user_id'])
9291
self.assertEqual('fake', n1.payload['tenant_id'])
9392
self.assertEqual(key_name, n1.payload['key_name'])
9493

95-
n2 = fake_notifier.NOTIFICATIONS[1]
94+
n2 = self.notifier.notifications[1]
9695
self.assertEqual('INFO', n2.priority)
9796
self.assertEqual('keypair.%s.end' % action, n2.event_type)
9897
self.assertEqual('api.%s' % CONF.host, n2.publisher_id)

nova/tests/unit/compute/test_resource_tracker.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
from nova import test
4242
from nova.tests import fixtures
4343
from nova.tests.unit import fake_instance
44-
from nova.tests.unit import fake_notifier
4544
from nova.tests.unit.objects import test_pci_device as fake_pci_device
4645
from nova.tests.unit import utils
4746
from nova import utils as nova_utils
@@ -3797,7 +3796,7 @@ def test_get_host_metrics_exception(self, mock_LOG_warning):
37973796

37983797
@mock.patch('nova.compute.utils.notify_about_metrics_update')
37993798
def test_get_host_metrics(self, mock_notify):
3800-
self.useFixture(fixtures.NotificationFixture(self))
3799+
self.notifier = self.useFixture(fixtures.NotificationFixture(self))
38013800

38023801
class FakeCPUMonitor(monitor_base.MonitorBase):
38033802

@@ -3842,8 +3841,8 @@ def populate_metrics(self, monitor_list):
38423841
'nodename': _NODENAME,
38433842
}
38443843

3845-
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
3846-
msg = fake_notifier.NOTIFICATIONS[0]
3844+
self.assertEqual(1, len(self.notifier.notifications))
3845+
msg = self.notifier.notifications[0]
38473846
self.assertEqual('compute.metrics.update', msg.event_type)
38483847
for p_key in payload:
38493848
if p_key == 'metrics':

nova/tests/unit/conductor/test_conductor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
from nova.tests.unit.compute import test_compute
5959
from nova.tests.unit import fake_build_request
6060
from nova.tests.unit import fake_instance
61-
from nova.tests.unit import fake_notifier
6261
from nova.tests.unit import fake_request_spec
6362
from nova.tests.unit import fake_server_actions
6463
from nova.tests.unit import utils as test_utils
@@ -1782,7 +1781,7 @@ def test_rebuild_instance_with_scheduler(self, mock_notify):
17821781
**compute_args)
17831782
self.assertEqual(inst_obj.project_id, fake_spec.project_id)
17841783
self.assertEqual('compute.instance.rebuild.scheduled',
1785-
fake_notifier.NOTIFICATIONS[0].event_type)
1784+
self.notifier.notifications[0].event_type)
17861785
mock_notify.assert_called_once_with(
17871786
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
17881787
source='nova-conductor')
@@ -1833,7 +1832,7 @@ def test_rebuild_instance_with_device_profile(self, mock_notify,
18331832
**compute_args)
18341833
self.assertEqual(inst_obj.project_id, fake_spec.project_id)
18351834
self.assertEqual('compute.instance.rebuild.scheduled',
1836-
fake_notifier.NOTIFICATIONS[0].event_type)
1835+
self.notifier.notifications[0].event_type)
18371836
mock_notify.assert_called_once_with(
18381837
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
18391838
source='nova-conductor')
@@ -2031,7 +2030,7 @@ def test_evacuate_instance_with_request_spec(self, mock_notify):
20312030
fake_spec, fake_selection)
20322031

20332032
self.assertEqual('compute.instance.rebuild.scheduled',
2034-
fake_notifier.NOTIFICATIONS[0].event_type)
2033+
self.notifier.notifications[0].event_type)
20352034
mock_notify.assert_called_once_with(
20362035
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
20372036
source='nova-conductor')
@@ -2103,7 +2102,7 @@ def test_evacuate_instance_with_request_spec_device_profile(
21032102
mock_del_arqs.assert_called_once()
21042103

21052104
self.assertEqual('compute.instance.rebuild.scheduled',
2106-
fake_notifier.NOTIFICATIONS[0].event_type)
2105+
self.notifier.notifications[0].event_type)
21072106
mock_notify.assert_called_once_with(
21082107
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
21092108
source='nova-conductor')
@@ -2176,7 +2175,7 @@ def test_evacuate_instance_with_request_spec_arq_bind_fail(
21762175
mock_del_arqs_instance.assert_called_once()
21772176

21782177
self.assertEqual('compute.instance.rebuild.scheduled',
2179-
fake_notifier.NOTIFICATIONS[0].event_type)
2178+
self.notifier.notifications[0].event_type)
21802179
mock_notify.assert_called_once_with(
21812180
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
21822181
source='nova-conductor')

nova/tests/unit/objects/test_aggregate.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from nova import exception
2020
from nova.objects import aggregate
2121
from nova import test
22-
from nova.tests.unit import fake_notifier
2322
from nova.tests.unit.objects import test_objects
2423

2524

@@ -141,7 +140,6 @@ def test_update_metadata_api(self,
141140
mock_notify,
142141
mock_api_metadata_add,
143142
mock_api_metadata_delete):
144-
fake_notifier.NOTIFICATIONS = []
145143
agg = aggregate.Aggregate()
146144
agg._context = self.context
147145
agg.id = 123
@@ -150,12 +148,12 @@ def test_update_metadata_api(self,
150148
mock_obj_from_primitive.return_value = agg
151149

152150
agg.update_metadata({'todelete': None, 'toadd': 'myval'})
153-
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
154-
msg = fake_notifier.NOTIFICATIONS[0]
151+
self.assertEqual(2, len(self.notifier.notifications))
152+
msg = self.notifier.notifications[0]
155153
self.assertEqual('aggregate.updatemetadata.start', msg.event_type)
156154
self.assertEqual({'todelete': None, 'toadd': 'myval'},
157155
msg.payload['meta_data'])
158-
msg = fake_notifier.NOTIFICATIONS[1]
156+
msg = self.notifier.notifications[1]
159157
self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
160158
mock_notify.assert_has_calls([
161159
mock.call(context=self.context, aggregate=agg,

0 commit comments

Comments
 (0)