(self)
| 195 | await client.close() |
| 196 | |
| 197 | async def _init_client(self): |
| 198 | self.mongoses = [] |
| 199 | self.connection_attempts = [] |
| 200 | self.client = await self._connect(host, port) |
| 201 | |
| 202 | if HAVE_SSL and not self.client: |
| 203 | # Is MongoDB configured for SSL? |
| 204 | self.client = await self._connect(host, port, **TLS_OPTIONS) |
| 205 | if self.client: |
| 206 | self.tls = True |
| 207 | self.default_client_options.update(TLS_OPTIONS) |
| 208 | self.tlsCertificateKeyFile = True |
| 209 | |
| 210 | if self.client: |
| 211 | self.connected = True |
| 212 | |
| 213 | try: |
| 214 | self.cmd_line = await self.client.admin.command("getCmdLineOpts") |
| 215 | except pymongo.errors.OperationFailure as e: |
| 216 | assert e.details is not None |
| 217 | msg = e.details.get("errmsg", "") |
| 218 | if e.code == 13 or "unauthorized" in msg or "login" in msg: |
| 219 | # Unauthorized. |
| 220 | self.auth_enabled = True |
| 221 | else: |
| 222 | raise |
| 223 | else: |
| 224 | self.auth_enabled = self._server_started_with_auth() |
| 225 | |
| 226 | if self.auth_enabled: |
| 227 | if not IS_SRV: |
| 228 | # See if db_user already exists. |
| 229 | if not await self._check_user_provided(): |
| 230 | await _create_user(self.client.admin, db_user, db_pwd) |
| 231 | |
| 232 | if self.client: |
| 233 | await self.client.close() |
| 234 | |
| 235 | self.client = await self._connect( |
| 236 | host, |
| 237 | port, |
| 238 | username=db_user, |
| 239 | password=db_pwd, |
| 240 | replicaSet=self.replica_set_name, |
| 241 | **self.default_client_options, |
| 242 | ) |
| 243 | |
| 244 | # May not have this if OperationFailure was raised earlier. |
| 245 | self.cmd_line = await self.client.admin.command("getCmdLineOpts") |
| 246 | |
| 247 | self.server_status = await self.client.admin.command("serverStatus") |
| 248 | if self.storage_engine == "mmapv1": |
| 249 | # MMAPv1 does not support retryWrites=True. |
| 250 | self.default_client_options["retryWrites"] = False |
| 251 | |
| 252 | hello = await self.hello |
| 253 | self.sessions_enabled = "logicalSessionTimeoutMinutes" in hello |
| 254 |
no test coverage detected