py3: create_cert_db: write to file in a compatible way

Py3 expect bytes to be writed using os.write. Instead of that using
io module is more pythonic.

https://fedorahosted.org/freeipa/ticket/4985

Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
Martin Basti 2017-01-09 11:53:59 +01:00
parent 84a9611cb8
commit 23239bccc1

View File

@ -19,6 +19,7 @@
from __future__ import print_function
import io
import os
import os.path
import pwd
@ -314,9 +315,8 @@ class HTTPInstance(service.Service):
# Create the password file for this db
password = ipautil.ipa_generate_password()
f = os.open(pwd_file, os.O_CREAT | os.O_RDWR)
os.write(f, password)
os.close(f)
with io.open(pwd_file, 'w') as f:
f.write(password)
ipautil.run([paths.CERTUTIL, "-d", database, "-f", pwd_file, "-N"])