Fix flavor specification at instance overview page

The details page uses flavor id to resolve instance flavor, relying
on legacy Nova API v2.46. This patch adds the current Nova API
option, resolving instance flavor by flavor name, so flavor
specification at instance overview page is displayed properly.

Change-Id: I1fe45063c9d1cdd8682998329d81f843d30f80b3
(cherry picked from commit d0e9e976f2)
This commit is contained in:
Tatiana Ovchinnikova 2022-06-27 09:52:48 -05:00
parent 82698aa890
commit 5945113962
2 changed files with 30 additions and 5 deletions

View File

@ -1330,6 +1330,7 @@ class InstanceDetailTests(InstanceTestBase):
"server_get", "server_get",
"instance_volumes_list", "instance_volumes_list",
"flavor_get", "flavor_get",
"flavor_list",
'is_feature_available', 'is_feature_available',
), ),
api.neutron: ( api.neutron: (
@ -1342,7 +1343,7 @@ class InstanceDetailTests(InstanceTestBase):
def _get_instance_details(self, server, qs=None, def _get_instance_details(self, server, qs=None,
flavor_return=None, volumes_return=None, flavor_return=None, volumes_return=None,
security_groups_return=None, security_groups_return=None,
flavor_exception=False): flavor_exception=False, nova_api_ge_2_47=False):
url = reverse('horizon:project:instances:detail', args=[server.id]) url = reverse('horizon:project:instances:detail', args=[server.id])
if qs: if qs:
@ -1377,8 +1378,12 @@ class InstanceDetailTests(InstanceTestBase):
helpers.IsHttpRequest(), mock.ANY) helpers.IsHttpRequest(), mock.ANY)
self.mock_instance_volumes_list.assert_called_once_with( self.mock_instance_volumes_list.assert_called_once_with(
helpers.IsHttpRequest(), server.id) helpers.IsHttpRequest(), server.id)
self.mock_flavor_get.assert_called_once_with( if nova_api_ge_2_47:
helpers.IsHttpRequest(), server.flavor['id']) self.mock_flavor_list.assert_called_once_with(
helpers.IsHttpRequest())
else:
self.mock_flavor_get.assert_called_once_with(
helpers.IsHttpRequest(), server.flavor['id'])
self.mock_server_security_groups.assert_called_once_with( self.mock_server_security_groups.assert_called_once_with(
helpers.IsHttpRequest(), server.id) helpers.IsHttpRequest(), server.id)
self.mock_floating_ip_simple_associate_supported \ self.mock_floating_ip_simple_associate_supported \
@ -1562,6 +1567,19 @@ class InstanceDetailTests(InstanceTestBase):
self.mock_is_extension_supported.assert_called_once_with( self.mock_is_extension_supported.assert_called_once_with(
helpers.IsHttpRequest(), 'mac-learning') helpers.IsHttpRequest(), 'mac-learning')
@helpers.create_mocks({api.neutron: ['is_extension_supported']})
def test_instance_details_nova_api_ge_2_47(self):
server = self.servers.first()
server.flavor = {
'original_name': 'm1.tiny',
}
self.mock_is_extension_supported.return_value = False
res = self._get_instance_details(server, nova_api_ge_2_47=True)
self.assertTemplateUsed(res,
'project/instances/_detail_overview.html')
self.mock_is_extension_supported.assert_called_once_with(
helpers.IsHttpRequest(), 'mac-learning')
@helpers.create_mocks({api.nova: ['server_console_output'], @helpers.create_mocks({api.nova: ['server_console_output'],
api.neutron: ['is_extension_supported']}) api.neutron: ['is_extension_supported']})
def test_instance_log(self): def test_instance_log(self):

View File

@ -527,9 +527,16 @@ class DetailView(tabs.TabView):
def _get_flavor(self, instance): def _get_flavor(self, instance):
instance_id = instance.id instance_id = instance.id
flavor_id = instance.flavor.get('id')
try: try:
instance.full_flavor = api.nova.flavor_get( if flavor_id: # Nova API <= 2.46
self.request, instance.flavor["id"]) instance.full_flavor = api.nova.flavor_get(
self.request, flavor_id)
else:
flavors = api.nova.flavor_list(self.request)
flavor_name_dict = dict((str(f.name), f) for f in flavors)
instance.full_flavor = \
flavor_name_dict[instance.flavor['original_name']]
except Exception: except Exception:
msg = _('Unable to retrieve flavor information for instance ' msg = _('Unable to retrieve flavor information for instance '
'"%(name)s" (%(id)s).') % {'name': instance.name, '"%(name)s" (%(id)s).') % {'name': instance.name,