Fix python3 errors in novajoin-ipa-setup

With python3 we are getting the following error:
Traceback (most recent call last):
  File "/usr/bin/novajoin-ipa-setup", line 103, in <module>
    args['tls_ca_cert'] = cafile.decode('UTF-8')
  AttributeError: 'str' object has no attribute 'decode'

Let's just use the normal assignment in case the .decode() call
fails.

Also apply the same fixes to files/cloud-config-novajoin.json

Tested and we correctly get past this error.

Change-Id: Ia77ebde46ff885c9f929d834f981acb97f26a4ec
Co-Authored-By: Luca Miccini <lmiccini@redhat.com>
Closes-Bug: #1820961
This commit is contained in:
Michele Baldessari 2019-03-20 08:55:42 +01:00
parent 74fd4c4357
commit e8b18c4bd4
2 changed files with 9 additions and 3 deletions

View File

@ -1 +1 @@
{"cloud-init": "#cloud-config\npackages:\n - python-simplejson\n - ipa-client\n - ipa-admintools\n - openldap-clients\n - hostname\nwrite_files:\n - content: |\n #!/bin/sh\n \n function get_metadata_config_drive {\n if [ -f /run/cloud-init/status.json ]; then\n # Get metadata from config drive\n data=`cat /run/cloud-init/status.json`\n config_drive=`echo $data | python -c 'import json,re,sys;obj=json.load(sys.stdin);ds=obj.get(\"v1\", {}).get(\"datasource\"); print re.findall(r\"source=(.*)]\", ds)[0]'`\n if [[ -b $config_drive ]]; then\n temp_dir=`mktemp -d`\n mount $config_drive $temp_dir\n if [ -f $temp_dir/openstack/latest/vendor_data2.json ]; then\n data=`cat $temp_dir/openstack/latest/vendor_data2.json`\n umount $config_drive\n rmdir $temp_dir\n else\n umount $config_drive\n rmdir $temp_dir\n fi\n else \n echo \"Unable to retrieve metadata from config drive.\"\n return 1\n fi\n else\n echo \"Unable to retrieve metadata from config drive.\"\n return 1\n fi\n \n return 0\n }\n \n function get_metadata_network {\n # Get metadata over the network\n data=$(timeout 300 /bin/bash -c 'data=\"\"; while [ -z \"$data\" ]; do sleep $[ ( $RANDOM % 10 ) + 1 ]s; data=`curl -s http://169.254.169.254/openstack/2016-10-06/vendor_data2.json 2>/dev/null`; done; echo $data')\n \n if [[ $? != 0 ]] ; then\n echo \"Unable to retrieve metadata from metadata service.\"\n return 1\n fi\n }\n \n \n if ! get_metadata_config_drive; then\n if ! get_metadata_network; then\n echo \"FATAL: No metadata available\"\n exit 1\n fi\n fi\n \n # Get the instance hostname out of the metadata\n fqdn=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get(\"join\", {}).get(\"hostname\", \"\")'`\n \n if [ -z \"$fqdn\" ]; then\n echo \"Unable to determine hostname\"\n exit 1\n fi\n \n realm=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get(\"join\", {}).get(\"krb_realm\", \"\")'`\n otp=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get(\"join\", {}).get(\"ipaotp\", \"\")'`\n \n hostname=`/bin/hostname -f`\n \n # run ipa-client-install\n OPTS=\"-U -w $otp\"\n if [ $hostname != $fqdn ]; then\n OPTS=\"$OPTS --hostname $fqdn\"\n fi\n if [ -n \"$realm\" ]; then\n OPTS=\"$OPTS --realm=$realm\"\n fi\n ipa-client-install $OPTS\n path: /root/setup-ipa-client.sh\n permissions: '0700'\n owner: root:root\nruncmd:\n- sh -x /root/setup-ipa-client.sh > /var/log/setup-ipa-client.log 2>&1"} {"cloud-init": "#cloud-config\npackages:\n - python-simplejson\n - ipa-client\n - ipa-admintools\n - openldap-clients\n - hostname\nwrite_files:\n - content: |\n #!/bin/sh\n \n function get_metadata_config_drive {\n if [ -f /run/cloud-init/status.json ]; then\n # Get metadata from config drive\n data=`cat /run/cloud-init/status.json`\n config_drive=`echo $data | python -c 'import json,re,sys;obj=json.load(sys.stdin);ds=obj.get(\"v1\", {}).get(\"datasource\"); print(re.findall(r\"source=(.*)]\", ds)[0])'`\n if [[ -b $config_drive ]]; then\n temp_dir=`mktemp -d`\n mount $config_drive $temp_dir\n if [ -f $temp_dir/openstack/latest/vendor_data2.json ]; then\n data=`cat $temp_dir/openstack/latest/vendor_data2.json`\n umount $config_drive\n rmdir $temp_dir\n else\n umount $config_drive\n rmdir $temp_dir\n fi\n else \n echo \"Unable to retrieve metadata from config drive.\"\n return 1\n fi\n else\n echo \"Unable to retrieve metadata from config drive.\"\n return 1\n fi\n \n return 0\n }\n \n function get_metadata_network {\n # Get metadata over the network\n data=$(timeout 300 /bin/bash -c 'data=\"\"; while [ -z \"$data\" ]; do sleep $[ ( $RANDOM % 10 ) + 1 ]s; data=`curl -s http://169.254.169.254/openstack/2016-10-06/vendor_data2.json 2>/dev/null`; done; echo $data')\n \n if [[ $? != 0 ]] ; then\n echo \"Unable to retrieve metadata from metadata service.\"\n return 1\n fi\n }\n \n \n if ! get_metadata_config_drive; then\n if ! get_metadata_network; then\n echo \"FATAL: No metadata available\"\n exit 1\n fi\n fi\n \n # Get the instance hostname out of the metadata\n fqdn=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get(\"join\", {}).get(\"hostname\", \"\"))'`\n \n if [ -z \"$fqdn\" ]; then\n echo \"Unable to determine hostname\"\n exit 1\n fi\n \n realm=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get(\"join\", {}).get(\"krb_realm\", \"\"))'`\n otp=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get(\"join\", {}).get(\"ipaotp\", \"\"))'`\n \n hostname=`/bin/hostname -f`\n \n # run ipa-client-install\n OPTS=\"-U -w $otp\"\n if [ $hostname != $fqdn ]; then\n OPTS=\"$OPTS --hostname $fqdn\"\n fi\n if [ -n \"$realm\" ]; then\n OPTS=\"$OPTS --realm=$realm\"\n fi\n ipa-client-install $OPTS\n path: /root/setup-ipa-client.sh\n permissions: '0700'\n owner: root:root\nruncmd:\n- sh -x /root/setup-ipa-client.sh > /var/log/setup-ipa-client.log 2>&1"}

View File

@ -100,10 +100,16 @@ if __name__ == '__main__':
if version.NUM_VERSION >= 40500: if version.NUM_VERSION >= 40500:
cafile = novajoin.create_cafile(opts.server, opts.realm) cafile = novajoin.create_cafile(opts.server, opts.realm)
# Workaround for https://pagure.io/freeipa/issue/7145 # Workaround for https://pagure.io/freeipa/issue/7145
args['tls_ca_cert'] = cafile.decode('UTF-8') try:
args['tls_ca_cert'] = cafile.decode('UTF-8')
except AttributeError:
args['tls_ca_cert'] = cafile
else: else:
nss_db = novajoin.create_nssdb(opts.server, opts.realm) nss_db = novajoin.create_nssdb(opts.server, opts.realm)
args['nss_dir'] = nss_db.secdir.decode('UTF-8') try:
args['nss_dir'] = nss_db.secdir.decode('UTF-8')
except AttributeError:
args['nss_dir'] = nss_db.secdir
api.bootstrap(**args) api.bootstrap(**args)
api.finalize() api.finalize()