python/samba: PY3 port samba.tests.samba_tool.visualize_drs
authorNoel Power <noel.power@suse.com>
Tue, 20 Nov 2018 17:02:25 +0000 (17:02 +0000)
committerNoel Power <npower@samba.org>
Mon, 10 Dec 2018 09:38:24 +0000 (10:38 +0100)
* Fix calling samba-tool with correct PYTHON version
* Fix integer division needs '//' operator (this was causing
  'uncaught exception - list indices must be integers or slices,
   not float'

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/samba_tool/visualize_drs.py
python/samba/uptodateness.py

index 0f566ea80c74d0fa9b8b051611af5d5041f06e43..9b1588bd1efb4a7157808a3d083974c22941c963 100644 (file)
@@ -49,6 +49,10 @@ PARTITION_NAMES = [
     "DNSFOREST",
 ]
 
+def adjust_cmd_for_py_version(parts):
+    if os.getenv("PYTHON", None):
+        parts.insert(0, os.environ["PYTHON"])
+    return parts
 
 def set_auto_replication(dc, allow):
     credstring = '-U%s%%%s' % (os.environ["USERNAME"], os.environ["PASSWORD"])
@@ -56,21 +60,21 @@ def set_auto_replication(dc, allow):
 
     for opt in ['DISABLE_INBOUND_REPL',
                 'DISABLE_OUTBOUND_REPL']:
-        cmd = ['bin/samba-tool',
+        cmd = adjust_cmd_for_py_version(['bin/samba-tool',
                'drs', 'options',
                credstring, dc,
-               "--dsa-option=%s%s" % (on_or_off, opt)]
+               "--dsa-option=%s%s" % (on_or_off, opt)])
 
         subprocess.check_call(cmd)
 
 
 def force_replication(src, dest, base):
     credstring = '-U%s%%%s' % (os.environ["USERNAME"], os.environ["PASSWORD"])
-    cmd = ['bin/samba-tool',
+    cmd = adjust_cmd_for_py_version(['bin/samba-tool',
            'drs', 'replicate',
            dest, src, base,
            credstring,
-           '--sync-forced']
+           '--sync-forced'])
 
     subprocess.check_call(cmd)
 
index d2662549dfcb57a7ea6945df2a61cd73262e2f9b..3964bd7d6dbef42fd5abd42ae1c28004c57ca361 100644 (file)
@@ -176,11 +176,11 @@ def get_utdv_summary(distances, filters=None):
         maximum = values[-1]
         length = len(values)
         if length % 2 == 0:
-            index = length/2 - 1
+            index = length//2 - 1
             median = (values[index] + values[index+1])/2.0
             median = round(median, 1)  # keep only 1 decimal digit like 2.5
         else:
-            index = (length - 1)/2
+            index = (length - 1)//2
             median = values[index]
             median = float(median)  # ensure median is always a float like 1.0
         # if value not exist, that's a failure