Skip to content

Commit 53f5b36

Browse files
committed
chore(e2e): automatically create db user and add ip address to the access list before running tests
1 parent 697e4ce commit 53f5b36

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

.evergreen/functions.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,6 @@ functions:
685685
DEBUG: ${debug|}
686686
COMPASS_E2E_ATLAS_CLOUD_SANDBOX_USERNAME: ${e2e_tests_compass_web_atlas_username}
687687
COMPASS_E2E_ATLAS_CLOUD_SANDBOX_PASSWORD: ${e2e_tests_compass_web_atlas_password}
688-
COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DBUSER_USERNAME: ${e2e_tests_compass_web_atlas_db_username}
689-
COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DBUSER_PASSWORD: ${e2e_tests_compass_web_atlas_password}
690688
MCLI_PUBLIC_API_KEY: ${e2e_tests_mcli_public_api_key}
691689
MCLI_PRIVATE_API_KEY: ${e2e_tests_mcli_private_api_key}
692690
MCLI_ORG_ID: ${e2e_tests_mcli_org_id}

.evergreen/start-atlas-cloud-cluster.sh

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
RUN_ID="$(date +"%s")-$(git rev-parse --short HEAD)"
4+
DELETE_AFTER="$(date -u -Iseconds -d '+2 hours' 2>/dev/null || date -u -Iseconds -v '+2H')"
5+
36
# This script helps to automatically provision Atlas cluster for running the e2e
47
# tests against. In CI this will always create a new cluster and delete it when
58
# the test run is finished. You can also use this script locally to run e2e
@@ -16,9 +19,6 @@
1619
#
1720
# - Setup a new org and project. Save the org id and project id for later.
1821
#
19-
# - Create new db user with username / password auth and admin role. This user
20-
# will be used to prepopulate dbs with data in tests. Save the credentials.
21-
#
2222
# - Create a new API key (Access Manager > Project Access > Create Application >
2323
# API Key) for the project you created and save the public and private keys.
2424
#
@@ -38,8 +38,6 @@
3838
#
3939
# COMPASS_E2E_ATLAS_CLOUD_SANDBOX_USERNAME Cloud user you created
4040
# COMPASS_E2E_ATLAS_CLOUD_SANDBOX_PASSWORD Cloud user password
41-
# COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DBUSER_USERNAME Db user for the project
42-
# COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DBUSER_PASSWORD Db user password
4341
#
4442
# - Source the script followed by running the tests to make sure that some
4543
# variables exported from this script are available for the test env:
@@ -53,10 +51,13 @@ _ATLAS_CLOUD_TEST_CLUSTER_NAME=${ATLAS_CLOUD_TEST_CLUSTER_NAME:-""}
5351
# truncate if it's too long) so we're very limited in terms of how unique this
5452
# name can be. Hopefully the epoch + part of git hash is enough for these to not
5553
# overlap when tests are running
56-
DEFAULT_ATLAS_CLOUD_TEST_CLUSTER_NAME="e2e-$(date +"%s")-$(git rev-parse HEAD)"
54+
DEFAULT_ATLAS_CLOUD_TEST_CLUSTER_NAME="e2e-$RUN_ID"
5755

5856
ATLAS_CLUSTER_NAME="${_ATLAS_CLOUD_TEST_CLUSTER_NAME:-$DEFAULT_ATLAS_CLOUD_TEST_CLUSTER_NAME}"
5957

58+
ATLAS_TEST_DB_USERNAME="testuser-$RUN_ID"
59+
ATLAS_TEST_DB_PASSWORD="$(head -c 32 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9')"
60+
6061
function atlascli() {
6162
docker run \
6263
-e MCLI_PUBLIC_API_KEY \
@@ -79,10 +80,26 @@ cleanup() {
7980
else
8081
echo "Custom cluster name provided ($_ATLAS_CLOUD_TEST_CLUSTER_NAME), skipping cluster cleanup"
8182
fi
83+
echo "Deleting Atlas db user \`$ATLAS_TEST_DB_USERNAME\`..."
84+
atlascli dbusers delete $ATLAS_TEST_DB_USERNAME --force
8285
}
8386

8487
trap cleanup EXIT
8588

89+
echo "Allowing access from current ip..."
90+
atlascli accessList create \
91+
--currentIp \
92+
--deleteAfter "$DELETE_AFTER"
93+
94+
echo "Creating Atlas db user \`$ATLAS_TEST_DB_USERNAME\`..."
95+
atlascli dbusers create atlasAdmin \
96+
--username "$ATLAS_TEST_DB_USERNAME" \
97+
--password "$ATLAS_TEST_DB_PASSWORD" \
98+
--deleteAfter "$DELETE_AFTER" # so that it's autoremoved if cleaning up failed for some reason
99+
100+
export COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DBUSER_USERNAME="$ATLAS_TEST_DB_USERNAME"
101+
export COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DBUSER_PASSWORD="$ATLAS_TEST_DB_PASSWORD"
102+
86103
echo "Creating Atlas deployment \`$ATLAS_CLUSTER_NAME\` to test against..."
87104
atlascli clusters create $ATLAS_CLUSTER_NAME \
88105
--provider AWS \

0 commit comments

Comments
 (0)