Skip to content

Commit ac32720

Browse files
kevinAlbseramongodb
andcommitted
CDRIVER-4677 conditionally restore AWS instance profile (#1410)
* add `restore-instance-profile` function --------- Co-authored-by: Ezra Chung <[email protected]>
1 parent 7dff5cf commit ac32720

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ post:
4242
- func: upload-test-results
4343
- func: stop-mongo-orchestration
4444
- func: stop-load-balancer
45+
- func: restore-instance-profile
4546

4647
include:
4748
- filename: .evergreen/generated_configs/legacy-config.yml
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from config_generator.etc.function import Function
2+
from config_generator.etc.utils import bash_exec
3+
4+
5+
class RestoreInstanceProfile(Function):
6+
name = 'restore-instance-profile'
7+
commands = [
8+
bash_exec(
9+
script='''\
10+
# Restore the AWS Instance Profile that may have been removed in AWS tasks.
11+
12+
if [[ ! -d drivers-evergreen-tools ]]; then
13+
echo "drivers-evergreen-tools not present ... skipping"
14+
exit 0
15+
fi
16+
17+
cd drivers-evergreen-tools/.evergreen/auth_aws
18+
if [[ ! -f aws_e2e_setup.json ]]; then
19+
echo "aws_e2e_setup.json not present ... skipping"
20+
exit 0
21+
fi
22+
23+
. ./activate-authawsvenv.sh
24+
25+
echo "restoring instance profile ... "
26+
# Capture and hide logs on success. Logs may included expected `HTTP Error 404: Not Found` messages when checking for instance profile.
27+
if ! { python ./lib/aws_assign_instance_profile.py 2>&1 >|output.txt; }; then
28+
echo "restoring instance profile ... failed"
29+
cat output.txt 1>&2
30+
exit 1
31+
fi
32+
echo "restoring instance profile ... succeeded"
33+
'''
34+
),
35+
]
36+
37+
@classmethod
38+
def call(cls, **kwargs):
39+
return cls.default_call(**kwargs)
40+
41+
42+
def functions():
43+
return RestoreInstanceProfile.defn()

.evergreen/generated_configs/functions.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,36 @@ functions:
288288
set -o errexit
289289
bash tools/poetry.sh install --with=docs
290290
bash tools/poetry.sh run bash .evergreen/scripts/check-release-archive.sh
291+
restore-instance-profile:
292+
- command: subprocess.exec
293+
params:
294+
binary: bash
295+
args:
296+
- -c
297+
- |
298+
# Restore the AWS Instance Profile that may have been removed in AWS tasks.
299+
300+
if [[ ! -d drivers-evergreen-tools ]]; then
301+
echo "drivers-evergreen-tools not present ... skipping"
302+
exit 0
303+
fi
304+
305+
cd drivers-evergreen-tools/.evergreen/auth_aws
306+
if [[ ! -f aws_e2e_setup.json ]]; then
307+
echo "aws_e2e_setup.json not present ... skipping"
308+
exit 0
309+
fi
310+
311+
. ./activate-authawsvenv.sh
312+
313+
echo "restoring instance profile ... "
314+
# Capture and hide logs on success. Logs may included expected `HTTP Error 404: Not Found` messages when checking for instance profile.
315+
if ! { python ./lib/aws_assign_instance_profile.py 2>&1 >|output.txt; }; then
316+
echo "restoring instance profile ... failed"
317+
cat output.txt 1>&2
318+
exit 1
319+
fi
320+
echo "restoring instance profile ... succeeded"
291321
run-mock-kms-servers:
292322
- command: subprocess.exec
293323
type: setup

0 commit comments

Comments
 (0)