| 1 |
#!/usr/bin/env python |
| 2 |
# |
| 3 |
# Copyright 2009-present MongoDB, Inc. |
| 4 |
# |
| 5 |
# Licensed under the Apache License, Version 2.0(the "License"); |
| 6 |
# you may not use this file except in compliance with the License. |
| 7 |
# You may obtain a copy of the License at |
| 8 |
# |
| 9 |
# http: // www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
# See the License for the specific language governing permissions and |
| 15 |
# limitations under the License. |
| 16 |
|
| 17 |
from collections import OrderedDict as OD |
| 18 |
from typing import MutableSequence |
| 19 |
|
| 20 |
from evergreen_config_generator.functions import func, shell_exec |
| 21 |
from evergreen_config_generator.taskgroups import TaskGroup |
| 22 |
from evergreen_config_generator.tasks import NamedTask |
| 23 |
from evergreen_config_generator.variants import Variant |
| 24 |
|
| 25 |
|
| 26 |
def _create_tasks(): |
| 27 |
passtask = NamedTask( |
| 28 |
task_name='testgcpkms-task', |
| 29 |
commands=[ |
| 30 |
func('fetch-source'), |
| 31 |
shell_exec( |
| 32 |
r""" |
| 33 |
echo "Building test-gcpkms ... begin" |
| 34 |
pushd mongoc |
| 35 |
.evergreen/scripts/compile-test-gcpkms.sh |
| 36 |
popd |
| 37 |
echo "Building test-gcpkms ... end" |
| 38 |
echo "Copying files ... begin" |
| 39 |
export GCPKMS_GCLOUD=${GCPKMS_GCLOUD} |
| 40 |
export GCPKMS_PROJECT=${GCPKMS_PROJECT} |
| 41 |
export GCPKMS_ZONE=${GCPKMS_ZONE} |
| 42 |
export GCPKMS_INSTANCENAME=${GCPKMS_INSTANCENAME} |
| 43 |
DRIVERS_TOOLS=$(pwd)/drivers-evergreen-tools |
| 44 |
mkdir testgcpkms |
| 45 |
cp ./mongoc/src/libmongoc/test-gcpkms ./mongoc/install/lib/libmongocrypt.* testgcpkms |
| 46 |
tar czf testgcpkms.tgz testgcpkms/* |
| 47 |
GCPKMS_SRC="testgcpkms.tgz" GCPKMS_DST=$GCPKMS_INSTANCENAME: $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/copy-file.sh |
| 48 |
echo "Copying files ... end" |
| 49 |
echo "Untarring file ... begin" |
| 50 |
GCPKMS_CMD="tar xf testgcpkms.tgz" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh |
| 51 |
echo "Untarring file ... end" |
| 52 |
""", |
| 53 |
test=False, |
| 54 |
add_expansions_to_env=True, |
| 55 |
), |
| 56 |
shell_exec( |
| 57 |
r""" |
| 58 |
export GCPKMS_GCLOUD=${GCPKMS_GCLOUD} |
| 59 |
export GCPKMS_PROJECT=${GCPKMS_PROJECT} |
| 60 |
export GCPKMS_ZONE=${GCPKMS_ZONE} |
| 61 |
export GCPKMS_INSTANCENAME=${GCPKMS_INSTANCENAME} |
| 62 |
DRIVERS_TOOLS=$(pwd)/drivers-evergreen-tools |
| 63 |
GCPKMS_CMD="LD_LIBRARY_PATH=./testgcpkms MONGODB_URI='mongodb://localhost:27017' ./testgcpkms/test-gcpkms" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh |
| 64 |
""" |
| 65 |
), |
| 66 |
], |
| 67 |
) |
| 68 |
|
| 69 |
failtask = NamedTask( |
| 70 |
task_name='testgcpkms-fail-task', |
| 71 |
commands=[ |
| 72 |
shell_exec( |
| 73 |
r""" |
| 74 |
pushd mongoc |
| 75 |
.evergreen/scripts/compile-test-gcpkms.sh |
| 76 |
popd""", |
| 77 |
test=False, |
| 78 |
add_expansions_to_env=True, |
| 79 |
), |
| 80 |
shell_exec( |
| 81 |
r""" |
| 82 |
export GCPKMS_GCLOUD=${GCPKMS_GCLOUD} |
| 83 |
export GCPKMS_PROJECT=${GCPKMS_PROJECT} |
| 84 |
export GCPKMS_ZONE=${GCPKMS_ZONE} |
| 85 |
export GCPKMS_INSTANCENAME=${GCPKMS_INSTANCENAME} |
| 86 |
LD_LIBRARY_PATH=$(pwd)/install MONGODB_URI='mongodb://localhost:27017' EXPECT_ERROR='Failed to connect to: metadata.google.internal' ./mongoc/src/libmongoc/test-gcpkms""" |
| 87 |
), |
| 88 |
], |
| 89 |
) |
| 90 |
|
| 91 |
return [passtask, failtask] |
| 92 |
|
| 93 |
|
| 94 |
def _create_variant(): |
| 95 |
return Variant( |
| 96 |
name='testgcpkms-variant', |
| 97 |
display_name='GCP KMS', |
| 98 |
run_on='debian11-latest-small', # GCP Virtual Machine is actually Debian 11. |
| 99 |
tasks=['testgcpkms_task_group', 'testgcpkms-fail-task'], |
| 100 |
batchtime=20160, |
| 101 |
) # Use a batchtime of 14 days as suggested by the CSFLE test README |
| 102 |
|
| 103 |
|
| 104 |
def _create_task_group(): |
| 105 |
task_group = TaskGroup(name='testgcpkms_task_group') |
| 106 |
task_group.setup_group_can_fail_task = True |
| 107 |
task_group.setup_group_timeout_secs = 1800 # 30 minutes |
| 108 |
task_group.setup_group = [ |
| 109 |
func('fetch-det'), |
| 110 |
# Create and set up a GCE instance using driver tools script |
| 111 |
shell_exec( |
| 112 |
r""" |
| 113 |
DRIVERS_TOOLS=$(pwd)/drivers-evergreen-tools |
| 114 |
echo '${testgcpkms_key_file}' > /tmp/testgcpkms_key_file.json |
| 115 |
export GCPKMS_KEYFILE=/tmp/testgcpkms_key_file.json |
| 116 |
export GCPKMS_DRIVERS_TOOLS=$DRIVERS_TOOLS |
| 117 |
export GCPKMS_SERVICEACCOUNT="${testgcpkms_service_account}" |
| 118 |
$DRIVERS_TOOLS/.evergreen/csfle/gcpkms/create-and-setup-instance.sh""", |
| 119 |
test=False, |
| 120 |
), |
| 121 |
# Load the GCPKMS_GCLOUD, GCPKMS_INSTANCE, GCPKMS_PROJECT, and GCPKMS_ZONE expansions. |
| 122 |
OD([('command', 'expansions.update'), ('params', OD([('file', 'testgcpkms-expansions.yml')]))]), |
| 123 |
] |
| 124 |
|
| 125 |
task_group.teardown_group = [ |
| 126 |
shell_exec( |
| 127 |
r""" |
| 128 |
DRIVERS_TOOLS=$(pwd)/drivers-evergreen-tools |
| 129 |
export GCPKMS_GCLOUD=${GCPKMS_GCLOUD} |
| 130 |
export GCPKMS_PROJECT=${GCPKMS_PROJECT} |
| 131 |
export GCPKMS_ZONE=${GCPKMS_ZONE} |
| 132 |
export GCPKMS_INSTANCENAME=${GCPKMS_INSTANCENAME} |
| 133 |
$DRIVERS_TOOLS/.evergreen/csfle/gcpkms/delete-instance.sh""", |
| 134 |
test=False, |
| 135 |
) |
| 136 |
] |
| 137 |
task_group.tasks = ['testgcpkms-task'] |
| 138 |
return task_group |
| 139 |
|
| 140 |
|
| 141 |
def testgcpkms_generate( |
| 142 |
all_tasks: MutableSequence[NamedTask], |
| 143 |
all_variants: MutableSequence[Variant], |
| 144 |
all_task_groups: MutableSequence[TaskGroup], |
| 145 |
): |
| 146 |
all_tasks.extend(_create_tasks()) |
| 147 |
all_variants.append(_create_variant()) |
| 148 |
all_task_groups.append(_create_task_group()) |