Rely on proxy for compute.flavor cloud layer operations

- stop applying normalization to flavor operations in the cloud layer
- return bare flavor resources
- drop logic for fetching extra_specs in cloud layer (already present in
  proxy)
- use conn.compute.extensions to get extensions
- drop flavor.links attribute as being absoutely useless on the resource

Change-Id: Id6fc34fd1aa7dec37a4886eeef9206cda685f4bb
This commit is contained in:
Artem Goncharov
2021-10-05 14:37:54 +02:00
parent 806a525733
commit 07eb09f631
6 changed files with 48 additions and 39 deletions

View File

@@ -72,13 +72,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
@_utils.cache_on_arguments()
def _nova_extensions(self):
extensions = set()
data = proxy._json_response(
self.compute.get('/extensions'),
error_message="Error fetching extension list for nova")
for extension in self._get_and_munchify('extensions', data):
extensions.add(extension['alias'])
extensions = set([e.alias for e in self.compute.extensions()])
return extensions
def _has_nova_extension(self, extension_name):
@@ -160,13 +154,8 @@ class ComputeCloudMixin(_normalize.Normalizer):
:returns: A list of flavor ``munch.Munch``.
"""
data = self.compute.flavors(details=True)
flavors = []
for flavor in data:
if not flavor.extra_specs and get_extra:
flavor.fetch_extra_specs(self.compute)
flavors.append(flavor._to_munch(original_names=False))
flavors = list(self.compute.flavors(
details=True, get_extra_specs=get_extra))
return flavors
def list_server_security_groups(self, server):
@@ -429,9 +418,9 @@ class ComputeCloudMixin(_normalize.Normalizer):
if not filters:
filters = {}
flavor = self.compute.find_flavor(
name_or_id, get_extra_specs=get_extra, **filters)
if flavor:
return flavor._to_munch(original_names=False)
name_or_id, get_extra_specs=get_extra,
ignore_missing=True, **filters)
return flavor
def get_flavor_by_id(self, id, get_extra=False):
""" Get a flavor by ID
@@ -442,8 +431,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
specs.
:returns: A flavor ``munch.Munch``.
"""
flavor = self.compute.get_flavor(id, get_extra_specs=get_extra)
return flavor._to_munch(original_names=False)
return self.compute.get_flavor(id, get_extra_specs=get_extra)
def get_server_console(self, server, length=None):
"""Get the console log for a server.
@@ -1393,9 +1381,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
if flavorid == 'auto':
attrs['id'] = None
flavor = self.compute.create_flavor(**attrs)
return flavor._to_munch(original_names=False)
return self.compute.create_flavor(**attrs)
def delete_flavor(self, name_or_id):
"""Delete a flavor

View File

@@ -36,11 +36,10 @@ class Flavor(resource.Resource):
_max_microversion = '2.61'
# Properties
#: Links pertaining to this flavor. This is a list of dictionaries,
#: each including keys ``href`` and ``rel``.
links = resource.Body('links')
#: The name of this flavor.
name = resource.Body('name')
name = resource.Body('name', alias='original_name')
#: The name of this flavor when returned by server list/show
original_name = resource.Body('original_name')
#: The description of the flavor.
description = resource.Body('description')
#: Size of the disk this flavor offers. *Type: int*

View File

@@ -745,6 +745,35 @@ class TestCase(base.TestCase):
self.assertEqual(
len(self.calls), len(self.adapter.request_history))
def assertResourceEqual(self, actual, expected, resource_type):
"""Helper for the assertEqual which compares Resource object against
dictionary representing expected state.
:param Resource actual: actual object.
:param dict expected: dictionary representing expected object.
:param class resource_type: class type to be applied for the expected
resource.
"""
return self.assertEqual(
resource_type(**expected).to_dict(computed=False),
actual.to_dict(computed=False)
)
def assertResourceListEqual(self, actual, expected, resource_type):
"""Helper for the assertEqual which compares Resource lists object against
dictionary representing expected state.
:param list actual: List of actual objects.
:param listexpected: List of dictionaries representing expected
objects.
:param class resource_type: class type to be applied for the expected
resource.
"""
self.assertEqual(
[resource_type(**f).to_dict(computed=False) for f in expected],
[f.to_dict(computed=False) for f in actual]
)
class IronicTestCase(TestCase):

View File

@@ -440,14 +440,12 @@ class TestMemoryCache(base.TestCase):
self.assertEqual([], self.cloud.list_flavors())
fake_flavor_dicts = [
_flavor.Flavor(connection=self.cloud,
**f)._to_munch(original_names=False)
for f in fakes.FAKE_FLAVOR_LIST
]
self.cloud.list_flavors.invalidate(self.cloud)
self.assertEqual(fake_flavor_dicts, self.cloud.list_flavors())
self.assertResourceListEqual(
self.cloud.list_flavors(),
fakes.FAKE_FLAVOR_LIST,
_flavor.Flavor
)
self.assert_calls()

View File

@@ -535,11 +535,9 @@ class TestShade(base.TestCase):
endpoint=fakes.COMPUTE_ENDPOINT),
status_code=404),
])
with testtools.ExpectedException(
exc.OpenStackCloudURINotFound,
"Error fetching extension list for nova"
):
self.cloud._nova_extensions()
self.assertRaises(
exceptions.ResourceNotFound,
self.cloud._nova_extensions)
self.assert_calls()

View File

@@ -66,7 +66,6 @@ class TestFlavor(base.TestCase):
def test_make_basic(self):
sot = flavor.Flavor(**BASIC_EXAMPLE)
self.assertEqual(BASIC_EXAMPLE['id'], sot.id)
self.assertEqual(BASIC_EXAMPLE['links'], sot.links)
self.assertEqual(BASIC_EXAMPLE['name'], sot.name)
self.assertEqual(BASIC_EXAMPLE['description'], sot.description)
self.assertEqual(BASIC_EXAMPLE['disk'], sot.disk)