Merge "Add project to unscoped stack list response"
This commit is contained in:
commit
54117fe58a
@ -181,7 +181,8 @@ class StackController(object):
|
|||||||
except AttributeError as exc:
|
except AttributeError as exc:
|
||||||
logger.warning("Old Engine Version: %s" % str(exc))
|
logger.warning("Old Engine Version: %s" % str(exc))
|
||||||
|
|
||||||
return stacks_view.collection(req, stacks=stacks, count=count)
|
return stacks_view.collection(req, stacks=stacks, count=count,
|
||||||
|
tenant_safe=tenant_safe)
|
||||||
|
|
||||||
@util.policy_enforce
|
@util.policy_enforce
|
||||||
def global_index(self, req):
|
def global_index(self, req):
|
||||||
|
@ -31,7 +31,7 @@ basic_keys = (engine_api.STACK_ID,
|
|||||||
engine_api.STACK_UPDATED_TIME)
|
engine_api.STACK_UPDATED_TIME)
|
||||||
|
|
||||||
|
|
||||||
def format_stack(req, stack, keys=None):
|
def format_stack(req, stack, keys=None, tenant_safe=True):
|
||||||
def transform(key, value):
|
def transform(key, value):
|
||||||
if keys and key not in keys:
|
if keys and key not in keys:
|
||||||
return
|
return
|
||||||
@ -39,6 +39,8 @@ def format_stack(req, stack, keys=None):
|
|||||||
if key == engine_api.STACK_ID:
|
if key == engine_api.STACK_ID:
|
||||||
yield ('id', value['stack_id'])
|
yield ('id', value['stack_id'])
|
||||||
yield ('links', [util.make_link(req, value)])
|
yield ('links', [util.make_link(req, value)])
|
||||||
|
if not tenant_safe:
|
||||||
|
yield ('project', value['tenant'])
|
||||||
elif key == engine_api.STACK_ACTION:
|
elif key == engine_api.STACK_ACTION:
|
||||||
return
|
return
|
||||||
elif (key == engine_api.STACK_STATUS and
|
elif (key == engine_api.STACK_STATUS and
|
||||||
@ -57,8 +59,10 @@ def format_stack(req, stack, keys=None):
|
|||||||
transform(k, v) for k, v in stack.items()))
|
transform(k, v) for k, v in stack.items()))
|
||||||
|
|
||||||
|
|
||||||
def collection(req, stacks, count=None):
|
def collection(req, stacks, count=None, tenant_safe=True):
|
||||||
formatted_stacks = [format_stack(req, s, basic_keys) for s in stacks]
|
keys = basic_keys
|
||||||
|
formatted_stacks = [format_stack(req, s, keys, tenant_safe)
|
||||||
|
for s in stacks]
|
||||||
|
|
||||||
result = {'stacks': formatted_stacks}
|
result = {'stacks': formatted_stacks}
|
||||||
links = views_common.get_collection_links(req, formatted_stacks)
|
links = views_common.get_collection_links(req, formatted_stacks)
|
||||||
|
@ -58,6 +58,30 @@ class TestFormatStack(HeatTestCase):
|
|||||||
self.assertIn('links', result)
|
self.assertIn('links', result)
|
||||||
self.assertEqual(['blah'], result['links'])
|
self.assertEqual(['blah'], result['links'])
|
||||||
|
|
||||||
|
@mock.patch.object(stacks_view, 'util', new=mock.Mock())
|
||||||
|
def test_doesnt_add_project_by_default(self):
|
||||||
|
stack = {'stack_identity': {'stack_id': 'foo', 'tenant': 'bar'}}
|
||||||
|
|
||||||
|
result = stacks_view.format_stack(self.request, stack, None)
|
||||||
|
self.assertNotIn('project', result)
|
||||||
|
|
||||||
|
@mock.patch.object(stacks_view, 'util', new=mock.Mock())
|
||||||
|
def test_doesnt_add_project_if_tenant_safe(self):
|
||||||
|
stack = {'stack_identity': {'stack_id': 'foo', 'tenant': 'bar'}}
|
||||||
|
|
||||||
|
result = stacks_view.format_stack(self.request, stack,
|
||||||
|
None, tenant_safe=True)
|
||||||
|
self.assertNotIn('project', result)
|
||||||
|
|
||||||
|
@mock.patch.object(stacks_view, 'util', new=mock.Mock())
|
||||||
|
def test_adds_project_if_not_tenant_safe(self):
|
||||||
|
stack = {'stack_identity': {'stack_id': 'foo', 'tenant': 'bar'}}
|
||||||
|
|
||||||
|
result = stacks_view.format_stack(self.request, stack,
|
||||||
|
None, tenant_safe=False)
|
||||||
|
self.assertIn('project', result)
|
||||||
|
self.assertEqual('bar', result['project'])
|
||||||
|
|
||||||
def test_includes_all_other_keys(self):
|
def test_includes_all_other_keys(self):
|
||||||
stack = {'foo': 'bar'}
|
stack = {'foo': 'bar'}
|
||||||
|
|
||||||
@ -116,7 +140,8 @@ class TestStacksViewBuilder(HeatTestCase):
|
|||||||
stacks_view.collection(self.request, stacks)
|
stacks_view.collection(self.request, stacks)
|
||||||
mock_format_stack.assert_called_once_with(self.request,
|
mock_format_stack.assert_called_once_with(self.request,
|
||||||
self.stack1,
|
self.stack1,
|
||||||
expected_keys)
|
expected_keys,
|
||||||
|
mock.ANY)
|
||||||
|
|
||||||
@mock.patch.object(stacks_view.views_common, 'get_collection_links')
|
@mock.patch.object(stacks_view.views_common, 'get_collection_links')
|
||||||
def test_append_collection_links(self, mock_get_collection_links):
|
def test_append_collection_links(self, mock_get_collection_links):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user