summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2017-04-19 08:50:06 +0200
committerChristian Heimes <cheimes@redhat.com>2017-04-24 12:15:30 +0200
commitfcbabc0ce929d91f63098bba4867d102ac04ead0 (patch)
treedd676b467650eb991a7876e9c896be73c219f91f
parentba32351d7c362e6b0e313cde0929c56f3f55ec5f (diff)
downloadpki-fcbabc0ce929d91f63098bba4867d102ac04ead0.tar.gz
pki-fcbabc0ce929d91f63098bba4867d102ac04ead0.tar.xz
pki-fcbabc0ce929d91f63098bba4867d102ac04ead0.zip
Python 3 support and Travis testing
Fix Python 3 support for pkispawn: Config values are text values. Therefore the config file has to be written as text file. Test Python 3 support in Travis CI. The little script py3rewrite copies pki.server Python files and rewrites pkispawn and pkidestroy to use Python 3. Change-Id: Ia516f80df94cacc2acfa70929ad16bb5b9c39ddf Signed-off-by: Christian Heimes <cheimes@redhat.com>
-rw-r--r--.travis.yml7
-rwxr-xr-x.travis/40-spawn-ca2
-rwxr-xr-x.travis/50-spawn-kra2
-rwxr-xr-x.travis/99-destroy11
-rwxr-xr-x.travis/py3rewrite46
-rw-r--r--base/server/python/pki/server/__init__.py4
6 files changed, 68 insertions, 4 deletions
diff --git a/.travis.yml b/.travis.yml
index 2714bbc5a..54ae88431 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -44,6 +44,13 @@ install:
script:
- docker exec -ti ${CONTAINER} ${SCRIPTDIR}/40-spawn-ca
- docker exec -ti ${CONTAINER} ${SCRIPTDIR}/50-spawn-kra
+ - docker exec -ti ${CONTAINER} ${SCRIPTDIR}/99-destroy
+ # copy pki.server for Python 3 and rewrite pkispawn/pkidestroy shebang
+ - docker exec -ti ${CONTAINER} ${SCRIPTDIR}/py3rewrite
+ - docker exec -ti ${CONTAINER} ${SCRIPTDIR}/30-setup-389ds
+ - docker exec -ti ${CONTAINER} ${SCRIPTDIR}/40-spawn-ca
+ - docker exec -ti ${CONTAINER} ${SCRIPTDIR}/50-spawn-kra
+ - docker exec -ti ${CONTAINER} ${SCRIPTDIR}/99-destroy
after_script:
- docker kill ${CONTAINER}
diff --git a/.travis/40-spawn-ca b/.travis/40-spawn-ca
index 9986698db..d6771dbc9 100755
--- a/.travis/40-spawn-ca
+++ b/.travis/40-spawn-ca
@@ -1,7 +1,7 @@
#!/bin/bash
set -e
-pkispawn -v -f ${BUILDDIR}/pki/.travis/pki.cfg -s CA
+pkispawn -vv -f ${BUILDDIR}/pki/.travis/pki.cfg -s CA
echo "Waiting for port 8080"
for i in {1..20}; do
diff --git a/.travis/50-spawn-kra b/.travis/50-spawn-kra
index 80cb039c9..93f2f4c3f 100755
--- a/.travis/50-spawn-kra
+++ b/.travis/50-spawn-kra
@@ -1,7 +1,7 @@
#!/bin/bash
set -e
-pkispawn -v -f ${BUILDDIR}/pki/.travis/pki.cfg -s KRA
+pkispawn -vv -f ${BUILDDIR}/pki/.travis/pki.cfg -s KRA
echo "Waiting for port 8080"
for i in {1..20}; do
diff --git a/.travis/99-destroy b/.travis/99-destroy
new file mode 100755
index 000000000..d2fb1ad39
--- /dev/null
+++ b/.travis/99-destroy
@@ -0,0 +1,11 @@
+#!/bin/bash
+set -e
+
+if [ -d /etc/pki/pkitest/kra ]; then
+ pkidestroy -v -i pkitest -s KRA
+fi
+
+pkidestroy -v -i pkitest -s CA
+
+remove-ds.pl -f -i slapd-pkitest
+
diff --git a/.travis/py3rewrite b/.travis/py3rewrite
new file mode 100755
index 000000000..f8a208d2e
--- /dev/null
+++ b/.travis/py3rewrite
@@ -0,0 +1,46 @@
+#!/usr/bin/python3
+import os
+import shutil
+
+from distutils.sysconfig import get_python_lib
+
+
+BUILDDIR = os.environ['BUILDDIR']
+PKIBASE = os.path.join(BUILDDIR, 'pki', 'base')
+PKICLIENT = os.path.join(PKIBASE, 'common', 'python', 'pki')
+PKISERVER = os.path.join(PKIBASE, 'server', 'python', 'pki', 'server')
+PKISBIN = os.path.join(PKIBASE, 'server', 'sbin')
+
+SITEPACKAGES = get_python_lib()
+
+
+def copyscript(src, dst):
+ with open(src) as f:
+ lines = f.readlines()
+ lines[0] = '#!/usr/bin/python3\n'
+ with open(dst, 'w') as f:
+ os.fchmod(f.fileno(), 0o755)
+ f.writelines(lines)
+
+
+def copyfiles():
+ shutil.rmtree(os.path.join(SITEPACKAGES, 'pki'))
+ shutil.copytree(
+ PKICLIENT,
+ os.path.join(SITEPACKAGES, 'pki')
+ )
+ shutil.copytree(
+ PKISERVER,
+ os.path.join(SITEPACKAGES, 'pki', 'server')
+ )
+ copyscript(
+ os.path.join(PKISBIN, 'pkispawn'),
+ '/usr/sbin/pkispawn'
+ )
+ copyscript(
+ os.path.join(PKISBIN, 'pkidestroy'),
+ '/usr/sbin/pkidestroy'
+ )
+
+if __name__ == '__main__':
+ copyfiles()
diff --git a/base/server/python/pki/server/__init__.py b/base/server/python/pki/server/__init__.py
index 88986548d..46c6711ed 100644
--- a/base/server/python/pki/server/__init__.py
+++ b/base/server/python/pki/server/__init__.py
@@ -296,9 +296,9 @@ class PKISubsystem(object):
def save(self):
sorted_config = sorted(self.config.items(), key=operator.itemgetter(0))
- with io.open(self.cs_conf, 'wb') as f:
+ with io.open(self.cs_conf, 'w') as f:
for (key, value) in sorted_config:
- f.write('%s=%s\n' % (key, value))
+ f.write(u'%s=%s\n' % (key, value))
def is_valid(self):
return os.path.exists(self.conf_dir)