From 87a869a408b9732e9ff46e8fecfa1487b3699ffa Mon Sep 17 00:00:00 2001 From: Michele Baldessari Date: Wed, 23 Jan 2019 14:10:41 +0100 Subject: [PATCH] Fix nova_cell_v2_discover_host.py with python3 When this script runs via python3 it fails with: "stdout: ", "stderr: + command -v python3", "+ python3 /docker-config-scripts/nova_cell_v2_discover_host.py", "Traceback (most recent call last):", " File \"/docker-config-scripts/nova_cell_v2_discover_host.py\", line 75, in ", " TypeError: a bytes-like object is required, not 'str'" This is because in python3 subprocess.check_output() will return bytes and trying to split it using a string '\n' will break with the error above. Let's just use the universal_newlines=True parameter which we have been using everywhere in tripleo so far. Also skip any empty lines that might show up in the output which would give the error: ValueError: not enough values to unpack (expected 2, got 0) Tested with a python3 deployment and got a successful deployment (rhel8 os + f28 based-containers). Change-Id: Ic7904c4f3027cc5e7e05d52757e36dbc05f3d487 Co-Authored-By: Damien Ciabrini Closes-Bug: #1813014 --- docker_config_scripts/nova_cell_v2_discover_host.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docker_config_scripts/nova_cell_v2_discover_host.py b/docker_config_scripts/nova_cell_v2_discover_host.py index 768cf56d00..9604773fc3 100644 --- a/docker_config_scripts/nova_cell_v2_discover_host.py +++ b/docker_config_scripts/nova_cell_v2_discover_host.py @@ -48,7 +48,7 @@ try: '/etc/nova/nova.conf', 'DEFAULT', 'host' - ]).rstrip() + ], universal_newlines=True).rstrip() except subprocess.CalledProcessError: # If host isn't set nova defaults to this my_host = socket.gethostname() @@ -58,7 +58,7 @@ except subprocess.CalledProcessError: retries = 10 for i in range(retries): try: - service_list = subprocess.check_output([ + service_output = subprocess.check_output([ 'openstack', '-q', '--os-interface', @@ -72,8 +72,12 @@ for i in range(retries): 'Zone', '-f', 'value' - ]).split('\n') + ], universal_newlines=True) + service_list = service_output.split('\n') for entry in service_list: + # skip any empty lines + if not entry: + continue host, zone = entry.split() if host == my_host and zone != 'internal': print('(cellv2) Service registered, running discovery')