Skip to content

Commit 92741f3

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

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
@@ -285,6 +285,36 @@ functions:
285285
echo "Cannot append kerberos.realm to /etc/krb5.conf; skipping." 1>&2
286286
fi
287287
fi
288+
restore-instance-profile:
289+
- command: subprocess.exec
290+
params:
291+
binary: bash
292+
args:
293+
- -c
294+
- |
295+
# Restore the AWS Instance Profile that may have been removed in AWS tasks.
296+
297+
if [[ ! -d drivers-evergreen-tools ]]; then
298+
echo "drivers-evergreen-tools not present ... skipping"
299+
exit 0
300+
fi
301+
302+
cd drivers-evergreen-tools/.evergreen/auth_aws
303+
if [[ ! -f aws_e2e_setup.json ]]; then
304+
echo "aws_e2e_setup.json not present ... skipping"
305+
exit 0
306+
fi
307+
308+
. ./activate-authawsvenv.sh
309+
310+
echo "restoring instance profile ... "
311+
# Capture and hide logs on success. Logs may included expected `HTTP Error 404: Not Found` messages when checking for instance profile.
312+
if ! { python ./lib/aws_assign_instance_profile.py 2>&1 >|output.txt; }; then
313+
echo "restoring instance profile ... failed"
314+
cat output.txt 1>&2
315+
exit 1
316+
fi
317+
echo "restoring instance profile ... succeeded"
288318
run-mock-kms-servers:
289319
- command: subprocess.exec
290320
type: setup

0 commit comments

Comments
 (0)