PEP8: fix E201: whitespace after '('
[vlendec/samba-autobuild/.git] / source3 / script / tests / test_wbinfo_sids2xids_int.py
index 3ad3156ea93acfaba8922f6e42c1c81ed75d7e96..6999142cefd403d316b8933ae2221689f750457e 100755 (executable)
@@ -1,17 +1,23 @@
 #!/usr/bin/env python
 
+from __future__ import print_function
 import sys,os,subprocess
 
 
 if len(sys.argv) != 3:
-    print "Usage: test_wbinfo_sids2xids_int.py wbinfo net"
+    print("Usage: test_wbinfo_sids2xids_int.py wbinfo net")
     sys.exit(1)
 
 wbinfo = sys.argv[1]
 netcmd = sys.argv[2]
 
-def flush_cache():
-    os.system(netcmd + " cache flush")
+def flush_cache(sids=[], uids=[], gids=[]):
+    for sid in sids:
+        os.system(netcmd + (" cache del IDMAP/SID2XID/%s" % (sid)))
+    for uids in uids:
+        os.system(netcmd + (" cache del IDMAP/UID2SID/%s" % (uid)))
+    for gids in gids:
+        os.system(netcmd + (" cache del IDMAP/GID2SID/%s" % (gid)))
 
 def fill_cache(inids, idtype='gid'):
     for inid in inids:
@@ -29,9 +35,9 @@ domsid = domsid.split(' ')[0]
 #print domain
 #print domsid
 
-sids=[ domsid + '-512', 'S-1-5-32-545', domsid + '-513', 'S-1-1-0', 'S-1-3-1', 'S-1-5-1' ]
+sids=[domsid + '-512', 'S-1-5-32-545', domsid + '-513', 'S-1-1-0', 'S-1-3-1', 'S-1-5-1' ]
 
-flush_cache()
+flush_cache(sids=sids)
 
 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' +  ','.join(sids)],
                              stdout=subprocess.PIPE).communicate()[0].strip()
@@ -73,8 +79,8 @@ def check_singular(sids, ids, idtype='gid'):
         outid = subprocess.Popen([wbinfo, '--sid-to-%s' % idtype, sid],
                                  stdout=subprocess.PIPE).communicate()[0].strip()
         if outid != ids[i]:
-            print "Expected %s, got %s\n" % (outid, ids[i])
-            flush_cache()
+            print("Expected %s, got %s\n" % (outid, ids[i]))
+            flush_cache(sids=sids, uids=uids, gids=gids)
             sys.exit(1)
         i += 1
 
@@ -89,8 +95,8 @@ def check_multiple(sids, idtypes):
         result = line.split(' ')[2:]
 
         if result[0] != idtypes[i]:
-            print "Expected %s, got %s\n" % (idtypes[i], result[0])
-            flush_cache()
+            print("Expected %s, got %s\n" % (idtypes[i], result[0]))
+            flush_cache(sids=sids, uids=uids, gids=gids)
             sys.exit(1)
         i += 1
 
@@ -99,22 +105,22 @@ check_singular(sids, gids, 'gid')
 check_singular(sids, uids, 'uid')
 
 # second round: with empty cache
-flush_cache()
+flush_cache(sids=sids, gids=gids)
 check_singular(sids, gids, 'gid')
-flush_cache()
+flush_cache(sids=sids, uids=uids)
 check_singular(sids, uids, 'uid')
 
 # third round: with filled cache via uid-to-sid
-flush_cache()
+flush_cache(sids=uids, uids=uids)
 fill_cache(uids, 'uid')
 check_multiple(sids, idtypes)
 
 # fourth round: with filled cache via gid-to-sid
-flush_cache()
+flush_cache(sids=sids, gids=gids)
 fill_cache(gids, 'gid')
 check_multiple(sids, idtypes)
 
 # flush the cache so any incorrect mappings don't break other tests
-flush_cache()
+flush_cache(sids=sids, uids=uids, gids=gids)
 
 sys.exit(0)