From 5d774fa732ddb0d71b42eed09be041efcc76c6fe Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Wed, 4 Apr 2018 11:19:48 +1200 Subject: [PATCH] selftest: enable py3 for samba.tests.upgradeprovision 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 Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- python/samba/descriptor.py | 16 ++++++++-------- python/samba/upgradehelpers.py | 3 ++- selftest/tests.py | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/python/samba/descriptor.py b/python/samba/descriptor.py index cf797cc3e94a..a9c5e1580f0f 100644 --- a/python/samba/descriptor.py +++ b/python/samba/descriptor.py @@ -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 diff --git a/python/samba/upgradehelpers.py b/python/samba/upgradehelpers.py index a1ec804597c3..e219602e0c78 100644 --- a/python/samba/upgradehelpers.py +++ b/python/samba/upgradehelpers.py @@ -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]) diff --git a/selftest/tests.py b/selftest/tests.py index a3df849f6ac4..c0c4bbc63bb6 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -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) -- 2.34.1