Skip to content

Commit f07da34

Browse files
PYTHON-2545 Test Atlas Serverless (#664)
1 parent 9833ce0 commit f07da34

37 files changed

+291
-82
lines changed

.evergreen/config.yml

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ functions:
415415
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}"
416416
export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}"
417417
fi
418+
if [ -n "${test_serverless}" ]; then
419+
export TEST_SERVERLESS=1
420+
export MONGODB_URI="${MONGODB_URI}"
421+
export SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}"
422+
export SERVERLESS_ATLAS_PASSWORD="${SERVERLESS_ATLAS_PASSWORD}"
423+
fi
418424
419425
PYTHON_BINARY=${PYTHON_BINARY} \
420426
GREEN_FRAMEWORK=${GREEN_FRAMEWORK} \
@@ -836,9 +842,41 @@ post:
836842
- func: "cleanup"
837843
- func: "teardown_docker"
838844

839-
tasks:
840-
845+
task_groups:
846+
- name: serverless_task_group
847+
setup_group_can_fail_task: true
848+
setup_group_timeout_secs: 1800 # 30 minutes
849+
setup_group:
850+
- func: "fetch source"
851+
- func: "prepare resources"
852+
- command: shell.exec
853+
params:
854+
shell: "bash"
855+
script: |
856+
${PREPARE_SHELL}
857+
set +o xtrace
858+
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
859+
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
860+
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
861+
bash ${DRIVERS_TOOLS}/.evergreen/serverless/create-instance.sh
862+
- command: expansions.update
863+
params:
864+
file: serverless-expansion.yml
865+
teardown_group:
866+
- command: shell.exec
867+
params:
868+
script: |
869+
${PREPARE_SHELL}
870+
set +o xtrace
871+
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
872+
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
873+
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
874+
SERVERLESS_INSTANCE_NAME=${SERVERLESS_INSTANCE_NAME} \
875+
bash ${DRIVERS_TOOLS}/.evergreen/serverless/delete-instance.sh
876+
tasks:
877+
- ".serverless"
841878

879+
tasks:
842880
# Wildcard task. Do you need to find out what tools are available and where?
843881
# Throw it here, and execute this task on all buildvariants
844882
- name: getdata
@@ -1184,6 +1222,11 @@ tasks:
11841222
TOPOLOGY: "sharded_cluster"
11851223
- func: "run tests"
11861224

1225+
- name: "test-serverless"
1226+
tags: ["serverless"]
1227+
commands:
1228+
- func: "run tests"
1229+
11871230
- name: "test-enterprise-auth"
11881231
tags: ["enterprise-auth"]
11891232
commands:
@@ -2040,6 +2083,15 @@ axes:
20402083
test_loadbalancer: true
20412084
batchtime: 10080 # 7 days
20422085

2086+
- id: serverless
2087+
display_name: "Serverless"
2088+
values:
2089+
- id: "enabled"
2090+
display_name: "Serverless"
2091+
variables:
2092+
test_serverless: true
2093+
batchtime: 10080 # 7 days
2094+
20432095
buildvariants:
20442096
- matrix_name: "tests-all"
20452097
matrix_spec:
@@ -2473,6 +2525,16 @@ buildvariants:
24732525
tasks:
24742526
- name: "atlas-connect"
24752527

2528+
- matrix_name: "serverless"
2529+
matrix_spec:
2530+
platform: awslinux
2531+
python-version: *amazon1-pythons
2532+
auth-ssl: auth-ssl
2533+
serverless: "*"
2534+
display_name: "Serverless ${python-version} ${platform}"
2535+
tasks:
2536+
- "serverless_task_group"
2537+
24762538
- matrix_name: "data-lake-spec-tests"
24772539
matrix_spec:
24782540
platform: ubuntu-16.04

.evergreen/run-tests.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ if [ -n "$MONGODB_API_VERSION" ]; then
3939
fi
4040

4141
if [ "$AUTH" != "noauth" ]; then
42-
if [ -z "$DATA_LAKE" ]; then
43-
export DB_USER="bob"
44-
export DB_PASSWORD="pwd123"
45-
else
42+
if [ ! -z "$DATA_LAKE" ]; then
4643
export DB_USER="mhuser"
4744
export DB_PASSWORD="pencil"
45+
elif [ ! -z "$TEST_SERVERLESS" ]; then
46+
export DB_USER=$SERVERLESS_ATLAS_USER
47+
export DB_PASSWORD=$SERVERLESS_ATLAS_PASSWORD
48+
else
49+
export DB_USER="bob"
50+
export DB_PASSWORD="pwd123"
4851
fi
4952
fi
5053

