From 48e19d9bbc4902e3c7a867f8a24cb57ec3447b88 Mon Sep 17 00:00:00 2001 From: Rob Raymond Date: Mon, 30 Jun 2014 11:04:59 -0600 Subject: [PATCH] Changes to work with api keystone. Changes for tests --- monitoring/alarms/panel.py | 1 - monitoring/api/monitor.py | 4 +- monitoring/notifications/panel.py | 1 - monitoring/test/helpers.py | 82 ++++++++++++++++++++ monitoring/test/settings.py | 2 +- monitoring/test/test_data/__init__.py | 0 monitoring/test/test_data/exceptions.py | 23 ++++++ monitoring/test/test_data/monitoring_data.py | 15 ++++ monitoring/test/test_data/utils.py | 43 ++++++++++ monitoring/test/urls.py | 27 +++++++ requirements.txt | 8 -- 11 files changed, 192 insertions(+), 14 deletions(-) create mode 100644 monitoring/test/helpers.py create mode 100644 monitoring/test/test_data/__init__.py create mode 100644 monitoring/test/test_data/exceptions.py create mode 100644 monitoring/test/test_data/monitoring_data.py create mode 100644 monitoring/test/test_data/utils.py create mode 100644 monitoring/test/urls.py diff --git a/monitoring/alarms/panel.py b/monitoring/alarms/panel.py index d7c61890..a7c42bc5 100644 --- a/monitoring/alarms/panel.py +++ b/monitoring/alarms/panel.py @@ -22,4 +22,3 @@ import horizon class Monitoring(horizon.Panel): name = _("Alarms") slug = 'alarms' - permissions = ('openstack.roles.admin', ) diff --git a/monitoring/api/monitor.py b/monitoring/api/monitor.py index 631a2ce6..addb5da9 100644 --- a/monitoring/api/monitor.py +++ b/monitoring/api/monitor.py @@ -34,12 +34,10 @@ def monclient(request, password=None): cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) endpoint = getattr(settings, 'MONITORING_ENDPOINT', 'http://192.168.10.4:8080/v2.0') - project_id = getattr(settings, 'MONITORING_PROJECT', - '82510970543135') LOG.debug('monclient connection created using token "%s" and url "%s"' % (request.user.token.id, endpoint)) kwargs = { - 'token': project_id, # workaround API should be request.user.token.id + 'token': request.user.token.id, 'insecure': insecure, 'ca_file': cacert, 'username': request.user.username, diff --git a/monitoring/notifications/panel.py b/monitoring/notifications/panel.py index 7b8aeee3..f46a2e46 100644 --- a/monitoring/notifications/panel.py +++ b/monitoring/notifications/panel.py @@ -22,4 +22,3 @@ import horizon class Notifications(horizon.Panel): name = _("Notifications") slug = 'notifications' - permissions = ('openstack.roles.admin', ) diff --git a/monitoring/test/helpers.py b/monitoring/test/helpers.py new file mode 100644 index 00000000..326b84b8 --- /dev/null +++ b/monitoring/test/helpers.py @@ -0,0 +1,82 @@ +# +# 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 os +import warnings + +from django.core.handlers import wsgi +from django.utils import unittest + +from monitoring.test.test_data import utils as test_data_utils +from openstack_dashboard.test import helpers as openstack_dashboard_helpers + + +# Makes output of failing mox tests much easier to read. +wsgi.WSGIRequest.__repr__ = lambda self: "" + +# Silences the warning about with statements. +warnings.filterwarnings('ignore', 'With-statements now directly support ' + 'multiple context managers', DeprecationWarning, + r'^tuskar_ui[.].*[._]tests$') + + +def create_stubs(stubs_to_create={}): + return openstack_dashboard_helpers.create_stubs(stubs_to_create) + + +@unittest.skipIf(os.environ.get('SKIP_UNITTESTS', False), + "The SKIP_UNITTESTS env variable is set.") +class TestCase(openstack_dashboard_helpers.TestCase): + """Specialized base test case class for Horizon which gives access to + numerous additional features: + + * A full suite of test data through various attached objects and + managers (e.g. ``self.servers``, ``self.user``, etc.). See the + docs for :class:`~horizon.tests.test_data.utils.TestData` for more + information. + * The ``mox`` mocking framework via ``self.mox``. + * A set of request context data via ``self.context``. + * A ``RequestFactory`` class which supports Django's ``contrib.messages`` + framework via ``self.factory``. + * A ready-to-go request object via ``self.request``. + * The ability to override specific time data controls for easier testing. + * Several handy additional assertion methods. + """ + def setUp(self): + super(TestCase, self).setUp() + + # load tuskar-specific test data + test_data_utils.load_test_data(self) + + +class BaseAdminViewTests(openstack_dashboard_helpers.BaseAdminViewTests): + """A ``TestCase`` subclass which sets an active user with the "admin" role + for testing admin-only views and functionality. + """ + def setUp(self): + super(BaseAdminViewTests, self).setUp() + + # load tuskar-specific test data + test_data_utils.load_test_data(self) + + +class APITestCase(openstack_dashboard_helpers.APITestCase): + """The ``APITestCase`` class is for use with tests which deal with the + underlying clients rather than stubbing out the + openstack_dashboard.api.* methods. + """ + def setUp(self): + super(APITestCase, self).setUp() + + # load tuskar-specfic test data + test_data_utils.load_test_data(self) diff --git a/monitoring/test/settings.py b/monitoring/test/settings.py index 1a55c55c..825bc418 100644 --- a/monitoring/test/settings.py +++ b/monitoring/test/settings.py @@ -32,7 +32,7 @@ STATIC_URL = '/static/' SECRET_KEY = secret_key_utils.generate_or_read_from_file( os.path.join(TEST_DIR, '.secret_key_store')) -ROOT_URLCONF = 'tuskar_ui.test.urls' +ROOT_URLCONF = 'monitoring.test.urls' TEMPLATE_DIRS = ( os.path.join(TEST_DIR, 'templates'), ) diff --git a/monitoring/test/test_data/__init__.py b/monitoring/test/test_data/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/monitoring/test/test_data/exceptions.py b/monitoring/test/test_data/exceptions.py new file mode 100644 index 00000000..ae562d6f --- /dev/null +++ b/monitoring/test/test_data/exceptions.py @@ -0,0 +1,23 @@ +# +# 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. + +from monclient.openstack.common.apiclient import exceptions as monclient +from openstack_dashboard.test.test_data import exceptions + + +def data(TEST): + TEST.exceptions = exceptions.data + + monitoring_exception = monclient.ClientException + TEST.exceptions.monitoring = exceptions.create_stubbed_exception( + monitoring_exception) diff --git a/monitoring/test/test_data/monitoring_data.py b/monitoring/test/test_data/monitoring_data.py new file mode 100644 index 00000000..551a171d --- /dev/null +++ b/monitoring/test/test_data/monitoring_data.py @@ -0,0 +1,15 @@ +# 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. + + +def data(TEST): + pass diff --git a/monitoring/test/test_data/utils.py b/monitoring/test/test_data/utils.py new file mode 100644 index 00000000..7e3671f8 --- /dev/null +++ b/monitoring/test/test_data/utils.py @@ -0,0 +1,43 @@ +# +# 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. + +from openstack_dashboard.test.test_data import utils + + +def load_test_data(load_onto=None): + from monitoring.test.test_data import exceptions + from monitoring.test.test_data import monitoring_data + from openstack_dashboard.test.test_data import cinder_data + from openstack_dashboard.test.test_data import glance_data + from openstack_dashboard.test.test_data import heat_data + from openstack_dashboard.test.test_data import keystone_data + from openstack_dashboard.test.test_data import neutron_data + from openstack_dashboard.test.test_data import nova_data + from openstack_dashboard.test.test_data import swift_data + + # The order of these loaders matters, some depend on others. + loaders = (exceptions.data, + keystone_data.data, + glance_data.data, + nova_data.data, + cinder_data.data, + neutron_data.data, + swift_data.data, + heat_data.data, + monitoring_data.data) + if load_onto: + for data_func in loaders: + data_func(load_onto) + return load_onto + else: + return utils.TestData(*loaders) diff --git a/monitoring/test/urls.py b/monitoring/test/urls.py new file mode 100644 index 00000000..4e6e290f --- /dev/null +++ b/monitoring/test/urls.py @@ -0,0 +1,27 @@ +# +# 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. + +from django.conf import urls +from django.views import generic + +import openstack_dashboard.urls + +urlpatterns = urls.patterns( + '', + urls.url( + r'^qunit_tuskar', + generic.TemplateView.as_view( + template_name="infrastructure/qunit.html"), + name='qunit_tests'), + urls.url(r'', urls.include(openstack_dashboard.urls)) +) diff --git a/requirements.txt b/requirements.txt index c2588d72..e699e990 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,14 +7,6 @@ eventlet>=0.13.0 kombu>=2.4.8 iso8601>=0.1.8 netaddr>=0.7.6 -python-cinderclient>=1.0.6 -python-glanceclient>=0.9.0 -python-heatclient>=0.2.3 -python-keystoneclient>=0.4.1 -python-novaclient>=2.15.0 -python-neutronclient>=2.3.0,<3 -python-swiftclient>=1.5 -python-ceilometerclient>=1.0.6 pytz>=2010h # Horizon Utility Requirements # for SECURE_KEY generation