From ddcdfad9bed42aa0e4486f91efc5893f1da20a8a Mon Sep 17 00:00:00 2001 From: liusheng Date: Wed, 22 Nov 2017 21:27:57 +0800 Subject: [PATCH] Add versioned notifications of rebuild server action This change add the implememtation of versioned notifications of server rebuild action. - Add notification for server.rebuild.end event - Add notification for server.rebuild.error event - Add notification for server.rebuild.start event Change-Id: If168a95dc090f18e6464a03e5ceec9978b2c2df2 --- .../server-rebuild-end.json | 56 ++++++++++++++++ .../server-rebuild-error.json | 66 +++++++++++++++++++ .../server-rebuild-start.json | 56 ++++++++++++++++ mogan/engine/manager.py | 15 ++++- mogan/notifications/objects/server.py | 3 + mogan/objects/fields.py | 3 +- .../unit/notifications/test_notification.py | 2 +- 7 files changed, 197 insertions(+), 4 deletions(-) create mode 100644 doc/notification_samples/server-rebuild-end.json create mode 100644 doc/notification_samples/server-rebuild-error.json create mode 100644 doc/notification_samples/server-rebuild-start.json diff --git a/doc/notification_samples/server-rebuild-end.json b/doc/notification_samples/server-rebuild-end.json new file mode 100644 index 00000000..0597639b --- /dev/null +++ b/doc/notification_samples/server-rebuild-end.json @@ -0,0 +1,56 @@ +{ + "event_type": "server.rebuild.end", + "payload": { + "mogan_object.name": "ServerActionPayload", + "mogan_object.namespace": "mogan", + "mogan_object.version": "1.0", + "mogan_object.data": { + "node": "node-0", + "addresses": [ + { + "mogan_object.name": "ServerAddressesPayload", + "mogan_object.namespace": "mogan", + "mogan_object.version": "1.0", + "mogan_object.data": { + "preserve_on_delete": false, + "network_id": "432c58a4-e616-48f2-a592-069350c8de4d", + "fixed_ips": [ + { + "subnet_id": "de7322f3-52aa-4007-92f7-65a94b42ae95", + "ip_address": "10.0.0.11" + }, + { + "subnet_id": "50a1d493-d9f6-4d2b-bad8-0d7ce40e934a", + "ip_address": "fdc1:111a:e65d:0:f816:3eff:fecf:d3da" + } + ], + "floating_ip": null, + "mac_address": "52:54:00:83:8f:a7", + "port_id": "a9508283-e432-4404-a41f-edb718c60910" + } + } + ], + "availability_zone": null, + "updated_at": "2017-11-22T08:50:34Z", + "image_uuid": "a765954c-92e6-4f3a-ad13-6412be6047b7", + "user_id": "a3efc47b85014843b93e06fa176c8ff1", + "uuid": "0a56733a-dba5-4fdc-8c0b-90ac9b299974", + "affinity_zone": null, + "power_state": "power on", + "flavor_uuid": "abad84a7-d4eb-4cae-9f7c-c39ebab7c55d", + "project_id": "dea7c33a22fd4e96b1b3a0afcbc17586", + "launched_at": "2017-11-22T08:45:56Z", + "metadata": {}, + "status": "active", + "description": null, + "key_name": null, + "partitions": {}, + "name": "test", + "fault": null, + "created_at": "2017-11-22T08:43:36Z", + "locked_by": null + } + }, + "priority": "INFO", + "publisher_id": "mogan-engine:localhost", +} diff --git a/doc/notification_samples/server-rebuild-error.json b/doc/notification_samples/server-rebuild-error.json new file mode 100644 index 00000000..6a3e03a0 --- /dev/null +++ b/doc/notification_samples/server-rebuild-error.json @@ -0,0 +1,66 @@ +{ + "event_type": "server.rebuild.error", + "payload": { + "mogan_object.name": "ServerActionPayload", + "mogan_object.namespace": "mogan", + "mogan_object.version": "1.0", + "mogan_object.data": { + "node": "node-1", + "addresses": [ + { + "mogan_object.name": "ServerAddressesPayload", + "mogan_object.namespace": "mogan", + "mogan_object.version": "1.0", + "mogan_object.data": { + "preserve_on_delete": false, + "network_id": "432c58a4-e616-48f2-a592-069350c8de4d", + "fixed_ips": [ + { + "subnet_id": "de7322f3-52aa-4007-92f7-65a94b42ae95", + "ip_address": "10.0.0.7" + }, + { + "subnet_id": "50a1d493-d9f6-4d2b-bad8-0d7ce40e934a", + "ip_address": "fdc1:111a:e65d:0:f816:3eff:fef9:f1f" + } + ], + "floating_ip": null, + "mac_address": "52:54:00:7b:71:1f", + "port_id": "e50199e8-e0de-4d86-b0ce-175cac119ab7" + } + } + ], + "availability_zone": null, + "updated_at": "2017-11-22T13:17:40Z", + "image_uuid": "a765954c-92e6-4f3a-ad13-6412be6047b7", + "user_id": "a3efc47b85014843b93e06fa176c8ff1", + "uuid": "dbfa5263-891b-41e8-877c-5d92ac85e49e", + "affinity_zone": null, + "power_state": "power on", + "flavor_uuid": "abad84a7-d4eb-4cae-9f7c-c39ebab7c55d", + "project_id": "dea7c33a22fd4e96b1b3a0afcbc17586", + "launched_at": "2017-11-22T13:17:40Z", + "metadata": {}, + "status": "error", + "description": null, + "key_name": null, + "partitions": {}, + "name": "test", + "fault": { + "mogan_object.name": "ExceptionPayload", + "mogan_object.namespace": "mogan", + "mogan_object.version": "1.0", + "mogan_object.data": { + "module_name": "mogan.baremetal.ironic.driver", + "exception": "ServerDeployFailure", + "exception_message": "Failed to request Ironic to rebuild server dbfa5263-891b-41e8-877c-5d92ac85e49e: error (HTTP 500)", + "function_name": "rebuild" + } + }, + "created_at": "2017-11-22T13:15:21Z", + "locked_by": null + } + }, + "priority": "ERROR", + "publisher_id": "mogan-engine:localhost" +} diff --git a/doc/notification_samples/server-rebuild-start.json b/doc/notification_samples/server-rebuild-start.json new file mode 100644 index 00000000..d7673f40 --- /dev/null +++ b/doc/notification_samples/server-rebuild-start.json @@ -0,0 +1,56 @@ +{ + "event_type": "server.rebuild.start", + "payload": { + "mogan_object.name": "ServerActionPayload", + "mogan_object.namespace": "mogan", + "mogan_object.version": "1.0", + "mogan_object.data": { + "node": "node-0", + "addresses": [ + { + "mogan_object.name": "ServerAddressesPayload", + "mogan_object.namespace": "mogan", + "mogan_object.version": "1.0", + "mogan_object.data": { + "preserve_on_delete": false, + "network_id": "432c58a4-e616-48f2-a592-069350c8de4d", + "fixed_ips": [ + { + "subnet_id": "de7322f3-52aa-4007-92f7-65a94b42ae95", + "ip_address": "10.0.0.11" + }, + { + "subnet_id": "50a1d493-d9f6-4d2b-bad8-0d7ce40e934a", + "ip_address": "fdc1:111a:e65d:0:f816:3eff:fecf:d3da" + } + ], + "floating_ip": null, + "mac_address": "52:54:00:83:8f:a7", + "port_id": "a9508283-e432-4404-a41f-edb718c60910" + } + } + ], + "availability_zone": null, + "updated_at": "2017-11-22T08:45:56Z", + "image_uuid": "a765954c-92e6-4f3a-ad13-6412be6047b7", + "user_id": "a3efc47b85014843b93e06fa176c8ff1", + "uuid": "0a56733a-dba5-4fdc-8c0b-90ac9b299974", + "affinity_zone": null, + "power_state": "power on", + "flavor_uuid": "abad84a7-d4eb-4cae-9f7c-c39ebab7c55d", + "project_id": "dea7c33a22fd4e96b1b3a0afcbc17586", + "launched_at": "2017-11-22T08:45:56Z", + "metadata": {}, + "status": "rebuilding", + "description": null, + "key_name": null, + "partitions": {}, + "name": "test", + "fault": null, + "created_at": "2017-11-22T08:43:36Z", + "locked_by": null + } + }, + "priority": "INFO", + "publisher_id": "mogan-engine:localhost" +} diff --git a/mogan/engine/manager.py b/mogan/engine/manager.py index 5d9d03b0..047f5b67 100644 --- a/mogan/engine/manager.py +++ b/mogan/engine/manager.py @@ -540,8 +540,6 @@ class EngineManager(base_manager.BaseEngineManager): def _rebuild_server(self, context, server, preserve_ephemeral): """Perform rebuild action on the specified server.""" - # TODO(zhenguo): Add rebuild notification - self.driver.rebuild(context, server, preserve_ephemeral) @wrap_server_fault @@ -554,6 +552,11 @@ class EngineManager(base_manager.BaseEngineManager): """ LOG.debug('Rebuilding server: %s', server) + notifications.notify_about_server_action( + context, server, self.host, + action=fields.NotificationAction.REBUILD, + phase=fields.NotificationPhase.START) + fsm = utils.get_state_machine(start_state=server.status) try: @@ -565,7 +568,15 @@ class EngineManager(base_manager.BaseEngineManager): "Exception: %(exception)s", {"uuid": server.uuid, "exception": e}) + notifications.notify_about_server_action( + context, server, self.host, + action=fields.NotificationAction.REBUILD, + phase=fields.NotificationPhase.ERROR, exception=e) utils.process_event(fsm, server, event='done') + notifications.notify_about_server_action( + context, server, self.host, + action=fields.NotificationAction.REBUILD, + phase=fields.NotificationPhase.END) LOG.info('Server was successfully rebuilt') def get_serial_console(self, context, server, console_type): diff --git a/mogan/notifications/objects/server.py b/mogan/notifications/objects/server.py index 6b41dc86..f033c34c 100644 --- a/mogan/notifications/objects/server.py +++ b/mogan/notifications/objects/server.py @@ -128,6 +128,9 @@ class ServerActionPayload(ServerPayload): @base.notification_sample('server-create-error.json') @base.notification_sample('server-delete-start.json') @base.notification_sample('server-delete-end.json') +@base.notification_sample('server-rebuild-start.json') +@base.notification_sample('server-rebuild-end.json') +@base.notification_sample('server-rebuild-error.json') @mogan_base.MoganObjectRegistry.register_notification class ServerActionNotification(base.NotificationBase): # Version 1.0: Initial version diff --git a/mogan/objects/fields.py b/mogan/objects/fields.py index accb101a..e86fdf66 100644 --- a/mogan/objects/fields.py +++ b/mogan/objects/fields.py @@ -150,8 +150,9 @@ class NotificationAction(BaseMoganEnum): SOFT_REBOOT = 'soft_reboot' SHUTDOWN = 'shutdown' CREATE = 'create' + REBUILD = 'rebuild' - ALL = (UPDATE, EXCEPTION, DELETE, CREATE, POWER_OFF) + ALL = (UPDATE, EXCEPTION, DELETE, CREATE, POWER_OFF, REBUILD) class NotificationPhaseField(object_fields.BaseEnumField): diff --git a/mogan/tests/unit/notifications/test_notification.py b/mogan/tests/unit/notifications/test_notification.py index 5b422160..466a6d98 100644 --- a/mogan/tests/unit/notifications/test_notification.py +++ b/mogan/tests/unit/notifications/test_notification.py @@ -231,7 +231,7 @@ notification_object_data = { 'ServerActionPayload': '1.0-8dc4429afa34d86ab92c9387e3ccd0c3', 'ServerActionNotification': '1.0-20087e599436bd9db62ae1fb5e2dfef2', 'ExceptionPayload': '1.0-7c31986d8d78bed910c324965c431e18', - 'EventType': '1.0-93493dd78bdfed806fca70c91d85cbb4', + 'EventType': '1.0-589894aac7c98fb640eca394f67ad621', 'NotificationPublisher': '1.0-4b0b0d662b21eeed0b23617f3f11794b' }