Skip to content

fix(test) - Reduce dependency on AWS config file - #201

Merged
kddejong merged 1 commit into
aws-cloudformation:masterfrom
kddejong:fix/clean/teststest
Oct 17, 2022
Merged

fix(test) - Reduce dependency on AWS config file#201
kddejong merged 1 commit into
aws-cloudformation:masterfrom
kddejong:fix/clean/teststest

Conversation

@kddejong

@kddejongkddejong commented Oct 14, 2022

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

  • Current versions of tests rely on some information being in ~/.aws/config when doing mocks. This PR will completely remove that dependency.

You will have issues with the current version of the tests if you have no ~/.aws/config or are using the credential_process attribute in a profile

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kddejongkddejong changed the title Clean up testsfix(test) - Reduce dependency on AWS config fileOct 14, 2022
@kddejong
kddejongforce-pushed the fix/clean/teststest branch 2 times, most recently from 83ac371 to fccaa23CompareOctober 14, 2022 21:22
@kddejong

Copy link
Copy Markdown
ContributorAuthor

Waiting on #202

@kddejongkddejong added bug Something isn't working p1 Medium Priority labels Oct 15, 2022
@kddejong

Copy link
Copy Markdown
ContributorAuthor

Cross referencing this issue I raised with boto3 as I don't believe the credential_process should be executed on session.client or boto3.client call. More details on credential_process

boto/boto3#3456

@kddejong

Copy link
Copy Markdown
ContributorAuthor

If no ~/.aws/config file exists

tests/lib/resource_test.py:92: AssertionError
------------------------------ Captured log call -------------------------------
ERROR cloudformation_cli_python_lib.resource:resource.py:192 Exception caught You must specify a region.
Traceback (most recent call last):
File "/root/cloudformation-cli-python-plugin/src/cloudformation_cli_python_lib/resource.py", line 207, in __call__
metrics.add_metrics_publisher(provider_sess, event.resourceType)
File "/root/cloudformation-cli-python-plugin/src/cloudformation_cli_python_lib/metrics.py", line 249, in add_metrics_publisher
publisher = MetricsPublisher(session, type_name)
File "/root/cloudformation-cli-python-plugin/src/cloudformation_cli_python_lib/metrics.py", line 39, in __init__
self._client = session.client("cloudwatch")
File "/usr/local/lib/python3.7/site-packages/boto3/session.py", line 309, in client
config=config,
File "/usr/local/lib/python3.7/site-packages/botocore/session.py", line 986, in create_client
auth_token=auth_token,
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 136, in create_client
auth_token,
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 481, in _get_client_args
auth_token,
File "/usr/local/lib/python3.7/site-packages/botocore/args.py", line 96, in get_client_args
scoped_config,
File "/usr/local/lib/python3.7/site-packages/botocore/args.py", line 192, in compute_client_args
s3_config=s3_config,
File "/usr/local/lib/python3.7/site-packages/botocore/args.py", line 284, in _compute_endpoint_config
return self._resolve_endpoint(**resolve_endpoint_kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/args.py", line 390, in _resolve_endpoint
service_name, region_name, endpoint_url, is_secure
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 576, in resolve
use_fips_endpoint=use_fips_endpoint,
File "/usr/local/lib/python3.7/site-packages/botocore/regions.py", line 217, in construct_endpoint
use_fips_endpoint,
File "/usr/local/lib/python3.7/site-packages/botocore/regions.py", line 260, in _endpoint_for_partition
raise NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.

@mmaengmmaeng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@kddejong
kddejongforce-pushed the fix/clean/teststest branch 3 times, most recently from d05021b to 66dc84dCompareOctober 16, 2022 18:45

stubber.add_client_error("put_metric_data", "InternalServiceError")
stubber.activate()
client = mock_session.client("cloudwatch")

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

big fan of stubber but haven't gotten it working with the mocked session. This also brings more consistency as these are the only tests using stubber.

@kddejong
kddejong merged commit bc9cc9e into aws-cloudformation:masterOct 17, 2022
@kddejong
kddejong deleted the fix/clean/teststest branch October 17, 2022 15:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingp1Medium Priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@kddejong@ericzbeard@mmaeng