-
-
Notifications
You must be signed in to change notification settings - Fork 170
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
Conversation
Since we need privileged settings for the Docker container
@@ -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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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...
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! |
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.