From ed1838b7afb4ba8f96c4ab8b2b7cba24e481ed0b Mon Sep 17 00:00:00 2001 From: Grzegorz Grasza Date: Mon, 26 Nov 2018 17:32:42 +0100 Subject: [PATCH] Fix errors preventing novajoin to start on Python 3 This patch also moves the novajoin-install and novajoin-ipa-setup scripts to the default python scripts directory. This is because there is no other way to fixup the #! line for python3, apart from modifying setup.py, which is managed by the global requirements repo. Change-Id: I21ccb475905feebdb91aa158ce3845744b2f0a5f --- .gitignore | 1 + novajoin/configure_ipa.py | 2 +- novajoin/ipa.py | 12 ++++++------ requirements.txt | 1 + scripts/novajoin-install | 8 ++++---- setup.cfg | 7 ++++--- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 6c4bce4..0719691 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ files/join.conf tools/lintstack.head.py *.pyc *.egg-info/ +.eggs/ .tox .testrepository .stestr diff --git a/novajoin/configure_ipa.py b/novajoin/configure_ipa.py index ec5c890..0430d50 100644 --- a/novajoin/configure_ipa.py +++ b/novajoin/configure_ipa.py @@ -56,7 +56,7 @@ import nss.nss as nss logger = logging.getLogger() -allowed_chars = string.letters + string.digits +allowed_chars = string.ascii_letters + string.digits KRB5_CONF_TMPL = """ includedir /var/lib/sss/pubconf/krb5.include.d/ diff --git a/novajoin/ipa.py b/novajoin/ipa.py index 6af9d62..c099d37 100644 --- a/novajoin/ipa.py +++ b/novajoin/ipa.py @@ -105,7 +105,7 @@ class IPANovaJoinBase(object): def split_hostname(self, hostname): """Split a hostname into its host and domain parts""" parts = hostname.split('.') - domain = ('.'.join(parts[1:]) + '.').decode('UTF-8') + domain = six.text_type('.'.join(parts[1:]) + '.') return (parts[0], domain) def get_host_and_realm(self): @@ -282,7 +282,7 @@ class IPAClient(IPANovaJoinBase): # 'description': 'IPA host for %s' % inst.display_description, hostargs = { 'description': u'IPA host for OpenStack', - 'userpassword': ipaotp.decode('UTF-8'), + 'userpassword': six.text_type(ipaotp), 'force': True # we don't have an ip addr yet so # use force to add anyway } @@ -295,23 +295,23 @@ class IPAClient(IPANovaJoinBase): hostargs['nshostlocation'] = location modargs = { - 'userpassword': ipaotp.decode('UTF-8'), + 'userpassword': six.text_type(ipaotp), } try: self._call_ipa('host_mod', *params, **modargs) - self.host_cache[hostname] = ipaotp.decode('UTF-8') + self.host_cache[hostname] = six.text_type(ipaotp) except errors.NotFound: try: self._call_ipa('host_add', *params, **hostargs) - self.host_cache[hostname] = ipaotp.decode('UTF-8') + self.host_cache[hostname] = six.text_type(ipaotp) except errors.DuplicateEntry: # We have no idea what the OTP is for the existing host. return False except (errors.ValidationError, errors.DNSNotARecordError): # Assumes despite these exceptions the host was created # and the OTP was set. - self.host_cache[hostname] = ipaotp.decode('UTF-8') + self.host_cache[hostname] = six.text_type(ipaotp) except errors.ValidationError: # Updating the OTP on an enrolled-host is not allowed # in IPA and really a no-op. diff --git a/requirements.txt b/requirements.txt index 51cb2c3..685c9d0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,7 @@ six>=1.10.0 # MIT python-keystoneclient>=3.8.0 # Apache-2.0 keystoneauth1>=3.3.0 # Apache-2.0 oslo.concurrency>=3.25.0 # Apache-2.0 +oslo.config>=6.1.0 # Apache-2.0 oslo.messaging>=5.29.0 # Apache-2.0 oslo.policy>=1.30.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 diff --git a/scripts/novajoin-install b/scripts/novajoin-install index 74786c4..4ebed00 100755 --- a/scripts/novajoin-install +++ b/scripts/novajoin-install @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright 2016 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -79,8 +79,7 @@ def install(opts): os.environ['OS_USERNAME'] os.environ['OS_AUTH_URL'] except KeyError as e: - raise ConfigurationError('%s environment variable not set.' - % e.message) + raise ConfigurationError('%s environment variable not set.' % e) try: pwd.getpwnam(opts.user) @@ -89,12 +88,13 @@ def install(opts): opts.user) api.bootstrap(context='novajoin') - api.finalize() novajoin = configure_ipa.NovajoinRole(user=opts.user) if not opts.no_kinit: novajoin.kinit(opts.principal, api.env.realm, opts.password) + api.finalize() + try: api.Backend.rpcclient.connect() except errors.CCacheError: diff --git a/setup.cfg b/setup.cfg index 075cfa1..c0d07e1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,9 +32,6 @@ data_files = /etc/novajoin = files/join-api-paste.ini files/cloud-config-novajoin.json - /usr/sbin = - scripts/novajoin-install - /usr/libexec = scripts/novajoin-ipa-setup /usr/share/man/man1 = man/novajoin-install.1 man/novajoin-notify.1 @@ -43,6 +40,10 @@ data_files = packages = novajoin +scripts = + scripts/novajoin-install + scripts/novajoin-ipa-setup + [build_sphinx] source-dir = doc/source build-dir = doc/build