Skip to content

Commit 4491b47

Browse files
author
Tomasz Trębski
committed
Add monitoring_policy.json
monasca-ui misses policies file to control the permissions over actions executed from within Horizon plugin. Extra: * enabled running tests with configured policies * removed unbounded policy sample file (cherry picked from commmit a7e8a14) Change-Id: I273f06332fa11a81ea8de2c13059dce9d160e90d
1 parent bdb475d commit 4491b47

7 files changed

Lines changed: 60 additions & 60 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ For more details go to http://docs.openstack.org/developer/horizon/quickstart.ht
5353
* Link monasca into Horizon:
5454

5555
```
56-
cp ../monasca-ui/monitoring/enabled/_50_admin_add_monitoring_panel.py openstack_dashboard/enabled/.
57-
ln -s ../monasca-ui/monitoring monitoring
56+
ln -sf $(pwd)/../monasca-ui/monitoring/enabled/_50_admin_add_monitoring_panel.py \
57+
$(pwd)/openstack_dashboard/enabled/_50_admin_add_monitoring_panel.py
58+
ln -sf $(pwd)/../monasca-ui/monitoring/conf/monitoring_policy.json \
59+
$(pwd)/openstack_dashboard/conf/monitoring_policy.json
60+
ln -sfF $(pwd)/../monasca-ui/monitoring $(pwd)/monitoring
5861
./run_tests #load monasca-client into virtualenv
5962
```
6063

@@ -86,7 +89,7 @@ you may not use this file except in compliance with the License.
8689
You may obtain a copy of the License at
8790

8891
http://www.apache.org/licenses/LICENSE-2.0
89-
92+
9093
Unless required by applicable law or agreed to in writing, software
9194
distributed under the License is distributed on an "AS IS" BASIS,
9295
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or

monasca_policy.json.sample

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"owner" : "user_id:%(user_id)s",
3+
"admin_required": "role:admin or is_admin:1",
4+
"admin_or_owner": "rule:admin_required or rule:owner",
5+
6+
"monasca_user_role": "role:monasca-user",
7+
8+
"default": "@",
9+
10+
"monitoring:monitoring": "rule:admin_or_owner",
11+
"monitoring:kibana_access": "rule:monasca_user_role"
12+
}

monitoring/config/local_settings.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@
6767
GRAFANA_URL = getattr(settings, 'GRAFANA_URL', None)
6868

6969
ENABLE_KIBANA_BUTTON = getattr(settings, 'ENABLE_KIBANA_BUTTON', False)
70-
KIBANA_POLICY_RULE = getattr(settings, 'KIBANA_POLICY_RULE', 'admin_required')
71-
KIBANA_POLICY_SCOPE = getattr(settings, 'KIBANA_POLICY_SCOPE', 'identity')
70+
KIBANA_POLICY_RULE = getattr(settings, 'KIBANA_POLICY_RULE',
71+
'monitoring:kibana_access')
72+
KIBANA_POLICY_SCOPE = getattr(settings, 'KIBANA_POLICY_SCOPE',
73+
'monitoring')
7274
KIBANA_HOST = getattr(settings, 'KIBANA_HOST', 'http://192.168.10.4:5601/')
7375

7476
OPENSTACK_SSL_NO_VERIFY = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
7577
OPENSTACK_SSL_CACERT = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
78+
79+
POLICY_FILES = getattr(settings, 'POLICY_FILES', {})
80+
POLICY_FILES.update({'monitoring': 'monitoring_policy.json',}) # noqa
81+
setattr(settings, 'POLICY_FILES', POLICY_FILES)

monitoring/test/helpers.py

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
# under the License.
1313

1414
import os
15+
import unittest
1516
import warnings
1617

1718
from django.core.handlers import wsgi
18-
from django.utils import unittest
19+
import mock
20+
from openstack_dashboard.test import helpers
1921

2022
from monitoring.test.test_data import utils as test_data_utils
21-
from openstack_dashboard.test import helpers as openstack_dashboard_helpers
2223

2324

2425
# Makes output of failing mox tests much easier to read.
@@ -30,53 +31,30 @@
3031
r'^tuskar_ui[.].*[._]tests$')
3132

3233

33-
def create_stubs(stubs_to_create={}):
34-
return openstack_dashboard_helpers.create_stubs(stubs_to_create)
34+
def create_stubs(stubs_to_create=None):
35+
if stubs_to_create is None:
36+
stubs_to_create = {}
37+
return helpers.create_stubs(stubs_to_create)
3538