test/__init__.py

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
COMPRESSORS = os.environ.get("COMPRESSORS")
9595
MONGODB_API_VERSION = os.environ.get("MONGODB_API_VERSION")
9696
TEST_LOADBALANCER = bool(os.environ.get("TEST_LOADBALANCER"))
97+
TEST_SERVERLESS = bool(os.environ.get("TEST_SERVERLESS"))
9798
SINGLE_MONGOS_LB_URI = os.environ.get("SINGLE_MONGOS_LB_URI")
9899
MULTI_MONGOS_LB_URI = os.environ.get("MULTI_MONGOS_LB_URI")
99100
if TEST_LOADBALANCER:
@@ -104,6 +105,13 @@
104105
host, port = res['nodelist'][0]
105106
db_user = res['username'] or db_user
106107
db_pwd = res['password'] or db_pwd
108+
elif TEST_SERVERLESS:
109+
res = parse_uri(os.environ["MONGODB_URI"])
110+
host, port = res['nodelist'].pop(0)
111+
additional_serverless_mongoses = res['nodelist']
112+
db_user = res['username'] or db_user
113+
db_pwd = res['password'] or db_pwd
114+
TLS_OPTIONS = {'tls': True}
107115

108116

109117
def is_server_resolvable():
@@ -231,6 +239,7 @@ def __init__(self):
231239
self.conn_lock = threading.Lock()
232240
self.is_data_lake = False
233241
self.load_balancer = TEST_LOADBALANCER
242+
self.serverless = TEST_SERVERLESS
234243
if self.load_balancer:
235244
self.default_client_options["loadBalanced"] = True
236245
if COMPRESSORS:
@@ -309,22 +318,26 @@ def _init_client(self):
309318
if self.client:
310319
self.connected = True
311320

312-
try:
313-
self.cmd_line = self.client.admin.command('getCmdLineOpts')
314-
except pymongo.errors.OperationFailure as e:
315-
msg = e.details.get('errmsg', '')
316-
if e.code == 13 or 'unauthorized' in msg or 'login' in msg:
317-
# Unauthorized.
318-
self.auth_enabled = True
319-
else:
320-
raise
321+
if self.serverless:
322+
self.auth_enabled = True
321323
else:
322-
self.auth_enabled = self._server_started_with_auth()
324+
try:
325+
self.cmd_line = self.client.admin.command('getCmdLineOpts')
326+
except pymongo.errors.OperationFailure as e:
327+
msg = e.details.get('errmsg', '')
328+
if e.code == 13 or 'unauthorized' in msg or 'login' in msg:
329+
# Unauthorized.
330+
self.auth_enabled = True
331+
else:
332+
raise
333+
else:
334+
self.auth_enabled = self._server_started_with_auth()
323335

324336
if self.auth_enabled:
325-
# See if db_user already exists.
326-
if not self._check_user_provided():
327-
_create_user(self.client.admin, db_user, db_pwd)
337+
if not self.serverless:
338+
# See if db_user already exists.
339+
if not self._check_user_provided():
340+
_create_user(self.client.admin, db_user, db_pwd)
328341

