Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 17, 2022

Conversation

kddejong
Copy link
Contributor

@kddejong kddejong commented Oct 14, 2022

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.

@kddejong kddejong changed the title Clean up tests fix(test) - Reduce dependency on AWS config file Oct 14, 2022
@kddejong kddejong force-pushed the fix/clean/teststest branch 2 times, most recently from 83ac371 to fccaa23 Compare October 14, 2022 21:22
@kddejong
Copy link
Contributor Author

Waiting on #202

@kddejong kddejong added bug Something isn't working p1 Medium Priority labels Oct 15, 2022
@kddejong
Copy link
Contributor Author

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
Contributor Author

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.

Copy link
Contributor

@mmaeng mmaeng left a comment

Choose a reason for hiding this comment

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

LGTM

@kddejong kddejong force-pushed the fix/clean/teststest branch 3 times, most recently from d05021b to 66dc84d Compare October 16, 2022 18:45
@kddejong kddejong force-pushed the fix/clean/teststest branch from 66dc84d to 9aa2b7e Compare October 16, 2022 19:06

stubber.add_client_error("put_metric_data", "InternalServiceError")
stubber.activate()
client = mock_session.client("cloudwatch")
Copy link
Contributor Author

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:master Oct 17, 2022
@kddejong kddejong deleted the fix/clean/teststest branch October 17, 2022 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1 Medium Priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants