python3: overcloud deployment with network isolation fails

Bug #1819665 reported by Emilien Macchi on 2019-03-12
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tripleo
High
Emilien Macchi

Bug Description

Deploying an overcloud on a host with Python 3 only fails if network isolation is enabled:

Creating Swift container to store the plan
Creating plan from template files in: /tmp/tripleoclient-432c7fy7/tripleo-heat-templates
Exception occured while running the command
Traceback (most recent call last):
  File "/usr/lib64/python3.6/http/client.py", line 986, in send
    self.sock.sendall(data)
TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/tripleoclient/command.py", line 29, in run
    super(Command, self).run(parsed_args)
  File "/usr/lib/python3.6/site-packages/osc_lib/command/command.py", line 41, in run
    return super(Command, self).run(parsed_args)
  File "/usr/lib/python3.6/site-packages/cliff/command.py", line 184, in run
    return_code = self.take_action(parsed_args) or 0
  File "/usr/lib/python3.6/site-packages/tripleoclient/v1/overcloud_deploy.py", line 908, in take_action
    self._deploy_tripleo_heat_templates_tmpdir(stack, parsed_args)
  File "/usr/lib/python3.6/site-packages/tripleoclient/v1/overcloud_deploy.py", line 365, in _deploy_tripleo_heat_templates_tmpdir
    new_tht_root, tht_root)
  File "/usr/lib/python3.6/site-packages/tripleoclient/v1/overcloud_deploy.py", line 396, in _deploy_tripleo_heat_templates
    parsed_args.networks_file)
  File "/usr/lib/python3.6/site-packages/tripleoclient/workflows/plan_management.py", line 169, in create_plan_from_templates
    plan_env_file, networks_file)
  File "/usr/lib/python3.6/site-packages/tripleoclient/workflows/plan_management.py", line 50, in _upload_templates
    utils.rel_or_abs_path(roles_file, tht_root))
  File "/usr/lib/python3.6/site-packages/tripleoclient/workflows/plan_management.py", line 278, in _upload_file
    swift_client.put_object(container, filename, file_content)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 1895, in put_object
    response_dict=response_dict)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 1737, in _retry
    service_token=self.service_token, **kwargs)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 1364, in put_object
    conn.putrequest(path, headers=headers, data=data)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 468, in putrequest
    return self.request('PUT', full_path, data, headers, files)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 458, in request
    files=files, **self.requests_args)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 441, in _request
    return self.request_session.request(*arg, **kwarg)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 472, in send
    low_conn.send(i)
  File "/usr/lib64/python3.6/http/client.py", line 990, in send
    self.sock.sendall(d)
TypeError: a bytes-like object is required, not 'str'
a bytes-like object is required, not 'str'

Changed in tripleo:
milestone: none → stein-3
importance: Undecided → High
status: New → Triaged
assignee: nobody → Emilien Macchi (emilienm)
Michele Baldessari (michele) wrote :

Here is a smaller reproducer (aka one that uses the newly-introduced wrappers for swift)
(undercloud) [stack@undercloud-0 ~]$ echo 'test' > /tmp/foo
(undercloud) [stack@undercloud-0 ~]$ python3 prova.py
Traceback (most recent call last):
  File "/usr/lib64/python3.6/http/client.py", line 986, in send
    self.sock.sendall(data)
TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "prova.py", line 26, in <module>
    swiftutils.put_object_string(conn, 'overcloud', 'foo', file_content)
  File "/usr/lib/python3.6/site-packages/tripleo_common/utils/swift.py", line 192, in put_object_string
    return swift.put_object(container, object_name, contents)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 1895, in put_object
    response_dict=response_dict)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 1737, in _retry
    service_token=self.service_token, **kwargs)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 1364, in put_object
    conn.putrequest(path, headers=headers, data=data)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 468, in putrequest
    return self.request('PUT', full_path, data, headers, files)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 458, in request
    files=files, **self.requests_args)
  File "/usr/lib/python3.6/site-packages/swiftclient/client.py", line 441, in _request
    return self.request_session.request(*arg, **kwarg)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 472, in send
    low_conn.send(i)
  File "/usr/lib64/python3.6/http/client.py", line 990, in send
    self.sock.sendall(d)
TypeError: a bytes-like object is required, not 'str'
(undercloud) [stack@undercloud-0 ~]$ cat prova.py
from keystoneauth1 import session
from keystoneauth1.identity import v3
from swiftclient.client import Connection
from tripleo_common.utils import swift as swiftutils

_authurl = 'http://192.168.24.1:5000/v3/'
_auth_version = '3'
_user = 'admin'
# (sudo hiera -c /etc/puppet/hiera.yaml keystone::admin_password)
_key = '6aMpWobr5ySX47vwJefUgMGAA'
_os_options = {
    'user_domain_name': 'Default',
    'project_domain_name': 'Default',
    'project_name': 'admin'
}

conn = Connection(
    authurl=_authurl,
    user=_user,
    key=_key,
    os_options=_os_options,
    auth_version=_auth_version
)

with open('/tmp/foo') as file_content:
    swiftutils.put_object_string(conn, 'overcloud', 'foo', file_content)

Fix proposed to branch: master
Review: https://review.openstack.org/642766

Changed in tripleo:
status: Triaged → In Progress

Reviewed: https://review.openstack.org/642766
Committed: https://git.openstack.org/cgit/openstack/python-tripleoclient/commit/?id=39822599734e3aa3995e25e3c2ca09acc5d1aff9
Submitter: Zuul
Branch: master

commit 39822599734e3aa3995e25e3c2ca09acc5d1aff9
Author: Emilien Macchi <email address hidden>
Date: Tue Mar 12 10:34:04 2019 -0400

    Make _upload_file to work with Python 3

    Open the content from the file in Swift as bytes and in read
    mode, otherwise Python 3 fails to open it as it comes as a string by default.

    Closes-Bug: #1819665
    Change-Id: I0da24d3508174190b431b660e67365f242ef04d8

Changed in tripleo:
status: In Progress → Fix Released

This issue was fixed in the openstack/python-tripleoclient 11.4.0 release.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers