Merge "Omit rsrc prop data in rpc api for multiple events"

This commit is contained in:
Jenkins 2017-03-03 16:36:45 +00:00 committed by Gerrit Code Review
commit 164264be08
5 changed files with 36 additions and 34 deletions

View File

@ -378,7 +378,8 @@ def format_stack_preview(stack):
return fmt_stack
def format_event(event, stack_identifier, root_stack_identifier=None):
def format_event(event, stack_identifier, root_stack_identifier=None,
include_rsrc_prop_data=True):
result = {
rpc_api.EVENT_ID: dict(event.identifier(stack_identifier)),
rpc_api.EVENT_STACK_ID: dict(stack_identifier),
@ -390,10 +391,11 @@ def format_event(event, stack_identifier, root_stack_identifier=None):
rpc_api.EVENT_RES_STATUS: event.resource_status,
rpc_api.EVENT_RES_STATUS_DATA: event.resource_status_reason,
rpc_api.EVENT_RES_TYPE: event.resource_type,
rpc_api.EVENT_RES_PROPERTIES: event.resource_properties,
}
if root_stack_identifier:
result[rpc_api.EVENT_ROOT_STACK_ID] = dict(root_stack_identifier)
if include_rsrc_prop_data:
result[rpc_api.EVENT_RES_PROPERTIES] = event.resource_properties
return result

View File

