Skip to content

Commit

Permalink
auth/credentials/tests: Python 3.6 avoid deepcopy error
Browse files Browse the repository at this point in the history
In PY3 both deepcopy & (shallow)copy fail with

  Traceback (most recent call last):
    File "auth/credentials/tests/bind.py", line 42, in <module>
      creds_machine = copy.copy(creds)
    File "/usr/lib64/python3.6/copy.py", line 96, in copy
      rv = reductor(4)
  TypeError: can't pickle credentials.Credentials objects

This patch avoids the nasty copies but creating and populating the
Credential objects instead of copying

Signed-off-by: Noel Power <[email protected]>
Reviewed-by: Andrew Bartlett <[email protected]>
  • Loading branch information
noelpower authored and Noel Power committed Dec 10, 2018
1 parent b209def commit cc11f71
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions auth/credentials/tests/bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
from samba import gensec
import samba.tests
from samba.tests import delete_force
from samba.credentials import Credentials

def create_credential(lp, other):
c = Credentials()
c.guess(lp)
c.set_gensec_features(other.get_gensec_features())
return c

parser = optparse.OptionParser("ldap [options] <host>")
sambaopts = options.SambaOptions(parser)
Expand All @@ -39,12 +46,12 @@
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp)
creds.set_gensec_features(creds.get_gensec_features() | gensec.FEATURE_SEAL)
creds_machine = copy.deepcopy(creds)
creds_user1 = copy.deepcopy(creds)
creds_user2 = copy.deepcopy(creds)
creds_user3 = copy.deepcopy(creds)
creds_user4 = copy.deepcopy(creds)

creds_machine = create_credential(lp, creds)
creds_user1 = create_credential(lp, creds)
creds_user2 = create_credential(lp, creds)
creds_user3 = create_credential(lp, creds)
creds_user4 = create_credential(lp, creds)

class BindTests(samba.tests.TestCase):

Expand Down

0 comments on commit cc11f71

Please sign in to comment.