libvirt: safe_decode xml for i18n logging
The xml argument passed to _create_domain can be a utf-8 encoded string
which causes a UnicodeDecodeError when it is substituted into the _LE
unicode translated message. Safely decoding the xml argument before
attempting to substitute it into the error message avoids the
UnicodeDecodeError.
(cherry picked from commit 96a2283c1a
)
Conflicts:
nova/tests/unit/virt/libvirt/test_driver.py
nova/virt/libvirt/driver.py
Change to strutils (instead of encodeutils) and test is located in
"tests/" instead of "tests/unit/".
Closes-Bug: #1453274
Change-Id: I4cf1836f4ca9097f7c6d98c5212a14d24111fe67
This commit is contained in:
parent
be8be3916f
commit
8f13587ba5
|
@ -9364,12 +9364,17 @@ Active: 8381604 kB
|
|||
self.assertEqual(fake_xml, xml)
|
||||
raise libvirt.libvirtError('virDomainDefineXML() failed')
|
||||
|
||||
def fake_safe_decode(text, *args, **kwargs):
|
||||
return text + 'safe decoded'
|
||||
|
||||
self.log_error_called = False
|
||||
|
||||
def fake_error(msg, *args):
|
||||
self.log_error_called = True
|
||||
self.assertIn(fake_xml, msg % args)
|
||||
self.assertIn('safe decoded', msg % args)
|
||||
|
||||
self.stubs.Set(strutils, 'safe_decode', fake_safe_decode)
|
||||
self.stubs.Set(nova.virt.libvirt.driver.LOG, 'error', fake_error)
|
||||
|
||||
self.create_fake_libvirt_mock(defineXML=fake_defineXML)
|
||||
|
|
|
@ -4370,7 +4370,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
err = None
|
||||
try:
|
||||
if xml:
|
||||
err = _LE('Error defining a domain with XML: %s') % xml
|
||||
err = (_LE('Error defining a domain with XML: %s') %
|
||||
strutils.safe_decode(xml, errors='ignore'))
|
||||
domain = self._conn.defineXML(xml)
|
||||
|
||||
if power_on:
|
||||
|
|
Loading…
Reference in New Issue