Federation mapping debug should show direct_maps values

If you use keystone-manage mapping_engine --engine-debug to test your
rules (or when debug logging is on during run time) the diagnostic
output fails to emit a piece of crucial information, the contents
direct map array. What you'll get instead is this:

direct_maps: <keystone.federation.utils.DirectMaps object at 0x7f7121887b00>

That's because the DirectMaps class does not have a __str__() method
and Python resorts to __ref__() in the absence of __str__() and all
__ref__() does is print the class name and it's memory location, not
very useful.

This patch adds a __str__() method to the DirectMaps class so the
debug output now includes the actual direct map data like this:

direct_maps: [['jdoe@example.com'], ['Group1', 'Group3']]

Co-Authored-By: Lance Bragstad <lbragstad@gmail.com>
Change-Id: I07643fbe3e1e712b7eac716a7f671a2d513e920b
Closes-Bug: 1841486
Signed-off-by: John Dennis <jdennis@redhat.com>
This commit is contained in:
John Dennis 2019-08-26 19:32:22 -04:00 committed by Colleen Murphy
parent 22f34056cc
commit b33abb4b07
3 changed files with 37 additions and 0 deletions

View File

@ -243,6 +243,10 @@ class DirectMaps(object):
def __init__(self):
self._matches = []
def __str__(self):
"""return the direct map array as a string."""
return '%s' % self._matches
def add(self, values):
"""Add a matched value to the list of matches.

View File

@ -1866,6 +1866,32 @@ class TestMappingEngineTester(unit.BaseTestCase):
self.assertRaises(exception.ValidationError,
mapping_engine.main)
def test_mapping_engine_tester_logs_direct_maps(self):
tempfilejson = self.useFixture(temporaryfile.SecureTempFile())
tmpfilejsonname = tempfilejson.file_name
updated_mapping = copy.deepcopy(mapping_fixtures.MAPPING_SMALL)
with open(tmpfilejsonname, 'w') as f:
f.write(jsonutils.dumps(updated_mapping))
self.command_rules = tmpfilejsonname
tempfile = self.useFixture(temporaryfile.SecureTempFile())
tmpfilename = tempfile.file_name
with open(tmpfilename, 'w') as f:
f.write("\n")
f.write("UserName:me\n")
f.write("orgPersonType:NoContractor\n")
f.write("LastName:Bo\n")
f.write("FirstName:Jill\n")
self.command_input = tmpfilename
self.command_prefix = None
self.command_engine_debug = True
self.useFixture(fixtures.MockPatchObject(
CONF, 'command', self.FakeConfCommand(self)))
mapping_engine = cli.MappingEngineTester()
logging = self.useFixture(fixtures.FakeLogger(level=log.DEBUG))
mapping_engine.main()
expected_msg = "direct_maps: [['me']]"
self.assertThat(logging.output, matchers.Contains(expected_msg))
class CliStatusTestCase(unit.SQLDriverOverrides, unit.TestCase):

View File

@ -0,0 +1,7 @@
---
fixes:
- |
[`bug 1841486 <https://bugs.launchpad.net/keystone/+bug/1841486>`_]
The ``keystone-manage mapping_engine --engine-debug`` CLI tool now outputs
useful information about the direct mappings from an assertion after
processing mapping rules.