'nova delete' of instance with unicode display_name raises CommandError

Bug #1403379 reported by Eli Qiao on 2014-12-17
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-novaclient
Medium
Ryan Selden

Bug Description

can not delete an instance which display name is Chinese.
[tagett@stack-01 devstack]$ nova --debug delete 测试

'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
DEBUG (shell:908) Unable to delete the specified server(s).
Traceback (most recent call last):
  File "/opt/stack/python-novaclient/novaclient/shell.py", line 905, in main
    OpenStackComputeShell().main(argv)
  File "/opt/stack/python-novaclient/novaclient/shell.py", line 832, in main
    args.func(self.cs, args)
  File "/opt/stack/python-novaclient/novaclient/v1_1/shell.py", line 1876, in do_delete
    _("Unable to delete the specified server(s)."))
  File "/opt/stack/python-novaclient/novaclient/utils.py", line 320, in do_action_on_many
    raise exceptions.CommandError(error_msg)

Eli Qiao (taget-9) on 2014-12-17
affects: nova → python-novaclient
lvmxh (shaohef) on 2014-12-17
Changed in python-novaclient:
assignee: nobody → lvmxh (shaohef)

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

Changed in python-novaclient:
status: New → In Progress
lvmxh (shaohef) on 2014-12-24
information type: Public → Public Security
information type: Public Security → Private Security

Why was this bug switched to a security vulnerability? Also, why make it private when it was already public for days and has a corresponding patch in our public code review system?

I'm switching this back to public security for now, and will add an incomplete security advisory task if you intend for it to be evaluated for that purpose.

Jeremy Stanley (fungi) on 2014-12-24
information type: Private Security → Public Security
Jeremy Stanley (fungi) on 2015-01-01
information type: Public Security → Public

Change abandoned by Joe Gordon (<email address hidden>) on branch: master
Review: https://review.openstack.org/143635
Reason: This review is > 4 weeks without comment, and failed Jenkins the last time it was checked. We are abandoning this for now. Feel free to reactivate the review by pressing the restore button and leaving a 'recheck' comment to get fresh test results.

@lvmxh: Are you still planning to work on this bug ?

Changed in python-novaclient:
assignee: lvmxh (shaohef) → nobody
melanie witt (melwitt) wrote :

I think this is a duplicate likely fixed by https://review.openstack.org/#/c/248626/

melanie witt (melwitt) wrote :

Sorry, nevermind. That fix was for listing instances with unicode characters in display_name.

I was able to reproduce this bug with novaclient 4.0.0 by:

$ nova boot --image cirros-0.3.4-x86_64-uec --flavor m1.nano --poll 测试
$ nova delete 测试
'ascii' codec can't encode characters in position 25-26: ordinal not in range(128)
ERROR (CommandError): Unable to delete the specified server(s).

Changed in python-novaclient:
importance: Undecided → Medium
status: In Progress → Confirmed
tags: added: low-hanging-fruit
melanie witt (melwitt) wrote :

Even more interesting, the instance is actually deleted with 'nova delete' but the command shows an error anyway, trying to print the success message.

summary: - can not delete an instance with Chinese name
+ 'nova delete' of instance with unicode display_name raises CommandError
Changed in python-novaclient:
assignee: nobody → Anusha Unnam (anusha-unnam)
Changed in python-novaclient:
status: Confirmed → In Progress
Anusha Unnam (anusha-unnam) wrote :

Hi,

This bug is valid only if the system default encoding is ANSI. If the system default encoding is UTF-8 everything works fine. Unicode can be fully represented within UTF-8.

The print statement "print(success_msg % resource)" from do_action_on_many() in novaclient/utils.py is causing the error. It was trying to print the unicode characters(name of server), if the default encoding is ANSI it is giving the unicodeencodeerror since ANSI has no such characters, which is leading to commanderror.

The default encoding can be changed by adding this line "export LC_ALL=en_US.UTF-8" in bashrc file.

So can I add in the code to change the default encoding to UTF-8 if it is not already UTF-8?

not only nova delete, other commands also giving the same error if any of them are trying to print the unicode characters. Can anyone suggest me if I am wrong and any other suggestions?

Hi All,

On current master code, the same error message "'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)" displayed on the console when user passes the 4 byte unicode charater to the below listed apis,

List of APIs failing:

1. aggregate-delete
2. aggregate-remove-host
3. aggregate-show
4. delete
5. flavor-show
6. floating-ip-delete
7. get-mks-console
8. get-password
9. get-rdp-console
10. get-serial-console
11. get-spice-consol
12. get-vnc-console
13. host-update
14. hypervisor-show
15. keypair-delete
16. keypair-show
17. lock
18. migrate
19. network-delete
20. network-show
21. reboot
22. rebuild
23. remove-fixed-ip
24. remove-secgroup
25. rename
26. rescue
27. reset-network
30. reset-state
31. resize
32. resize-confirm
33. resize-revert
34. resume
35. secgroup-delete
36. secgroup-update
37. server-group-delete
38. server-group-get
39. server-migration-show
40. server-tag-delete
41. set-password
42. shelve
43. shelve-offload
44. show
45. ssh
46. start
47. stop
48. suspend
50. unlock
51. unpause
52. unrescue
53. unshelve
54. update
55. volume-update
56. volume-attach
57. volume-attachments
58. volume-detach
59. restore
60. host-action

Ryan Selden (ryanx-seldon) wrote :

I've got a fix for this so I'll post it because nothing's happened in a while.

Changed in python-novaclient:
assignee: Anusha Unnam (anusha-unnam) → Ryan Selden (ryanx-seldon)

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

Change abandoned by Anusha Unnam (<email address hidden>) on branch: master
Review: https://review.openstack.org/323550

Reviewed: https://review.openstack.org/346026
Committed: https://git.openstack.org/cgit/openstack/python-novaclient/commit/?id=d8c07006dd85ad64a4a4a4cb47558c0a19e42e24
Submitter: Jenkins
Branch: master

commit d8c07006dd85ad64a4a4a4cb47558c0a19e42e24
Author: bhagyashris <email address hidden>
Date: Tue Jul 5 19:24:21 2016 +0530

    Fix 'UnicodeEncodeError' for unicode values

    Used '%' instead of format() because "%" formatting operation
    returns a unicode string for both unicode and non-unicode
    format strings.

    Encoded the exception error message in novaclient.shell.main and
    novaclient.utils.do_action_on_many method to avoid
    "UnicodeEncodeError" and print valid message.

    NOTE:
    Not used u'{0}.format(<str>) because in python 3 everything
    is unicode so no need to add explicit 'u' to format string.

    Closes-Bug: #1403379
    Change-Id: I13f1ef2e1b41299b417cad3759a5cda241890df7

Changed in python-novaclient:
status: In Progress → Fix Released

Change abandoned by Sean Dague (<email address hidden>) on branch: master
Review: https://review.openstack.org/350230
Reason: This review is > 6 weeks without comment, and failed Jenkins the last time it was checked. We are abandoning this for now. Feel free to reactivate the review by pressing the restore button and leaving a 'recheck' comment to get fresh test results.

This issue was fixed in the openstack/python-novaclient 7.0.0 release.

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

Other bug subscribers