Skip to content

Add tests and fixes for AWS helpers #2

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

Merged
merged 4 commits into from
Apr 12, 2018
Merged

Add tests and fixes for AWS helpers #2

merged 4 commits into from
Apr 12, 2018

Conversation

brikis98
Copy link
Member

In #1, I had test for everything but the two AWS bash scripts, as those are tricky to unit test. I started to use those scripts in another project, and, not too surprisingly, hit a bug.

So, I bit the bullet, and figured out how to unit test these suckers using moto, a mock EC2 metadata server, and some other hacks. It was a PITA, that included some yak shaving around bats, but the upside is I actually found and fixed several bugs, so I guess it was worth the effort.

@@ -7,31 +7,34 @@ set -e

source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/log.sh"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/aws.sh"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/assertions.sh"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/assert.sh"
Copy link
Member Author

@brikis98 brikis98 Apr 12, 2018

Choose a reason for hiding this comment

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

Bug fix 1

local readonly max_retries=60
local readonly sleep_between_retries=5
asg_size=$(aws_wrapper_get_asg_size "$asg_name" "$aws_region" "$max_retries" "$sleep_between_retries")
assert_not_empty_or_null "$asg_size" "size of ASG $asg_name in $aws_region"
Copy link
Member Author

@brikis98 brikis98 Apr 12, 2018

Choose a reason for hiding this comment

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

Bug fix 2

@@ -157,9 +158,11 @@ function aws_wrapper_get_ips_in_asg {
local readonly asg_name="$1"
local readonly aws_region="$2"
local readonly use_public_ips="$3"
local readonly max_retries="${4:-60}"
local readonly sleep_between_retries="${5:-5}"
Copy link
Member Author

Choose a reason for hiding this comment

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

Also, I've made retries/timeouts optionally configurable throughout this code, which I needed for testing, but is actually a handy feature to have in general.

@@ -0,0 +1,41 @@
# A dirt-simple mock for the EC2 metadata service, built on top of Python and Flask. It allows you to set a mock value
Copy link
Member Author

Choose a reason for hiding this comment

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

This is my mock EC2 metadata server. I tried a bunch of open source ones, and they were all poorly supported, buggy, and only mocked a few of the endpoints I needed. Perhaps some day, we can clean this one up and open source it as a standalone project...

@brikis98
Copy link
Member Author

Merging now. Please take a look, as there are some handy patterns here for mocking out EC2 metadata, AWS APIs, overriding AWS CLI behavior, etc. Feedback welcome!

@brikis98 brikis98 merged commit f3c6ce5 into master Apr 12, 2018
@brikis98 brikis98 deleted the aws-fixes branch April 12, 2018 17:24
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.

1 participant