e2ef492311
Revert fix from bug #1329050, which adds a plugin panel to its dashboard's class. Adding a plugin panel to a dashboard whose class has its panels defined in a tuple will fail because the new plugin cannot be appended to the tuple. The code errors out before the panel gets added to the dashboard's panel list. However, at this point, the panel has already been registered with the dashboard. This causes Dashboard.get_panels() to see the panel in its registry but not in its panel groups. Consequently, the panel gets put in the "Other" panel group instead of its configured one, as described in bug #1378558. By not adding the the plugin panel to its dashboard's class, the panel gets added to its dashboard's panel list. Now the original issue from bug #1329050 resurfaces. The root cause of that is that every time Dashboard._autodiscover() is called, it instantiates all its panel group classes, wiping out any panels previously added to any of the panel groups. Avoid this by always processing all the plugin panel groups before any of the plugin panels, which also ensures that the panel groups exist before their panels. Making this change exposed an issue where the Horizon URLs were being loaded twice during the plugin infrastructure's unit tests, causing plugin panels to be added multiple times to their dashboards. Fix that by removing the second, unnecessary call. Also create a second test plugin panel group and panel to test the scenarios described in the two bugs addressed here, adding two panel groups at a time. Change-Id: Id6a99c3ff18102c8f47431638d4dda98f14ec641 Closes-Bug: 1378558
79 lines
3.2 KiB
Python
79 lines
3.2 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import copy
|
|
|
|
from django.conf import settings
|
|
from django.test.utils import override_settings
|
|
|
|
import horizon
|
|
|
|
from openstack_dashboard.test import helpers as test
|
|
from openstack_dashboard.test.test_panels.plugin_panel \
|
|
import panel as plugin_panel
|
|
from openstack_dashboard.test.test_panels.second_panel \
|
|
import panel as second_panel
|
|
import openstack_dashboard.test.test_plugins.panel_group_config
|
|
from openstack_dashboard.utils import settings as util_settings
|
|
|
|
|
|
PANEL_GROUP_SLUG = 'plugin_panel_group'
|
|
SECOND_PANEL_GROUP_SLUG = 'second_panel_group'
|
|
HORIZON_CONFIG = copy.deepcopy(settings.HORIZON_CONFIG)
|
|
INSTALLED_APPS = list(settings.INSTALLED_APPS)
|
|
|
|
# NOTE: Ensure dashboards and default_dashboard are not included in
|
|
# HORIZON_CONFIG to ensure warning messages from update_dashboards below.
|
|
HORIZON_CONFIG.pop('dashboards', None)
|
|
HORIZON_CONFIG.pop('default_dashboard', None)
|
|
|
|
util_settings.update_dashboards([
|
|
openstack_dashboard.test.test_plugins.panel_group_config,
|
|
], HORIZON_CONFIG, INSTALLED_APPS)
|
|
|
|
|
|
@override_settings(HORIZON_CONFIG=HORIZON_CONFIG,
|
|
INSTALLED_APPS=INSTALLED_APPS)
|
|
class PanelGroupPluginTests(test.PluginTestCase):
|
|
def test_add_panel_group(self):
|
|
dashboard = horizon.get_dashboard("admin")
|
|
self.assertIsNotNone(dashboard.get_panel_group(PANEL_GROUP_SLUG))
|
|
|
|
def test_add_second_panel_group(self):
|
|
# Check that the second panel group was added to the dashboard.
|
|
dashboard = horizon.get_dashboard("admin")
|
|
self.assertIsNotNone(
|
|
dashboard.get_panel_group(SECOND_PANEL_GROUP_SLUG))
|
|
|
|
def test_add_panel(self):
|
|
# Check that the panel is in its configured dashboard and panel group.
|
|
dashboard = horizon.get_dashboard("admin")
|
|
panel_group = dashboard.get_panel_group(PANEL_GROUP_SLUG)
|
|
self.assertIn(plugin_panel.PluginPanel,
|
|
[p.__class__ for p in dashboard.get_panels()])
|
|
self.assertIn(plugin_panel.PluginPanel,
|
|
[p.__class__ for p in panel_group])
|
|
|
|
def test_add_second_panel(self):
|
|
# Check that the second panel is in its configured dashboard and panel
|
|
# group.
|
|
dashboard = horizon.get_dashboard("admin")
|
|
second_panel_group = dashboard.get_panel_group(SECOND_PANEL_GROUP_SLUG)
|
|
self.assertIn(second_panel.SecondPanel,
|
|
[p.__class__ for p in dashboard.get_panels()])
|
|
self.assertIn(second_panel.SecondPanel,
|
|
[p.__class__ for p in second_panel_group])
|
|
|
|
def test_unregistered_panel_group(self):
|
|
dashboard = horizon.get_dashboard("admin")
|
|
self.assertIsNone(dashboard.get_panel_group("nonexistent_panel"))
|