Skip to content

Commit

Permalink
Refs #RHIROS-1176 - handle condition where description is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
upadhyeammit committed Oct 10, 2023
1 parent 0d6bbc0 commit cc9676a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 0 additions & 2 deletions ros/api/common/instance_types_helper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from ros.lib.aws_instance_types import INSTANCE_TYPES
from ros.extensions import cache


@cache.cached(timeout=0)
def instance_types_desc_dict():
instance_and_descriptions = {}
for instance, info in INSTANCE_TYPES.items():
Expand Down
11 changes: 9 additions & 2 deletions ros/api/v1/suggested_instance_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
)
from ros.api.common.instance_types_helper import instance_types_desc_dict
from ros.api.common.utils import sorting_order
from ros.lib.config import get_logger

LOG = get_logger(__name__)


def non_null_suggested_instance_types():
Expand Down Expand Up @@ -71,8 +74,12 @@ def get(self):
for row in query_result:
# FIXME: As of now we only support AWS cloud, so statically adding it to the dict. Fix this code block
# upon supporting multiple clouds.
record = {'instance_type': row.top_candidate, 'cloud_provider': 'AWS', 'system_count': row.system_count,
'description': instance_types_desc_dict()[row.top_candidate]}
record = {'instance_type': row.top_candidate, 'cloud_provider': 'AWS', 'system_count': row.system_count}
try:
record['description'] = instance_types_desc_dict()[row.top_candidate]
except KeyError:
LOG.info(f"Unable to get the description for {row.top_candidate}! "
f"Looks like lib/aws_instance_types.py is stale!")
suggested_instance_types.append(record)
return build_paginated_system_list_response(limit, offset, suggested_instance_types, count)

Expand Down

0 comments on commit cc9676a

Please sign in to comment.