Add normalize stack function for heat stack_list

With the stack object the _filter_list
was not able to do the:
e.get('id')
e.get('name')

Also the stack dict don't have the 'name' key,
so need to set name -> stack_name

Unit test add for get_stack and list_stacks function

Change-Id: Ia1f3c949cc01906166175a9dcd3b844bc6947e28
This commit is contained in:
Mathieu Bultel 2016-02-04 14:16:17 -05:00 committed by David Shrewsbury
parent 07a191da8b
commit 1e738dbc91
6 changed files with 21 additions and 8 deletions

View File

@ -461,6 +461,13 @@ def normalize_roles(roles):
return meta.obj_list_to_dict(ret)
def normalize_stacks(stacks):
""" Normalize Stack Object """
for stack in stacks:
stack['name'] = stack['stack_name']
return stacks
def valid_kwargs(*valid_args):
# This decorator checks if argument passed as **kwargs to a function are
# present in valid_args.

View File

@ -1138,7 +1138,7 @@ class OpenStackCloud(object):
"""
with _utils.shade_exceptions("Error fetching stack list"):
stacks = self.manager.submitTask(_tasks.StackList())
return stacks
return _utils.normalize_stacks(stacks)
def list_server_security_groups(self, server):
"""List all security groups associated with the given server.

View File

@ -81,7 +81,8 @@ class Task(object):
# NOTE(Shrews): Since the client API might decide to subclass one
# of these result types, we use isinstance() here instead of type().
if isinstance(self._result, list):
if (isinstance(self._result, list) or
isinstance(self._result, types.GeneratorType)):
return meta.obj_list_to_dict(self._result)
elif (not isinstance(self._result, bool) and
not isinstance(self._result, int) and

View File

@ -224,6 +224,7 @@ class FakeHypervisor(object):
class FakeStack(object):
def __init__(self, id, name, description=None, status='CREATE_COMPLETE'):
self.id = id
self.name = name
self.stack_name = name
self.stack_description = description
self.stack_status = status

View File

@ -143,3 +143,13 @@ class TestStack(base.TestCase):
)
self.assertEqual(2, mock_get.call_count)
self.assertEqual(stack, ret)
@mock.patch.object(shade.OpenStackCloud, 'heat_client')
def test_get_stack(self, mock_heat):
stack = fakes.FakeStack('azerty', 'stack',)
mock_heat.stacks.list.return_value = [stack]
res = self.cloud.get_stack('stack')
self.assertIsNotNone(res)
self.assertEqual(stack.stack_name, res['stack_name'])
self.assertEqual(stack.stack_name, res['name'])
self.assertEqual(stack.stack_status, res['stack_status'])

View File

@ -13,8 +13,6 @@
# limitations under the License.
import types
from shade import task_manager
from shade.tests.unit import base
@ -73,10 +71,6 @@ class TestTaskManager(base.TestCase):
"""
self.assertRaises(TestException, self.manager.submitTask, TestTask())
def test_dont_munchify_generators(self):
ret = self.manager.submitTask(TestTaskGenerator())
self.assertIsInstance(ret, types.GeneratorType)
def test_dont_munchify_int(self):
ret = self.manager.submitTask(TestTaskInt())
self.assertIsInstance(ret, int)