Live Migration failure: 'ascii' codec can't encode characters in position 251-252

Bug #1768807 reported by LittleMice
4
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Medium
melanie witt
Rocky
Fix Released
Medium
Tobias Urdin

Bug Description

when i do live migration,it raise the error as below:

2018-05-03 18:38:00.838 1570085 ERROR nova.virt.libvirt.driver [req-7a3691d2-f850-4258-8c7a-54dcaa6189aa 659e4083e38046f8a23060addb53bd96 58942649d31846858f033ee805fcb5bc - default default] [instance: b9f91fe7-70b0-4efc-800a-0482914da186] Live Migration failure: 'ascii' codec can't encode characters in position 251-252: ordinal not in range(128): UnicodeEncodeError: 'ascii' codec can't encode characters in position 251-252: ordinal not in range(128)

I have two computer node: compute1 ,compute2.

The instance created at compute2 migrate to compute1 and migrate back to compute2 is work well.
But the instance created at compute1 migrate to compute2 will make a fault as above.

The two node configure file is same as well.

Revision history for this message
LittleMice (whscfan) wrote :

I has solved this issue.
It is a error encode from unicode use direct with str() function.
The source code is in /usr/lib/python2.7/dist-packages/nova/virt/libvirt/guest.py ,line number is 666.
I has change str(value) to value.encode('utf-8') as below ,which solved the issue.

 # migrateToURI3 via params must not be unicode.
                if six.PY2:
                    LOG.debug("Params items : %s" %params.items())
                    params = {key: value.encode('utf-8') if isinstance(value, unicode)
                                              else value
                              for key, value in params.items()}

Revision history for this message
Zhao Chao (zhaochao1984) wrote :

Looks like this should be related to Nova, tag as "Invalid" first. If the problem still exists in the master of Nova, please change the affected project to Nova, thanks.

Changed in trove:
status: New → Opinion
status: Opinion → Invalid
LittleMice (whscfan)
affects: trove → nova
Changed in nova:
status: Invalid → Incomplete
status: Incomplete → New
melanie witt (melwitt)
tags: added: libvirt
removed: nova openstack
Revision history for this message
melanie witt (melwitt) wrote :

Thanks for including detail about how you were able to fix the issue locally in your environment.

Looking at the code, I think that the destination XML for live migration can contain unicode characters (for example, the guest domain 'name'), so if that's the case, the code LittleMice pasted will fail the call to str():

https://github.com/openstack/nova/blob/2813e785584142411b615f409424345d012fdbc4/nova/virt/libvirt/guest.py#L668

So indeed we need to encode the unicode string in that case.

Changed in nova:
assignee: nobody → melanie witt (melwitt)
importance: Undecided → Medium
status: New → Triaged
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

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

Changed in nova:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/591080
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=f046d8b54009978a3c83939dc190edbc1ebc09ae
Submitter: Zuul
Branch: master

commit f046d8b54009978a3c83939dc190edbc1ebc09ae
Author: melanie witt <email address hidden>
Date: Fri Aug 10 20:28:41 2018 +0000

    Handle unicode characters in migration params

    There can be unicode characters in the params for live migration, for
    example, the guest domain name in the destination XML. We need to
    convert those to bytes when we call migrateToURI3 under python2.

    The existing code was just calling str() for this, but that will fail
    with the error:

      UnicodeEncodeError: 'ascii' codec can't encode characters...

    We need to encode the unicode characters to do conversion.

    The existing unit test wasn't using any unicode characters in its test
    data, so this scenario wasn't covered.

    Closes-Bug: #1768807

    Change-Id: I4b34139a3c5e3e2b7cf7cbe50bdf3da3131b9b1c

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/rocky)

Fix proposed to branch: stable/rocky
Review: https://review.openstack.org/618734

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/rocky)

Reviewed: https://review.openstack.org/618734
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=7520d159b5c33757fce398224e053183ff118663
Submitter: Zuul
Branch: stable/rocky

commit 7520d159b5c33757fce398224e053183ff118663
Author: melanie witt <email address hidden>
Date: Fri Aug 10 20:28:41 2018 +0000

    Handle unicode characters in migration params

    There can be unicode characters in the params for live migration, for
    example, the guest domain name in the destination XML. We need to
    convert those to bytes when we call migrateToURI3 under python2.

    The existing code was just calling str() for this, but that will fail
    with the error:

      UnicodeEncodeError: 'ascii' codec can't encode characters...

    We need to encode the unicode characters to do conversion.

    The existing unit test wasn't using any unicode characters in its test
    data, so this scenario wasn't covered.

    Closes-Bug: #1768807

    Change-Id: I4b34139a3c5e3e2b7cf7cbe50bdf3da3131b9b1c
    (cherry picked from commit f046d8b54009978a3c83939dc190edbc1ebc09ae)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 18.1.0

This issue was fixed in the openstack/nova 18.1.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/queens)

Fix proposed to branch: stable/queens
Review: https://review.openstack.org/636678

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/queens)

Reviewed: https://review.openstack.org/636678
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=4c127db2f35329fda5f09be1f968f9a32b8c6836
Submitter: Zuul
Branch: stable/queens

commit 4c127db2f35329fda5f09be1f968f9a32b8c6836
Author: melanie witt <email address hidden>
Date: Fri Aug 10 23:28:00 2018 +0300

    Handle unicode characters in migration params

    There can be unicode characters in the params for live migration, for
    example, the guest domain name in the destination XML. We need to
    convert those to bytes when we call migrateToURI3 under python2.

    The existing code was just calling str() for this, but that will fail
    with the error:

      UnicodeEncodeError: 'ascii' codec can't encode characters...

    We need to encode the unicode characters to do conversion.

    The existing unit test wasn't using any unicode characters in its test
    data, so this scenario wasn't covered.

    Conflicts:
     nova/tests/unit/virt/libvirt/test_guest.py
     nova/virt/libvirt/guest.py

    NOTE(s10): Conflict is caused by Id9ee1feeadf612fa79c3d280cee3a614a74a00a7
    not being in Queens.

    Closes-Bug: #1768807

    Change-Id: I4b34139a3c5e3e2b7cf7cbe50bdf3da3131b9b1c
    (cherry picked from commit f046d8b54009978a3c83939dc190edbc1ebc09ae)
    (cherry picked from commit 7520d159b5c33757fce398224e053183ff118663)

tags: added: in-stable-queens
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 19.0.0.0rc1

This issue was fixed in the openstack/nova 19.0.0.0rc1 release candidate.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 17.0.10

This issue was fixed in the openstack/nova 17.0.10 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.