KeyError on getting PanelGroup

When trying to get a PanelGroup at runtime and
you specify a nonregistered panel, a KeyError is
thrown when calling Dashboard.get_panel_group.
Retrieving values from a Dict using the [] formulation
results in a KeyError for non existent keys.  Using
Dict#get returns None for non existent keys which is
what this change does.

This is relevant to the dynamic panel efforts going on.

Closes-Bug: 1396682
Change-Id: I532c3be04fdd229dfd8e01b68320b2eecb6fd866
This commit is contained in:
Mike Hagedorn 2014-11-26 12:16:22 -05:00
parent ec012c6943
commit 754585d67b
2 changed files with 9 additions and 1 deletions

View File

@ -459,7 +459,10 @@ class Dashboard(Registry, HorizonComponent):
return all_panels
def get_panel_group(self, slug):
return self._panel_groups[slug]
"""Returns the specified :class:~horizon.PanelGroup
or None if not registered
"""
return self._panel_groups.get(slug)
def get_panel_groups(self):
registered = copy.copy(self._registry)

View File

@ -49,3 +49,8 @@ class PanelGroupPluginTests(test.PluginTestCase):
dashboard = horizon.get_dashboard("admin")
self.assertIn(plugin_panel.PluginPanel,
[p.__class__ for p in dashboard.get_panels()])
def test_unregistered_panel_group(self):
dashboard = horizon.get_dashboard("admin")
self.assertIsNone(dashboard.get_panel_group("nonexistent_panel"))