-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-2545 Test serverless proxy #664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 21 commits
258a0cb
3791da5
d4ae3bc
5f069c6
00ccaf2
dc09d95
b0c5776
fd6ac53
199f751
8c2c812
8cab22c
893f728
c95cd66
5fcfaa8
0bfdf88
86f9a2e
ea21540
153188e
82e3b1d
2f8e405
2df9fde
5544ae0
8232d17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,7 @@ | |
| COMPRESSORS = os.environ.get("COMPRESSORS") | ||
| MONGODB_API_VERSION = os.environ.get("MONGODB_API_VERSION") | ||
| TEST_LOADBALANCER = bool(os.environ.get("TEST_LOADBALANCER")) | ||
| TEST_SERVERLESS = bool(os.environ.get("TEST_SERVERLESS")) | ||
| SINGLE_MONGOS_LB_URI = os.environ.get("SINGLE_MONGOS_LB_URI") | ||
| MULTI_MONGOS_LB_URI = os.environ.get("MULTI_MONGOS_LB_URI") | ||
| if TEST_LOADBALANCER: | ||
|
|
@@ -104,6 +105,13 @@ | |
| host, port = res['nodelist'][0] | ||
| db_user = res['username'] or db_user | ||
| db_pwd = res['password'] or db_pwd | ||
| elif TEST_SERVERLESS: | ||
| res = parse_uri(os.environ["MONGODB_URI"]) | ||
| host, port = res['nodelist'].pop(0) | ||
| additional_serverless_mongoses = res['nodelist'] | ||
| db_user = res['username'] or db_user | ||
| db_pwd = res['password'] or db_pwd | ||
| TLS_OPTIONS = {'tls': True} | ||
|
|
||
|
|
||
| def is_server_resolvable(): | ||
|
|
@@ -231,6 +239,7 @@ def __init__(self): | |
| self.conn_lock = threading.Lock() | ||
| self.is_data_lake = False | ||
| self.load_balancer = TEST_LOADBALANCER | ||
| self.serverless = TEST_SERVERLESS | ||
| if self.load_balancer: | ||
| self.default_client_options["loadBalanced"] = True | ||
| if COMPRESSORS: | ||
|
|
@@ -309,22 +318,26 @@ def _init_client(self): | |
| if self.client: | ||
| self.connected = True | ||
|
|
||
| try: | ||
| self.cmd_line = self.client.admin.command('getCmdLineOpts') | ||
| except pymongo.errors.OperationFailure as e: | ||
| msg = e.details.get('errmsg', '') | ||
| if e.code == 13 or 'unauthorized' in msg or 'login' in msg: | ||
| # Unauthorized. | ||
| self.auth_enabled = True | ||
| else: | ||
| raise | ||
| if self.serverless: | ||
| self.auth_enabled = True | ||
| else: | ||
| self.auth_enabled = self._server_started_with_auth() | ||
| try: | ||
| self.cmd_line = self.client.admin.command('getCmdLineOpts') | ||
| except pymongo.errors.OperationFailure as e: | ||
| msg = e.details.get('errmsg', '') | ||
| if e.code == 13 or 'unauthorized' in msg or 'login' in msg: | ||
| # Unauthorized. | ||
| self.auth_enabled = True | ||
| else: | ||
| raise | ||
| else: | ||
| self.auth_enabled = self._server_started_with_auth() | ||
|
|
||
| if self.auth_enabled: | ||
| # See if db_user already exists. | ||
| if not self._check_user_provided(): | ||
| _create_user(self.client.admin, db_user, db_pwd) | ||
| if not self.serverless: | ||
| # See if db_user already exists. | ||
| if not self._check_user_provided(): | ||
| _create_user(self.client.admin, db_user, db_pwd) | ||
|
|
||
| self.client = self._connect( | ||
| host, port, username=db_user, password=db_pwd, | ||
|
|
@@ -334,10 +347,13 @@ def _init_client(self): | |
| # May not have this if OperationFailure was raised earlier. | ||
| self.cmd_line = self.client.admin.command('getCmdLineOpts') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does getCmdLineOpts actually work on serverless?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works but doesn't give us any useful info: |
||
|
|
||
| self.server_status = self.client.admin.command('serverStatus') | ||
| if self.storage_engine == "mmapv1": | ||
| # MMAPv1 does not support retryWrites=True. | ||
| self.default_client_options['retryWrites'] = False | ||
| if self.serverless: | ||
| self.server_status = {} | ||
| else: | ||
| self.server_status = self.client.admin.command('serverStatus') | ||
| if self.storage_engine == "mmapv1": | ||
| # MMAPv1 does not support retryWrites=True. | ||
| self.default_client_options['retryWrites'] = False | ||
|
|
||
| ismaster = self.ismaster | ||
| self.sessions_enabled = 'logicalSessionTimeoutMinutes' in ismaster | ||
|
|
@@ -374,33 +390,41 @@ def _init_client(self): | |
| self.nodes = set([(host, port)]) | ||
| self.w = len(ismaster.get("hosts", [])) or 1 | ||
| self.version = Version.from_client(self.client) | ||
| self.server_parameters = self.client.admin.command( | ||
| 'getParameter', '*') | ||
|
|
||
| if 'enableTestCommands=1' in self.cmd_line['argv']: | ||
| if TEST_SERVERLESS: | ||
| self.test_commands_enabled = True | ||
| elif 'parsed' in self.cmd_line: | ||
| params = self.cmd_line['parsed'].get('setParameter', []) | ||
| if 'enableTestCommands=1' in params: | ||
| self.has_ipv6 = False | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Serverless doesn't support ipv6?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure... It seems we only use this in one test (
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah okay, I don't think we need to run that test on serverless. A maybe useful test would be to manually resolve the serverless host to ipv6 and then attempt to connect. Up to you. I don't think it's needed. Should be something that's tested on the cloud team's side. |
||
| else: | ||
| self.server_parameters = self.client.admin.command( | ||
| 'getParameter', '*') | ||
| if 'enableTestCommands=1' in self.cmd_line['argv']: | ||
| self.test_commands_enabled = True | ||
| else: | ||
| params = self.cmd_line['parsed'].get('setParameter', {}) | ||
| if params.get('enableTestCommands') == '1': | ||
| elif 'parsed' in self.cmd_line: | ||
| params = self.cmd_line['parsed'].get('setParameter', []) | ||
| if 'enableTestCommands=1' in params: | ||
| self.test_commands_enabled = True | ||
| else: | ||
| params = self.cmd_line['parsed'].get('setParameter', {}) | ||
| if params.get('enableTestCommands') == '1': | ||
| self.test_commands_enabled = True | ||
| self.has_ipv6 = self._server_started_with_ipv6() | ||
|
|
||
| self.is_mongos = (self.ismaster.get('msg') == 'isdbgrid') | ||
| self.has_ipv6 = self._server_started_with_ipv6() | ||
| if self.is_mongos: | ||
| # Check for another mongos on the next port. | ||
| address = self.client.address | ||
| next_address = address[0], address[1] + 1 | ||
| self.mongoses.append(address) | ||
| mongos_client = self._connect(*next_address, | ||
| **self.default_client_options) | ||
| if mongos_client: | ||
| ismaster = mongos_client.admin.command('ismaster') | ||
| if ismaster.get('msg') == 'isdbgrid': | ||
| self.mongoses.append(next_address) | ||
| if self.serverless: | ||
| self.mongoses.append(self.client.address) | ||
| self.mongoses.extend(additional_serverless_mongoses) | ||
| else: | ||
| # Check for another mongos on the next port. | ||
| address = self.client.address | ||
| next_address = address[0], address[1] + 1 | ||
| self.mongoses.append(address) | ||
| mongos_client = self._connect( | ||
| *next_address, **self.default_client_options) | ||
| if mongos_client: | ||
| ismaster = mongos_client.admin.command('ismaster') | ||
| if ismaster.get('msg') == 'isdbgrid': | ||
| self.mongoses.append(next_address) | ||
|
|
||
| def init(self): | ||
| with self.conn_lock: | ||
|
|
@@ -891,6 +915,9 @@ def setUpClass(cls): | |
| if (client_context.load_balancer and | ||
| not getattr(cls, 'RUN_ON_LOAD_BALANCER', False)): | ||
| raise SkipTest('this test does not support load balancers') | ||
| if (client_context.serverless and | ||
| not getattr(cls, 'RUN_ON_SERVERLESS', False)): | ||
| raise SkipTest('this test does not support serverless') | ||
| cls.client = client_context.client | ||
| cls.db = cls.client.pymongo_test | ||
| if client_context.auth_enabled: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I haven't since "task_groups" before. I gather it's a way to add arbitrary setup/teardown code to an existing task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I too, haven't used them before. I picked this right out of the sample in https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/config.yml