From b33abb4b070d72c16af914e4292adb205bdee5fa Mon Sep 17 00:00:00 2001 From: John Dennis Date: Mon, 26 Aug 2019 19:32:22 -0400 Subject: [PATCH] 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: 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 Change-Id: I07643fbe3e1e712b7eac716a7f671a2d513e920b Closes-Bug: 1841486 Signed-off-by: John Dennis --- keystone/federation/utils.py | 4 +++ keystone/tests/unit/test_cli.py | 26 +++++++++++++++++++ .../notes/bug-1841486-425f367925f5e03f.yaml | 7 +++++ 3 files changed, 37 insertions(+) create mode 100644 releasenotes/notes/bug-1841486-425f367925f5e03f.yaml diff --git a/keystone/federation/utils.py b/keystone/federation/utils.py index 92028fa7db..86bc6569da 100644 --- a/keystone/federation/utils.py +++ b/keystone/federation/utils.py @@ -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. diff --git a/keystone/tests/unit/test_cli.py b/keystone/tests/unit/test_cli.py index 42c771a9f4..cdc0e1327c 100644 --- a/keystone/tests/unit/test_cli.py +++ b/keystone/tests/unit/test_cli.py @@ -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): diff --git a/releasenotes/notes/bug-1841486-425f367925f5e03f.yaml b/releasenotes/notes/bug-1841486-425f367925f5e03f.yaml new file mode 100644 index 0000000000..da7d744509 --- /dev/null +++ b/releasenotes/notes/bug-1841486-425f367925f5e03f.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + [`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.