Merge "Get rid of normalization in orchestration CL" into feature/r1

This commit is contained in:
Zuul 2021-12-31 12:47:49 +00:00 committed by Gerrit Code Review
commit e720330455
2 changed files with 18 additions and 29 deletions

View File

@ -15,7 +15,6 @@
# openstack.resource.Resource.list and openstack.resource2.Resource.list
import types # noqa
from openstack.cloud import _normalize
from openstack.cloud import _utils
from openstack.cloud import exc
from openstack.orchestration.util import event_utils
@ -30,7 +29,7 @@ def _no_pending_stacks(stacks):
return True
class OrchestrationCloudMixin(_normalize.Normalizer):
class OrchestrationCloudMixin:
@property
def _orchestration_client(self):
@ -213,13 +212,13 @@ class OrchestrationCloudMixin(_normalize.Normalizer):
"""List all stacks.
:param dict query: Query parameters to limit stacks.
:returns: a list of ``munch.Munch`` containing the stack description.
:returns: a list of :class:`openstack.orchestration.v1.stack.Stack`
objects containing the stack description.
:raises: ``OpenStackCloudException`` if something goes wrong during the
OpenStack API call.
"""
data = self.orchestration.stacks(**query)
return self._normalize_stacks(data)
return list(self.orchestration.stacks(**query))
def get_stack(self, name_or_id, filters=None, resolve_outputs=True):
"""Get exactly one stack.
@ -230,7 +229,8 @@ class OrchestrationCloudMixin(_normalize.Normalizer):
:param resolve_outputs: If True, then outputs for this
stack will be resolved
:returns: a ``munch.Munch`` containing the stack description
:returns: a :class:`openstack.orchestration.v1.stack.Stack`
containing the stack description
:raises: ``OpenStackCloudException`` if something goes wrong during the
OpenStack API call or if multiple matches are found.
@ -248,7 +248,6 @@ class OrchestrationCloudMixin(_normalize.Normalizer):
return []
except exc.OpenStackCloudURINotFound:
return []
stack = self._normalize_stack(stack)
return _utils._filter_list([stack], name_or_id, filters)
return _utils._get_entity(

View File

@ -29,6 +29,11 @@ class TestStack(base.TestCase):
self.stack_tag = self.getUniqueString('tag')
self.stack = fakes.make_fake_stack(self.stack_id, self.stack_name)
def _compare_stacks(self, exp, real):
self.assertDictEqual(
stack.Stack(**exp).to_dict(computed=False),
real.to_dict(computed=False))
def test_list_stacks(self):
fake_stacks = [
self.stack,
@ -43,10 +48,7 @@ class TestStack(base.TestCase):
json={"stacks": fake_stacks}),
])
stacks = self.cloud.list_stacks()
self.assertEqual(
[f.toDict() for f in self.cloud._normalize_stacks(
stack.Stack(**st) for st in fake_stacks)],
[f.toDict() for f in stacks])
[self._compare_stacks(b, a) for a, b in zip(stacks, fake_stacks)]
self.assert_calls()
@ -67,10 +69,7 @@ class TestStack(base.TestCase):
json={"stacks": fake_stacks}),
])
stacks = self.cloud.list_stacks(name='a', status='b')
self.assertEqual(
[f.toDict() for f in self.cloud._normalize_stacks(
stack.Stack(**st) for st in fake_stacks)],
[f.toDict() for f in stacks])
[self._compare_stacks(b, a) for a, b in zip(stacks, fake_stacks)]
self.assert_calls()
@ -100,10 +99,7 @@ class TestStack(base.TestCase):
json={"stacks": fake_stacks}),
])
stacks = self.cloud.search_stacks()
self.assertEqual(
self.cloud._normalize_stacks(
stack.Stack(**st) for st in fake_stacks),
stacks)
[self._compare_stacks(b, a) for a, b in zip(stacks, fake_stacks)]
self.assert_calls()
def test_search_stacks_filters(self):
@ -122,10 +118,7 @@ class TestStack(base.TestCase):
])
filters = {'status': 'FAILED'}
stacks = self.cloud.search_stacks(filters=filters)
self.assertEqual(
self.cloud._normalize_stacks(
stack.Stack(**st) for st in fake_stacks[1:]),
stacks)
[self._compare_stacks(b, a) for a, b in zip(stacks, fake_stacks)]
self.assert_calls()
def test_search_stacks_exception(self):
@ -618,10 +611,9 @@ class TestStack(base.TestCase):
res = self.cloud.get_stack(self.stack_name)
self.assertIsNotNone(res)
self.assertEqual(self.stack['stack_name'], res['stack_name'])
self.assertEqual(self.stack['stack_name'], res['name'])
self.assertEqual(self.stack['stack_status'], res['stack_status'])
self.assertEqual('COMPLETE', res['status'])
self.assertEqual('CREATE_COMPLETE', res['status'])
self.assert_calls()
@ -647,10 +639,8 @@ class TestStack(base.TestCase):
res = self.cloud.get_stack(self.stack_name)
self.assertIsNotNone(res)
self.assertEqual(in_progress['stack_name'], res['stack_name'])
self.assertEqual(in_progress['stack_name'], res['name'])
self.assertEqual(in_progress['stack_name'], res.name)
self.assertEqual(in_progress['stack_status'], res['stack_status'])
self.assertEqual('CREATE', res['action'])
self.assertEqual('IN_PROGRESS', res['status'])
self.assertEqual('CREATE_IN_PROGRESS', res['status'])
self.assert_calls()