selftest: enable py3 for samba.tests.upgradeprovision
authorJoe Guo <joeg@catalyst.net.nz>
Tue, 3 Apr 2018 23:19:48 +0000 (11:19 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 5 Apr 2018 06:59:10 +0000 (08:59 +0200)
1. `has_key` was removed from dict in Python 3, use `in` instead.
2. `cmp` was removed in Python 3, define it ourselves.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/descriptor.py
python/samba/upgradehelpers.py
selftest/tests.py

index cf797cc3e94aa25877b9a2da30088f4726d8391f..a9c5e1580f0f0eefb96bdcb01ed1c9700c3e4636 100644 (file)
@@ -543,23 +543,23 @@ def get_diff_sds(refsd, cursd, domainsid, checkSacl = True):
     hash_cur = chunck_sddl(cursddl)
     hash_ref = chunck_sddl(refsddl)
 
-    if not hash_cur.has_key("owner"):
+    if "owner" not in hash_cur:
         txt = "\tNo owner in current SD"
-    elif hash_ref.has_key("owner") and hash_cur["owner"] != hash_ref["owner"]:
+    elif "owner" in hash_ref and hash_cur["owner"] != hash_ref["owner"]:
         txt = "\tOwner mismatch: %s (in ref) %s" \
               "(in current)\n" % (hash_ref["owner"], hash_cur["owner"])
 
-    if not hash_cur.has_key("group"):
+    if "group" not in hash_cur:
         txt = "%s\tNo group in current SD" % txt
-    elif hash_ref.has_key("group") and hash_cur["group"] != hash_ref["group"]:
+    elif "group" in hash_ref and hash_cur["group"] != hash_ref["group"]:
         txt = "%s\tGroup mismatch: %s (in ref) %s" \
               "(in current)\n" % (txt, hash_ref["group"], hash_cur["group"])
 
-    parts = [ "dacl" ]
+    parts = ["dacl"]
     if checkSacl:
         parts.append("sacl")
     for part in parts:
-        if hash_cur.has_key(part) and hash_ref.has_key(part):
+        if part in hash_cur and part in hash_ref:
 
             # both are present, check if they contain the same ACE
             h_cur = set()
@@ -590,9 +590,9 @@ def get_diff_sds(refsd, cursd, domainsid, checkSacl = True):
                     txt = "%s\t\t%s ACE is not present in the" \
                           " current\n" % (txt, item)
 
-        elif hash_cur.has_key(part) and not hash_ref.has_key(part):
+        elif part in hash_cur and part not in hash_ref:
             txt = "%s\tReference ACL hasn't a %s part\n" % (txt, part)
-        elif not hash_cur.has_key(part) and hash_ref.has_key(part):
+        elif part not in hash_cur and part in hash_ref:
             txt = "%s\tCurrent ACL hasn't a %s part\n" % (txt, part)
 
     return txt
index a1ec804597c372d2682fe0e2948adc8c06503398..e219602e0c789d0fdc444a78aa2bc43c8ee2ebcc 100644 (file)
@@ -282,6 +282,7 @@ def dn_sort(x, y):
     len1 = len(tab1)-1
     len2 = len(tab2)-1
     # Note: python range go up to upper limit but do not include it
+    cmp = lambda x, y:  (x > y) - (x < y)  # cmp is removed in py3
     for i in range(0, minimum):
         ret = cmp(tab1[len1-i], tab2[len2-i])
         if ret != 0:
@@ -351,7 +352,7 @@ def update_secrets(newsecrets_ldb, secrets_ldb, messagefunc):
         hash[str(current[i]["dn"]).lower()] = current[i]["dn"]
 
     for k in hash_new.keys():
-        if not hash.has_key(k):
+        if k not in hash:
             listMissing.append(hash_new[k])
         else:
             listPresent.append(hash_new[k])
index a3df849f6ac47534fc71b6563ea4dc0e2f2981fc..c0c4bbc63bb61ad6580d7af37b74e97399735820 100644 (file)
@@ -145,7 +145,7 @@ plantestsuite(
     ["PYTHON=%s" % python,
      os.path.join(bbdir, "functionalprep.sh"),
      '$PREFIX_ABS/provision', configuration])
-planpythontestsuite("none", "samba.tests.upgradeprovision")
+planpythontestsuite("none", "samba.tests.upgradeprovision", py3_compatible=True)
 planpythontestsuite("none", "samba.tests.xattr", py3_compatible=True)
 planpythontestsuite("none", "samba.tests.ntacls", py3_compatible=True)
 planpythontestsuite("none", "samba.tests.policy",  py3_compatible=True)