fix: ignore errors when flavors are deleted

The code used to list flavors when in the admin
or project side was not consistent and raised
alerts if viewing in the admin side but not in the
project side.

This patch moves their behaviour to be consistent
and refactors the code to use the same code-base.

Closes-Bug: #2042362
Change-Id: I37cc02102285b1e83ec1343b710a57fb5ac4ba15
This commit is contained in:
okozachenko 2023-11-02 01:27:20 +11:00
parent fb1a3e88da
commit aa21f4baa3
4 changed files with 9 additions and 24 deletions

View File

@ -133,10 +133,6 @@ class InstanceViewTest(test.BaseAdminViewTests):
res = self.client.get(INDEX_URL)
instances = res.context['table'].data
self.assertTemplateUsed(res, INDEX_TEMPLATE)
# Since error messages produced for each instance are identical,
# there will be only one error message for all instances
# (messages de-duplication).
self.assertMessageCount(res, error=1)
self.assertCountEqual(instances, servers)
self.assertEqual(self.mock_image_list_detailed.call_count, 4)

View File

@ -33,6 +33,8 @@ from openstack_dashboard.dashboards.admin.instances \
from openstack_dashboard.dashboards.admin.instances \
import tables as project_tables
from openstack_dashboard.dashboards.admin.instances import tabs
from openstack_dashboard.dashboards.project.instances \
import utils as instance_utils
from openstack_dashboard.dashboards.project.instances import views
from openstack_dashboard.dashboards.project.instances.workflows \
import update_instance
@ -215,18 +217,9 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView):
else:
inst.image['name'] = _("-")
flavor_id = inst.flavor["id"]
try:
if flavor_id in flavor_dict:
inst.full_flavor = flavor_dict[flavor_id]
else:
# If the flavor_id is not in flavor_dict list,
# gets it via nova api.
inst.full_flavor = api.nova.flavor_get(
self.request, flavor_id)
except Exception:
msg = _('Unable to retrieve instance size information.')
exceptions.handle(self.request, msg)
inst.full_flavor = instance_utils.resolve_flavor(self.request,
inst, flavor_dict)
tenant = tenant_dict.get(inst.tenant_id, None)
inst.tenant_name = getattr(tenant, "name", None)
return instances

View File

@ -316,6 +316,7 @@ class InstanceTableTests(InstanceTestBase, InstanceTableTestMixin):
self.mock_is_feature_available.return_value = True
self.mock_server_list_paged.return_value = [servers, False, False]
self.mock_servers_update_addresses.return_value = None
self.mock_flavor_get.side_effect = self.exceptions.nova
self.mock_flavor_list.side_effect = self.exceptions.nova
self.mock_image_list_detailed.return_value = (self.images.list(),
False, False)

View File

@ -171,14 +171,9 @@ class IndexView(tables.PagedTableMixin, tables.DataTableView):
for instance in instances:
self._populate_image_info(instance, image_dict, volume_dict)
flavor_id = instance.flavor["id"]
if flavor_id in flavor_dict:
instance.full_flavor = flavor_dict[flavor_id]
else:
# If the flavor_id is not in flavor_dict,
# put info in the log file.
LOG.info('Unable to retrieve flavor "%s" for instance "%s".',
flavor_id, instance.id)
instance.full_flavor = instance_utils.resolve_flavor(self.request,
instance,
flavor_dict)
return instances