Avoid extra flavor_get in resize server form
commit d269b1640f
fixes the bug on
the resize server form, but it introduced an extra flavor_get call
even when we retrieve the list of flavors. This commit recovers
the previous behavior that we first looks up the list of flavors.
Related-Bug: #1940834
Change-Id: I891aa6b8652f330326535732d0886362dfabb989
This commit is contained in:
parent
ba079cbe38
commit
a7956cd004
@ -2172,13 +2172,11 @@ class InstanceTests2(InstanceTestBase, InstanceTableTestMixin):
|
||||
@helpers.create_mocks({api.nova: ('server_get',
|
||||
'flavor_list',
|
||||
'tenant_absolute_limits',
|
||||
'is_feature_available',
|
||||
'flavor_get')})
|
||||
'is_feature_available')})
|
||||
def _test_instance_resize_get(self, server, nova_api_lt_2_47=False):
|
||||
self.mock_server_get.return_value = server
|
||||
self.mock_flavor_list.return_value = self.flavors.list()
|
||||
self.mock_tenant_absolute_limits.return_value = self.limits['absolute']
|
||||
self.mock_flavor_get.return_value = self.flavors.first()
|
||||
|
||||
url = reverse('horizon:project:instances:resize', args=[server.id])
|
||||
res = self.client.get(url)
|
||||
@ -2220,11 +2218,6 @@ class InstanceTests2(InstanceTestBase, InstanceTableTestMixin):
|
||||
mock.call(helpers.IsHttpRequest()))
|
||||
self.mock_tenant_absolute_limits.assert_called_once_with(
|
||||
helpers.IsHttpRequest(), reserved=True)
|
||||
if nova_api_lt_2_47:
|
||||
self.mock_flavor_get.assert_called_once_with(
|
||||
helpers.IsHttpRequest(), server.flavor['id'])
|
||||
else:
|
||||
self.mock_flavor_get.assert_not_called()
|
||||
|
||||
def test_instance_resize_get_nova_api_lt_2_47(self):
|
||||
server = self.servers.first()
|
||||
@ -2250,11 +2243,9 @@ class InstanceTests2(InstanceTestBase, InstanceTableTestMixin):
|
||||
helpers.IsHttpRequest(), server.id)
|
||||
|
||||
@helpers.create_mocks({api.nova: ('server_get',
|
||||
'flavor_list',
|
||||
'flavor_get')})
|
||||
def _test_instance_resize_get_flavor_list_exception(
|
||||
self, server, nova_api_lt_2_47=False):
|
||||
self.mock_server_get.return_value = server
|
||||
'flavor_list',)})
|
||||
def test_instance_resize_get_flavor_list_exception(self):
|
||||
server = self.servers.first()
|
||||
self.mock_flavor_list.side_effect = self.exceptions.nova
|
||||
|
||||
url = reverse('horizon:project:instances:resize',
|
||||
@ -2266,21 +2257,6 @@ class InstanceTests2(InstanceTestBase, InstanceTableTestMixin):
|
||||
self.mock_server_get.assert_called_once_with(helpers.IsHttpRequest(),
|
||||
server.id)
|
||||
self.mock_flavor_list.assert_called_once_with(helpers.IsHttpRequest())
|
||||
if nova_api_lt_2_47:
|
||||
self.mock_flavor_get.assert_called_once_with(
|
||||
helpers.IsHttpRequest(), server.flavor['id'])
|
||||
else:
|
||||
self.mock_flavor_get.assert_not_called()
|
||||
|
||||
def test_instance_resize_get_flavor_list_exception_nova_api_lt_2_47(self):
|
||||
server = self.servers.first()
|
||||
self._test_instance_resize_get_flavor_list_exception(
|
||||
server, nova_api_lt_2_47=True)
|
||||
|
||||
def test_instance_resize_get_flavor_list_exception(self):
|
||||
server = self.servers.first()
|
||||
self._populate_server_flavor_nova_api_ge_2_47(server)
|
||||
self._test_instance_resize_get_flavor_list_exception(server)
|
||||
|
||||
# TODO(amotoki): This is requred only when nova API <=2.46 is used.
|
||||
# Once server_get() uses nova API >=2.47 only, this test can be droppped.
|
||||
|
@ -236,11 +236,12 @@ def server_group_field_data(request):
|
||||
return [("", _("No server groups available")), ]
|
||||
|
||||
|
||||
def resolve_flavor(request, instance, **kwargs):
|
||||
def resolve_flavor(request, instance, flavors=None, **kwargs):
|
||||
"""Resolves name of instance flavor independent of API microversion
|
||||
|
||||
:param request: django http request object
|
||||
:param instance: api._nova.Server instance to resolve flavor
|
||||
:param flavors: dict of flavors already retrieved
|
||||
:param kwargs: flavor parameters to return if hit some flavor discrepancy
|
||||
:return: flavor name or default placeholder
|
||||
"""
|
||||
@ -252,8 +253,12 @@ def resolve_flavor(request, instance, **kwargs):
|
||||
"""
|
||||
return namedtuple('Flavor', flavor_dict.keys())(*flavor_dict.values())
|
||||
|
||||
if flavors is None:
|
||||
flavors = {}
|
||||
flavor_id = instance.flavor.get('id')
|
||||
if flavor_id: # Nova API <=2.46
|
||||
if flavor_id in flavors:
|
||||
return flavors[flavor_id]
|
||||
try:
|
||||
return api.nova.flavor_get(request, flavor_id)
|
||||
except Exception:
|
||||
|
@ -588,8 +588,9 @@ class ResizeView(workflows.WorkflowView):
|
||||
redirect = reverse("horizon:project:instances:index")
|
||||
msg = _('Unable to retrieve instance details.')
|
||||
exceptions.handle(self.request, msg, redirect=redirect)
|
||||
instance.flavor_name = instance_utils.resolve_flavor(self.request,
|
||||
instance).name
|
||||
flavors = self.get_flavors()
|
||||
flavor = instance_utils.resolve_flavor(self.request, instance, flavors)
|
||||
instance.flavor_name = flavor.name
|
||||
return instance
|
||||
|
||||
@memoized.memoized_method
|
||||
|
Loading…
Reference in New Issue
Block a user