ctdb-scripts: Improve update and listing code
[samba4-gss.git] / python / samba / tests / process_limits.py
blobe9800053b877975dcc888d3e3d3eda8c7ac1dba1
1 # Tests for limiting processes forked on accept by the standard process model
3 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests limits on processes forked by fork on accept in the standard process
19 model.
20 NOTE: This test runs in an environment with an artificially low setting for
21 smbd max processes
22 """
25 import os
26 from samba.tests import TestCase
27 from samba.samdb import SamDB
28 from ldb import LdbError, ERR_OPERATIONS_ERROR
31 class StandardModelProcessLimitTests(TestCase):
33 def simple_bind(self):
34 creds = self.insta_creds(template=self.get_credentials())
35 creds.set_bind_dn("%s\\%s" % (creds.get_domain(),
36 creds.get_username()))
38 return SamDB(url="ldaps://%s" % os.environ["SERVER"],
39 lp=self.get_loadparm(),
40 credentials=creds)
42 def test_process_limits(self):
43 creds = self.insta_creds(template=self.get_credentials())
44 creds.set_bind_dn("%s\\%s" % (creds.get_domain(),
45 creds.get_username()))
47 connections = []
48 try:
49 # Open a series of LDAP connections, the maximum number of
50 # active connections should be 20, so the 21st should fail.
51 # But as it is possible that there may be other processes holding
52 # connections, need to allow for earlier connection failures.
53 for _ in range(21):
54 connections.append(self.simple_bind())
55 self.fail(
56 "Processes not limited, able to make more than 20 connections")
57 except LdbError as e:
58 (errno, estr) = e.args
59 if errno != ERR_OPERATIONS_ERROR:
60 raise
61 if not (estr.endswith("NT_STATUS_CONNECTION_DISCONNECTED") or
62 estr.endswith("NT_STATUS_CONNECTION_RESET")):
63 raise
64 pass
66 # Clean up the connections we've just opened, by deleting the
67 # connection in python. This should invoke the talloc destructor to
68 # release any resources and close the actual connection to the server.
69 for c in connections:
70 del c