build: Change bin/default/python -> bin/python symlink to bin/default/python_modules
[bbaumbach/samba-autobuild/.git] / source4 / scripting / python / samba / tests / libsmb_samba_internal.py
1 # Unix SMB/CIFS implementation.
2 # Copyright Volker Lendecke <vl@samba.org> 2012
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 """Tests for samba.samba3.libsmb_samba_internal."""
19
20 from samba.samba3 import libsmb_samba_internal
21 from samba.dcerpc import security
22 from samba.samba3 import param as s3param
23 from samba import credentials
24 import samba.tests
25 import threading
26 import sys
27 import os
28
29 class LibsmbTestCase(samba.tests.TestCase):
30
31     class OpenClose(threading.Thread):
32
33         def __init__(self, conn, filename, num_ops):
34             threading.Thread.__init__(self)
35             self.conn = conn
36             self.filename = filename
37             self.num_ops = num_ops
38             self.exc = False
39
40         def run(self):
41             c = self.conn
42             try:
43                 for i in range(self.num_ops):
44                     f = c.create(self.filename, CreateDisposition=3,
45                                  DesiredAccess=security.SEC_STD_DELETE)
46                     c.delete_on_close(f, True)
47                     c.close(f)
48             except Exception:
49                 self.exc = sys.exc_info()
50
51     def test_OpenClose(self):
52
53         lp = s3param.get_context()
54         lp.load(os.getenv("SMB_CONF_PATH"))
55
56         creds = credentials.Credentials()
57         creds.set_username(os.getenv("USERNAME"))
58         creds.set_password(os.getenv("PASSWORD"))
59
60         c = libsmb_samba_internal.Conn(os.getenv("SERVER_IP"), "tmp", creds)
61
62         mythreads = []
63
64         for i in range(3):
65             t = LibsmbTestCase.OpenClose(c, "test" + str(i), 10)
66             mythreads.append(t)
67
68         for t in mythreads:
69             t.start()
70
71         for t in mythreads:
72             t.join()
73             if t.exc:
74                 raise t.exc[0](t.exc[1])
75
76 if __name__ == "__main__":
77     import unittest
78     unittest.main()