diff --git a/releasenotes/notes/remove-nova-legacy-notifications-e1b6d10eff58f30a.yaml b/releasenotes/notes/remove-nova-legacy-notifications-e1b6d10eff58f30a.yaml new file mode 100644 index 000000000..9eaa29c66 --- /dev/null +++ b/releasenotes/notes/remove-nova-legacy-notifications-e1b6d10eff58f30a.yaml @@ -0,0 +1,5 @@ +--- +deprecations: + - | + Watcher removes the support to Nova legacy notifications because of Nova + will deprecate them. diff --git a/watcher/decision_engine/model/collector/nova.py b/watcher/decision_engine/model/collector/nova.py index d4fccdb5c..7ad311c9f 100644 --- a/watcher/decision_engine/model/collector/nova.py +++ b/watcher/decision_engine/model/collector/nova.py @@ -164,13 +164,6 @@ class NovaClusterDataModelCollector(base.BaseClusterDataModelCollector): nova.InstanceCreated(self), nova.InstanceUpdated(self), nova.InstanceDeletedEnd(self), - - nova.LegacyInstanceCreatedEnd(self), - nova.LegacyInstanceUpdated(self), - nova.LegacyInstanceDeletedEnd(self), - nova.LegacyLiveMigratedEnd(self), - nova.LegacyInstanceResizeConfirmEnd(self), - nova.LegacyInstanceRebuildEnd(self), ] def get_audit_scope_handler(self, audit_scope): diff --git a/watcher/decision_engine/model/notification/nova.py b/watcher/decision_engine/model/notification/nova.py index f8640badf..31cf036e8 100644 --- a/watcher/decision_engine/model/notification/nova.py +++ b/watcher/decision_engine/model/notification/nova.py @@ -88,32 +88,6 @@ class NovaNotification(base.NotificationEndpoint): self.update_instance_mapping(instance, node) - def legacy_update_instance(self, instance, data): - memory_mb = data['memory_mb'] - num_cores = data['vcpus'] - disk_gb = data['root_gb'] - instance_metadata = data['metadata'] - - instance.update({ - 'state': data['state'], - 'hostname': data['hostname'], - 'human_id': data['display_name'], - 'memory': memory_mb, - 'vcpus': num_cores, - 'disk': disk_gb, - 'disk_capacity': disk_gb, - 'metadata': instance_metadata, - }) - - try: - node = self.get_or_create_node(data['host']) - except exception.ComputeNodeNotFound as exc: - LOG.exception(exc) - # If we can't create the node, we consider the instance as unmapped - node = None - - self.update_instance_mapping(instance, node) - def update_compute_node(self, node, data): """Update the compute node using the notification data.""" node_data = data['nova_object.data'] @@ -212,10 +186,6 @@ class VersionedNotificationEndpoint(NovaNotification): publisher_id_regex = r'^nova-compute.*' -class UnversionedNotificationEndpoint(NovaNotification): - publisher_id_regex = r'^compute.*' - - class ServiceUpdated(VersionedNotificationEndpoint): @property @@ -357,171 +327,3 @@ class InstanceDeletedEnd(VersionedNotificationEndpoint): node = None self.delete_instance(instance, node) - - -class LegacyInstanceUpdated(UnversionedNotificationEndpoint): - - @property - def filter_rule(self): - """Nova compute.instance.update notification filter""" - return filtering.NotificationFilter( - publisher_id=self.publisher_id_regex, - event_type='compute.instance.update', - ) - - def info(self, ctxt, publisher_id, event_type, payload, metadata): - ctxt.request_id = metadata['message_id'] - ctxt.project_domain = event_type - LOG.info("Event '%(event)s' received from %(publisher)s " - "with metadata %(metadata)s", - dict(event=event_type, - publisher=publisher_id, - metadata=metadata)) - LOG.debug(payload) - - instance_uuid = payload['instance_id'] - node_uuid = payload.get('node') - instance = self.get_or_create_instance(instance_uuid, node_uuid) - - self.legacy_update_instance(instance, payload) - - -class LegacyInstanceCreatedEnd(UnversionedNotificationEndpoint): - - @property - def filter_rule(self): - """Nova compute.instance.create.end notification filter""" - return filtering.NotificationFilter( - publisher_id=self.publisher_id_regex, - event_type='compute.instance.create.end', - ) - - def info(self, ctxt, publisher_id, event_type, payload, metadata): - ctxt.request_id = metadata['message_id'] - ctxt.project_domain = event_type - LOG.info("Event '%(event)s' received from %(publisher)s " - "with metadata %(metadata)s", - dict(event=event_type, - publisher=publisher_id, - metadata=metadata)) - LOG.debug(payload) - - instance_uuid = payload['instance_id'] - node_uuid = payload.get('node') - instance = self.get_or_create_instance(instance_uuid, node_uuid) - - self.legacy_update_instance(instance, payload) - - -class LegacyInstanceDeletedEnd(UnversionedNotificationEndpoint): - - @property - def filter_rule(self): - """Nova compute.instance.delete.end notification filter""" - return filtering.NotificationFilter( - publisher_id=self.publisher_id_regex, - event_type='compute.instance.delete.end', - ) - - def info(self, ctxt, publisher_id, event_type, payload, metadata): - ctxt.request_id = metadata['message_id'] - ctxt.project_domain = event_type - LOG.info("Event '%(event)s' received from %(publisher)s " - "with metadata %(metadata)s", - dict(event=event_type, - publisher=publisher_id, - metadata=metadata)) - LOG.debug(payload) - instance_uuid = payload['instance_id'] - node_uuid = payload.get('node') - instance = self.get_or_create_instance(instance_uuid, node_uuid) - - try: - node = self.get_or_create_node(payload['host']) - except exception.ComputeNodeNotFound as exc: - LOG.exception(exc) - # If we can't create the node, we consider the instance as unmapped - node = None - - self.delete_instance(instance, node) - - -class LegacyLiveMigratedEnd(UnversionedNotificationEndpoint): - - @property - def filter_rule(self): - """Nova *.live_migration.post.dest.end notification filter""" - return filtering.NotificationFilter( - publisher_id=self.publisher_id_regex, - event_type='compute.instance.live_migration.post.dest.end', - ) - - def info(self, ctxt, publisher_id, event_type, payload, metadata): - ctxt.request_id = metadata['message_id'] - ctxt.project_domain = event_type - LOG.info("Event '%(event)s' received from %(publisher)s " - "with metadata %(metadata)s", - dict(event=event_type, - publisher=publisher_id, - metadata=metadata)) - LOG.debug(payload) - - instance_uuid = payload['instance_id'] - node_uuid = payload.get('node') - instance = self.get_or_create_instance(instance_uuid, node_uuid) - - self.legacy_update_instance(instance, payload) - - -class LegacyInstanceResizeConfirmEnd(UnversionedNotificationEndpoint): - - @property - def filter_rule(self): - """Nova compute.instance.resize.confirm.end filter""" - return filtering.NotificationFilter( - publisher_id=self.publisher_id_regex, - event_type='compute.instance.resize.confirm.end', - ) - - def info(self, ctxt, publisher_id, event_type, payload, metadata): - ctxt.request_id = metadata['message_id'] - ctxt.project_domain = event_type - LOG.info("Event '%(event)s' received from %(publisher)s " - "with metadata %(metadata)s", - dict(event=event_type, - publisher=publisher_id, - metadata=metadata)) - LOG.debug(payload) - - instance_uuid = payload['instance_id'] - node_uuid = payload.get('node') - instance = self.get_or_create_instance(instance_uuid, node_uuid) - - self.legacy_update_instance(instance, payload) - - -class LegacyInstanceRebuildEnd(UnversionedNotificationEndpoint): - - @property - def filter_rule(self): - """Nova compute.instance.rebuild.end filter""" - return filtering.NotificationFilter( - publisher_id=self.publisher_id_regex, - event_type='compute.instance.rebuild.end', - ) - - def info(self, ctxt, publisher_id, event_type, payload, metadata): - ctxt.request_id = metadata['message_id'] - ctxt.project_domain = event_type - LOG.info("Event '%(event)s' received from %(publisher)s " - "with metadata %(metadata)s", - dict(event=event_type, - publisher=publisher_id, - metadata=metadata)) - LOG.debug(payload) - - instance_uuid = payload['instance_id'] - node_uuid = payload.get('node') - instance = self.get_or_create_instance(instance_uuid, node_uuid) - - self.legacy_update_instance(instance, payload) diff --git a/watcher/tests/decision_engine/model/notification/fake_managers.py b/watcher/tests/decision_engine/model/notification/fake_managers.py index 0d196f325..bc1ca651c 100644 --- a/watcher/tests/decision_engine/model/notification/fake_managers.py +++ b/watcher/tests/decision_engine/model/notification/fake_managers.py @@ -60,11 +60,6 @@ class FakeManager(service_manager.ServiceManager): novanotification.InstanceCreated(self.fake_cdmc), novanotification.InstanceUpdated(self.fake_cdmc), novanotification.InstanceDeletedEnd(self.fake_cdmc), - - novanotification.LegacyInstanceCreatedEnd(self.fake_cdmc), - novanotification.LegacyInstanceUpdated(self.fake_cdmc), - novanotification.LegacyLiveMigratedEnd(self.fake_cdmc), - novanotification.LegacyInstanceDeletedEnd(self.fake_cdmc), ] diff --git a/watcher/tests/decision_engine/model/notification/test_nova_notifications.py b/watcher/tests/decision_engine/model/notification/test_nova_notifications.py index a49d60a7f..85147247a 100644 --- a/watcher/tests/decision_engine/model/notification/test_nova_notifications.py +++ b/watcher/tests/decision_engine/model/notification/test_nova_notifications.py @@ -322,250 +322,3 @@ class TestNovaNotifications(NotificationTestCase): self.assertRaises( exception.InstanceNotFound, compute_model.get_instance_by_uuid, instance0_uuid) - - -class TestLegacyNovaNotifications(NotificationTestCase): - - FAKE_METADATA = {'message_id': None, 'timestamp': None} - - def setUp(self): - super(TestLegacyNovaNotifications, self).setUp() - # fake cluster - self.fake_cdmc = faker_cluster_state.FakerModelCollector() - - def test_legacy_instance_created_end(self): - compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes() - self.fake_cdmc.cluster_data_model = compute_model - handler = novanotification.LegacyInstanceCreatedEnd(self.fake_cdmc) - - instance0_uuid = 'c03c0bf9-f46e-4e4f-93f1-817568567ee2' - self.assertRaises( - exception.InstanceNotFound, - compute_model.get_instance_by_uuid, instance0_uuid) - - message = self.load_message( - 'scenario3_legacy_instance-create-end.json') - - handler.info( - ctxt=self.context, - publisher_id=message['publisher_id'], - event_type=message['event_type'], - payload=message['payload'], - metadata=self.FAKE_METADATA, - ) - - instance0 = compute_model.get_instance_by_uuid(instance0_uuid) - - self.assertEqual(element.InstanceState.ACTIVE.value, instance0.state) - self.assertEqual(1, instance0.vcpus) - self.assertEqual(1, instance0.disk_capacity) - self.assertEqual(512, instance0.memory) - - def test_legacy_instance_updated(self): - compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes() - self.fake_cdmc.cluster_data_model = compute_model - handler = novanotification.LegacyInstanceUpdated(self.fake_cdmc) - - instance0_uuid = '73b09e16-35b7-4922-804e-e8f5d9b740fc' - instance0 = compute_model.get_instance_by_uuid(instance0_uuid) - - message = self.load_message('scenario3_legacy_instance-update.json') - - self.assertEqual(element.InstanceState.ACTIVE.value, instance0.state) - - handler.info( - ctxt=self.context, - publisher_id=message['publisher_id'], - event_type=message['event_type'], - payload=message['payload'], - metadata=self.FAKE_METADATA, - ) - - self.assertEqual(element.InstanceState.PAUSED.value, instance0.state) - - @mock.patch.object(nova_helper, "NovaHelper") - def test_legacy_instance_update_node_notfound_still_creates( - self, m_nova_helper_cls): - m_get_compute_node_by_hostname = mock.Mock( - side_effect=lambda uuid: mock.Mock( - name='m_get_compute_node_by_hostname', - id=3, - uuid=uuid, - hypervisor_hostname="Node_2", - state='up', - status='enabled', - memory_mb=7777, - vcpus=42, - free_disk_gb=974, - local_gb=1337)) - m_nova_helper_cls.return_value = mock.Mock( - get_compute_node_by_hostname=m_get_compute_node_by_hostname, - name='m_nova_helper') - - compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes() - self.fake_cdmc.cluster_data_model = compute_model - handler = novanotification.LegacyInstanceUpdated(self.fake_cdmc) - - instance0_uuid = '9966d6bd-a45c-4e1c-9d57-3054899a3ec7' - - message = self.load_message( - 'scenario3_notfound_legacy_instance-update.json') - - handler.info( - ctxt=self.context, - publisher_id=message['publisher_id'], - event_type=message['event_type'], - payload=message['payload'], - metadata=self.FAKE_METADATA, - ) - - instance0 = compute_model.get_instance_by_uuid(instance0_uuid) - - self.assertEqual(element.InstanceState.PAUSED.value, instance0.state) - self.assertEqual(1, instance0.vcpus) - self.assertEqual(1, instance0.disk) - self.assertEqual(1, instance0.disk_capacity) - self.assertEqual(512, instance0.memory) - - m_get_compute_node_by_hostname.assert_any_call('Node_2') - node_2 = compute_model.get_node_by_uuid('Node_2') - self.assertEqual(7777, node_2.memory) - self.assertEqual(42, node_2.vcpus) - self.assertEqual(974, node_2.disk) - self.assertEqual(1337, node_2.disk_capacity) - - @mock.patch.object(nova_helper, "NovaHelper") - def test_legacy_instance_update_node_notfound_set_unmapped( - self, m_nova_helper_cls): - m_get_compute_node_by_hostname = mock.Mock( - side_effect=exception.ComputeNodeNotFound) - m_nova_helper_cls.return_value = mock.Mock( - get_compute_node_by_hostname=m_get_compute_node_by_hostname, - name='m_nova_helper') - - compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes() - self.fake_cdmc.cluster_data_model = compute_model - handler = novanotification.LegacyInstanceUpdated(self.fake_cdmc) - - instance0_uuid = '9966d6bd-a45c-4e1c-9d57-3054899a3ec7' - - message = self.load_message( - 'scenario3_notfound_legacy_instance-update.json') - - handler.info( - ctxt=self.context, - publisher_id=message['publisher_id'], - event_type=message['event_type'], - payload=message['payload'], - metadata=self.FAKE_METADATA, - ) - - instance0 = compute_model.get_instance_by_uuid(instance0_uuid) - - self.assertEqual(element.InstanceState.PAUSED.value, instance0.state) - self.assertEqual(1, instance0.vcpus) - self.assertEqual(1, instance0.disk) - self.assertEqual(1, instance0.disk_capacity) - self.assertEqual(512, instance0.memory) - - m_get_compute_node_by_hostname.assert_any_call('Node_2') - self.assertRaises( - exception.ComputeNodeNotFound, - compute_model.get_node_by_uuid, 'Node_2') - - def test_legacy_live_migrated_end(self): - compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes() - self.fake_cdmc.cluster_data_model = compute_model - handler = novanotification.LegacyLiveMigratedEnd(self.fake_cdmc) - - instance0_uuid = '73b09e16-35b7-4922-804e-e8f5d9b740fc' - instance0 = compute_model.get_instance_by_uuid(instance0_uuid) - - node = compute_model.get_node_by_instance_uuid(instance0_uuid) - self.assertEqual('Node_0', node.uuid) - - message = self.load_message( - 'scenario3_legacy_livemigration-post-dest-end.json') - handler.info( - ctxt=self.context, - publisher_id=message['publisher_id'], - event_type=message['event_type'], - payload=message['payload'], - metadata=self.FAKE_METADATA, - ) - node = compute_model.get_node_by_instance_uuid(instance0_uuid) - self.assertEqual('Node_1', node.uuid) - self.assertEqual(element.InstanceState.ACTIVE.value, instance0.state) - - def test_legacy_instance_deleted_end(self): - compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes() - self.fake_cdmc.cluster_data_model = compute_model - handler = novanotification.LegacyInstanceDeletedEnd(self.fake_cdmc) - - instance0_uuid = '73b09e16-35b7-4922-804e-e8f5d9b740fc' - - # Before - self.assertTrue(compute_model.get_instance_by_uuid(instance0_uuid)) - - message = self.load_message( - 'scenario3_legacy_instance-delete-end.json') - handler.info( - ctxt=self.context, - publisher_id=message['publisher_id'], - event_type=message['event_type'], - payload=message['payload'], - metadata=self.FAKE_METADATA, - ) - - # After - self.assertRaises( - exception.InstanceNotFound, - compute_model.get_instance_by_uuid, instance0_uuid) - - def test_legacy_instance_resize_confirm_end(self): - compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes() - self.fake_cdmc.cluster_data_model = compute_model - handler = novanotification.LegacyLiveMigratedEnd(self.fake_cdmc) - - instance0_uuid = '73b09e16-35b7-4922-804e-e8f5d9b740fc' - instance0 = compute_model.get_instance_by_uuid(instance0_uuid) - - node = compute_model.get_node_by_instance_uuid(instance0_uuid) - self.assertEqual('Node_0', node.uuid) - - message = self.load_message( - 'scenario3_legacy_instance-resize-confirm-end.json') - handler.info( - ctxt=self.context, - publisher_id=message['publisher_id'], - event_type=message['event_type'], - payload=message['payload'], - metadata=self.FAKE_METADATA, - ) - node = compute_model.get_node_by_instance_uuid(instance0_uuid) - self.assertEqual('Node_1', node.uuid) - self.assertEqual(element.InstanceState.ACTIVE.value, instance0.state) - - def test_legacy_instance_rebuild_end(self): - compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes() - self.fake_cdmc.cluster_data_model = compute_model - handler = novanotification.LegacyLiveMigratedEnd(self.fake_cdmc) - - instance0_uuid = '73b09e16-35b7-4922-804e-e8f5d9b740fc' - instance0 = compute_model.get_instance_by_uuid(instance0_uuid) - - node = compute_model.get_node_by_instance_uuid(instance0_uuid) - self.assertEqual('Node_0', node.uuid) - - message = self.load_message( - 'scenario3_legacy_instance-rebuild-end.json') - handler.info( - ctxt=self.context, - publisher_id=message['publisher_id'], - event_type=message['event_type'], - payload=message['payload'], - metadata=self.FAKE_METADATA, - ) - node = compute_model.get_node_by_instance_uuid(instance0_uuid) - self.assertEqual('Node_1', node.uuid) - self.assertEqual(element.InstanceState.ACTIVE.value, instance0.state)