Use NotificationFixture for legacy notifications too
Change-Id: Ic16c575c8f36e8a3c50b6e302b9fdf961cb3ed22
This commit is contained in:
parent
f1f599d098
commit
b14f6ba62e
4
nova/tests/fixtures/notifications.py
vendored
4
nova/tests/fixtures/notifications.py
vendored
@ -37,3 +37,7 @@ class NotificationFixture(fixtures.Fixture):
|
|||||||
@property
|
@property
|
||||||
def versioned_notifications(self):
|
def versioned_notifications(self):
|
||||||
return fake_notifier.VERSIONED_NOTIFICATIONS
|
return fake_notifier.VERSIONED_NOTIFICATIONS
|
||||||
|
|
||||||
|
@property
|
||||||
|
def notifications(self):
|
||||||
|
return fake_notifier.NOTIFICATIONS
|
||||||
|
@ -21,7 +21,6 @@ from nova.tests import fixtures as nova_fixtures
|
|||||||
from nova.tests.functional import fixtures as func_fixtures
|
from nova.tests.functional import fixtures as func_fixtures
|
||||||
from nova.tests.functional import integrated_helpers
|
from nova.tests.functional import integrated_helpers
|
||||||
from nova.tests.unit import fake_network
|
from nova.tests.unit import fake_network
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -64,8 +63,8 @@ class FailedEvacuateStateTests(test.TestCase,
|
|||||||
def _wait_for_notification_event_type(self, event_type, max_retries=10):
|
def _wait_for_notification_event_type(self, event_type, max_retries=10):
|
||||||
retry_counter = 0
|
retry_counter = 0
|
||||||
while True:
|
while True:
|
||||||
if len(fake_notifier.NOTIFICATIONS) > 0:
|
if len(self.notifier.notifications) > 0:
|
||||||
for notification in fake_notifier.NOTIFICATIONS:
|
for notification in self.notifier.notifications:
|
||||||
if notification.event_type == event_type:
|
if notification.event_type == event_type:
|
||||||
return
|
return
|
||||||
if retry_counter == max_retries:
|
if retry_counter == max_retries:
|
||||||
|
@ -14,7 +14,6 @@ import time
|
|||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.tests.functional import integrated_helpers
|
from nova.tests.functional import integrated_helpers
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
|
|
||||||
|
|
||||||
class BuildRescheduleClaimFailsTestCase(
|
class BuildRescheduleClaimFailsTestCase(
|
||||||
@ -29,12 +28,12 @@ class BuildRescheduleClaimFailsTestCase(
|
|||||||
|
|
||||||
def _wait_for_unversioned_notification(self, event_type):
|
def _wait_for_unversioned_notification(self, event_type):
|
||||||
for x in range(20): # wait up to 10 seconds
|
for x in range(20): # wait up to 10 seconds
|
||||||
for notification in fake_notifier.NOTIFICATIONS:
|
for notification in self.notifier.notifications:
|
||||||
if notification.event_type == event_type:
|
if notification.event_type == event_type:
|
||||||
return notification
|
return notification
|
||||||
time.sleep(.5)
|
time.sleep(.5)
|
||||||
self.fail('Timed out waiting for unversioned notification %s. Got: %s'
|
self.fail('Timed out waiting for unversioned notification %s. Got: %s'
|
||||||
% (event_type, fake_notifier.NOTIFICATIONS))
|
% (event_type, self.notifier.notifications))
|
||||||
|
|
||||||
def test_build_reschedule_alt_host_alloc_fails(self):
|
def test_build_reschedule_alt_host_alloc_fails(self):
|
||||||
# Start two compute services so we have one alternate host.
|
# Start two compute services so we have one alternate host.
|
||||||
|
@ -76,7 +76,6 @@ from nova.tests.unit import fake_diagnostics
|
|||||||
from nova.tests.unit import fake_instance
|
from nova.tests.unit import fake_instance
|
||||||
from nova.tests.unit import fake_network
|
from nova.tests.unit import fake_network
|
||||||
from nova.tests.unit import fake_network_cache_model
|
from nova.tests.unit import fake_network_cache_model
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
from nova.tests.unit import fake_server_actions
|
from nova.tests.unit import fake_server_actions
|
||||||
from nova.tests.unit import matchers
|
from nova.tests.unit import matchers
|
||||||
from nova.tests.unit.objects import test_diagnostics
|
from nova.tests.unit.objects import test_diagnostics
|
||||||
@ -149,7 +148,7 @@ class BaseTestCase(test.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BaseTestCase, self).setUp()
|
super(BaseTestCase, self).setUp()
|
||||||
|
|
||||||
self.useFixture(fixtures.NotificationFixture(self))
|
self.notifier = self.useFixture(fixtures.NotificationFixture(self))
|
||||||
|
|
||||||
self.compute = compute_manager.ComputeManager()
|
self.compute = compute_manager.ComputeManager()
|
||||||
# NOTE(gibi): this is a hack to make the fake virt driver use the nodes
|
# NOTE(gibi): this is a hack to make the fake virt driver use the nodes
|
||||||
@ -877,17 +876,17 @@ class ComputeVolumeTestCase(BaseTestCase):
|
|||||||
self.flags(volume_usage_poll_interval=10)
|
self.flags(volume_usage_poll_interval=10)
|
||||||
self.compute._poll_volume_usage(self.context)
|
self.compute._poll_volume_usage(self.context)
|
||||||
# Check that a volume.usage and volume.attach notification was sent
|
# Check that a volume.usage and volume.attach notification was sent
|
||||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(2, len(self.notifier.notifications))
|
||||||
|
|
||||||
self.compute.detach_volume(self.context, uuids.volume_id, instance,
|
self.compute.detach_volume(self.context, uuids.volume_id, instance,
|
||||||
'attach-id')
|
'attach-id')
|
||||||
|
|
||||||
# Check that volume.attach, 2 volume.usage, and volume.detach
|
# Check that volume.attach, 2 volume.usage, and volume.detach
|
||||||
# notifications were sent
|
# notifications were sent
|
||||||
self.assertEqual(4, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(4, len(self.notifier.notifications))
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual('compute.instance.volume.attach', msg.event_type)
|
self.assertEqual('compute.instance.volume.attach', msg.event_type)
|
||||||
msg = fake_notifier.NOTIFICATIONS[2]
|
msg = self.notifier.notifications[2]
|
||||||
self.assertEqual('volume.usage', msg.event_type)
|
self.assertEqual('volume.usage', msg.event_type)
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
self.assertEqual(instance['uuid'], payload['instance_id'])
|
self.assertEqual(instance['uuid'], payload['instance_id'])
|
||||||
@ -898,7 +897,7 @@ class ComputeVolumeTestCase(BaseTestCase):
|
|||||||
self.assertEqual(1, payload['writes'])
|
self.assertEqual(1, payload['writes'])
|
||||||
self.assertEqual(20, payload['write_bytes'])
|
self.assertEqual(20, payload['write_bytes'])
|
||||||
self.assertIsNone(payload['availability_zone'])
|
self.assertIsNone(payload['availability_zone'])
|
||||||
msg = fake_notifier.NOTIFICATIONS[3]
|
msg = self.notifier.notifications[3]
|
||||||
self.assertEqual('compute.instance.volume.detach', msg.event_type)
|
self.assertEqual('compute.instance.volume.detach', msg.event_type)
|
||||||
mock_notify_usage.assert_has_calls([
|
mock_notify_usage.assert_has_calls([
|
||||||
mock.call(self.context, test.MatchType(objects.VolumeUsage),
|
mock.call(self.context, test.MatchType(objects.VolumeUsage),
|
||||||
@ -2257,7 +2256,7 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||||
[], block_device_mapping=[])
|
[], block_device_mapping=[])
|
||||||
|
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
instance.task_state = task_states.RESCUING
|
instance.task_state = task_states.RESCUING
|
||||||
instance.save()
|
instance.save()
|
||||||
self.compute.rescue_instance(self.context, instance, None,
|
self.compute.rescue_instance(self.context, instance, None,
|
||||||
@ -2267,7 +2266,7 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
expected_notifications = ['compute.instance.rescue.start',
|
expected_notifications = ['compute.instance.rescue.start',
|
||||||
'compute.instance.exists',
|
'compute.instance.exists',
|
||||||
'compute.instance.rescue.end']
|
'compute.instance.rescue.end']
|
||||||
self.assertEqual([m.event_type for m in fake_notifier.NOTIFICATIONS],
|
self.assertEqual([m.event_type for m in self.notifier.notifications],
|
||||||
expected_notifications)
|
expected_notifications)
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
mock.call(self.context, instance, 'fake-mini',
|
mock.call(self.context, instance, 'fake-mini',
|
||||||
@ -2275,7 +2274,7 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
mock.call(self.context, instance, 'fake-mini',
|
mock.call(self.context, instance, 'fake-mini',
|
||||||
uuids.fake_image_ref_1, phase='end')])
|
uuids.fake_image_ref_1, phase='end')])
|
||||||
|
|
||||||
for n, msg in enumerate(fake_notifier.NOTIFICATIONS):
|
for n, msg in enumerate(self.notifier.notifications):
|
||||||
self.assertEqual(msg.event_type, expected_notifications[n])
|
self.assertEqual(msg.event_type, expected_notifications[n])
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -2291,7 +2290,7 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
image_ref_url = self.image_api.generate_image_url(FAKE_IMAGE_REF,
|
image_ref_url = self.image_api.generate_image_url(FAKE_IMAGE_REF,
|
||||||
self.context)
|
self.context)
|
||||||
self.assertEqual(payload['image_ref_url'], image_ref_url)
|
self.assertEqual(payload['image_ref_url'], image_ref_url)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertIn('rescue_image_name', msg.payload)
|
self.assertIn('rescue_image_name', msg.payload)
|
||||||
|
|
||||||
self.compute.terminate_instance(self.context, instance, [])
|
self.compute.terminate_instance(self.context, instance, [])
|
||||||
@ -2311,14 +2310,14 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||||
[], block_device_mapping=[])
|
[], block_device_mapping=[])
|
||||||
|
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
instance.task_state = task_states.UNRESCUING
|
instance.task_state = task_states.UNRESCUING
|
||||||
instance.save()
|
instance.save()
|
||||||
self.compute.unrescue_instance(self.context, instance)
|
self.compute.unrescue_instance(self.context, instance)
|
||||||
|
|
||||||
expected_notifications = ['compute.instance.unrescue.start',
|
expected_notifications = ['compute.instance.unrescue.start',
|
||||||
'compute.instance.unrescue.end']
|
'compute.instance.unrescue.end']
|
||||||
self.assertEqual([m.event_type for m in fake_notifier.NOTIFICATIONS],
|
self.assertEqual([m.event_type for m in self.notifier.notifications],
|
||||||
expected_notifications)
|
expected_notifications)
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
mock.call(context, instance, 'fake-mini',
|
mock.call(context, instance, 'fake-mini',
|
||||||
@ -2326,7 +2325,7 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
mock.call(context, instance, 'fake-mini',
|
mock.call(context, instance, 'fake-mini',
|
||||||
action='unrescue', phase='end')])
|
action='unrescue', phase='end')])
|
||||||
|
|
||||||
for n, msg in enumerate(fake_notifier.NOTIFICATIONS):
|
for n, msg in enumerate(self.notifier.notifications):
|
||||||
self.assertEqual(msg.event_type, expected_notifications[n])
|
self.assertEqual(msg.event_type, expected_notifications[n])
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -2520,30 +2519,30 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
instance, {}, {}, {}, [], block_device_mapping=[])
|
instance, {}, {}, {}, [], block_device_mapping=[])
|
||||||
instance.task_state = task_states.PAUSING
|
instance.task_state = task_states.PAUSING
|
||||||
instance.save()
|
instance.save()
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
self.compute.pause_instance(self.context, instance=instance)
|
self.compute.pause_instance(self.context, instance=instance)
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
mock.call(ctxt, instance, 'fake-mini',
|
mock.call(ctxt, instance, 'fake-mini',
|
||||||
action='pause', phase='start'),
|
action='pause', phase='start'),
|
||||||
mock.call(ctxt, instance, 'fake-mini',
|
mock.call(ctxt, instance, 'fake-mini',
|
||||||
action='pause', phase='end')])
|
action='pause', phase='end')])
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.pause.start')
|
'compute.instance.pause.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.pause.end')
|
'compute.instance.pause.end')
|
||||||
instance.task_state = task_states.UNPAUSING
|
instance.task_state = task_states.UNPAUSING
|
||||||
instance.save()
|
instance.save()
|
||||||
mock_notify.reset_mock()
|
mock_notify.reset_mock()
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
self.compute.unpause_instance(self.context, instance=instance)
|
self.compute.unpause_instance(self.context, instance=instance)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.unpause.start')
|
'compute.instance.unpause.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.unpause.end')
|
'compute.instance.unpause.end')
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
@ -2569,12 +2568,12 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
instance.save()
|
instance.save()
|
||||||
self.compute.resume_instance(context, instance)
|
self.compute.resume_instance(context, instance)
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 6)
|
self.assertEqual(len(self.notifier.notifications), 6)
|
||||||
|
|
||||||
msg = fake_notifier.NOTIFICATIONS[2]
|
msg = self.notifier.notifications[2]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.suspend.start')
|
'compute.instance.suspend.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[3]
|
msg = self.notifier.notifications[3]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.suspend.end')
|
'compute.instance.suspend.end')
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
@ -2656,11 +2655,11 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
instance.task_state = task_states.RESUMING
|
instance.task_state = task_states.RESUMING
|
||||||
instance.save()
|
instance.save()
|
||||||
self.compute.resume_instance(self.context, instance)
|
self.compute.resume_instance(self.context, instance)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 6)
|
self.assertEqual(len(self.notifier.notifications), 6)
|
||||||
msg = fake_notifier.NOTIFICATIONS[4]
|
msg = self.notifier.notifications[4]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.resume.start')
|
'compute.instance.resume.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[5]
|
msg = self.notifier.notifications[5]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.resume.end')
|
'compute.instance.resume.end')
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
@ -4211,13 +4210,13 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
|
|
||||||
instance = self._create_fake_instance_obj()
|
instance = self._create_fake_instance_obj()
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
self.assertEqual(len(self.notifier.notifications), 0)
|
||||||
with mock.patch.object(self.compute.network_api,
|
with mock.patch.object(self.compute.network_api,
|
||||||
'add_fixed_ip_to_instance', dummy):
|
'add_fixed_ip_to_instance', dummy):
|
||||||
self.compute.add_fixed_ip_to_instance(self.context, network_id=1,
|
self.compute.add_fixed_ip_to_instance(self.context, network_id=1,
|
||||||
instance=instance)
|
instance=instance)
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
self.compute.terminate_instance(self.context, instance, [])
|
self.compute.terminate_instance(self.context, instance, [])
|
||||||
|
|
||||||
def test_remove_fixed_ip_usage_notification(self):
|
def test_remove_fixed_ip_usage_notification(self):
|
||||||
@ -4229,13 +4228,13 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
|
|
||||||
instance = self._create_fake_instance_obj()
|
instance = self._create_fake_instance_obj()
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
self.assertEqual(len(self.notifier.notifications), 0)
|
||||||
with mock.patch.object(self.compute.network_api,
|
with mock.patch.object(self.compute.network_api,
|
||||||
'remove_fixed_ip_from_instance', dummy):
|
'remove_fixed_ip_from_instance', dummy):
|
||||||
self.compute.remove_fixed_ip_from_instance(self.context, 1,
|
self.compute.remove_fixed_ip_from_instance(self.context, 1,
|
||||||
instance=instance)
|
instance=instance)
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
self.compute.terminate_instance(self.context, instance, [])
|
self.compute.terminate_instance(self.context, instance, [])
|
||||||
|
|
||||||
def test_run_instance_usage_notification(self, request_spec=None):
|
def test_run_instance_usage_notification(self, request_spec=None):
|
||||||
@ -4253,12 +4252,12 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
expected_image_name},
|
expected_image_name},
|
||||||
accel_uuids=[],
|
accel_uuids=[],
|
||||||
block_device_mapping=[])
|
block_device_mapping=[])
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
instance.refresh()
|
instance.refresh()
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
||||||
# The last event is the one with the sugar in it.
|
# The last event is the one with the sugar in it.
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.create.end')
|
self.assertEqual(msg.event_type, 'compute.instance.create.end')
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -4309,10 +4308,10 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
|
|
||||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||||
[], block_device_mapping=[])
|
[], block_device_mapping=[])
|
||||||
self.assertGreaterEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertGreaterEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[-1]
|
msg = self.notifier.notifications[-1]
|
||||||
|
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.create.error')
|
self.assertEqual(msg.event_type, 'compute.instance.create.error')
|
||||||
self.assertEqual('ERROR', msg.priority)
|
self.assertEqual('ERROR', msg.priority)
|
||||||
@ -4335,10 +4334,10 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||||
[], block_device_mapping=[])
|
[], block_device_mapping=[])
|
||||||
|
|
||||||
self.assertGreaterEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertGreaterEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[-1]
|
msg = self.notifier.notifications[-1]
|
||||||
|
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.create.error')
|
self.assertEqual(msg.event_type, 'compute.instance.create.error')
|
||||||
self.assertEqual('ERROR', msg.priority)
|
self.assertEqual('ERROR', msg.priority)
|
||||||
@ -4360,10 +4359,10 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
self.context, instance, {}, {}, {}, [],
|
self.context, instance, {}, {}, {}, [],
|
||||||
block_device_mapping=[])
|
block_device_mapping=[])
|
||||||
|
|
||||||
self.assertGreaterEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertGreaterEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[-1]
|
msg = self.notifier.notifications[-1]
|
||||||
|
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.create.error')
|
self.assertEqual(msg.event_type, 'compute.instance.create.error')
|
||||||
self.assertEqual('ERROR', msg.priority)
|
self.assertEqual('ERROR', msg.priority)
|
||||||
@ -4384,20 +4383,20 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
instance = self._create_fake_instance_obj()
|
instance = self._create_fake_instance_obj()
|
||||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||||
[], block_device_mapping=[])
|
[], block_device_mapping=[])
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
time_fixture.advance_time_delta(cur_time - old_time)
|
time_fixture.advance_time_delta(cur_time - old_time)
|
||||||
self.compute.terminate_instance(self.context, instance, [])
|
self.compute.terminate_instance(self.context, instance, [])
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 4)
|
self.assertEqual(len(self.notifier.notifications), 4)
|
||||||
|
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.delete.start')
|
self.assertEqual(msg.event_type, 'compute.instance.delete.start')
|
||||||
msg1 = fake_notifier.NOTIFICATIONS[1]
|
msg1 = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg1.event_type, 'compute.instance.shutdown.start')
|
self.assertEqual(msg1.event_type, 'compute.instance.shutdown.start')
|
||||||
msg1 = fake_notifier.NOTIFICATIONS[2]
|
msg1 = self.notifier.notifications[2]
|
||||||
self.assertEqual(msg1.event_type, 'compute.instance.shutdown.end')
|
self.assertEqual(msg1.event_type, 'compute.instance.shutdown.end')
|
||||||
msg1 = fake_notifier.NOTIFICATIONS[3]
|
msg1 = self.notifier.notifications[3]
|
||||||
self.assertEqual(msg1.event_type, 'compute.instance.delete.end')
|
self.assertEqual(msg1.event_type, 'compute.instance.delete.end')
|
||||||
payload = msg1.payload
|
payload = msg1.payload
|
||||||
self.assertEqual(payload['tenant_id'], self.project_id)
|
self.assertEqual(payload['tenant_id'], self.project_id)
|
||||||
@ -5080,7 +5079,7 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
[], block_device_mapping=[])
|
[], block_device_mapping=[])
|
||||||
time_fixture.advance_time_delta(cur_time - old_time)
|
time_fixture.advance_time_delta(cur_time - old_time)
|
||||||
|
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
instance = db.instance_get_by_uuid(self.context, inst_ref['uuid'])
|
instance = db.instance_get_by_uuid(self.context, inst_ref['uuid'])
|
||||||
orig_sys_metadata = db.instance_system_metadata_get(self.context,
|
orig_sys_metadata = db.instance_system_metadata_get(self.context,
|
||||||
inst_ref['uuid'])
|
inst_ref['uuid'])
|
||||||
@ -5107,17 +5106,17 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
new_image_ref_url = self.image_api.generate_image_url(new_image_ref,
|
new_image_ref_url = self.image_api.generate_image_url(new_image_ref,
|
||||||
self.context)
|
self.context)
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 3)
|
self.assertEqual(len(self.notifier.notifications), 3)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.exists')
|
'compute.instance.exists')
|
||||||
self.assertEqual(msg.payload['image_ref_url'], image_ref_url)
|
self.assertEqual(msg.payload['image_ref_url'], image_ref_url)
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.rebuild.start')
|
'compute.instance.rebuild.start')
|
||||||
self.assertEqual(msg.payload['image_ref_url'], new_image_ref_url)
|
self.assertEqual(msg.payload['image_ref_url'], new_image_ref_url)
|
||||||
self.assertEqual(msg.payload['image_name'], 'fake_name')
|
self.assertEqual(msg.payload['image_name'], 'fake_name')
|
||||||
msg = fake_notifier.NOTIFICATIONS[2]
|
msg = self.notifier.notifications[2]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.rebuild.end')
|
'compute.instance.rebuild.end')
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
@ -5168,18 +5167,18 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
migration=migration, image={}, flavor=new_type,
|
migration=migration, image={}, flavor=new_type,
|
||||||
clean_shutdown=True, request_spec=request_spec)
|
clean_shutdown=True, request_spec=request_spec)
|
||||||
time_fixture.advance_time_delta(cur_time - old_time)
|
time_fixture.advance_time_delta(cur_time - old_time)
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
|
|
||||||
self.compute.finish_resize(self.context,
|
self.compute.finish_resize(self.context,
|
||||||
migration=migration,
|
migration=migration,
|
||||||
disk_info={}, image={}, instance=instance,
|
disk_info={}, image={}, instance=instance,
|
||||||
request_spec=request_spec)
|
request_spec=request_spec)
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.finish_resize.start')
|
'compute.instance.finish_resize.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.finish_resize.end')
|
'compute.instance.finish_resize.end')
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
@ -5210,7 +5209,7 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||||
[], block_device_mapping=[])
|
[], block_device_mapping=[])
|
||||||
time_fixture.advance_time_delta(cur_time - old_time)
|
time_fixture.advance_time_delta(cur_time - old_time)
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
|
|
||||||
instance.host = 'foo'
|
instance.host = 'foo'
|
||||||
instance.task_state = task_states.RESIZE_PREP
|
instance.task_state = task_states.RESIZE_PREP
|
||||||
@ -5224,14 +5223,14 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
instance.uuid,
|
instance.uuid,
|
||||||
'pre-migrating')
|
'pre-migrating')
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 3)
|
self.assertEqual(len(self.notifier.notifications), 3)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.exists')
|
'compute.instance.exists')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.resize.prep.start')
|
'compute.instance.resize.prep.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[2]
|
msg = self.notifier.notifications[2]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.resize.prep.end')
|
'compute.instance.resize.prep.end')
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
@ -6064,7 +6063,7 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
# creating instance testdata
|
# creating instance testdata
|
||||||
instance = self._create_fake_instance_obj({'host': 'dummy'})
|
instance = self._create_fake_instance_obj({'host': 'dummy'})
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
fake_notifier.NOTIFICATIONS = []
|
|
||||||
migrate_data = objects.LibvirtLiveMigrateData(
|
migrate_data = objects.LibvirtLiveMigrateData(
|
||||||
is_shared_instance_path=False)
|
is_shared_instance_path=False)
|
||||||
vifs = migrate_data_obj.VIFMigrateData.create_skeleton_migrate_vifs(
|
vifs = migrate_data_obj.VIFMigrateData.create_skeleton_migrate_vifs(
|
||||||
@ -6079,11 +6078,11 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
migrate_data=migrate_data)
|
migrate_data=migrate_data)
|
||||||
self.assertIs(migrate_data, ret)
|
self.assertIs(migrate_data, ret)
|
||||||
self.assertTrue(ret.wait_for_vif_plugged, ret)
|
self.assertTrue(ret.wait_for_vif_plugged, ret)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.live_migration.pre.start')
|
'compute.instance.live_migration.pre.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.live_migration.pre.end')
|
'compute.instance.live_migration.pre.end')
|
||||||
|
|
||||||
@ -6683,7 +6682,6 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
# creating instance testdata
|
# creating instance testdata
|
||||||
c = context.get_admin_context()
|
c = context.get_admin_context()
|
||||||
instance = self._create_fake_instance_obj({'host': 'dummy'})
|
instance = self._create_fake_instance_obj({'host': 'dummy'})
|
||||||
fake_notifier.NOTIFICATIONS = []
|
|
||||||
|
|
||||||
# start test
|
# start test
|
||||||
with mock.patch.object(self.compute.network_api,
|
with mock.patch.object(self.compute.network_api,
|
||||||
@ -6693,11 +6691,11 @@ class ComputeTestCase(BaseTestCase,
|
|||||||
destroy_disks=True,
|
destroy_disks=True,
|
||||||
migrate_data=None)
|
migrate_data=None)
|
||||||
self.assertIsNone(ret)
|
self.assertIsNone(ret)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.live_migration.rollback.dest.start')
|
'compute.instance.live_migration.rollback.dest.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'compute.instance.live_migration.rollback.dest.end')
|
'compute.instance.live_migration.rollback.dest.end')
|
||||||
mock_setup.assert_called_once_with(c, instance, self.compute.host,
|
mock_setup.assert_called_once_with(c, instance, self.compute.host,
|
||||||
@ -9451,8 +9449,8 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
metadata = self.compute_api.get_instance_metadata(_context, instance)
|
metadata = self.compute_api.get_instance_metadata(_context, instance)
|
||||||
self.assertEqual(metadata, {'key1': 'value1', 'key2': 'value2'})
|
self.assertEqual(metadata, {'key1': 'value1', 'key2': 'value2'})
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
self.assertEqual(len(self.notifier.notifications), 1)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
self.assertIn('metadata', payload)
|
self.assertIn('metadata', payload)
|
||||||
self.assertEqual(payload['metadata'], metadata)
|
self.assertEqual(payload['metadata'], metadata)
|
||||||
@ -9463,8 +9461,8 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
metadata = self.compute_api.get_instance_metadata(_context, instance)
|
metadata = self.compute_api.get_instance_metadata(_context, instance)
|
||||||
self.assertEqual(metadata, new_metadata)
|
self.assertEqual(metadata, new_metadata)
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
self.assertIn('metadata', payload)
|
self.assertIn('metadata', payload)
|
||||||
self.assertEqual(payload['metadata'], metadata)
|
self.assertEqual(payload['metadata'], metadata)
|
||||||
@ -9473,8 +9471,8 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
metadata = self.compute_api.get_instance_metadata(_context, instance)
|
metadata = self.compute_api.get_instance_metadata(_context, instance)
|
||||||
self.assertEqual(metadata, {'key3': 'value3'})
|
self.assertEqual(metadata, {'key3': 'value3'})
|
||||||
|
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 3)
|
self.assertEqual(len(self.notifier.notifications), 3)
|
||||||
msg = fake_notifier.NOTIFICATIONS[2]
|
msg = self.notifier.notifications[2]
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
self.assertIn('metadata', payload)
|
self.assertIn('metadata', payload)
|
||||||
self.assertEqual(payload['metadata'], {'key3': 'value3'})
|
self.assertEqual(payload['metadata'], {'key3': 'value3'})
|
||||||
@ -11859,7 +11857,7 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
self.assertEqual(self.compute.host, migs[0].source_compute)
|
self.assertEqual(self.compute.host, migs[0].source_compute)
|
||||||
self.assertEqual('accepted', migs[0].status)
|
self.assertEqual('accepted', migs[0].status)
|
||||||
self.assertEqual('compute.instance.evacuate',
|
self.assertEqual('compute.instance.evacuate',
|
||||||
fake_notifier.NOTIFICATIONS[0].event_type)
|
self.notifier.notifications[0].event_type)
|
||||||
mock_notify.assert_called_once_with(
|
mock_notify.assert_called_once_with(
|
||||||
ctxt, instance, self.compute.host, action='evacuate',
|
ctxt, instance, self.compute.host, action='evacuate',
|
||||||
source='nova-api')
|
source='nova-api')
|
||||||
@ -12203,15 +12201,15 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
# Ensure metadata can be updated.
|
# Ensure metadata can be updated.
|
||||||
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
||||||
'fake_zone')
|
'fake_zone')
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
self.api.update_aggregate(self.context, aggr.id,
|
self.api.update_aggregate(self.context, aggr.id,
|
||||||
{'name': 'new_fake_aggregate'})
|
{'name': 'new_fake_aggregate'})
|
||||||
self.assertIsNone(availability_zones._get_cache().get('cache'))
|
self.assertIsNone(availability_zones._get_cache().get('cache'))
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updateprop.start')
|
'aggregate.updateprop.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updateprop.end')
|
'aggregate.updateprop.end')
|
||||||
|
|
||||||
@ -12234,13 +12232,13 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
aggr2 = self._init_aggregate_with_host(None, 'fake_aggregate2', None,
|
aggr2 = self._init_aggregate_with_host(None, 'fake_aggregate2', None,
|
||||||
fake_host)
|
fake_host)
|
||||||
metadata = {'name': 'new_fake_aggregate'}
|
metadata = {'name': 'new_fake_aggregate'}
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
self.api.update_aggregate(self.context, aggr2.id, metadata)
|
self.api.update_aggregate(self.context, aggr2.id, metadata)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updateprop.start')
|
'aggregate.updateprop.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updateprop.end')
|
'aggregate.updateprop.end')
|
||||||
|
|
||||||
@ -12264,13 +12262,13 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
self._init_aggregate_with_host(None, 'fake_aggregate2', None,
|
self._init_aggregate_with_host(None, 'fake_aggregate2', None,
|
||||||
fake_host)
|
fake_host)
|
||||||
metadata = {'availability_zone': 'new_fake_zone'}
|
metadata = {'availability_zone': 'new_fake_zone'}
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
self.api.update_aggregate(self.context, aggr1.id, metadata)
|
self.api.update_aggregate(self.context, aggr1.id, metadata)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.start')
|
'aggregate.updatemetadata.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.end')
|
'aggregate.updatemetadata.end')
|
||||||
|
|
||||||
@ -12281,7 +12279,7 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
mock_get_all_by_host):
|
mock_get_all_by_host):
|
||||||
# Ensure aggregate's availability zone can't be updated,
|
# Ensure aggregate's availability zone can't be updated,
|
||||||
# when aggregate has hosts in other availability zone
|
# when aggregate has hosts in other availability zone
|
||||||
fake_notifier.NOTIFICATIONS = []
|
|
||||||
values = _create_service_entries(self.context)
|
values = _create_service_entries(self.context)
|
||||||
fake_zone = values[0][0]
|
fake_zone = values[0][0]
|
||||||
fake_host = values[0][1][0]
|
fake_host = values[0][1][0]
|
||||||
@ -12306,11 +12304,11 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
None, fake_host2)
|
None, fake_host2)
|
||||||
metadata = {'availability_zone': fake_zone}
|
metadata = {'availability_zone': fake_zone}
|
||||||
self.api.update_aggregate(self.context, aggr3.id, metadata)
|
self.api.update_aggregate(self.context, aggr3.id, metadata)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 15)
|
self.assertEqual(len(self.notifier.notifications), 15)
|
||||||
msg = fake_notifier.NOTIFICATIONS[13]
|
msg = self.notifier.notifications[13]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.start')
|
'aggregate.updatemetadata.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[14]
|
msg = self.notifier.notifications[14]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.end')
|
'aggregate.updatemetadata.end')
|
||||||
aggr4 = self.api.create_aggregate(self.context, 'fake_aggregate', None)
|
aggr4 = self.api.create_aggregate(self.context, 'fake_aggregate', None)
|
||||||
@ -12326,7 +12324,7 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
mock_get_all_by_host):
|
mock_get_all_by_host):
|
||||||
# Ensure aggregate's availability zone can't be updated,
|
# Ensure aggregate's availability zone can't be updated,
|
||||||
# when aggregate has hosts in other availability zone
|
# when aggregate has hosts in other availability zone
|
||||||
fake_notifier.NOTIFICATIONS = []
|
|
||||||
values = _create_service_entries(self.context)
|
values = _create_service_entries(self.context)
|
||||||
fake_host = values[0][1][0]
|
fake_host = values[0][1][0]
|
||||||
mock_get_all_by_host.return_value = objects.ComputeNodeList(
|
mock_get_all_by_host.return_value = objects.ComputeNodeList(
|
||||||
@ -12351,17 +12349,17 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
metadata = {'foo_key1': 'foo_value1',
|
metadata = {'foo_key1': 'foo_value1',
|
||||||
'foo_key2': 'foo_value2',
|
'foo_key2': 'foo_value2',
|
||||||
'availability_zone': 'fake_zone'}
|
'availability_zone': 'fake_zone'}
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
availability_zones._get_cache().region.get_or_create(
|
availability_zones._get_cache().region.get_or_create(
|
||||||
'fake_ky', lambda: 'fake_value')
|
'fake_ky', lambda: 'fake_value')
|
||||||
aggr = self.api.update_aggregate_metadata(self.context, aggr.id,
|
aggr = self.api.update_aggregate_metadata(self.context, aggr.id,
|
||||||
metadata)
|
metadata)
|
||||||
self.assertIsNone(availability_zones._get_cache().get('fake_key'))
|
self.assertIsNone(availability_zones._get_cache().get('fake_key'))
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.start')
|
'aggregate.updatemetadata.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.end')
|
'aggregate.updatemetadata.end')
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
@ -12369,18 +12367,18 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
action='update_metadata', phase='start'),
|
action='update_metadata', phase='start'),
|
||||||
mock.call(context=self.context, aggregate=aggr,
|
mock.call(context=self.context, aggregate=aggr,
|
||||||
action='update_metadata', phase='end')])
|
action='update_metadata', phase='end')])
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
metadata['foo_key1'] = None
|
metadata['foo_key1'] = None
|
||||||
expected_payload_meta_data = {'foo_key1': None,
|
expected_payload_meta_data = {'foo_key1': None,
|
||||||
'foo_key2': 'foo_value2',
|
'foo_key2': 'foo_value2',
|
||||||
'availability_zone': 'fake_zone'}
|
'availability_zone': 'fake_zone'}
|
||||||
expected = self.api.update_aggregate_metadata(self.context,
|
expected = self.api.update_aggregate_metadata(self.context,
|
||||||
aggr.id, metadata)
|
aggr.id, metadata)
|
||||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(2, len(self.notifier.notifications))
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual('aggregate.updatemetadata.start', msg.event_type)
|
self.assertEqual('aggregate.updatemetadata.start', msg.event_type)
|
||||||
self.assertEqual(expected_payload_meta_data, msg.payload['meta_data'])
|
self.assertEqual(expected_payload_meta_data, msg.payload['meta_data'])
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
|
self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
|
||||||
self.assertEqual(expected_payload_meta_data, msg.payload['meta_data'])
|
self.assertEqual(expected_payload_meta_data, msg.payload['meta_data'])
|
||||||
self.assertThat(expected.metadata,
|
self.assertThat(expected.metadata,
|
||||||
@ -12408,14 +12406,14 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
aggr2 = self._init_aggregate_with_host(None, 'fake_aggregate2', None,
|
aggr2 = self._init_aggregate_with_host(None, 'fake_aggregate2', None,
|
||||||
fake_host)
|
fake_host)
|
||||||
metadata = {'foo_key2': 'foo_value3'}
|
metadata = {'foo_key2': 'foo_value3'}
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
aggr2 = self.api.update_aggregate_metadata(self.context, aggr2.id,
|
aggr2 = self.api.update_aggregate_metadata(self.context, aggr2.id,
|
||||||
metadata)
|
metadata)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.start')
|
'aggregate.updatemetadata.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.end')
|
'aggregate.updatemetadata.end')
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
@ -12446,13 +12444,13 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
self._init_aggregate_with_host(None, 'fake_aggregate2', None,
|
self._init_aggregate_with_host(None, 'fake_aggregate2', None,
|
||||||
fake_host)
|
fake_host)
|
||||||
metadata = {'availability_zone': 'new_fake_zone'}
|
metadata = {'availability_zone': 'new_fake_zone'}
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
self.api.update_aggregate_metadata(self.context, aggr1.id, metadata)
|
self.api.update_aggregate_metadata(self.context, aggr1.id, metadata)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.start')
|
'aggregate.updatemetadata.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.end')
|
'aggregate.updatemetadata.end')
|
||||||
|
|
||||||
@ -12479,7 +12477,7 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
mock_get_all_by_host):
|
mock_get_all_by_host):
|
||||||
# Ensure aggregate's availability zone can't be updated,
|
# Ensure aggregate's availability zone can't be updated,
|
||||||
# when aggregate has hosts in other availability zone
|
# when aggregate has hosts in other availability zone
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
values = _create_service_entries(self.context)
|
values = _create_service_entries(self.context)
|
||||||
fake_zone = values[0][0]
|
fake_zone = values[0][0]
|
||||||
fake_host = values[0][1][0]
|
fake_host = values[0][1][0]
|
||||||
@ -12499,11 +12497,11 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
None, fake_host)
|
None, fake_host)
|
||||||
metadata = {'availability_zone': fake_zone}
|
metadata = {'availability_zone': fake_zone}
|
||||||
self.api.update_aggregate_metadata(self.context, aggr3.id, metadata)
|
self.api.update_aggregate_metadata(self.context, aggr3.id, metadata)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 15)
|
self.assertEqual(len(self.notifier.notifications), 15)
|
||||||
msg = fake_notifier.NOTIFICATIONS[13]
|
msg = self.notifier.notifications[13]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.start')
|
'aggregate.updatemetadata.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[14]
|
msg = self.notifier.notifications[14]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.updatemetadata.end')
|
'aggregate.updatemetadata.end')
|
||||||
aggr4 = self.api.create_aggregate(self.context, 'fake_aggregate', None)
|
aggr4 = self.api.create_aggregate(self.context, 'fake_aggregate', None)
|
||||||
@ -12515,14 +12513,13 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
@mock.patch('nova.compute.utils.notify_about_aggregate_action')
|
@mock.patch('nova.compute.utils.notify_about_aggregate_action')
|
||||||
def test_delete_aggregate(self, mock_notify):
|
def test_delete_aggregate(self, mock_notify):
|
||||||
# Ensure we can delete an aggregate.
|
# Ensure we can delete an aggregate.
|
||||||
fake_notifier.NOTIFICATIONS = []
|
|
||||||
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
||||||
'fake_zone')
|
'fake_zone')
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.create.start')
|
'aggregate.create.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.create.end')
|
'aggregate.create.end')
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
@ -12532,13 +12529,13 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
action='create', phase='end')])
|
action='create', phase='end')])
|
||||||
|
|
||||||
mock_notify.reset_mock()
|
mock_notify.reset_mock()
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
self.api.delete_aggregate(self.context, aggr.id)
|
self.api.delete_aggregate(self.context, aggr.id)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.delete.start')
|
'aggregate.delete.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.delete.end')
|
'aggregate.delete.end')
|
||||||
self.assertRaises(exception.AggregateNotFound,
|
self.assertRaises(exception.AggregateNotFound,
|
||||||
@ -12600,14 +12597,14 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
host=fake_host,
|
host=fake_host,
|
||||||
hypervisor_hostname=fake_host)])
|
hypervisor_hostname=fake_host)])
|
||||||
|
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
aggr = self.api.add_host_to_aggregate(self.context,
|
aggr = self.api.add_host_to_aggregate(self.context,
|
||||||
aggr.id, fake_host)
|
aggr.id, fake_host)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.addhost.start')
|
'aggregate.addhost.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.addhost.end')
|
'aggregate.addhost.end')
|
||||||
self.assertEqual(len(aggr.hosts), 1)
|
self.assertEqual(len(aggr.hosts), 1)
|
||||||
@ -12723,12 +12720,12 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
# Ensure ComputeHostNotFound is raised when adding invalid host.
|
# Ensure ComputeHostNotFound is raised when adding invalid host.
|
||||||
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
||||||
'fake_zone')
|
'fake_zone')
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
self.assertRaises(exception.ComputeHostNotFound,
|
self.assertRaises(exception.ComputeHostNotFound,
|
||||||
self.api.add_host_to_aggregate,
|
self.api.add_host_to_aggregate,
|
||||||
self.context, aggr.id, 'invalid_host')
|
self.context, aggr.id, 'invalid_host')
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
self.assertEqual(fake_notifier.NOTIFICATIONS[1].publisher_id,
|
self.assertEqual(self.notifier.notifications[1].publisher_id,
|
||||||
'compute.fake-mini')
|
'compute.fake-mini')
|
||||||
mock_add_host.assert_not_called()
|
mock_add_host.assert_not_called()
|
||||||
|
|
||||||
@ -12747,7 +12744,7 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
|
|
||||||
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
||||||
'fake_zone')
|
'fake_zone')
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
values = _create_service_entries(self.context)
|
values = _create_service_entries(self.context)
|
||||||
fake_host = values[0][1][0]
|
fake_host = values[0][1][0]
|
||||||
self.assertRaises(exception.ComputeHostNotFound,
|
self.assertRaises(exception.ComputeHostNotFound,
|
||||||
@ -12764,7 +12761,7 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
# Ensure ComputeHostNotFound is raised when adding invalid host.
|
# Ensure ComputeHostNotFound is raised when adding invalid host.
|
||||||
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
||||||
'fake_zone')
|
'fake_zone')
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
self.assertRaises(exception.ComputeHostNotFound,
|
self.assertRaises(exception.ComputeHostNotFound,
|
||||||
self.api.add_host_to_aggregate,
|
self.api.add_host_to_aggregate,
|
||||||
self.context, aggr.id, 'invalid_host')
|
self.context, aggr.id, 'invalid_host')
|
||||||
@ -12795,7 +12792,7 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
aggr.id, host)
|
aggr.id, host)
|
||||||
host_to_remove = values[0][1][0]
|
host_to_remove = values[0][1][0]
|
||||||
|
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
mock_notify.reset_mock()
|
mock_notify.reset_mock()
|
||||||
mock_get_all_by_host.reset_mock()
|
mock_get_all_by_host.reset_mock()
|
||||||
mock_get_all_by_host.return_value = objects.ComputeNodeList(
|
mock_get_all_by_host.return_value = objects.ComputeNodeList(
|
||||||
@ -12805,11 +12802,11 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
expected = self.api.remove_host_from_aggregate(self.context,
|
expected = self.api.remove_host_from_aggregate(self.context,
|
||||||
aggr.id,
|
aggr.id,
|
||||||
host_to_remove)
|
host_to_remove)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
self.assertEqual(len(self.notifier.notifications), 2)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.removehost.start')
|
'aggregate.removehost.start')
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual(msg.event_type,
|
self.assertEqual(msg.event_type,
|
||||||
'aggregate.removehost.end')
|
'aggregate.removehost.end')
|
||||||
self.assertEqual(len(aggr.hosts) - 1, len(expected.hosts))
|
self.assertEqual(len(aggr.hosts) - 1, len(expected.hosts))
|
||||||
@ -12864,7 +12861,7 @@ class ComputeAPIAggrTestCase(BaseTestCase):
|
|||||||
|
|
||||||
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
|
||||||
'fake_zone')
|
'fake_zone')
|
||||||
fake_notifier.NOTIFICATIONS = []
|
self.notifier.reset()
|
||||||
_create_service_entries(
|
_create_service_entries(
|
||||||
self.context, values=[['az', [fake_host]]],
|
self.context, values=[['az', [fake_host]]],
|
||||||
skip_host_mapping_creation_for_hosts=[fake_host])
|
skip_host_mapping_creation_for_hosts=[fake_host])
|
||||||
|
@ -68,7 +68,6 @@ from nova.tests.unit import fake_flavor
|
|||||||
from nova.tests.unit import fake_instance
|
from nova.tests.unit import fake_instance
|
||||||
from nova.tests.unit import fake_network
|
from nova.tests.unit import fake_network
|
||||||
from nova.tests.unit import fake_network_cache_model
|
from nova.tests.unit import fake_network_cache_model
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
from nova.tests.unit.objects import test_instance_fault
|
from nova.tests.unit.objects import test_instance_fault
|
||||||
from nova.tests.unit.objects import test_instance_info_cache
|
from nova.tests.unit.objects import test_instance_info_cache
|
||||||
from nova.tests.unit.objects import test_instance_numa
|
from nova.tests.unit.objects import test_instance_numa
|
||||||
@ -9569,19 +9568,19 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase,
|
|||||||
|
|
||||||
force_complete.assert_called_once_with(self.instance)
|
force_complete.assert_called_once_with(self.instance)
|
||||||
|
|
||||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(2, len(self.notifier.notifications))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'compute.instance.live.migration.force.complete.start',
|
'compute.instance.live.migration.force.complete.start',
|
||||||
fake_notifier.NOTIFICATIONS[0].event_type)
|
self.notifier.notifications[0].event_type)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.instance.uuid,
|
self.instance.uuid,
|
||||||
fake_notifier.NOTIFICATIONS[0].payload['instance_id'])
|
self.notifier.notifications[0].payload['instance_id'])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'compute.instance.live.migration.force.complete.end',
|
'compute.instance.live.migration.force.complete.end',
|
||||||
fake_notifier.NOTIFICATIONS[1].event_type)
|
self.notifier.notifications[1].event_type)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.instance.uuid,
|
self.instance.uuid,
|
||||||
fake_notifier.NOTIFICATIONS[1].payload['instance_id'])
|
self.notifier.notifications[1].payload['instance_id'])
|
||||||
self.assertEqual(2, mock_notify.call_count)
|
self.assertEqual(2, mock_notify.call_count)
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
mock.call(self.context, self.instance, self.compute.host,
|
mock.call(self.context, self.instance, self.compute.host,
|
||||||
|
@ -48,7 +48,6 @@ from nova.tests.unit import fake_block_device
|
|||||||
from nova.tests.unit import fake_crypto
|
from nova.tests.unit import fake_crypto
|
||||||
from nova.tests.unit import fake_instance
|
from nova.tests.unit import fake_instance
|
||||||
from nova.tests.unit import fake_network
|
from nova.tests.unit import fake_network
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
from nova.tests.unit import fake_server_actions
|
from nova.tests.unit import fake_server_actions
|
||||||
from nova.tests.unit.objects import test_flavor
|
from nova.tests.unit.objects import test_flavor
|
||||||
|
|
||||||
@ -385,8 +384,8 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
instance.save()
|
instance.save()
|
||||||
compute_utils.notify_usage_exists(
|
compute_utils.notify_usage_exists(
|
||||||
rpc.get_notifier('compute'), self.context, instance, 'fake-host')
|
rpc.get_notifier('compute'), self.context, instance, 'fake-host')
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
self.assertEqual(len(self.notifier.notifications), 1)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.exists')
|
self.assertEqual(msg.event_type, 'compute.instance.exists')
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -450,7 +449,7 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
self.compute.terminate_instance(self.context, instance, [])
|
self.compute.terminate_instance(self.context, instance, [])
|
||||||
compute_utils.notify_usage_exists(
|
compute_utils.notify_usage_exists(
|
||||||
rpc.get_notifier('compute'), self.context, instance, 'fake-host')
|
rpc.get_notifier('compute'), self.context, instance, 'fake-host')
|
||||||
msg = fake_notifier.NOTIFICATIONS[-1]
|
msg = self.notifier.notifications[-1]
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.exists')
|
self.assertEqual(msg.event_type, 'compute.instance.exists')
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -814,7 +813,7 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
self.compute.terminate_instance(self.context, instance, [])
|
self.compute.terminate_instance(self.context, instance, [])
|
||||||
compute_utils.notify_usage_exists(
|
compute_utils.notify_usage_exists(
|
||||||
rpc.get_notifier('compute'), self.context, instance, 'fake-host')
|
rpc.get_notifier('compute'), self.context, instance, 'fake-host')
|
||||||
msg = fake_notifier.NOTIFICATIONS[-1]
|
msg = self.notifier.notifications[-1]
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.exists')
|
self.assertEqual(msg.event_type, 'compute.instance.exists')
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -887,8 +886,8 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
rpc.get_notifier('compute'),
|
rpc.get_notifier('compute'),
|
||||||
self.context, instance, 'create.start',
|
self.context, instance, 'create.start',
|
||||||
extra_usage_info=extra_usage_info)
|
extra_usage_info=extra_usage_info)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
self.assertEqual(len(self.notifier.notifications), 1)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
self.assertEqual(msg.event_type, 'compute.instance.create.start')
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -916,8 +915,8 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
compute_utils.notify_about_aggregate_update(self.context,
|
compute_utils.notify_about_aggregate_update(self.context,
|
||||||
"create.end",
|
"create.end",
|
||||||
aggregate_payload)
|
aggregate_payload)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
self.assertEqual(len(self.notifier.notifications), 1)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
self.assertEqual(msg.event_type, 'aggregate.create.end')
|
self.assertEqual(msg.event_type, 'aggregate.create.end')
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -929,8 +928,8 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
compute_utils.notify_about_aggregate_update(self.context,
|
compute_utils.notify_about_aggregate_update(self.context,
|
||||||
"create.start",
|
"create.start",
|
||||||
aggregate_payload)
|
aggregate_payload)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
self.assertEqual(len(self.notifier.notifications), 1)
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual(msg.priority, 'INFO')
|
self.assertEqual(msg.priority, 'INFO')
|
||||||
self.assertEqual(msg.event_type, 'aggregate.create.start')
|
self.assertEqual(msg.event_type, 'aggregate.create.start')
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -942,7 +941,7 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
compute_utils.notify_about_aggregate_update(self.context,
|
compute_utils.notify_about_aggregate_update(self.context,
|
||||||
"create.start",
|
"create.start",
|
||||||
aggregate_payload)
|
aggregate_payload)
|
||||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
self.assertEqual(len(self.notifier.notifications), 0)
|
||||||
|
|
||||||
|
|
||||||
class ComputeUtilsGetValFromSysMetadata(test.NoDBTestCase):
|
class ComputeUtilsGetValFromSysMetadata(test.NoDBTestCase):
|
||||||
|
@ -27,7 +27,6 @@ from nova import objects
|
|||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fixtures as nova_fixtures
|
from nova.tests import fixtures as nova_fixtures
|
||||||
from nova.tests.unit.api.openstack import fakes
|
from nova.tests.unit.api.openstack import fakes
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
from nova.tests.unit.objects import test_objects
|
from nova.tests.unit.objects import test_objects
|
||||||
from nova.tests.unit.objects import test_service
|
from nova.tests.unit.objects import test_service
|
||||||
|
|
||||||
@ -38,7 +37,8 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
self.host_api = compute.HostAPI()
|
self.host_api = compute.HostAPI()
|
||||||
self.aggregate_api = compute.AggregateAPI()
|
self.aggregate_api = compute.AggregateAPI()
|
||||||
self.ctxt = context.get_admin_context()
|
self.ctxt = context.get_admin_context()
|
||||||
self.useFixture(nova_fixtures.NotificationFixture(self))
|
self.notifier = self.useFixture(
|
||||||
|
nova_fixtures.NotificationFixture(self))
|
||||||
self.req = fakes.HTTPRequest.blank('')
|
self.req = fakes.HTTPRequest.blank('')
|
||||||
self.controller = services.ServiceController()
|
self.controller = services.ServiceController()
|
||||||
self.useFixture(nova_fixtures.SingleCellSimple())
|
self.useFixture(nova_fixtures.SingleCellSimple())
|
||||||
@ -54,7 +54,6 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
self._compare_obj(obj, db_obj_list[index])
|
self._compare_obj(obj, db_obj_list[index])
|
||||||
|
|
||||||
def test_set_host_enabled(self):
|
def test_set_host_enabled(self):
|
||||||
fake_notifier.NOTIFICATIONS = []
|
|
||||||
|
|
||||||
@mock.patch.object(self.host_api.rpcapi, 'set_host_enabled',
|
@mock.patch.object(self.host_api.rpcapi, 'set_host_enabled',
|
||||||
return_value='fake-result')
|
return_value='fake-result')
|
||||||
@ -64,14 +63,14 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
result = self.host_api.set_host_enabled(self.ctxt, 'fake_host',
|
result = self.host_api.set_host_enabled(self.ctxt, 'fake_host',
|
||||||
'fake_enabled')
|
'fake_enabled')
|
||||||
self.assertEqual('fake-result', result)
|
self.assertEqual('fake-result', result)
|
||||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(2, len(self.notifier.notifications))
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual('HostAPI.set_enabled.start', msg.event_type)
|
self.assertEqual('HostAPI.set_enabled.start', msg.event_type)
|
||||||
self.assertEqual('api.fake_host', msg.publisher_id)
|
self.assertEqual('api.fake_host', msg.publisher_id)
|
||||||
self.assertEqual('INFO', msg.priority)
|
self.assertEqual('INFO', msg.priority)
|
||||||
self.assertEqual('fake_enabled', msg.payload['enabled'])
|
self.assertEqual('fake_enabled', msg.payload['enabled'])
|
||||||
self.assertEqual('fake_host', msg.payload['host_name'])
|
self.assertEqual('fake_host', msg.payload['host_name'])
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual('HostAPI.set_enabled.end', msg.event_type)
|
self.assertEqual('HostAPI.set_enabled.end', msg.event_type)
|
||||||
self.assertEqual('api.fake_host', msg.publisher_id)
|
self.assertEqual('api.fake_host', msg.publisher_id)
|
||||||
self.assertEqual('INFO', msg.priority)
|
self.assertEqual('INFO', msg.priority)
|
||||||
@ -116,7 +115,6 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
_do_test()
|
_do_test()
|
||||||
|
|
||||||
def test_host_power_action(self):
|
def test_host_power_action(self):
|
||||||
fake_notifier.NOTIFICATIONS = []
|
|
||||||
|
|
||||||
@mock.patch.object(self.host_api.rpcapi, 'host_power_action',
|
@mock.patch.object(self.host_api.rpcapi, 'host_power_action',
|
||||||
return_value='fake-result')
|
return_value='fake-result')
|
||||||
@ -126,14 +124,14 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
result = self.host_api.host_power_action(self.ctxt, 'fake_host',
|
result = self.host_api.host_power_action(self.ctxt, 'fake_host',
|
||||||
'fake_action')
|
'fake_action')
|
||||||
self.assertEqual('fake-result', result)
|
self.assertEqual('fake-result', result)
|
||||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(2, len(self.notifier.notifications))
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual('HostAPI.power_action.start', msg.event_type)
|
self.assertEqual('HostAPI.power_action.start', msg.event_type)
|
||||||
self.assertEqual('api.fake_host', msg.publisher_id)
|
self.assertEqual('api.fake_host', msg.publisher_id)
|
||||||
self.assertEqual('INFO', msg.priority)
|
self.assertEqual('INFO', msg.priority)
|
||||||
self.assertEqual('fake_action', msg.payload['action'])
|
self.assertEqual('fake_action', msg.payload['action'])
|
||||||
self.assertEqual('fake_host', msg.payload['host_name'])
|
self.assertEqual('fake_host', msg.payload['host_name'])
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual('HostAPI.power_action.end', msg.event_type)
|
self.assertEqual('HostAPI.power_action.end', msg.event_type)
|
||||||
self.assertEqual('api.fake_host', msg.publisher_id)
|
self.assertEqual('api.fake_host', msg.publisher_id)
|
||||||
self.assertEqual('INFO', msg.priority)
|
self.assertEqual('INFO', msg.priority)
|
||||||
@ -143,7 +141,6 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
_do_test()
|
_do_test()
|
||||||
|
|
||||||
def test_set_host_maintenance(self):
|
def test_set_host_maintenance(self):
|
||||||
fake_notifier.NOTIFICATIONS = []
|
|
||||||
|
|
||||||
@mock.patch.object(self.host_api.rpcapi, 'host_maintenance_mode',
|
@mock.patch.object(self.host_api.rpcapi, 'host_maintenance_mode',
|
||||||
return_value='fake-result')
|
return_value='fake-result')
|
||||||
@ -153,14 +150,14 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
result = self.host_api.set_host_maintenance(self.ctxt, 'fake_host',
|
result = self.host_api.set_host_maintenance(self.ctxt, 'fake_host',
|
||||||
'fake_mode')
|
'fake_mode')
|
||||||
self.assertEqual('fake-result', result)
|
self.assertEqual('fake-result', result)
|
||||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(2, len(self.notifier.notifications))
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual('HostAPI.set_maintenance.start', msg.event_type)
|
self.assertEqual('HostAPI.set_maintenance.start', msg.event_type)
|
||||||
self.assertEqual('api.fake_host', msg.publisher_id)
|
self.assertEqual('api.fake_host', msg.publisher_id)
|
||||||
self.assertEqual('INFO', msg.priority)
|
self.assertEqual('INFO', msg.priority)
|
||||||
self.assertEqual('fake_host', msg.payload['host_name'])
|
self.assertEqual('fake_host', msg.payload['host_name'])
|
||||||
self.assertEqual('fake_mode', msg.payload['mode'])
|
self.assertEqual('fake_mode', msg.payload['mode'])
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual('HostAPI.set_maintenance.end', msg.event_type)
|
self.assertEqual('HostAPI.set_maintenance.end', msg.event_type)
|
||||||
self.assertEqual('api.fake_host', msg.publisher_id)
|
self.assertEqual('api.fake_host', msg.publisher_id)
|
||||||
self.assertEqual('INFO', msg.priority)
|
self.assertEqual('INFO', msg.priority)
|
||||||
|
@ -25,7 +25,6 @@ from nova.objects import keypair as keypair_obj
|
|||||||
from nova import quota
|
from nova import quota
|
||||||
from nova.tests.unit.compute import test_compute
|
from nova.tests.unit.compute import test_compute
|
||||||
from nova.tests.unit import fake_crypto
|
from nova.tests.unit import fake_crypto
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
from nova.tests.unit.objects import test_keypair
|
from nova.tests.unit.objects import test_keypair
|
||||||
from nova.tests.unit import utils as test_utils
|
from nova.tests.unit import utils as test_utils
|
||||||
|
|
||||||
@ -82,9 +81,9 @@ class KeypairAPITestCase(test_compute.BaseTestCase):
|
|||||||
self.stub_out("nova.db.api.key_pair_get", db_key_pair_get)
|
self.stub_out("nova.db.api.key_pair_get", db_key_pair_get)
|
||||||
|
|
||||||
def _check_notifications(self, action='create', key_name='foo'):
|
def _check_notifications(self, action='create', key_name='foo'):
|
||||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(2, len(self.notifier.notifications))
|
||||||
|
|
||||||
n1 = fake_notifier.NOTIFICATIONS[0]
|
n1 = self.notifier.notifications[0]
|
||||||
self.assertEqual('INFO', n1.priority)
|
self.assertEqual('INFO', n1.priority)
|
||||||
self.assertEqual('keypair.%s.start' % action, n1.event_type)
|
self.assertEqual('keypair.%s.start' % action, n1.event_type)
|
||||||
self.assertEqual('api.%s' % CONF.host, n1.publisher_id)
|
self.assertEqual('api.%s' % CONF.host, n1.publisher_id)
|
||||||
@ -92,7 +91,7 @@ class KeypairAPITestCase(test_compute.BaseTestCase):
|
|||||||
self.assertEqual('fake', n1.payload['tenant_id'])
|
self.assertEqual('fake', n1.payload['tenant_id'])
|
||||||
self.assertEqual(key_name, n1.payload['key_name'])
|
self.assertEqual(key_name, n1.payload['key_name'])
|
||||||
|
|
||||||
n2 = fake_notifier.NOTIFICATIONS[1]
|
n2 = self.notifier.notifications[1]
|
||||||
self.assertEqual('INFO', n2.priority)
|
self.assertEqual('INFO', n2.priority)
|
||||||
self.assertEqual('keypair.%s.end' % action, n2.event_type)
|
self.assertEqual('keypair.%s.end' % action, n2.event_type)
|
||||||
self.assertEqual('api.%s' % CONF.host, n2.publisher_id)
|
self.assertEqual('api.%s' % CONF.host, n2.publisher_id)
|
||||||
|
@ -41,7 +41,6 @@ from nova.scheduler.client import report
|
|||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fixtures
|
from nova.tests import fixtures
|
||||||
from nova.tests.unit import fake_instance
|
from nova.tests.unit import fake_instance
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
from nova.tests.unit.objects import test_pci_device as fake_pci_device
|
from nova.tests.unit.objects import test_pci_device as fake_pci_device
|
||||||
from nova.tests.unit import utils
|
from nova.tests.unit import utils
|
||||||
from nova import utils as nova_utils
|
from nova import utils as nova_utils
|
||||||
@ -3797,7 +3796,7 @@ class ComputeMonitorTestCase(BaseTestCase):
|
|||||||
|
|
||||||
@mock.patch('nova.compute.utils.notify_about_metrics_update')
|
@mock.patch('nova.compute.utils.notify_about_metrics_update')
|
||||||
def test_get_host_metrics(self, mock_notify):
|
def test_get_host_metrics(self, mock_notify):
|
||||||
self.useFixture(fixtures.NotificationFixture(self))
|
self.notifier = self.useFixture(fixtures.NotificationFixture(self))
|
||||||
|
|
||||||
class FakeCPUMonitor(monitor_base.MonitorBase):
|
class FakeCPUMonitor(monitor_base.MonitorBase):
|
||||||
|
|
||||||
@ -3842,8 +3841,8 @@ class ComputeMonitorTestCase(BaseTestCase):
|
|||||||
'nodename': _NODENAME,
|
'nodename': _NODENAME,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual('compute.metrics.update', msg.event_type)
|
self.assertEqual('compute.metrics.update', msg.event_type)
|
||||||
for p_key in payload:
|
for p_key in payload:
|
||||||
if p_key == 'metrics':
|
if p_key == 'metrics':
|
||||||
|
@ -58,7 +58,6 @@ from nova.tests.unit.api.openstack import fakes
|
|||||||
from nova.tests.unit.compute import test_compute
|
from nova.tests.unit.compute import test_compute
|
||||||
from nova.tests.unit import fake_build_request
|
from nova.tests.unit import fake_build_request
|
||||||
from nova.tests.unit import fake_instance
|
from nova.tests.unit import fake_instance
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
from nova.tests.unit import fake_request_spec
|
from nova.tests.unit import fake_request_spec
|
||||||
from nova.tests.unit import fake_server_actions
|
from nova.tests.unit import fake_server_actions
|
||||||
from nova.tests.unit import utils as test_utils
|
from nova.tests.unit import utils as test_utils
|
||||||
@ -1782,7 +1781,7 @@ class _BaseTaskTestCase(object):
|
|||||||
**compute_args)
|
**compute_args)
|
||||||
self.assertEqual(inst_obj.project_id, fake_spec.project_id)
|
self.assertEqual(inst_obj.project_id, fake_spec.project_id)
|
||||||
self.assertEqual('compute.instance.rebuild.scheduled',
|
self.assertEqual('compute.instance.rebuild.scheduled',
|
||||||
fake_notifier.NOTIFICATIONS[0].event_type)
|
self.notifier.notifications[0].event_type)
|
||||||
mock_notify.assert_called_once_with(
|
mock_notify.assert_called_once_with(
|
||||||
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
||||||
source='nova-conductor')
|
source='nova-conductor')
|
||||||
@ -1833,7 +1832,7 @@ class _BaseTaskTestCase(object):
|
|||||||
**compute_args)
|
**compute_args)
|
||||||
self.assertEqual(inst_obj.project_id, fake_spec.project_id)
|
self.assertEqual(inst_obj.project_id, fake_spec.project_id)
|
||||||
self.assertEqual('compute.instance.rebuild.scheduled',
|
self.assertEqual('compute.instance.rebuild.scheduled',
|
||||||
fake_notifier.NOTIFICATIONS[0].event_type)
|
self.notifier.notifications[0].event_type)
|
||||||
mock_notify.assert_called_once_with(
|
mock_notify.assert_called_once_with(
|
||||||
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
||||||
source='nova-conductor')
|
source='nova-conductor')
|
||||||
@ -2031,7 +2030,7 @@ class _BaseTaskTestCase(object):
|
|||||||
fake_spec, fake_selection)
|
fake_spec, fake_selection)
|
||||||
|
|
||||||
self.assertEqual('compute.instance.rebuild.scheduled',
|
self.assertEqual('compute.instance.rebuild.scheduled',
|
||||||
fake_notifier.NOTIFICATIONS[0].event_type)
|
self.notifier.notifications[0].event_type)
|
||||||
mock_notify.assert_called_once_with(
|
mock_notify.assert_called_once_with(
|
||||||
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
||||||
source='nova-conductor')
|
source='nova-conductor')
|
||||||
@ -2103,7 +2102,7 @@ class _BaseTaskTestCase(object):
|
|||||||
mock_del_arqs.assert_called_once()
|
mock_del_arqs.assert_called_once()
|
||||||
|
|
||||||
self.assertEqual('compute.instance.rebuild.scheduled',
|
self.assertEqual('compute.instance.rebuild.scheduled',
|
||||||
fake_notifier.NOTIFICATIONS[0].event_type)
|
self.notifier.notifications[0].event_type)
|
||||||
mock_notify.assert_called_once_with(
|
mock_notify.assert_called_once_with(
|
||||||
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
||||||
source='nova-conductor')
|
source='nova-conductor')
|
||||||
@ -2176,7 +2175,7 @@ class _BaseTaskTestCase(object):
|
|||||||
mock_del_arqs_instance.assert_called_once()
|
mock_del_arqs_instance.assert_called_once()
|
||||||
|
|
||||||
self.assertEqual('compute.instance.rebuild.scheduled',
|
self.assertEqual('compute.instance.rebuild.scheduled',
|
||||||
fake_notifier.NOTIFICATIONS[0].event_type)
|
self.notifier.notifications[0].event_type)
|
||||||
mock_notify.assert_called_once_with(
|
mock_notify.assert_called_once_with(
|
||||||
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
self.context, inst_obj, 'thebesthost', action='rebuild_scheduled',
|
||||||
source='nova-conductor')
|
source='nova-conductor')
|
||||||
|
@ -19,7 +19,6 @@ from oslo_utils import timeutils
|
|||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.objects import aggregate
|
from nova.objects import aggregate
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
from nova.tests.unit.objects import test_objects
|
from nova.tests.unit.objects import test_objects
|
||||||
|
|
||||||
|
|
||||||
@ -141,7 +140,6 @@ class _TestAggregateObject(object):
|
|||||||
mock_notify,
|
mock_notify,
|
||||||
mock_api_metadata_add,
|
mock_api_metadata_add,
|
||||||
mock_api_metadata_delete):
|
mock_api_metadata_delete):
|
||||||
fake_notifier.NOTIFICATIONS = []
|
|
||||||
agg = aggregate.Aggregate()
|
agg = aggregate.Aggregate()
|
||||||
agg._context = self.context
|
agg._context = self.context
|
||||||
agg.id = 123
|
agg.id = 123
|
||||||
@ -150,12 +148,12 @@ class _TestAggregateObject(object):
|
|||||||
mock_obj_from_primitive.return_value = agg
|
mock_obj_from_primitive.return_value = agg
|
||||||
|
|
||||||
agg.update_metadata({'todelete': None, 'toadd': 'myval'})
|
agg.update_metadata({'todelete': None, 'toadd': 'myval'})
|
||||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(2, len(self.notifier.notifications))
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = self.notifier.notifications[0]
|
||||||
self.assertEqual('aggregate.updatemetadata.start', msg.event_type)
|
self.assertEqual('aggregate.updatemetadata.start', msg.event_type)
|
||||||
self.assertEqual({'todelete': None, 'toadd': 'myval'},
|
self.assertEqual({'todelete': None, 'toadd': 'myval'},
|
||||||
msg.payload['meta_data'])
|
msg.payload['meta_data'])
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = self.notifier.notifications[1]
|
||||||
self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
|
self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
mock.call(context=self.context, aggregate=agg,
|
mock.call(context=self.context, aggregate=agg,
|
||||||
|
@ -210,7 +210,8 @@ class _BaseTestCase(test.TestCase):
|
|||||||
self.user_id = 'fake-user'
|
self.user_id = 'fake-user'
|
||||||
self.project_id = 'fake-project'
|
self.project_id = 'fake-project'
|
||||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||||
self.useFixture(nova_fixtures.NotificationFixture(self))
|
self.notifier = self.useFixture(
|
||||||
|
nova_fixtures.NotificationFixture(self))
|
||||||
|
|
||||||
# NOTE(danms): register these here instead of at import time
|
# NOTE(danms): register these here instead of at import time
|
||||||
# so that they're not always present
|
# so that they're not always present
|
||||||
|
@ -20,7 +20,6 @@ from nova import context as nova_context
|
|||||||
from nova import exception_wrapper
|
from nova import exception_wrapper
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fixtures as nova_fixtures
|
from nova.tests import fixtures as nova_fixtures
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
|
|
||||||
|
|
||||||
def bad_function_exception(self, context, extra, blah="a", boo="b", zoo=None):
|
def bad_function_exception(self, context, extra, blah="a", boo="b", zoo=None):
|
||||||
@ -67,7 +66,7 @@ class WrapExceptionTestCase(test.NoDBTestCase):
|
|||||||
wrapped = exception_wrapper.wrap_exception(
|
wrapped = exception_wrapper.wrap_exception(
|
||||||
service='compute', binary='nova-compute')
|
service='compute', binary='nova-compute')
|
||||||
self.assertEqual(99, wrapped(good_function)(1, 2))
|
self.assertEqual(99, wrapped(good_function)(1, 2))
|
||||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
def test_wrap_exception_unknown_module(self):
|
def test_wrap_exception_unknown_module(self):
|
||||||
@ -88,8 +87,8 @@ class WrapExceptionTestCase(test.NoDBTestCase):
|
|||||||
self.assertRaises(test.TestingException,
|
self.assertRaises(test.TestingException,
|
||||||
wrapped(bad_function_exception), 1, ctxt, 3, zoo=3)
|
wrapped(bad_function_exception), 1, ctxt, 3, zoo=3)
|
||||||
|
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
notification = fake_notifier.NOTIFICATIONS[0]
|
notification = self.notifier.notifications[0]
|
||||||
self.assertEqual('bad_function_exception', notification.event_type)
|
self.assertEqual('bad_function_exception', notification.event_type)
|
||||||
self.assertEqual(ctxt, notification.context)
|
self.assertEqual(ctxt, notification.context)
|
||||||
self.assertEqual(3, notification.payload['args']['extra'])
|
self.assertEqual(3, notification.payload['args']['extra'])
|
||||||
|
@ -34,7 +34,6 @@ from nova.objects import base as obj_base
|
|||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fixtures
|
from nova.tests import fixtures
|
||||||
from nova.tests.unit import fake_network
|
from nova.tests.unit import fake_network
|
||||||
from nova.tests.unit import fake_notifier
|
|
||||||
|
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
@ -105,7 +104,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
verify_states=True)
|
verify_states=True)
|
||||||
|
|
||||||
notifications.send_update(self.context, old, self.instance)
|
notifications.send_update(self.context, old, self.instance)
|
||||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
def test_task_notif(self):
|
def test_task_notif(self):
|
||||||
@ -126,7 +125,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
old_vm_state, new_vm_state, old_task_state, new_task_state,
|
old_vm_state, new_vm_state, old_task_state, new_task_state,
|
||||||
verify_states=True)
|
verify_states=True)
|
||||||
|
|
||||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
# ok now enable task state notifications and re-try
|
# ok now enable task state notifications and re-try
|
||||||
@ -134,7 +133,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
group='notifications')
|
group='notifications')
|
||||||
|
|
||||||
notifications.send_update(self.context, old, self.instance)
|
notifications.send_update(self.context, old, self.instance)
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -153,7 +152,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
old_vm_state, new_vm_state, old_task_state, new_task_state,
|
old_vm_state, new_vm_state, old_task_state, new_task_state,
|
||||||
service="compute", host=None, verify_states=True)
|
service="compute", host=None, verify_states=True)
|
||||||
|
|
||||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
def test_send_on_vm_change(self):
|
def test_send_on_vm_change(self):
|
||||||
@ -163,9 +162,9 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
self.instance.vm_state = vm_states.ACTIVE
|
self.instance.vm_state = vm_states.ACTIVE
|
||||||
notifications.send_update(self.context, old, self.instance)
|
notifications.send_update(self.context, old, self.instance)
|
||||||
|
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
# service name should default to 'compute'
|
# service name should default to 'compute'
|
||||||
notif = fake_notifier.NOTIFICATIONS[0]
|
notif = self.notifier.notifications[0]
|
||||||
self.assertEqual('compute.testhost', notif.publisher_id)
|
self.assertEqual('compute.testhost', notif.publisher_id)
|
||||||
|
|
||||||
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
||||||
@ -184,7 +183,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
self.instance.task_state = task_states.SPAWNING
|
self.instance.task_state = task_states.SPAWNING
|
||||||
notifications.send_update(self.context, old, self.instance)
|
notifications.send_update(self.context, old, self.instance)
|
||||||
|
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'instance.update',
|
'instance.update',
|
||||||
@ -195,7 +194,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
notifications.send_update_with_states(self.context, self.instance,
|
notifications.send_update_with_states(self.context, self.instance,
|
||||||
vm_states.BUILDING, vm_states.BUILDING, task_states.SPAWNING,
|
vm_states.BUILDING, vm_states.BUILDING, task_states.SPAWNING,
|
||||||
task_states.SPAWNING, verify_states=True)
|
task_states.SPAWNING, verify_states=True)
|
||||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
self.assertEqual(0, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
def test_vm_update_with_states(self):
|
def test_vm_update_with_states(self):
|
||||||
@ -210,7 +209,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
|
|
||||||
def _verify_notification(self, expected_state=vm_states.ACTIVE,
|
def _verify_notification(self, expected_state=vm_states.ACTIVE,
|
||||||
expected_new_task_state=task_states.SPAWNING):
|
expected_new_task_state=task_states.SPAWNING):
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'instance.update',
|
'instance.update',
|
||||||
@ -220,7 +219,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
display_name = self.instance.display_name
|
display_name = self.instance.display_name
|
||||||
hostname = self.instance.hostname
|
hostname = self.instance.hostname
|
||||||
node = self.instance.node
|
node = self.instance.node
|
||||||
payload = fake_notifier.NOTIFICATIONS[0].payload
|
payload = self.notifier.notifications[0].payload
|
||||||
self.assertEqual(vm_states.BUILDING, payload["old_state"])
|
self.assertEqual(vm_states.BUILDING, payload["old_state"])
|
||||||
self.assertEqual(expected_state, payload["state"])
|
self.assertEqual(expected_state, payload["state"])
|
||||||
self.assertEqual(task_states.SPAWNING, payload["old_task_state"])
|
self.assertEqual(task_states.SPAWNING, payload["old_task_state"])
|
||||||
@ -283,11 +282,11 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
notifications.send_update_with_states(self.context, self.instance,
|
notifications.send_update_with_states(self.context, self.instance,
|
||||||
vm_states.BUILDING, vm_states.BUILDING, task_states.SPAWNING,
|
vm_states.BUILDING, vm_states.BUILDING, task_states.SPAWNING,
|
||||||
None)
|
None)
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
# service name should default to 'compute'
|
# service name should default to 'compute'
|
||||||
notif = fake_notifier.NOTIFICATIONS[0]
|
notif = self.notifier.notifications[0]
|
||||||
self.assertEqual('compute.testhost', notif.publisher_id)
|
self.assertEqual('compute.testhost', notif.publisher_id)
|
||||||
|
|
||||||
# in the versioned notification it defaults to nova-compute
|
# in the versioned notification it defaults to nova-compute
|
||||||
@ -298,11 +297,11 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
notifications.send_update_with_states(self.context, self.instance,
|
notifications.send_update_with_states(self.context, self.instance,
|
||||||
vm_states.BUILDING, vm_states.BUILDING, task_states.SPAWNING,
|
vm_states.BUILDING, vm_states.BUILDING, task_states.SPAWNING,
|
||||||
None, service="nova-compute")
|
None, service="nova-compute")
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
# service name should default to 'compute'
|
# service name should default to 'compute'
|
||||||
notif = fake_notifier.NOTIFICATIONS[0]
|
notif = self.notifier.notifications[0]
|
||||||
self.assertEqual('nova-compute.testhost', notif.publisher_id)
|
self.assertEqual('nova-compute.testhost', notif.publisher_id)
|
||||||
|
|
||||||
notif = self.notifier.versioned_notifications[0]
|
notif = self.notifier.versioned_notifications[0]
|
||||||
@ -312,11 +311,11 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
notifications.send_update_with_states(self.context, self.instance,
|
notifications.send_update_with_states(self.context, self.instance,
|
||||||
vm_states.BUILDING, vm_states.BUILDING, task_states.SPAWNING,
|
vm_states.BUILDING, vm_states.BUILDING, task_states.SPAWNING,
|
||||||
None, host="someotherhost")
|
None, host="someotherhost")
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
# service name should default to 'compute'
|
# service name should default to 'compute'
|
||||||
notif = fake_notifier.NOTIFICATIONS[0]
|
notif = self.notifier.notifications[0]
|
||||||
self.assertEqual('compute.someotherhost', notif.publisher_id)
|
self.assertEqual('compute.someotherhost', notif.publisher_id)
|
||||||
|
|
||||||
notif = self.notifier.versioned_notifications[0]
|
notif = self.notifier.versioned_notifications[0]
|
||||||
@ -397,8 +396,8 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_send_access_ip_update(self):
|
def test_send_access_ip_update(self):
|
||||||
notifications.send_update(self.context, self.instance, self.instance)
|
notifications.send_update(self.context, self.instance, self.instance)
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
notif = fake_notifier.NOTIFICATIONS[0]
|
notif = self.notifier.notifications[0]
|
||||||
payload = notif.payload
|
payload = notif.payload
|
||||||
access_ip_v4 = str(self.instance.access_ip_v4)
|
access_ip_v4 = str(self.instance.access_ip_v4)
|
||||||
access_ip_v6 = str(self.instance.access_ip_v6)
|
access_ip_v6 = str(self.instance.access_ip_v6)
|
||||||
@ -410,14 +409,14 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
param = {"display_name": "new_display_name"}
|
param = {"display_name": "new_display_name"}
|
||||||
new_name_inst = self._wrapped_create(params=param)
|
new_name_inst = self._wrapped_create(params=param)
|
||||||
notifications.send_update(self.context, self.instance, new_name_inst)
|
notifications.send_update(self.context, self.instance, new_name_inst)
|
||||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
self.assertEqual(1, len(self.notifier.versioned_notifications))
|
||||||
|
|
||||||
old_display_name = self.instance.display_name
|
old_display_name = self.instance.display_name
|
||||||
new_display_name = new_name_inst.display_name
|
new_display_name = new_name_inst.display_name
|
||||||
|
|
||||||
for payload in [
|
for payload in [
|
||||||
fake_notifier.NOTIFICATIONS[0].payload,
|
self.notifier.notifications[0].payload,
|
||||||
self.notifier.versioned_notifications[0][
|
self.notifier.versioned_notifications[0][
|
||||||
'payload']['nova_object.data']]:
|
'payload']['nova_object.data']]:
|
||||||
|
|
||||||
@ -468,7 +467,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
fail_sending)
|
fail_sending)
|
||||||
|
|
||||||
notifications.send_update(self.context, self.instance, self.instance)
|
notifications.send_update(self.context, self.instance, self.instance)
|
||||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
|
|
||||||
@mock.patch.object(notifications.LOG, 'exception')
|
@mock.patch.object(notifications.LOG, 'exception')
|
||||||
def test_fail_sending_update_instance_not_found(self, mock_log_exception):
|
def test_fail_sending_update_instance_not_found(self, mock_log_exception):
|
||||||
@ -480,7 +479,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
side_effect=notfound):
|
side_effect=notfound):
|
||||||
notifications.send_update(
|
notifications.send_update(
|
||||||
self.context, self.instance, self.instance)
|
self.context, self.instance, self.instance)
|
||||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
self.assertEqual(0, mock_log_exception.call_count)
|
self.assertEqual(0, mock_log_exception.call_count)
|
||||||
|
|
||||||
@mock.patch.object(notifications.LOG, 'exception')
|
@mock.patch.object(notifications.LOG, 'exception')
|
||||||
@ -496,7 +495,7 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
self.context, self.instance,
|
self.context, self.instance,
|
||||||
vm_states.BUILDING, vm_states.ERROR,
|
vm_states.BUILDING, vm_states.ERROR,
|
||||||
task_states.NETWORKING, new_task_state=None)
|
task_states.NETWORKING, new_task_state=None)
|
||||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
self.assertEqual(0, mock_log_exception.call_count)
|
self.assertEqual(0, mock_log_exception.call_count)
|
||||||
|
|
||||||
def _decorated_function(self, arg1, arg2):
|
def _decorated_function(self, arg1, arg2):
|
||||||
|
Loading…
Reference in New Issue
Block a user