Skip to content

CDRIVER-4677 conditionally restore AWS instance profile #1410

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 8 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ post:
- func: upload-test-results
- func: stop-mongo-orchestration
- func: stop-load-balancer
- func: restore-instance-profile

include:
- filename: .evergreen/generated_configs/legacy-config.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from config_generator.etc.function import Function
from config_generator.etc.utils import bash_exec


class RestoreInstanceProfile(Function):
name = 'restore-instance-profile'
commands = [
bash_exec(
script='''\
# Restore the AWS Instance Profile that may have been removed in AWS tasks.

if [[ ! -d drivers-evergreen-tools ]]; then
echo "drivers-evergreen-tools not present ... skipping"
exit 0
fi

cd drivers-evergreen-tools/.evergreen/auth_aws
if [[ ! -f aws_e2e_setup.json ]]; then
echo "aws_e2e_setup.json not present ... skipping"
exit 0
fi

. ./activate-authawsvenv.sh

echo "restoring instance profile ... "
# Capture and hide logs on success. Logs may included expected `HTTP Error 404: Not Found` messages when checking for instance profile.
if ! { python ./lib/aws_assign_instance_profile.py 2>&1 >|output.txt; }; then
echo "restoring instance profile ... failed"
cat output.txt 1>&2
exit 1
fi
echo "restoring instance profile ... succeeded"
'''
),
]

@classmethod
def call(cls, **kwargs):
return cls.default_call(**kwargs)


def functions():
return RestoreInstanceProfile.defn()
30 changes: 30 additions & 0 deletions .evergreen/generated_configs/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,36 @@ functions:
echo "Cannot append kerberos.realm to /etc/krb5.conf; skipping." 1>&2
fi
fi
restore-instance-profile:
- command: subprocess.exec
params:
binary: bash
args:
- -c
- |
# Restore the AWS Instance Profile that may have been removed in AWS tasks.

if [[ ! -d drivers-evergreen-tools ]]; then
echo "drivers-evergreen-tools not present ... skipping"
exit 0
fi

cd drivers-evergreen-tools/.evergreen/auth_aws
if [[ ! -f aws_e2e_setup.json ]]; then
echo "aws_e2e_setup.json not present ... skipping"
exit 0
fi

. ./activate-authawsvenv.sh

echo "restoring instance profile ... "
# Capture and hide logs on success. Logs may included expected `HTTP Error 404: Not Found` messages when checking for instance profile.
if ! { python ./lib/aws_assign_instance_profile.py 2>&1 >|output.txt; }; then
echo "restoring instance profile ... failed"
cat output.txt 1>&2
exit 1
fi
echo "restoring instance profile ... succeeded"
run-mock-kms-servers:
- command: subprocess.exec
type: setup
Expand Down