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
This commit is contained in:
liusheng 2017-11-22 21:27:57 +08:00
parent fce0cb4c25
commit ddcdfad9be
7 changed files with 197 additions and 4 deletions

View File

@ -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",
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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'
}