summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/common/test_policy.py
diff options
context:
space:
mode:
authorVasyl Saienko <vsaienko@mirantis.com>2016-10-03 10:44:08 +0300
committerVasyl Saienko <vsaienko@mirantis.com>2016-10-04 11:32:21 +0300
commitf17dd1febf974da47be39641e2f5c1b833e087f7 (patch)
tree44d13e19fb52c5d89668b011b9b97e7687446052 /ironic/tests/unit/common/test_policy.py
parent0e3b3e8671d9962c6f0a09b779b366ce408fe877 (diff)
downloadironic-f17dd1febf974da47be39641e2f5c1b833e087f7.tar.gz
Add entry_point for oslo policy scripts
There are two helper scripts in oslo.policy to help deployers understand their policy configuration better. With the setup.cfg entry these can be called directly from oslo.policy. Change-Id: Icfff952f0742b188968603cd3335a3ef50965337 Closes-Bug: #1625804
Diffstat (limited to 'ironic/tests/unit/common/test_policy.py')
-rw-r--r--ironic/tests/unit/common/test_policy.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/ironic/tests/unit/common/test_policy.py b/ironic/tests/unit/common/test_policy.py
index 97d337558..db0a3e437 100644
--- a/ironic/tests/unit/common/test_policy.py
+++ b/ironic/tests/unit/common/test_policy.py
@@ -15,6 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.
+import sys
+
+import mock
+from oslo_config import cfg
from oslo_policy import policy as oslo_policy
from ironic.common import exception
@@ -119,3 +123,34 @@ class PolicyTestCase(base.TestCase):
exception.IronicException,
policy.enforce, 'has_foo_role', creds, creds, True,
exception.IronicException)
+
+ @mock.patch.object(cfg, 'CONF', autospec=True)
+ @mock.patch.object(policy, 'get_enforcer', autospec=True)
+ def test_get_oslo_policy_enforcer_no_args(self, mock_gpe, mock_cfg):
+ mock_gpe.return_value = mock.Mock()
+ args = []
+ with mock.patch.object(sys, 'argv', args):
+ policy.get_oslo_policy_enforcer()
+ mock_cfg.assert_called_once_with([], project='ironic')
+ self.assertEqual(1, mock_gpe.call_count)
+
+ @mock.patch.object(cfg, 'CONF', autospec=True)
+ @mock.patch.object(policy, 'get_enforcer', autospec=True)
+ def test_get_oslo_policy_enforcer_namespace(self, mock_gpe, mock_cfg):
+ mock_gpe.return_value = mock.Mock()
+ args = ['opg', '--namespace', 'ironic']
+ with mock.patch.object(sys, 'argv', args):
+ policy.get_oslo_policy_enforcer()
+ mock_cfg.assert_called_once_with([], project='ironic')
+ self.assertEqual(1, mock_gpe.call_count)
+
+ @mock.patch.object(cfg, 'CONF', autospec=True)
+ @mock.patch.object(policy, 'get_enforcer', autospec=True)
+ def test_get_oslo_policy_enforcer_config_file(self, mock_gpe, mock_cfg):
+ mock_gpe.return_value = mock.Mock()
+ args = ['opg', '--namespace', 'ironic', '--config-file', 'my.cfg']
+ with mock.patch.object(sys, 'argv', args):
+ policy.get_oslo_policy_enforcer()
+ mock_cfg.assert_called_once_with(['--config-file', 'my.cfg'],
+ project='ironic')
+ self.assertEqual(1, mock_gpe.call_count)