@ -1763,8 +1763,12 @@ class EngineService(service.ServiceBase):
show_nested=True)
stack_identifiers = {s.id: s.identifier() for s in stacks}
# a 'uuid' in filters indicates we are showing a full event, i.e.
# the only time we need to load the event's rsrc prop data.
include_rsrc_prop_data = (filters and 'uuid' in filters)
return [api.format_event(e, stack_identifiers.get(e.stack_id),
root_stack_identifier) for e in events]
root_stack_identifier, include_rsrc_prop_data)
for e in events]
def _authorize_stack_user(self, cnxt, stack, resource_name):
"""Filter access to describe_stack_resource for in-instance users.

View File

@ -87,7 +87,6 @@ class EventControllerTest(tools.ControllerTest, common.HeatTestCase):
u'resource_action': u'CREATE',
u'resource_status': u'IN_PROGRESS',
u'physical_resource_id': None,
u'resource_properties': {u'UserData': u'blah'},
u'resource_type': u'AWS::EC2::Instance',
}
]
@ -161,7 +160,6 @@ class EventControllerTest(tools.ControllerTest, common.HeatTestCase):
u'resource_action': u'CREATE',
u'resource_status': u'IN_PROGRESS',
u'physical_resource_id': None,
u'resource_properties': {u'UserData': u'blah'},
u'resource_type': u'AWS::EC2::Instance',
}
]
@ -209,7 +207,6 @@ class EventControllerTest(tools.ControllerTest, common.HeatTestCase):
u'resource_action': u'CREATE',
u'resource_status': u'IN_PROGRESS',
u'physical_resource_id': None,
u'resource_properties': {u'UserData': u'blah'},
u'resource_type': u'AWS::EC2::Instance',
}
]
@ -260,7 +257,6 @@ class EventControllerTest(tools.ControllerTest, common.HeatTestCase):
u'resource_action': u'CREATE',
u'resource_status': u'IN_PROGRESS',
u'physical_resource_id': None,
u'resource_properties': {u'UserData': u'blah'},
u'resource_type': u'AWS::EC2::Instance',
}
]
@ -662,7 +658,6 @@ class EventControllerTest(tools.ControllerTest, common.HeatTestCase):
u'resource_action': u'CREATE',
u'resource_status': u'IN_PROGRESS',
u'physical_resource_id': None,
u'resource_properties': {u'UserData': u'blah'},
u'resource_type': u'AWS::EC2::Instance',
}
]

View File

@ -54,17 +54,6 @@ class StackEventTest(common.HeatTestCase):
self.assertIn('physical_resource_id', ev)
self.assertIn('resource_properties', ev)
# Big long user data field.. it mentions 'wordpress'
# a few times so this should work.
if ev.get('resource_properties'):
user_data = ev['resource_properties']['UserData']
self.assertIn('wordpress', user_data)
self.assertEqual('F17-x86_64-gold',
ev['resource_properties']['ImageId'])
self.assertEqual('m1.large',
ev['resource_properties']['InstanceType'])
self.assertEqual('CREATE', ev['resource_action'])
self.assertIn(ev['resource_status'], ('IN_PROGRESS', 'COMPLETE'))
@ -144,7 +133,6 @@ class StackEventTest(common.HeatTestCase):
self.assertIn('resource_name', ev)
self.assertIn('physical_resource_id', ev)
self.assertIn('resource_properties', ev)
self.assertIn('resource_status_reason', ev)
self.assertIn(ev['resource_action'],
@ -186,17 +174,6 @@ class StackEventTest(common.HeatTestCase):
self.assertIn('physical_resource_id', ev)
self.assertIn('resource_properties', ev)
# Big long user data field.. it mentions 'wordpress'
# a few times so this should work.
if ev.get('resource_properties'):
user_data = ev['resource_properties']['UserData']
self.assertIn('wordpress', user_data)
self.assertEqual('F17-x86_64-gold',
ev['resource_properties']['ImageId'])
self.assertEqual('m1.large',
ev['resource_properties']['InstanceType'])
self.assertEqual('CREATE', ev['resource_action'])
self.assertIn(ev['resource_status'], ('IN_PROGRESS', 'COMPLETE'))
@ -224,7 +201,7 @@ class StackEventTest(common.HeatTestCase):
marker = object()
sort_keys = object()
sort_dir = object()
filters = object()
filters = {}
mock_get.return_value = mock.Mock(id=1)
self.eng.list_events(self.ctx, 1, limit=limit, marker=marker,
sort_keys=sort_keys, sort_dir=sort_dir,
@ -241,7 +218,7 @@ class StackEventTest(common.HeatTestCase):
marker = object()
sort_keys = object()
sort_dir = object()
filters = object()
filters = {}
self.eng.list_events(self.ctx, None, limit=limit, marker=marker,
sort_keys=sort_keys, sort_dir=sort_dir,
@ -251,3 +228,26 @@ class StackEventTest(common.HeatTestCase):
marker=marker,
sort_dir=sort_dir,
filters=filters)
@tools.stack_context('service_event_list_single_event')
@mock.patch.object(service.EngineService, '_get_stack')
def test_event_list_single_has_rsrc_prop_data(self, mock_get):
mock_get.return_value = stack_object.Stack.get_by_id(self.ctx,
self.stack.id)
events = self.eng.list_events(self.ctx, self.stack.identifier())
self.assertEqual(4, len(events))
for ev in events:
self.assertNotIn('resource_properties', ev)
event_objs = event_object.Event.get_all_by_stack(
self.ctx,
self.stack.id)
for i in range(2):
event_uuid = event_objs[i]['uuid']
events = self.eng.list_events(self.ctx, self.stack.identifier(),
filters={'uuid': event_uuid})
self.assertEqual(1, len(events))
self.assertIn('resource_properties', events[0])
if i > 0:
self.assertEqual(4, len(events[0]['resource_properties']))

View File

@ -320,7 +320,8 @@ class FormatTest(common.HeatTestCase):
resource._update_stored_properties()
resource.store()
event = self._dummy_event(res_properties=resource._rsrc_prop_data)
formatted = api.format_event(event, self.stack.identifier())
formatted = api.format_event(event, self.stack.identifier(),
include_rsrc_prop_data=True)
self.assertEqual({'k1': 'v1'}, formatted[rpc_api.EVENT_RES_PROPERTIES])
def test_format_event_legacy_prop_data(self):