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:
parent
07a191da8b
commit
1e738dbc91
@ -461,6 +461,13 @@ def normalize_roles(roles):
|
|||||||
return meta.obj_list_to_dict(ret)
|
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):
|
def valid_kwargs(*valid_args):
|
||||||
# This decorator checks if argument passed as **kwargs to a function are
|
# This decorator checks if argument passed as **kwargs to a function are
|
||||||
# present in valid_args.
|
# present in valid_args.
|
||||||
|
@ -1138,7 +1138,7 @@ class OpenStackCloud(object):
|
|||||||
"""
|
"""
|
||||||
with _utils.shade_exceptions("Error fetching stack list"):
|
with _utils.shade_exceptions("Error fetching stack list"):
|
||||||
stacks = self.manager.submitTask(_tasks.StackList())
|
stacks = self.manager.submitTask(_tasks.StackList())
|
||||||
return stacks
|
return _utils.normalize_stacks(stacks)
|
||||||
|
|
||||||
def list_server_security_groups(self, server):
|
def list_server_security_groups(self, server):
|
||||||
"""List all security groups associated with the given server.
|
"""List all security groups associated with the given server.
|
||||||
|
@ -81,7 +81,8 @@ class Task(object):
|
|||||||
|
|
||||||
# NOTE(Shrews): Since the client API might decide to subclass one
|
# NOTE(Shrews): Since the client API might decide to subclass one
|
||||||
# of these result types, we use isinstance() here instead of type().
|
# 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)
|
return meta.obj_list_to_dict(self._result)
|
||||||
elif (not isinstance(self._result, bool) and
|
elif (not isinstance(self._result, bool) and
|
||||||
not isinstance(self._result, int) and
|
not isinstance(self._result, int) and
|
||||||
|
@ -224,6 +224,7 @@ class FakeHypervisor(object):
|
|||||||
class FakeStack(object):
|
class FakeStack(object):
|
||||||
def __init__(self, id, name, description=None, status='CREATE_COMPLETE'):
|
def __init__(self, id, name, description=None, status='CREATE_COMPLETE'):
|
||||||
self.id = id
|
self.id = id
|
||||||
|
self.name = name
|
||||||
self.stack_name = name
|
self.stack_name = name
|
||||||
self.stack_description = description
|
self.stack_description = description
|
||||||
self.stack_status = status
|
self.stack_status = status
|
||||||
|
@ -143,3 +143,13 @@ class TestStack(base.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(2, mock_get.call_count)
|
self.assertEqual(2, mock_get.call_count)
|
||||||
self.assertEqual(stack, ret)
|
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'])
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
import types
|
|
||||||
|
|
||||||
from shade import task_manager
|
from shade import task_manager
|
||||||
from shade.tests.unit import base
|
from shade.tests.unit import base
|
||||||
|
|
||||||
@ -73,10 +71,6 @@ class TestTaskManager(base.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertRaises(TestException, self.manager.submitTask, TestTask())
|
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):
|
def test_dont_munchify_int(self):
|
||||||
ret = self.manager.submitTask(TestTaskInt())
|
ret = self.manager.submitTask(TestTaskInt())
|
||||||
self.assertIsInstance(ret, int)
|
self.assertIsInstance(ret, int)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user