deb-heat/heat/tests/test_notifications.py
kairat_kushaev d8c41029b4 Reduce size of stack_identity in heat notifications
Reduce "stack_identity" field in heat notifications because
it is too long for other consumers (at least for ceilometer).
So UUID of the stack will be used as stack identity instead
of arn in heat notifications.
NOTE: stack statistics for existing stacks will not be 
considered in ceilometer because we changed stack identity
and ceilometer recognize stacks with UUIDs as 
"new" resources. I consulted with gordonchung about this 
and it seems that it is not critical for ceilometer.

Closes-bug: #1468916
Change-Id: I74d192b8076c344dceab5754681c129a9e0fcd22
2015-06-29 13:14:50 +00:00

121 lines
4.2 KiB
Python

#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo_utils import timeutils
from heat.engine import notification
from heat.tests import common
from heat.tests import utils
class StackTest(common.HeatTestCase):
def setUp(self):
super(StackTest, self).setUp()
self.ctx = utils.dummy_context()
def test_send(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'
notify = self.patchobject(notification, 'notify')
notification.stack.send(st)
notify.assert_called_once_with(
self.ctx, 'stack.f.error', 'ERROR',
{'state_reason': 'this is why',
'user_id': 'test_username',
'stack_identity': 'hay-are-en',
'stack_name': 'fred',
'tenant_id': 'test_tenant_id',
'create_at': created_time.isoformat(),
'state': 'x_f'})
class AutoScaleTest(common.HeatTestCase):
def setUp(self):
super(AutoScaleTest, self).setUp()
self.ctx = utils.dummy_context()
def test_send(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'
notify = self.patchobject(notification, 'notify')
notification.autoscaling.send(st, adjustment='x',
adjustment_type='y',
capacity='5',
groupname='c',
message='fred',
suffix='the-end')
notify.assert_called_once_with(
self.ctx, 'autoscaling.the-end', 'INFO',
{'state_reason': 'this is why',
'user_id': 'test_username',
'stack_identity': 'hay-are-en',
'stack_name': 'fred',
'tenant_id': 'test_tenant_id',
'create_at': created_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'
notify = self.patchobject(notification, 'notify')
notification.autoscaling.send(st, adjustment='x',
adjustment_type='y',
capacity='5',
groupname='c',
suffix='error')
notify.assert_called_once_with(
self.ctx, 'autoscaling.error', 'ERROR',
{'state_reason': 'this is why',
'user_id': 'test_username',
'stack_identity': 'hay-are-en',
'stack_name': 'fred',
'tenant_id': 'test_tenant_id',
'create_at': created_time.isoformat(),
'state': 'x_f', 'adjustment_type': 'y',
'groupname': 'c', 'capacity': '5',
'message': 'error', 'adjustment': 'x'})