3639

37-
@unittest.skipIf(os.environ.get('SKIP_UNITTESTS', False),
38-
"The SKIP_UNITTESTS env variable is set.")
39-
class TestCase(openstack_dashboard_helpers.TestCase):
40-
"""Specialized base test case class for Horizon which gives access to
41-
numerous additional features:
42-
43-
* A full suite of test data through various attached objects and
44-
managers (e.g. ``self.servers``, ``self.user``, etc.). See the
45-
docs for :class:`~horizon.tests.test_data.utils.TestData` for more
46-
information.
47-
* The ``mox`` mocking framework via ``self.mox``.
48-
* A set of request context data via ``self.context``.
49-
* A ``RequestFactory`` class which supports Django's ``contrib.messages``
50-
framework via ``self.factory``.
51-
* A ready-to-go request object via ``self.request``.
52-
* The ability to override specific time data controls for easier testing.
53-
* Several handy additional assertion methods.
54-
"""
55-
def setUp(self):
56-
super(TestCase, self).setUp()
57-
58-
# load tuskar-specific test data
40+
class MonitoringTestsMixin(object):
41+
def _setup_test_data(self):
42+
super(MonitoringTestsMixin, self)._setup_test_data()
5943
test_data_utils.load_test_data(self)
44+
self.policy_patcher = mock.patch(
45+
'openstack_auth.policy.check', lambda action, request: True)
46+
self.policy_check = self.policy_patcher.start()
6047

6148

62-
class BaseAdminViewTests(openstack_dashboard_helpers.BaseAdminViewTests):
63-
"""A ``TestCase`` subclass which sets an active user with the "admin" role
64-
for testing admin-only views and functionality.
65-
"""
66-
def setUp(self):
67-
super(BaseAdminViewTests, self).setUp()
49+
@unittest.skipIf(os.environ.get('SKIP_UNITTESTS', False),
50+
"The SKIP_UNITTESTS env variable is set.")
51+
class TestCase(MonitoringTestsMixin, helpers.TestCase):
52+
pass
6853

69-
# load tuskar-specific test data
70-
test_data_utils.load_test_data(self)
7154

55+
class BaseAdminViewTests(MonitoringTestsMixin, helpers.BaseAdminViewTests):
56+
pass
7257

73-
class APITestCase(openstack_dashboard_helpers.APITestCase):
74-
"""The ``APITestCase`` class is for use with tests which deal with the
75-
underlying clients rather than stubbing out the
76-
openstack_dashboard.api.* methods.
77-
"""
78-
def setUp(self):
79-
super(APITestCase, self).setUp()
8058

81-
# load tuskar-specfic test data
82-
test_data_utils.load_test_data(self)
59+
class APITestCase(MonitoringTestsMixin, helpers.APITestCase):
60+
pass

test-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ selenium>=2.50.1 # Apache-2.0
1919
# Docs Requirements
2020
sphinx!=1.3b1,<1.4,>=1.2.1 # BSD
2121
oslosphinx>=4.7.0 # Apache-2.0
22-
http://tarballs.openstack.org/horizon/horizon-master.tar.gz#egg=horizon

tox.ini

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
envlist = py27,pep8
3-
minversion = 2.0
3+
minversion = 2.6
44
skipsdist = True
55

66
[testenv]
@@ -15,14 +15,23 @@ passenv = http_proxy
1515
HTTPS_PROXY
1616
no_proxy
1717
NO_PROXY
18-
deps = -r{toxinidir}/test-requirements.txt
19-
-r{toxinidir}/requirements.txt
18+
deps =
19+
-r{toxinidir}/requirements.txt
20+
-r{toxinidir}/test-requirements.txt
21+
http://tarballs.openstack.org/horizon/horizon-stable-ocata.tar.gz#egg=horizon
2022
install_command = {toxinidir}/tools/tox_install.sh {env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/ocata} {opts} {packages}
21-
whitelist_externals = find
23+
whitelist_externals =
24+
/bin/bash
25+
find
2226
commands =
2327
find . -type f -name "*.pyc" -delete
2428
/bin/bash run_tests.sh -N {posargs}
2529

30+
[testenv:py27]
31+
setenv =
32+
{[testenv]setenv}
33+
DJANGO_SETTINGS_MODULE=monitoring.test.settings
34+
2635
[testenv:pep8]
2736
commands = /bin/bash run_tests.sh -N --pep8
2837

0 commit comments

Comments
 (0)