diff --git a/heat/engine/api.py b/heat/engine/api.py index 8b7c77a802..9204a3d31e 100644 --- a/heat/engine/api.py +++ b/heat/engine/api.py @@ -410,6 +410,8 @@ def format_notification_body(stack): state = '_'.join(stack.state) else: state = 'Unknown' + + updated_at = stack.updated_time and stack.updated_time.isoformat() result = { rpc_api.NOTIFY_TENANT_ID: stack.context.tenant_id, rpc_api.NOTIFY_USER_ID: stack.context.username, @@ -422,6 +424,9 @@ def format_notification_body(stack): rpc_api.NOTIFY_STATE: state, rpc_api.NOTIFY_STATE_REASON: stack.status_reason, rpc_api.NOTIFY_CREATE_AT: stack.created_time.isoformat(), + rpc_api.NOTIFY_DESCRIPTION: stack.t[stack.t.DESCRIPTION], + rpc_api.NOTIFY_TAGS: stack.tags, + rpc_api.NOTIFY_UPDATE_AT: updated_at } return result diff --git a/heat/rpc/api.py b/heat/rpc/api.py index 760209dec3..c503fff188 100644 --- a/heat/rpc/api.py +++ b/heat/rpc/api.py @@ -109,6 +109,9 @@ NOTIFY_KEYS = ( NOTIFY_STATE, NOTIFY_STATE_REASON, NOTIFY_CREATE_AT, + NOTIFY_DESCRIPTION, + NOTIFY_UPDATE_AT, + NOTIFY_TAGS, ) = ( 'tenant_id', 'user_id', @@ -119,6 +122,9 @@ NOTIFY_KEYS = ( 'state', 'state_reason', 'create_at', + STACK_DESCRIPTION, + 'updated_at', + STACK_TAGS, ) # This is the representation of a watch we expose to the API via RPC diff --git a/heat/tests/test_notifications.py b/heat/tests/test_notifications.py index 79c5d7b760..a2f68a46f2 100644 --- a/heat/tests/test_notifications.py +++ b/heat/tests/test_notifications.py @@ -36,7 +36,12 @@ class StackTest(common.HeatTestCase): st.created_time = created_time st.context = self.ctx st.id = 'hay-are-en' - + updated_time = timeutils.utcnow() + st.updated_time = updated_time + st.tags = ['tag1', 'tag2'] + st.t = mock.MagicMock() + st.t.__getitem__.return_value = 'for test' + st.t.DESCRIPTION = 'description' notify = self.patchobject(notification, 'notify') notification.stack.send(st) @@ -50,7 +55,10 @@ class StackTest(common.HeatTestCase): 'stack_name': 'fred', 'tenant_id': 'test_tenant_id', 'create_at': created_time.isoformat(), - 'state': 'x_f'}) + 'state': 'x_f', + 'description': 'for test', + 'tags': ['tag1', 'tag2'], + 'updated_at': updated_time.isoformat()}) class AutoScaleTest(common.HeatTestCase): @@ -58,7 +66,8 @@ class AutoScaleTest(common.HeatTestCase): super(AutoScaleTest, self).setUp() self.ctx = utils.dummy_context(user_id='test_user_id') - def test_send(self): + def _mock_stack(self): + created_time = timeutils.utcnow() st = mock.Mock() st.state = ('x', 'f') @@ -69,10 +78,20 @@ class AutoScaleTest(common.HeatTestCase): st.created_time = created_time st.context = self.ctx st.id = 'hay-are-en' + updated_time = timeutils.utcnow() + st.updated_time = updated_time + st.tags = ['tag1', 'tag2'] + st.t = mock.MagicMock() + st.t.__getitem__.return_value = 'for test' + st.t.DESCRIPTION = 'description' + return st + + def test_send(self): + stack = self._mock_stack() notify = self.patchobject(notification, 'notify') - notification.autoscaling.send(st, adjustment='x', + notification.autoscaling.send(stack, adjustment='x', adjustment_type='y', capacity='5', groupname='c', @@ -87,26 +106,19 @@ class AutoScaleTest(common.HeatTestCase): 'stack_identity': 'hay-are-en', 'stack_name': 'fred', 'tenant_id': 'test_tenant_id', - 'create_at': created_time.isoformat(), + 'create_at': stack.created_time.isoformat(), + 'description': 'for test', + 'tags': ['tag1', 'tag2'], + 'updated_at': stack.updated_time.isoformat(), 'state': 'x_f', 'adjustment_type': 'y', 'groupname': 'c', 'capacity': '5', 'message': 'fred', 'adjustment': 'x'}) def test_send_error(self): - created_time = timeutils.utcnow() - st = mock.Mock() - st.state = ('x', 'f') - st.status = st.state[0] - st.action = st.state[1] - st.name = 'fred' - st.status_reason = 'this is why' - st.created_time = created_time - st.context = self.ctx - st.id = 'hay-are-en' - + stack = self._mock_stack() notify = self.patchobject(notification, 'notify') - notification.autoscaling.send(st, adjustment='x', + notification.autoscaling.send(stack, adjustment='x', adjustment_type='y', capacity='5', groupname='c', @@ -120,7 +132,10 @@ class AutoScaleTest(common.HeatTestCase): 'stack_identity': 'hay-are-en', 'stack_name': 'fred', 'tenant_id': 'test_tenant_id', - 'create_at': created_time.isoformat(), + 'create_at': stack.created_time.isoformat(), + 'description': 'for test', + 'tags': ['tag1', 'tag2'], + 'updated_at': stack.updated_time.isoformat(), 'state': 'x_f', 'adjustment_type': 'y', 'groupname': 'c', 'capacity': '5', 'message': 'error', 'adjustment': 'x'})