329342
self.client = self._connect(
330343
host, port, username=db_user, password=db_pwd,
@@ -334,10 +347,13 @@ def _init_client(self):
334347
# May not have this if OperationFailure was raised earlier.
335348
self.cmd_line = self.client.admin.command('getCmdLineOpts')
336349

337-
self.server_status = self.client.admin.command('serverStatus')
338-
if self.storage_engine == "mmapv1":
339-
# MMAPv1 does not support retryWrites=True.
340-
self.default_client_options['retryWrites'] = False
350+
if self.serverless:
351+
self.server_status = {}
352+
else:
353+
self.server_status = self.client.admin.command('serverStatus')
354+
if self.storage_engine == "mmapv1":
355+
# MMAPv1 does not support retryWrites=True.
356+
self.default_client_options['retryWrites'] = False
341357

342358
ismaster = self.ismaster
343359
self.sessions_enabled = 'logicalSessionTimeoutMinutes' in ismaster
@@ -374,33 +390,41 @@ def _init_client(self):
374390
self.nodes = set([(host, port)])
375391
self.w = len(ismaster.get("hosts", [])) or 1
376392
self.version = Version.from_client(self.client)
377-
self.server_parameters = self.client.admin.command(
378-
'getParameter', '*')
379393

380-
if 'enableTestCommands=1' in self.cmd_line['argv']:
394+
if TEST_SERVERLESS:
381395
self.test_commands_enabled = True
382-
elif 'parsed' in self.cmd_line:
383-
params = self.cmd_line['parsed'].get('setParameter', [])
384-
if 'enableTestCommands=1' in params:
396+
self.has_ipv6 = False
397+
else:
398+
self.server_parameters = self.client.admin.command(
399+
'getParameter', '*')
400+
if 'enableTestCommands=1' in self.cmd_line['argv']:
385401
self.test_commands_enabled = True
386-
else:
387-
params = self.cmd_line['parsed'].get('setParameter', {})
388-
if params.get('enableTestCommands') == '1':
402+
elif 'parsed' in self.cmd_line:
403+
params = self.cmd_line['parsed'].get('setParameter', [])
404+
if 'enableTestCommands=1' in params:
389405
self.test_commands_enabled = True
406+
else:
407+
params = self.cmd_line['parsed'].get('setParameter', {})
408+
if params.get('enableTestCommands') == '1':
409+
self.test_commands_enabled = True
410+
self.has_ipv6 = self._server_started_with_ipv6()
390411

391412
self.is_mongos = (self.ismaster.get('msg') == 'isdbgrid')
392-
self.has_ipv6 = self._server_started_with_ipv6()
393413
if self.is_mongos:
394-
# Check for another mongos on the next port.
395-
address = self.client.address
396-
next_address = address[0], address[1] + 1
397-
self.mongoses.append(address)
398-
mongos_client = self._connect(*next_address,
399-
**self.default_client_options)
400-
if mongos_client:
401-
ismaster = mongos_client.admin.command('ismaster')
402-
if ismaster.get('msg') == 'isdbgrid':
403-
self.mongoses.append(next_address)
414+
if self.serverless:
415+
self.mongoses.append(self.client.address)
416+
self.mongoses.extend(additional_serverless_mongoses)
417+
else:
418+
# Check for another mongos on the next port.
419+
address = self.client.address
420+
next_address = address[0], address[1] + 1
421+
self.mongoses.append(address)
422+
mongos_client = self._connect(
423+
*next_address, **self.default_client_options)
424+
if mongos_client:
425+
ismaster = mongos_client.admin.command('ismaster')
426+
if ismaster.get('msg') == 'isdbgrid':
427+
self.mongoses.append(next_address)
404428

405429
def init(self):
406430
with self.conn_lock:
@@ -891,6 +915,9 @@ def setUpClass(cls):
891915
if (client_context.load_balancer and
892916
not getattr(cls, 'RUN_ON_LOAD_BALANCER', False)):
893917
raise SkipTest('this test does not support load balancers')
918+
if (client_context.serverless and
919+
not getattr(cls, 'RUN_ON_SERVERLESS', False)):
920+
raise SkipTest('this test does not support serverless')
894921
cls.client = client_context.client
895922
cls.db = cls.client.pymongo_test
896923
if client_context.auth_enabled:

test/crud/unified/aggregate-let.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "aggregate-let",
3-
"schemaVersion": "1.0",
3+
"schemaVersion": "1.4",
44
"createEntities": [
55
{
66
"client": {
@@ -310,7 +310,8 @@
310310
"description": "Aggregate to collection with let option",
311311
"runOnRequirements": [
312312
{
313-
"minServerVersion": "5.0"
313+
"minServerVersion": "5.0",
314+
"serverless": "forbid"
314315
}
315316
],
316317
"operations": [

test/crud/unified/aggregate-out-readConcern.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"description": "aggregate-out-readConcern",
3-
"schemaVersion": "1.1",
3+
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
66
"minServerVersion": "4.1.0",
77
"topologies": [
88
"replicaset",
99
"sharded"
10-
]
10+
],
11+
"serverless": "forbid"
1112
}
1213
],
1314
"createEntities": [

test/crud/v1/read/aggregate-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}
77
],
88
"minServerVersion": "3.4",
9+
"serverless": "forbid",
910
"tests": [
1011
{
1112
"description": "Aggregate with collation",

test/crud/v1/read/aggregate-out.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"minServerVersion": "2.6",
17+
"serverless": "forbid",
1718
"tests": [
1819
{
1920
"description": "Aggregate with $out",

test/crud/v1/read/count-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}
77
],
88
"minServerVersion": "3.4",
9+
"serverless": "forbid",
910
"tests": [
1011
{
1112
"description": "Count documents with collation",

test/crud/v1/read/distinct-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111
],
1212
"minServerVersion": "3.4",
13+
"serverless": "forbid",
1314
"tests": [
1415
{
1516
"description": "Distinct with a collation",

test/crud/v1/read/find-collation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}
77
],
88
"minServerVersion": "3.4",
9+
"serverless": "forbid",
910
"tests": [
1011
{
1112
"description": "Find with a collation",

0 commit comments

Comments
 (0)