diff --git a/openstack/instance_ha/v1/notification.py b/openstack/instance_ha/v1/notification.py index 4cf538861..42dabe6ee 100644 --- a/openstack/instance_ha/v1/notification.py +++ b/openstack/instance_ha/v1/notification.py @@ -15,6 +15,27 @@ from openstack import resource +class ProgressDetailsItem(resource.Resource): + #: The timestamp of recovery workflow task. + timestamp = resource.Body("timestamp") + #: The message of recovery workflow task. + message = resource.Body("message") + #: The progress of recovery workflow task. + progress = resource.Body("progress") + + +class RecoveryWorkflowDetailItem(resource.Resource): + #: The progress of recovery workflow. + progress = resource.Body("progress") + #: The name of recovery workflow. + name = resource.Body("name") + #: The state of recovery workflow. + state = resource.Body("state") + #: The progress details of this recovery workflow. + progress_details = resource.Body( + "progress_details", type=list, list_type=ProgressDetailsItem) + + class Notification(resource.Resource): resource_key = "notification" resources_key = "notifications" @@ -56,6 +77,10 @@ class Notification(resource.Resource): payload = resource.Body("payload") #: The source host uuid of this notification. source_host_uuid = resource.Body("source_host_uuid") + #: The recovery workflow details of this notification. + recovery_workflow_details = resource.Body( + "recovery_workflow_details", + type=list, list_type=RecoveryWorkflowDetailItem) _query_mapping = resource.QueryParameters( "sort_key", "sort_dir", source_host_uuid="source_host_uuid", diff --git a/openstack/tests/unit/instance_ha/v1/test_notification.py b/openstack/tests/unit/instance_ha/v1/test_notification.py index c5e94a03f..d4fb269d4 100644 --- a/openstack/tests/unit/instance_ha/v1/test_notification.py +++ b/openstack/tests/unit/instance_ha/v1/test_notification.py @@ -23,6 +23,16 @@ PAYLOAD = { "vir_domain_event": "STOPPED_FAILED", "event": "LIFECYCLE" } + +PROGRESS_DETAILS = [{"timestamp": "2019-02-28 07:21:33.291810", + "progress": 1.0, + "message": "Skipping recovery for process " + "nova-compute as it is already disabled"}] + +RECOVERY_WORKFLOW_DETAILS = [{"progress": 1.0, "state": "SUCCESS", + "name": "DisableComputeNodeTask", + "progress_details": PROGRESS_DETAILS}] + NOTIFICATION = { "id": FAKE_ID, "notification_uuid": FAKE_UUID, @@ -33,7 +43,8 @@ NOTIFICATION = { "status": "new", "generated_time": "2018-03-21T00:00:00.000000", "payload": PAYLOAD, - "source_host_uuid": FAKE_HOST_UUID + "source_host_uuid": FAKE_HOST_UUID, + "recovery_workflow_details": RECOVERY_WORKFLOW_DETAILS } @@ -62,6 +73,7 @@ class TestNotification(base.TestCase): def test_create(self): sot = notification.Notification(**NOTIFICATION) + rec_workflow_details = NOTIFICATION["recovery_workflow_details"][0] self.assertEqual(NOTIFICATION["id"], sot.id) self.assertEqual( NOTIFICATION["notification_uuid"], sot.notification_uuid) @@ -74,3 +86,26 @@ class TestNotification(base.TestCase): self.assertEqual(NOTIFICATION["payload"], sot.payload) self.assertEqual( NOTIFICATION["source_host_uuid"], sot.source_host_uuid) + self.assertEqual(rec_workflow_details["name"], + sot.recovery_workflow_details[0].name) + self.assertEqual(rec_workflow_details["state"], + sot.recovery_workflow_details[0].state) + self.assertEqual(rec_workflow_details["progress"], + sot.recovery_workflow_details[0].progress) + self.assertEqual( + rec_workflow_details["progress_details"][0]['progress'], + sot.recovery_workflow_details[0].progress_details[0].progress) + self.assertEqual( + rec_workflow_details["progress_details"][0]['message'], + sot.recovery_workflow_details[0].progress_details[0].message) + self.assertEqual( + rec_workflow_details["progress_details"][0]['timestamp'], + sot.recovery_workflow_details[0].progress_details[0].timestamp) + self.assertIsInstance(sot.recovery_workflow_details, list) + self.assertIsInstance( + sot.recovery_workflow_details[0].progress_details, list) + self.assertIsInstance(sot.recovery_workflow_details[0], + notification.RecoveryWorkflowDetailItem) + self.assertIsInstance( + sot.recovery_workflow_details[0].progress_details[0], + notification.ProgressDetailsItem) diff --git a/releasenotes/notes/add-new-field-progress-details-in-notification-resource-f7871acb6ffd46dc.yaml b/releasenotes/notes/add-new-field-progress-details-in-notification-resource-f7871acb6ffd46dc.yaml new file mode 100644 index 000000000..f0470b45d --- /dev/null +++ b/releasenotes/notes/add-new-field-progress-details-in-notification-resource-f7871acb6ffd46dc.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + In microversion 1.1, Masakari returns ``recovery_workflow_details`` information + of the notification in ``GET /notifications/{notification_id}`` API. Added + ``recovery_workflow_details`` attribute to Notification class to read the + recovery_workflow_details of the notification.