Fix logging in federation/idp.py

The existing code would raise a TypeError exception:

  TypeError: Message objects do not support addition.

This is because oslo.i18n Message objects do not support the +
operator and instead require substitution to be used.

Closes-Bug: 1484735
Change-Id: I65e093808b243d8eff5b3cefdf6d64c3d7216801
This commit is contained in:
Brant Knudson 2015-07-17 09:20:43 -05:00
parent e16aa8e5e5
commit 82bddf17cd
2 changed files with 11 additions and 9 deletions

View File

@ -426,11 +426,10 @@ def _sign_assertion(assertion):
stdout = subprocess.check_output(command_list,
stderr=subprocess.STDOUT)
except Exception as e:
msg = _LE('Error when signing assertion, reason: %(reason)s')
msg = msg % {'reason': e}
if hasattr(e, 'output'):
msg += ' output: %(output)s' % {'output': e.output}
LOG.error(msg)
msg = _LE('Error when signing assertion, reason: %(reason)s%(output)s')
LOG.error(msg,
{'reason': e,
'output': ' ' + e.output if hasattr(e, 'output') else ''})
raise exception.SAMLSigningError(reason=e)
finally:
try:

View File

@ -3451,12 +3451,15 @@ class SAMLGenerationTests(FederationTests):
returncode=sample_returncode, cmd=CONF.saml.xmlsec1_binary,
output=sample_output)
# FIXME(blk-u): This should raise exception.SAMLSigningError instead,
# but fails with TypeError due to concatenating string to Message, see
# bug 1484735.
self.assertRaises(TypeError,
logger_fixture = self.useFixture(fixtures.LoggerFixture())
self.assertRaises(exception.SAMLSigningError,
keystone_idp._sign_assertion,
self.signed_assertion)
expected_log = (
"Error when signing assertion, reason: Command '%s' returned "
"non-zero exit status %s %s\n" %
(CONF.saml.xmlsec1_binary, sample_returncode, sample_output))
self.assertEqual(expected_log, logger_fixture.output)
@mock.patch('oslo_utils.fileutils.write_to_tempfile')
def test__sign_assertion_fileutils_exc(self, write_to_tempfile_mock):