Skip to content

Conversation

@liangxiao1
Copy link

Handle failures When pass "all" in regions, us-west-2 is not proper when token is for aws-china and aws-us-gov.

Signed-off-by: Xiao Liang xiliang@redhat.com

Copy link
Collaborator

@jyejare jyejare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed response, was bzy with project work in Q1.

Needs changed to your code.

Comment on lines +16 to +27
default_regions = ['us-west-2', 'cn-northwest-1', 'us-gov-west-1']
for region in default_regions:
try:
with compute_client("aws", aws_region=region) as client:
regions = client.list_regions()
if regions:
break
except Exception as e:
pass
if "all" in regions:
logger.error(f"Unable to retrive region list using currrent token!")
sys.exit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default_regions = ['us-west-2', 'cn-northwest-1', 'us-gov-west-1']
for region in default_regions:
try:
with compute_client("aws", aws_region=region) as client:
regions = client.list_regions()
if regions:
break
except Exception as e:
pass
if "all" in regions:
logger.error(f"Unable to retrive region list using currrent token!")
sys.exit(1)
default_regions = ['us-west-2', 'cn-northwest-1', 'us-gov-west-1']
regions = []
for region in default_regions:
try:
with compute_client("aws", aws_region=region) as client:
_regions = client.list_regions()
if _regions:
regions += _regions
break
except Exception as e:
pass
else:
logger.error(f"Unable to retrive region list using currrent token!")
sys.exit(1)

You should append the list of regions from all default regions to iterate over.

Also, the error should only be thrown when break is not hit in any cycle of the loop. That is else.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should append the list of regions from all default regions to iterate over.

That's not what the proposed patch does, afaics, because of the break.
Does .list_regions() return all the regions, or just some?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .list_regions() can only retrieve the regions your account belongs. That means the default region lists(['us-west-2', 'cn-northwest-1', 'us-gov-west-1']) is isolated physically and managed by standalone IAM manage systems.

@jyejare
Copy link
Collaborator

jyejare commented Aug 8, 2023

Ping @liangxiao1 !

@liangxiao1
Copy link
Author

Ping @liangxiao1 !
Your changes looks good to me. Thanks

Handle failures When pass "all" in regions, us-west-2 is not
proper when token is for aws-china and aws-us-gov.

Signed-off-by: Xiao Liang <xiliang@redhat.com>
@jyejare
Copy link
Collaborator

jyejare commented Aug 22, 2023

@liangxiao1 Let me know once you push the code as per my comments! Also pre-commit checks are failing , please look into that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants