Zun

python3-zunclient - argument must be str, not bytes

Bug #1845394 reported by David Ivey
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Zun
Fix Committed
Critical
hongbin

Bug Description

I ran into the stack trace below when trying to attach to an existing container while troubleshooting why I could not get an interactive session. I am running openstack stein release on Ubuntu 18.04 and building zun based off of the stable/stein branch. When I run `openstack --debug appcontainer run --interactive --name mycontainer4 --net network=9853a758-876e-425b-be34-4c5c1dcc1ab9 cirros` /bin/sh everything works until it drops starts the main loop into the client.

POST call to container for https://dev-vta.cybbh.space:9517/v1/containers/6cd17799-76b4-4d38-9ae7-50e2923bbbf7/resize?w=267&h=62 used request id req-422d60d5-afe5-4f41-9fff-881f586513f1
putting tty into raw mode
starting main loop in client
                           entering close_wait
                                              quitting
                                                      restoring tty
that output does not provide much detail on why it closed the connections so I ran `openstack appcontainer --debug exec --interactive mycontainer4 /bin/sh` and received a lot more detail. It seems to be a python2 vs python3 bug. see stack trace below. I have not done any testing using python-zunclient instead.

Truncated output
putting tty into raw mode
starting main loop in client
                            restoring tty configuration
                                                       write() argument must be str, not bytes
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cliff/app.py", line 401, in run_subcommand
    result = cmd.run(parsed_args)
  File "/usr/lib/python3/dist-packages/osc_lib/command/command.py", line 41, in run
    return super(Command, self).run(parsed_args)
  File "/usr/lib/python3/dist-packages/cliff/command.py", line 184, in run
    return_code = self.take_action(parsed_args) or 0
  File "/usr/lib/python3/dist-packages/zunclient/osc/v1/containers.py", line 604, in take_action
    websocketclient.do_exec(client, url, container, exec_id, "~", 0.5)
  File "/usr/lib/python3/dist-packages/zunclient/common/websocketclient/websocketclient.py", line 389, in do_exec
    wscls.start_loop()
  File "/usr/lib/python3/dist-packages/zunclient/common/websocketclient/websocketclient.py", line 90, in start_loop
    self.run_forever()
  File "/usr/lib/python3/dist-packages/zunclient/common/websocketclient/websocketclient.py", line 108, in run_forever
    self.handle_socket(event)
  File "/usr/lib/python3/dist-packages/zunclient/common/websocketclient/websocketclient.py", line 182, in handle_socket
    sys.stdout.write(data)
TypeError: write() argument must be str, not bytes
clean_up ExecContainer: write() argument must be str, not bytes
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/osc_lib/shell.py", line 136, in run
    ret_val = super(OpenStackShell, self).run(argv)
  File "/usr/lib/python3/dist-packages/cliff/app.py", line 281, in run
    result = self.run_subcommand(remainder)
  File "/usr/lib/python3/dist-packages/osc_lib/shell.py", line 176, in run_subcommand
    ret_value = super(OpenStackShell, self).run_subcommand(argv)
  File "/usr/lib/python3/dist-packages/cliff/app.py", line 401, in run_subcommand
    result = cmd.run(parsed_args)
  File "/usr/lib/python3/dist-packages/osc_lib/command/command.py", line 41, in run
    return super(Command, self).run(parsed_args)
  File "/usr/lib/python3/dist-packages/cliff/command.py", line 184, in run
    return_code = self.take_action(parsed_args) or 0
  File "/usr/lib/python3/dist-packages/zunclient/osc/v1/containers.py", line 604, in take_action
    websocketclient.do_exec(client, url, container, exec_id, "~", 0.5)
  File "/usr/lib/python3/dist-packages/zunclient/common/websocketclient/websocketclient.py", line 389, in do_exec
    wscls.start_loop()
  File "/usr/lib/python3/dist-packages/zunclient/common/websocketclient/websocketclient.py", line 90, in start_loop
    self.run_forever()
  File "/usr/lib/python3/dist-packages/zunclient/common/websocketclient/websocketclient.py", line 108, in run_forever
    self.handle_socket(event)
  File "/usr/lib/python3/dist-packages/zunclient/common/websocketclient/websocketclient.py", line 182, in handle_socket
    sys.stdout.write(data)
TypeError: write() argument must be str, not bytes

END return value: 1

I can give you more details if needed

hongbin (hongbin034)
Changed in zun:
status: New → Triaged
importance: Undecided → High
assignee: nobody → hongbin (hongbin034)
Revision history for this message
hongbin (hongbin034) wrote :

@David,

Thanks for reporting the bug. I proposed a fix in master and will try to backport it to stable branches.

Changed in zun:
importance: High → Critical
Revision history for this message
David Ivey (yevi) wrote :

No problem, I will test your fix in my environment this morning and see if it works.

Revision history for this message
David Ivey (yevi) wrote :

After applying the fix you proposed I have not been able to reproduce the issue so far.

Revision history for this message
hongbin (hongbin034) wrote :

Sounds good. Thanks for confirming @David.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-zunclient 3.6.0

This issue was fixed in the openstack/python-zunclient 3.6.0 release.

Revision history for this message
samos667 (samos667) wrote :

Hi i have exactly the same error, you can tell me how i can fix this ?

Revision history for this message
samos667 (samos667) wrote :
Download full text (26.4 KiB)

root@sam:~# openstack --debug appcontainer exec --interactive container /bin/sh
START with options: --debug appcontainer exec --interactive container /bin/sh
options: Namespace(access_key='', access_secret='***', access_token='***', access_token_endpoint='', access_token_type='', application_credential_id='', application_credential_name='', application_credential_secret='***', auth_type='', auth_url='http://controller:5000/v3', cacert=None, cert='', client_id='', client_secret='***', cloud='', code='', consumer_key='', consumer_secret='***', debug=True, default_domain='default', default_domain_id='', default_domain_name='', deferred_help=False, discovery_endpoint='', domain_id='', domain_name='', endpoint='', identity_provider='', identity_provider_url='', insecure=None, interface='public', key='', log_file=None, openid_scope='', os_beta_command=False, os_compute_api_version='', os_container_api_version='1', os_dns_api_version='2', os_identity_api_version='3', os_image_api_version='', os_key_manager_api_version='1', os_network_api_version='', os_object_api_version='', os_orchestration_api_version='1', os_project_id=None, os_project_name=None, os_volume_api_version='', passcode='', password='***', profile='', project_domain_id='', project_domain_name='Default', project_id='', project_name='admin', protocol='', redirect_uri='', region_name='', remote_project_domain_id='', remote_project_domain_name='', remote_project_id='', remote_project_name='', service_provider='', service_provider_endpoint='', service_provider_entity_id='', system_scope='', timing=False, token='***', trust_id='', url='', user_domain_id='', user_domain_name='Default', user_id='', username='admin', verbose_level=3, verify=None)
Auth plugin password selected
auth_config_hook(): {'api_timeout': None, 'verify': True, 'cacert': None, 'cert': None, 'key': None, 'baremetal_status_code_retries': '5', 'image_status_code_retries': '5', 'disable_vendor_agent': {}, 'interface': 'public', 'floating_ip_source': 'neutron', 'image_api_use_tasks': False, 'image_format': 'qcow2', 'message': '', 'network_api_version': '2', 'object_store_api_version': '1', 'secgroup_source': 'neutron', 'status': 'active', 'auth': {'user_domain_name': 'Default', 'project_domain_name': 'Default', 'project_name': 'admin'}, 'verbose_level': 3, 'deferred_help': False, 'debug': True, 'default_domain': 'default', 'timing': False, 'auth_url': 'http://controller:5000/v3', 'username': 'admin', 'password': '***', 'beta_command': False, 'identity_api_version': '3', 'container_api_version': '1', 'orchestration_api_version': '1', 'dns_api_version': '2', 'key_manager_api_version': '1', 'region_name': '', 'auth_type': 'password', 'networks': []}
defaults: {'api_timeout': None, 'verify': True, 'cacert': None, 'cert': None, 'key': None, 'auth_type': 'password', 'baremetal_status_code_retries': 5, 'image_status_code_retries': 5, 'disable_vendor_agent': {}, 'interface': 'public', 'floating_ip_source': 'neutron', 'image_api_use_tasks': False, 'image_format': 'qcow2', 'message': '', 'network_api_version': '2', 'object_store_api_version': '1', 'secgroup_source': 'neutron', 'status': 'active'}
cloud cfg: {'api_timeout': None, 'verify'...

Revision history for this message
samos667 (samos667) wrote :

i have install zunclient today, how i can install 3.6 release ?

Revision history for this message
samos667 (samos667) wrote :
Revision history for this message
samos667 (samos667) wrote :

Finnaly i have check what is my version of my installed version of python-zunclient and it's version 3.6.
I would like to know if my problem comes from me or the client.

Revision history for this message
samos667 (samos667) wrote :

edit: i have manually update python-zunclient with:
# pip install --upgrade python-zunclient

But he also not work :(

Revision history for this message
samos667 (samos667) wrote :

ok so I solved my problem by manually editing the file "/usr/lib/python3/dist-packages/zunclient/common/websocketclient/websocketclient.py" by adding this https://github.com/openstack/python-zunclient/commit/54b24b3a731209f7144f6963c7fa30ed9c0a926a and modifying it https://github.com/openstack/python-zunclient/commit/bc1cfd9737380a4827fec97152139e6c2e918f38
Thanks to hongbin for the fix !

Revision history for this message
hongbin (hongbin034) wrote :

@samos667,

Both fixes are in python-zunclient 3.6.0 or later.

Revision history for this message
hongbin (hongbin034) wrote :

Fixed by: https://review.opendev.org/#/c/684878/ . I am going to close this bug.

Changed in zun:
status: Triaged → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-zunclient 3.5.1

This issue was fixed in the openstack/python-zunclient 3.5.1 release.

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

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.